Baue die Verwaltung Kommunikation, die öffentliche Anfrageschnittstelle und das CMS-Widget Anfrage
Anliegen, Feldkatalog, Feldgruppen, Anfragevorlagen mit Fassungen, Anfrage-Einstiege, Posteingang mit Status und Notizen, Einstellungen mit Empfängern. Das Widget speichert nur die Kennung eines veröffentlichten Einstiegs; Formular, Bedingungen und Annahme kommen zur Laufzeit vom Server (Kompaktformular und mehrstufiger Dialog aus derselben Beschreibung). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2ee1fc9866
commit
c6a8167601
45 files changed
+5415
No files matched your search
@@ -0,0 +1,483 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Communication\CommunicationSettings;
|
||||
use App\Domain\Communication\ExampleConfiguration;
|
||||
use App\Domain\Communication\FormToken;
|
||||
use App\Domain\Communication\Inquiry;
|
||||
use App\Domain\Communication\InquiryEntry;
|
||||
use App\Domain\Communication\InquiryField;
|
||||
use App\Domain\Communication\InquiryFieldGroup;
|
||||
use App\Domain\Communication\InquiryIssue;
|
||||
use App\Domain\Communication\InquiryNote;
|
||||
use App\Domain\Communication\InquiryService;
|
||||
use App\Domain\Communication\InquiryStatus;
|
||||
use App\Domain\Communication\InquiryTemplate;
|
||||
use App\Filament\Pages\KommunikationEinstellungen;
|
||||
use App\Filament\Resources\Communication\Entries\Pages\EditInquiryEntry;
|
||||
use App\Filament\Resources\Communication\Entries\Pages\ListInquiryEntries;
|
||||
use App\Filament\Resources\Communication\Fields\Pages\EditInquiryField;
|
||||
use App\Filament\Resources\Communication\Fields\Pages\ListInquiryFields;
|
||||
use App\Filament\Resources\Communication\Groups\Pages\EditInquiryFieldGroup;
|
||||
use App\Filament\Resources\Communication\Groups\Pages\ListInquiryFieldGroups;
|
||||
use App\Filament\Resources\Communication\Inquiries\Pages\ListInquiries;
|
||||
use App\Filament\Resources\Communication\Inquiries\Pages\ViewInquiry;
|
||||
use App\Filament\Resources\Communication\Issues\Pages\ListInquiryIssues;
|
||||
use App\Filament\Resources\Communication\Templates\Pages\EditInquiryTemplate;
|
||||
use App\Filament\Resources\Communication\Templates\Pages\ListInquiryTemplates;
|
||||
use App\Filament\Resources\Communication\Templates\RelationManagers\VersionsRelationManager;
|
||||
use App\Mail\CommunicationTestMail;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CommunicationAdminTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private function staff(string $role): User
|
||||
{
|
||||
$user = User::factory()->{$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');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,243 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Cms\Page;
|
||||
use App\Domain\Cms\PageService;
|
||||
use App\Domain\Cms\Widgets\WidgetRegistry;
|
||||
use App\Domain\Communication\ExampleConfiguration;
|
||||
use App\Domain\Communication\Inquiry;
|
||||
use App\Domain\Communication\InquiryEntry;
|
||||
use App\Domain\Communication\InquiryTemplate;
|
||||
use App\Domain\Communication\Publisher;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CommunicationPublicTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
config(['communication.min_fill_seconds' => 0]);
|
||||
app(ExampleConfiguration::class)->install();
|
||||
}
|
||||
|
||||
private function entry(string $key): InquiryEntry
|
||||
{
|
||||
return InquiryEntry::query()->where('key', $key)->firstOrFail();
|
||||
}
|
||||
|
||||
private function pageWith(string $path, ?InquiryEntry $entry, string $anchor = 'anfrage'): Page
|
||||
{
|
||||
$page = Page::query()->create(['path' => $path]);
|
||||
$revision = app(PageService::class)->saveRevision($page, [[
|
||||
'name' => 'Anfrage', 'anchor' => $anchor, 'layout' => 'u4',
|
||||
'slots' => [['type' => 'inquiry', 'v' => 1, 'variant' => 'standard', 'data' => [], 'refs' => ['entry' => $entry?->id]]],
|
||||
]], null, null, null);
|
||||
app(PageService::class)->publish($page, $revision);
|
||||
|
||||
return $page->fresh();
|
||||
}
|
||||
|
||||
public function test_the_definition_contains_the_form_a_token_and_the_first_state_but_no_rules(): void
|
||||
{
|
||||
$entry = $this->entry('schul_ag');
|
||||
|
||||
$response = $this->getJson(route('inquiry.definition', $entry))->assertOk();
|
||||
$response->assertHeader('Cache-Control');
|
||||
|
||||
$json = $response->json();
|
||||
$this->assertSame('wizard', $json['mode']);
|
||||
$this->assertSame('Schul-AG anfragen', $json['texts']['heading']);
|
||||
$this->assertSame('schul_ag', $json['defaults']['kursformat']);
|
||||
$this->assertNotEmpty($json['token']);
|
||||
$this->assertNotEmpty($json['csrf']);
|
||||
$this->assertArrayNotHasKey('rules', $json);
|
||||
$this->assertArrayNotHasKey('purpose', $json['fields']['email']);
|
||||
}
|
||||
|
||||
public function test_the_first_state_follows_the_preselection(): void
|
||||
{
|
||||
$json = $this->getJson(route('inquiry.definition', $this->entry('schul_ag')))->json();
|
||||
|
||||
$this->assertTrue($json['state']['steps']['skurs2']);
|
||||
$this->assertTrue($json['state']['groups']['schul_ag']);
|
||||
$this->assertSame('kursvorhaben', $json['state']['subissue']);
|
||||
}
|
||||
|
||||
public function test_an_unpublished_or_archived_entry_is_not_delivered(): void
|
||||
{
|
||||
$entry = $this->entry('kooperation');
|
||||
app(Publisher::class)->withdrawEntry($entry);
|
||||
|
||||
$this->getJson(route('inquiry.definition', $entry))->assertNotFound();
|
||||
$this->postJson(route('inquiry.state', $entry), ['values' => []])->assertNotFound();
|
||||
$this->postJson(route('inquiry.submit', $entry), ['values' => [], 'token' => 'x'])->assertStatus(419);
|
||||
}
|
||||
|
||||
public function test_the_server_decides_which_fields_are_visible(): void
|
||||
{
|
||||
$entry = $this->entry('kurse_workshops');
|
||||
|
||||
$this->postJson(route('inquiry.state', $entry), ['values' => ['anliegen' => 'kurse', 'unteranliegen' => 'kursinfo']])
|
||||
->assertOk()
|
||||
->assertJsonPath('steps.skurs2', false)
|
||||
->assertJsonPath('fields.region', true)
|
||||
->assertJsonPath('fields.einrichtung_name', false);
|
||||
|
||||
$this->postJson(route('inquiry.state', $entry), ['values' => ['anliegen' => 'kurse', 'unteranliegen' => 'kursvorhaben', 'kursformat' => 'schul_ag', 'ort_abweichend' => 'ja']])
|
||||
->assertOk()
|
||||
->assertJsonPath('groups.schul_ag', true)
|
||||
->assertJsonPath('groups.ort_angaben', true)
|
||||
->assertJsonPath('required.laufzeit', true);
|
||||
|
||||
$this->postJson(route('inquiry.state', $entry), ['values' => 'kaputt'])->assertStatus(422);
|
||||
}
|
||||
|
||||
public function test_a_visitor_sends_an_inquiry_without_an_account(): void
|
||||
{
|
||||
$entry = $this->entry('allgemeiner_kontakt');
|
||||
$token = $this->getJson(route('inquiry.definition', $entry))->json('token');
|
||||
|
||||
$this->postJson(route('inquiry.submit', $entry), [
|
||||
'token' => $token,
|
||||
'source' => '/kontakt',
|
||||
'values' => ['name' => 'Mira Beispiel', 'email' => 'mira@example.org', 'nachricht' => 'Hallo zusammen'],
|
||||
])->assertCreated()->assertJsonStructure(['reference']);
|
||||
|
||||
$inquiry = Inquiry::query()->firstOrFail();
|
||||
$this->assertSame('/kontakt', $inquiry->source_path);
|
||||
$this->assertSame('Mira Beispiel', $inquiry->contact_name);
|
||||
$this->assertNull(Inquiry::query()->first()->templateVersion->published_by);
|
||||
}
|
||||
|
||||
public function test_validation_errors_name_the_fields_and_keep_the_inquiry_out_of_the_database(): void
|
||||
{
|
||||
$entry = $this->entry('allgemeiner_kontakt');
|
||||
$token = $this->getJson(route('inquiry.definition', $entry))->json('token');
|
||||
|
||||
$this->postJson(route('inquiry.submit', $entry), ['token' => $token, 'values' => ['name' => 'Mira', 'email' => 'falsch']])
|
||||
->assertStatus(422)
|
||||
->assertJsonPath('fields.email', 'Bitte geben Sie eine gültige E-Mail-Adresse ein.')
|
||||
->assertJsonPath('fields.nachricht', 'Bitte füllen Sie dieses Feld aus.');
|
||||
|
||||
$this->assertSame(0, Inquiry::query()->count());
|
||||
}
|
||||
|
||||
public function test_submissions_are_rate_limited_per_address(): void
|
||||
{
|
||||
RateLimiter::clear('inq-m|127.0.0.1');
|
||||
$entry = $this->entry('allgemeiner_kontakt');
|
||||
$token = $this->getJson(route('inquiry.definition', $entry))->json('token');
|
||||
$values = ['values' => ['name' => 'M', 'email' => 'x', 'nachricht' => 'y'], 'token' => $token];
|
||||
|
||||
$statuses = [];
|
||||
for ($i = 0; $i < 7; $i++) {
|
||||
$statuses[] = $this->postJson(route('inquiry.submit', $entry), $values)->status();
|
||||
}
|
||||
|
||||
$this->assertContains(429, $statuses);
|
||||
$this->assertSame(422, $statuses[0]);
|
||||
}
|
||||
|
||||
public function test_the_widget_mounts_a_published_entry_on_two_pages_without_any_form_content(): void
|
||||
{
|
||||
$entry = $this->entry('allgemeiner_kontakt');
|
||||
$this->pageWith('/kontakt', $entry);
|
||||
$this->pageWith('/hilfe', $entry);
|
||||
|
||||
foreach (['/kontakt', '/hilfe'] as $path) {
|
||||
$html = $this->get($path)->assertOk()
|
||||
->assertSee('data-inquiry', false)
|
||||
->assertSee('data-definition-url="'.route('inquiry.definition', $entry).'"', false)
|
||||
->assertSee('id="anfrage"', false)
|
||||
->getContent();
|
||||
|
||||
// Nichts aus der Konfiguration steht in der gespeicherten Seite.
|
||||
$this->assertStringNotContainsString('Schreiben Sie uns', $html);
|
||||
$this->assertStringNotContainsString('nachricht', $html);
|
||||
}
|
||||
|
||||
// Die Revision enthält nur die Kennung.
|
||||
$blocks = Page::query()->where('path', '/kontakt')->firstOrFail()->publishedRevision->blocks;
|
||||
$this->assertSame(['entry' => $entry->id], $blocks[0]['refs']);
|
||||
$this->assertSame([], $blocks[0]['data']);
|
||||
}
|
||||
|
||||
public function test_a_central_change_reaches_every_page_without_touching_the_pages(): void
|
||||
{
|
||||
$entry = $this->entry('allgemeiner_kontakt');
|
||||
$this->pageWith('/kontakt', $entry);
|
||||
$revisionId = Page::query()->where('path', '/kontakt')->value('published_revision_id');
|
||||
|
||||
$template = $entry->template;
|
||||
$draft = $template->draft;
|
||||
$draft['texts']['heading'] = 'Neue zentrale Überschrift';
|
||||
$template->update(['draft' => $draft]);
|
||||
|
||||
$this->getJson(route('inquiry.definition', $entry))->assertJsonPath('texts.heading', 'Schreiben Sie uns');
|
||||
|
||||
app(Publisher::class)->publishTemplate($template);
|
||||
|
||||
$this->getJson(route('inquiry.definition', $entry))->assertJsonPath('texts.heading', 'Neue zentrale Überschrift');
|
||||
$this->assertSame($revisionId, Page::query()->where('path', '/kontakt')->value('published_revision_id'), 'Die Seite bleibt unverändert.');
|
||||
}
|
||||
|
||||
public function test_a_withdrawn_entry_leaves_the_page_valid_and_the_public_view_empty(): void
|
||||
{
|
||||
$entry = $this->entry('kooperation');
|
||||
$this->pageWith('/partner', $entry);
|
||||
app(Publisher::class)->withdrawEntry($entry);
|
||||
|
||||
$this->get('/partner')->assertOk()->assertDontSee('data-inquiry', false);
|
||||
}
|
||||
|
||||
public function test_the_page_editor_rejects_an_unpublished_entry_and_accepts_a_published_one(): void
|
||||
{
|
||||
$page = Page::query()->create(['path' => '/neu']);
|
||||
$draft = new InquiryEntry(['key' => 'entwurf', 'name' => 'Entwurf', 'template_id' => InquiryTemplate::query()->first()->id, 'config' => InquiryEntry::emptyConfig()]);
|
||||
$draft->save();
|
||||
|
||||
$widget = fn (int $id): array => [['layout' => 'u4', 'slots' => [['type' => 'inquiry', 'v' => 1, 'variant' => 'standard', 'data' => [], 'refs' => ['entry' => $id]]]]];
|
||||
|
||||
try {
|
||||
app(PageService::class)->saveRevision($page, $widget($draft->id), null, null, null);
|
||||
$this->fail('Erwartet: unveröffentlichter Einstieg abgelehnt.');
|
||||
} catch (ValidationException $e) {
|
||||
$this->assertNotEmpty($e->errors());
|
||||
}
|
||||
|
||||
$this->assertNotNull(app(PageService::class)->saveRevision($page, $widget($this->entry('kooperation')->id), null, null, null));
|
||||
}
|
||||
|
||||
public function test_the_widget_offers_nothing_but_the_entry_choice_in_the_cms(): void
|
||||
{
|
||||
$type = app(WidgetRegistry::class)->get('inquiry');
|
||||
|
||||
$this->assertSame([], $type->dataRules());
|
||||
$this->assertSame([], $type->dataFields());
|
||||
$this->assertSame(['entry'], array_keys($type->refRules()));
|
||||
$this->assertSame([], $type->settings());
|
||||
}
|
||||
|
||||
public function test_the_preview_of_a_page_shows_a_note_for_an_unpublished_entry(): void
|
||||
{
|
||||
$entry = $this->entry('kooperation');
|
||||
$page = $this->pageWith('/partner', $entry);
|
||||
app(Publisher::class)->withdrawEntry($entry);
|
||||
|
||||
$editor = User::factory()->redakteur()->create();
|
||||
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
|
||||
$this->actingAs($editor, 'staff')
|
||||
->get(route('pages.preview', $page->publishedRevision))
|
||||
->assertOk()
|
||||
->assertSee('nicht veröffentlicht', false);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user