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,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