{$role}()->create(); $user->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP'); return $user; } private function inquiry(): Inquiry { config(['communication.min_fill_seconds' => 0]); $entry = InquiryEntry::query()->where('key', 'kurse_workshops')->firstOrFail(); app(InquiryService::class)->submit($entry, [ 'token' => FormToken::issue($entry->id, $entry->template->published_version_id), 'source' => '/kurse', 'values' => [ 'anliegen' => 'kurse', 'unteranliegen' => 'kursinfo', 'kursformat' => 'schul_ag', 'region' => 'Hannover', 'vorname' => 'Mira', 'nachname' => 'Beispiel', 'email' => 'mira@example.org', 'nachricht' => 'Bitte um Rückruf.', ], ]); return Inquiry::query()->firstOrFail(); } public function test_the_issue_list_opens_for_the_editor_and_shows_the_hierarchy(): void { app(ExampleConfiguration::class)->install(); $this->actingAs($this->staff('redakteur'), 'staff') ->get('/verwaltung/kommunikation/anliegen') ->assertOk() ->assertSee('Kurse & Workshops', false) ->assertSee('Konkretes Kursvorhaben'); } public function test_every_configuration_area_and_its_object_pages_open(): void { app(ExampleConfiguration::class)->install(); $editor = $this->staff('redakteur'); foreach ([ '/verwaltung/kommunikation/anliegen/'.InquiryIssue::query()->first()->id, '/verwaltung/kommunikation/felder', '/verwaltung/kommunikation/felder/'.InquiryField::query()->where('key', 'kursformat')->value('id'), '/verwaltung/kommunikation/feldgruppen', '/verwaltung/kommunikation/feldgruppen/'.InquiryFieldGroup::query()->first()->id, '/verwaltung/kommunikation/vorlagen', '/verwaltung/kommunikation/vorlagen/'.InquiryTemplate::query()->where('key', 'kursanfragen')->value('id'), '/verwaltung/kommunikation/einstiege', '/verwaltung/kommunikation/einstiege/'.InquiryEntry::query()->where('key', 'schul_ag')->value('id'), ] as $url) { $this->actingAs($editor, 'staff')->get($url)->assertOk(); } $this->actingAs($editor, 'staff')->get('/verwaltung/kommunikation/vorlagen/'.InquiryTemplate::query()->where('key', 'kursanfragen')->value('id')) ->assertSee('Kursanfragen') ->assertSee('Fassungen'); } public function test_customer_service_reads_inquiries_but_cannot_configure_and_editors_cannot_read_inquiries(): void { app(ExampleConfiguration::class)->install(); $inquiry = $this->inquiry(); $this->actingAs($this->staff('kundenbetreuung'), 'staff')->get('/verwaltung/kommunikation/vorlagen')->assertForbidden(); $this->actingAs($this->staff('kundenbetreuung'), 'staff')->get('/verwaltung/anfragen')->assertOk()->assertSee('Mira Beispiel'); $this->actingAs($this->staff('kundenbetreuung'), 'staff')->get('/verwaltung/anfragen/'.$inquiry->id)->assertOk(); // D10: Redaktion und Katalogverwaltung sehen keine personenbezogenen Anfragen. foreach (['redakteur', 'katalogverwalter'] as $role) { $this->actingAs($this->staff($role), 'staff')->get('/verwaltung/anfragen')->assertForbidden(); $this->actingAs($this->staff($role), 'staff')->get('/verwaltung/anfragen/'.$inquiry->id)->assertForbidden(); $this->actingAs($this->staff($role), 'staff')->get('/verwaltung/kommunikation/einstellungen')->assertForbidden(); } } public function test_guests_are_sent_to_the_login(): void { $this->get('/verwaltung/kommunikation/anliegen')->assertRedirect('/verwaltung/login'); $this->get('/verwaltung/anfragen')->assertRedirect('/verwaltung/login'); } public function test_the_inbox_shows_structured_answers_readably_and_the_source(): void { app(ExampleConfiguration::class)->install(); $inquiry = $this->inquiry(); $this->actingAs($this->staff('kundenbetreuung'), 'staff')->get('/verwaltung/anfragen/'.$inquiry->id) ->assertOk() ->assertSee('Welches Format interessiert Sie?') ->assertSee('Schul-AG') ->assertSee('Hannover') ->assertSee('Bitte um Rückruf.') ->assertSee('/kurse') ->assertSee('mira@example.org') ->assertSee('Kurse & Workshops › Allgemeine Kursinformation', false) ->assertSee('Fassung 1'); } public function test_status_and_notes_are_maintained_by_hand(): void { app(ExampleConfiguration::class)->install(); $inquiry = $this->inquiry(); $user = $this->staff('kundenbetreuung'); $this->assertSame(InquiryStatus::Neu, $inquiry->status); Livewire::actingAs($user, 'staff')->test(ViewInquiry::class, ['record' => $inquiry->id]) ->callAction('status', ['status' => 'in_bearbeitung']) ->assertHasNoActionErrors(); Livewire::actingAs($user, 'staff')->test(ViewInquiry::class, ['record' => $inquiry->id]) ->callAction('note', ['body' => 'Rückruf am Donnerstag vereinbart.']) ->assertHasNoActionErrors(); $this->assertSame(InquiryStatus::InBearbeitung, $inquiry->fresh()->status); $note = InquiryNote::query()->firstOrFail(); $this->assertSame('Rückruf am Donnerstag vereinbart.', $note->body); $this->assertSame($user->id, $note->user_id); $this->actingAs($user, 'staff')->get('/verwaltung/anfragen/'.$inquiry->id)->assertSee('Rückruf am Donnerstag vereinbart.'); } public function test_the_inbox_list_searches_filters_and_sorts(): void { app(ExampleConfiguration::class)->install(); $first = $this->inquiry(); $user = $this->staff('kundenbetreuung'); Livewire::actingAs($user, 'staff')->test(ListInquiries::class) ->assertSee('Mira Beispiel') ->set('suche', 'mira@example.org') ->assertSee('Mira Beispiel') ->set('suche', 'gibtsnicht') ->assertDontSee('Mira Beispiel') ->call('resetFilters') ->set('zustand', 'erledigt') ->assertDontSee('Mira Beispiel') ->set('zustand', 'neu') ->assertSee('Mira Beispiel') ->set('anliegen', 'kurse') ->assertSee('Mira Beispiel') ->set('anliegen', 'allgemein') ->assertDontSee('Mira Beispiel'); $this->assertSame($first->id, Inquiry::query()->firstOrFail()->id); } public function test_only_system_administration_may_delete_an_inquiry(): void { app(ExampleConfiguration::class)->install(); $inquiry = $this->inquiry(); Livewire::actingAs($this->staff('kundenbetreuung'), 'staff')->test(ViewInquiry::class, ['record' => $inquiry->id]) ->assertActionHidden('erase'); Livewire::actingAs($this->staff('systemverwalter'), 'staff')->test(ViewInquiry::class, ['record' => $inquiry->id]) ->callAction('erase'); $this->assertSame(0, Inquiry::query()->count()); } public function test_a_failed_notification_can_be_repeated_from_the_inbox(): void { app(ExampleConfiguration::class)->install(); $inquiry = $this->inquiry(); $this->assertStringContainsString('keine Empfänger', (string) $inquiry->notification_error); Mail::fake(); CommunicationSettings::current()->update(['recipients' => ['team@example.org']]); Livewire::actingAs($this->staff('kundenbetreuung'), 'staff')->test(ViewInquiry::class, ['record' => $inquiry->id]) ->callAction('resend'); $this->assertNotNull($inquiry->fresh()->notified_at); $this->assertNull($inquiry->fresh()->notification_error); } public function test_the_settings_save_recipients_and_send_a_test_message(): void { Mail::fake(); $user = $this->staff('kundenbetreuung'); Livewire::actingAs($user, 'staff')->test(KommunikationEinstellungen::class) ->fillForm(['recipients' => "team@example.org\n kein-mail"]) ->call('save') ->assertHasFormErrors(['recipients']); Livewire::actingAs($user, 'staff')->test(KommunikationEinstellungen::class) ->fillForm(['recipients' => "team@example.org\nbuero@example.org", 'retention_months' => 24]) ->call('save') ->assertHasNoFormErrors(); $settings = CommunicationSettings::current(); $this->assertSame(['team@example.org', 'buero@example.org'], $settings->recipientList()); $this->assertSame(24, $settings->retention_months); Livewire::actingAs($user, 'staff')->test(KommunikationEinstellungen::class)->callAction('test'); Mail::assertSent(CommunicationTestMail::class, fn ($mail): bool => $mail->hasTo('buero@example.org')); } public function test_the_example_configuration_is_created_on_request_and_only_in_an_empty_area(): void { $user = $this->staff('systemverwalter'); Livewire::actingAs($user, 'staff')->test(KommunikationEinstellungen::class)->callAction('example'); $this->assertSame(5, InquiryEntry::query()->live()->count()); Livewire::actingAs($user, 'staff')->test(KommunikationEinstellungen::class)->assertActionHidden('example'); } public function test_an_issue_can_be_created_with_a_sub_issue_and_stays_unique(): void { $editor = $this->staff('redakteur'); Livewire::actingAs($editor, 'staff')->test(ListInquiryIssues::class) ->callAction('create', ['label' => 'Fördermittel', 'parent_id' => null]) ->assertHasNoActionErrors(); $parent = InquiryIssue::query()->where('label', 'Fördermittel')->firstOrFail(); Livewire::actingAs($editor, 'staff')->test(ListInquiryIssues::class) ->callAction('create', ['label' => 'Fördermittel', 'parent_id' => $parent->id]); $keys = InquiryIssue::query()->pluck('key')->all(); $this->assertSame(['foerdermittel', 'foerdermittel_2'], $keys); $this->assertSame($parent->id, InquiryIssue::query()->where('key', 'foerdermittel_2')->value('parent_id')); } public function test_a_choice_field_is_created_with_stable_option_keys_that_survive_renaming(): void { $editor = $this->staff('redakteur'); Livewire::actingAs($editor, 'staff')->test(ListInquiryFields::class) ->callAction('create', ['name' => 'Einrichtungstyp', 'label' => 'Einrichtungstyp', 'type' => 'select', 'options' => [['label' => 'Grundschule'], ['label' => 'Verein']]]) ->assertHasNoActionErrors(); $field = InquiryField::query()->where('key', 'einrichtungstyp')->firstOrFail(); $this->assertSame([['key' => 'grundschule', 'label' => 'Grundschule'], ['key' => 'verein', 'label' => 'Verein']], $field->optionList()); Livewire::actingAs($editor, 'staff')->test(EditInquiryField::class, ['record' => $field->id]) ->fillForm(['options' => [['key' => 'grundschule', 'label' => 'Primarschule'], ['key' => 'verein', 'label' => 'Verein'], ['label' => 'Sonstiges']]]) ->call('save') ->assertHasNoFormErrors(); $this->assertSame( [['key' => 'grundschule', 'label' => 'Primarschule'], ['key' => 'verein', 'label' => 'Verein'], ['key' => 'sonstiges', 'label' => 'Sonstiges']], $field->fresh()->optionList(), ); } public function test_a_purpose_must_fit_the_field_type(): void { $editor = $this->staff('redakteur'); Livewire::actingAs($editor, 'staff')->test(ListInquiryFields::class)->callAction('create', ['name' => 'Zahl', 'label' => 'Zahl', 'type' => 'number']); $field = InquiryField::query()->firstOrFail(); Livewire::actingAs($editor, 'staff')->test(EditInquiryField::class, ['record' => $field->id]) ->fillForm(['purpose' => 'email']) ->call('save') ->assertHasFormErrors(['purpose']); } public function test_a_field_group_keeps_the_chosen_order(): void { app(ExampleConfiguration::class)->install(); $editor = $this->staff('redakteur'); Livewire::actingAs($editor, 'staff')->test(ListInquiryFieldGroups::class)->callAction('create', ['name' => 'Neue Gruppe']); $group = InquiryFieldGroup::query()->where('key', 'neue_gruppe')->firstOrFail(); Livewire::actingAs($editor, 'staff')->test(EditInquiryFieldGroup::class, ['record' => $group->id]) ->fillForm(['items' => [['field' => 'email', 'required' => true], ['field' => 'telefon', 'required' => false]]]) ->call('save') ->assertHasNoFormErrors(); $this->assertSame(['email', 'telefon'], array_column($group->fresh()->itemList(), 'field')); } public function test_a_template_is_edited_checked_published_and_restored_through_the_interface(): void { app(ExampleConfiguration::class)->install(); $editor = $this->staff('redakteur'); $template = InquiryTemplate::query()->where('key', 'allgemein')->firstOrFail(); $firstVersion = $template->published_version_id; $component = Livewire::actingAs($editor, 'staff')->test(EditInquiryTemplate::class, ['record' => $template->id]); $component->fillForm(['draft.texts.heading' => 'Anders überschrieben'])->call('save')->assertHasNoFormErrors(); $this->assertSame('Anders überschrieben', $template->fresh()->draft['texts']['heading']); $this->assertTrue($template->fresh()->hasUnpublishedChanges()); $component->callAction('check')->assertNotified(); $component->callAction('publish', ['note' => 'Neue Überschrift'])->assertHasNoActionErrors(); $template->refresh(); $this->assertNotSame($firstVersion, $template->published_version_id); $this->assertSame('Neue Überschrift', $template->publishedVersion->note); $this->assertSame($editor->id, $template->publishedVersion->published_by); $this->assertSame('Anders überschrieben', $template->publishedVersion->definition['texts']['heading']); // Rückkehr zur ersten Fassung über die Fassungsliste. $old = $template->versions()->where('version', 1)->firstOrFail(); Livewire::actingAs($editor, 'staff')->test(VersionsRelationManager::class, ['ownerRecord' => $template, 'pageClass' => EditInquiryTemplate::class]) ->callTableAction('restore', $old); $this->assertSame($old->id, $template->fresh()->published_version_id); } public function test_the_template_editor_keeps_steps_items_and_rules_as_clean_lists(): void { app(ExampleConfiguration::class)->install(); $editor = $this->staff('redakteur'); $template = InquiryTemplate::query()->where('key', 'kursanfragen')->firstOrFail(); $before = $template->draft; Livewire::actingAs($editor, 'staff')->test(EditInquiryTemplate::class, ['record' => $template->id]) ->call('save') ->assertHasNoFormErrors(); $after = $template->fresh()->draft; $this->assertTrue(array_is_list($after['steps'])); $this->assertTrue(array_is_list($after['steps'][1]['items'])); $this->assertTrue(array_is_list($after['rules'])); $this->assertSame(count($before['rules']), count($after['rules'])); $this->assertSame($before['steps'][1]['items'], $after['steps'][1]['items']); $this->assertFalse($template->fresh()->hasUnpublishedChanges(), 'Speichern ohne Änderung erzeugt keine unveröffentlichten Änderungen.'); } public function test_an_entry_is_configured_checked_published_and_withdrawn(): void { app(ExampleConfiguration::class)->install(); $editor = $this->staff('redakteur'); $entry = InquiryEntry::query()->where('key', 'schul_ag')->firstOrFail(); $component = Livewire::actingAs($editor, 'staff')->test(EditInquiryEntry::class, ['record' => $entry->id]); $component->assertFormSet(['config.mode' => 'wizard']); $component->fillForm(['config.texts.heading' => 'Schul-AG: jetzt anfragen', 'config.preselect' => [['field' => 'kursformat', 'value' => 'vertiefung']]])->call('save'); $entry->refresh(); $this->assertSame('vertiefung', $entry->config['defaults']['kursformat']); $this->assertTrue($entry->hasUnpublishedChanges()); $this->assertSame('schul_ag', $entry->published_config['defaults']['kursformat'], 'Der veröffentlichte Stand ändert sich erst mit „Veröffentlichen“.'); $component->callAction('publish')->assertNotified(); $this->assertSame('vertiefung', $entry->fresh()->published_config['defaults']['kursformat']); $component->callAction('withdraw'); $this->assertFalse($entry->fresh()->isLive()); $this->assertNotNull($entry->fresh()->config); $component->callAction('publish'); $this->assertTrue($entry->fresh()->isLive()); } public function test_an_entry_cannot_be_published_with_a_value_the_template_does_not_know(): void { app(ExampleConfiguration::class)->install(); $editor = $this->staff('redakteur'); $entry = InquiryEntry::query()->where('key', 'schul_ag')->firstOrFail(); Livewire::actingAs($editor, 'staff')->test(EditInquiryEntry::class, ['record' => $entry->id]) ->fillForm(['config.preselect' => [['field' => 'kursformat', 'value' => 'gibt_es_nicht']]]) ->call('save') ->callAction('publish'); $this->assertSame('schul_ag', $entry->fresh()->published_config['defaults']['kursformat']); } public function test_templates_and_entries_can_be_archived_only_when_nothing_live_depends_on_them(): void { app(ExampleConfiguration::class)->install(); $editor = $this->staff('redakteur'); $template = InquiryTemplate::query()->where('key', 'kooperationsanfragen')->firstOrFail(); Livewire::actingAs($editor, 'staff')->test(EditInquiryTemplate::class, ['record' => $template->id])->callAction('archive'); $this->assertNull($template->fresh()->archived_at, 'Ein veröffentlichter Einstieg verwendet die Vorlage noch.'); $entry = InquiryEntry::query()->where('key', 'kooperation')->firstOrFail(); Livewire::actingAs($editor, 'staff')->test(EditInquiryEntry::class, ['record' => $entry->id])->callAction('archive'); $this->assertNotNull($entry->fresh()->archived_at); $this->assertFalse($entry->fresh()->isLive()); Livewire::actingAs($editor, 'staff')->test(EditInquiryTemplate::class, ['record' => $template->id])->callAction('archive'); $this->assertNotNull($template->fresh()->archived_at); } public function test_the_lists_search_and_filter_by_state(): void { app(ExampleConfiguration::class)->install(); $editor = $this->staff('redakteur'); Livewire::actingAs($editor, 'staff')->test(ListInquiryEntries::class) ->assertSee('Schul-AG') ->set('suche', 'Kooperation') ->assertSee('Kooperation') ->assertDontSee('Schul-AG') ->call('resetFilters') ->set('zustand', 'archiviert') ->assertDontSee('Schul-AG'); Livewire::actingAs($editor, 'staff')->test(ListInquiryTemplates::class) ->assertSee('Kursanfragen') ->assertSee('Fassung 1 gültig'); } public function test_the_preview_shows_the_form_for_the_editor_only(): void { app(ExampleConfiguration::class)->install(); $template = InquiryTemplate::query()->where('key', 'kursanfragen')->firstOrFail(); $entry = InquiryEntry::query()->where('key', 'schul_ag')->firstOrFail(); $editor = $this->staff('redakteur'); $this->actingAs($editor, 'staff')->get(route('communication.preview.template', $template))->assertOk()->assertSee('data-preview="1"', false); $this->actingAs($editor, 'staff')->get(route('communication.preview.template', ['template' => $template, 'modus' => 'wizard']))->assertOk()->assertSee('data-inquiry', false); $this->actingAs($editor, 'staff')->get(route('communication.preview.entry', $entry))->assertOk()->assertSee('data-preview="1"', false); $this->actingAs($editor, 'staff')->getJson(route('communication.preview.entry.definition', $entry))->assertOk()->assertJsonPath('mode', 'wizard'); $this->actingAs($editor, 'staff')->postJson(route('communication.preview.template.state', $template), ['values' => ['anliegen' => 'kurse', 'unteranliegen' => 'kursinfo']])->assertOk()->assertJsonPath('steps.skurs2', false); $this->actingAs($this->staff('kundenbetreuung'), 'staff')->get(route('communication.preview.template', $template))->assertForbidden(); } public function test_the_preview_is_closed_to_guests(): void { app(ExampleConfiguration::class)->install(); $template = InquiryTemplate::query()->where('key', 'kursanfragen')->firstOrFail(); $this->get(route('communication.preview.template', $template))->assertRedirect(); } public function test_the_preview_reports_configuration_problems_instead_of_a_broken_form(): void { app(ExampleConfiguration::class)->install(); $template = InquiryTemplate::query()->where('key', 'allgemein')->firstOrFail(); $draft = $template->draft; $draft['steps'][0]['items'] = [['kind' => 'issue']]; $template->update(['draft' => $draft]); $this->actingAs($this->staff('redakteur'), 'staff')->get(route('communication.preview.template', $template)) ->assertOk() ->assertSee('Die Vorschau ist nicht möglich') ->assertSee('E-Mail-Adresse für Rückfragen'); } }