Führe Abschnitte mit Raster, gemeinsames Designsystem und globales Website-Gerüst ein.
CI Feature / test (push) Failing after 20s

- Seite → Abschnitte → Plätze → Widgets: sechs Raster mit höchstens vier Einheiten,
  Hintergrund, Breite, Abstand und Trenner als Aufzählungswerte; je Platz ein Widget
  aus dem bestehenden Register. Neue Spalte page_revisions.sections (ergänzend);
  blocks erhält weiterhin alle Widgets in Lesereihenfolge als Rollback-Fassung.
- Widgets erhalten Mindest- und Vorzugsbreite; Darstellung über Container-Abfragen.
- Editor: Abschnitts-Repeater mit grafischer Rasterauswahl, Plätzen im Rasterverhältnis,
  breiter Arbeitsfläche, kompakten Vorschauen ohne Bildlaufleiste, Meldungen mit
  Abschnitt und Platz; Rasterwechsel entfernt nie ein Widget. Seite duplizieren.
- Designsystem: Marken- und Bedeutungs-Tokens (vorläufig), gemeinsame Grundkomponenten,
  Nunito/Source Sans 3 lokal; Mitgliederbereich nutzt dieselben Tokens und die Wortmarke.
- Kopfzeile, mobile Navigation, Untermenü (parent_id, ergänzend), Fußbereichsgruppen,
  vorbereiteter Warenkorbzugang (abgeschaltet). Öffentliche Seiten gleich für alle Besucher.
- cms:revert-published als Wiederherstellungsweg vor einem Code-Rollback.

Die Editor-Tests der ersten Iteration sind bewusst auf den neuen Formularzustand
(sections statt blocks) umgestellt; ihre Prüfungen gelten unverändert für die Widgets.
Der Vorschautest erwartet keine anmeldeabhängige Kopfzeile mehr (ADR-32).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-11-17 20:34:06 +01:00
1 parent db4bd30319
commit 480d55989b
57 files changed
+4730 -818

No files matched your search

+221 -42
View File
@@ -8,6 +8,7 @@
use App\Filament\Resources\NavigationItems\Pages\ManageNavigationItems;
use App\Filament\Resources\Pages\Pages\CreatePage;
use App\Filament\Resources\Pages\Pages\EditPage;
use App\Filament\Resources\Pages\Pages\ListPages;
use App\Filament\Support\WidgetEditor;
use App\Models\User;
use Filament\Actions\Testing\TestAction;
@@ -19,6 +20,11 @@
use Tests\Support\BuildsCatalog;
use Tests\TestCase;
/**
* Seiteneditor mit Abschnitten und Plätzen. Der Formularzustand ist seit dem Abschnittsraster
* {sections: {uuid: {id, layout, style, slots: {uuid: {widget: {uuid: Builder-Eintrag}}}}}}
* statt einer flachen Bausteinliste; die Prüfungen der ersten Iteration gelten unverändert für die Widgets darin.
*/
class CmsEditorTest extends TestCase
{
use BuildsCatalog;
@@ -31,35 +37,48 @@ protected function setUp(): void
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
}
public function test_editor_creates_a_page_from_registered_widgets_without_publishing_it(): void
public function test_editor_creates_a_page_with_sections_and_registered_widgets_without_publishing_it(): void
{
$program = $this->composition('Programm Abstand', 'programm');
$editor = $this->editor();
Livewire::actingAs($editor, 'staff')
Livewire::actingAs($this->editor(), 'staff')
->test(CreatePage::class)
->fillForm([
'path' => '/themen-test',
'seo_title' => 'Themenseite',
'blocks' => $this->keyed([
['type' => 'hero', 'data' => ['variant' => 'highlight', 'data' => ['heading' => 'Stark im Alltag', 'text' => 'Einstieg']]],
['type' => 'image_text', 'data' => ['variant' => 'image_right', 'data' => ['title' => 'Worum es geht', 'body' => '<p>Text mit <strong>Betonung</strong></p>'], 'refs' => []]],
['type' => 'cards', 'data' => ['variant' => 'compact', 'data' => ['items' => $this->keyed([['title' => 'Prävention', 'url' => '/praevention']])]]],
['type' => 'catalog_cards', 'data' => ['variant' => 'standard', 'data' => ['heading' => 'Programme'], 'refs' => ['items' => $this->keyed([['type' => 'composition', 'id' => $program->composition_id]])]]],
]),
'sections' => [
$this->sectionState('u4', [
['type' => 'hero', 'data' => ['variant' => 'highlight', 'data' => ['heading' => 'Stark im Alltag', 'text' => 'Einstieg']]],
], ['background' => 'dark', 'divider' => 'accent']),
$this->sectionState('u1_3', [
['type' => 'cards', 'data' => ['variant' => 'compact', 'data' => ['items' => $this->keyed([['title' => 'Prävention', 'url' => '/praevention']])]]],
['type' => 'image_text', 'data' => ['variant' => 'image_right', 'data' => ['title' => 'Worum es geht', 'body' => '<p>Text mit <strong>Betonung</strong></p>'], 'refs' => []]],
], ['width' => 'wide']),
$this->sectionState('u2_2', [
['type' => 'catalog_cards', 'data' => ['variant' => 'standard', 'data' => ['heading' => 'Programme'], 'refs' => ['items' => $this->keyed([['type' => 'composition', 'id' => $program->composition_id]])]]],
null,
]),
],
])
->call('create')
->assertHasNoFormErrors();
$page = Page::query()->where('path', '/themen-test')->firstOrFail();
$blocks = $page->latestRevision->blocks;
$revision = $page->latestRevision;
$sections = $revision->sections;
$blocks = $revision->blocks;
$this->assertNull($page->published_revision_id);
$this->assertSame(['hero', 'image_text', 'cards', 'catalog_cards'], array_column($blocks, 'type'));
$this->assertSame(['highlight', 'image_right', 'compact', 'standard'], array_column($blocks, 'variant'));
$this->assertSame([2], array_values(array_unique([$blocks[1]['v']])));
$this->assertStringContainsString('<strong>Betonung</strong>', $blocks[1]['data']['body']);
$this->assertSame([['title' => 'Prävention', 'text' => null, 'url' => '/praevention', 'image' => null]], $blocks[2]['data']['items']);
$this->assertSame(['u4', 'u1_3', 'u2_2'], array_column($sections, 'layout'));
$this->assertSame('dark', $sections[0]['style']['background']);
$this->assertSame('accent', $sections[0]['style']['divider']);
$this->assertSame('wide', $sections[1]['style']['width']);
$this->assertNull($sections[2]['slots'][1], 'Ein leerer Platz bleibt als Platz erhalten.');
$this->assertSame(['hero', 'cards', 'image_text', 'catalog_cards'], array_column($blocks, 'type'), 'Die Rollback-Spalte enthält alle Widgets in Lesereihenfolge.');
$this->assertSame(['highlight', 'compact', 'image_right', 'standard'], array_column($blocks, 'variant'));
$this->assertSame(2, $blocks[2]['v']);
$this->assertStringContainsString('<strong>Betonung</strong>', $blocks[2]['data']['body']);
$this->assertSame([['title' => 'Prävention', 'text' => null, 'url' => '/praevention', 'image' => null]], $blocks[1]['data']['items']);
$this->assertSame([['type' => 'composition', 'id' => $program->composition_id]], $blocks[3]['refs']['items']);
$this->get('/themen-test')->assertNotFound();
}
@@ -73,8 +92,8 @@ public function test_existing_page_opens_in_the_editor_and_saves_without_changin
$component = Livewire::actingAs($this->editor(), 'staff')
->test(EditPage::class, ['record' => $page->id]);
$state = $component->get('data.blocks');
$this->assertSame(['heading', 'prose', 'cards', 'call_to_action'], array_column(array_values($state), 'type'));
$this->assertSame(['heading', 'prose', 'cards', 'call_to_action'], $this->widgetTypes($component->get('data.sections')));
$this->assertSame(['u4', 'u4', 'u4', 'u4'], array_column(array_values($component->get('data.sections')), 'layout'), 'Bestand wird als einspaltige Abschnitte geöffnet.');
$component->call('save')->assertHasNoFormErrors();
@@ -82,6 +101,7 @@ public function test_existing_page_opens_in_the_editor_and_saves_without_changin
$this->assertSame($live, $page->published_revision_id);
$this->assertNotSame($live, $page->latestRevision->id);
$this->assertSame(['heading', 'prose', 'cards', 'call_to_action'], array_column($page->latestRevision->blocks, 'type'));
$this->assertCount(4, $page->latestRevision->sections);
$this->assertSame($before, $this->mainText($this->get('/')->getContent()));
Livewire::actingAs($this->editor(), 'staff')
@@ -100,17 +120,76 @@ public function test_editor_reorders_and_duplicates_sections(): void
$page = Page::query()->where('path', '/')->firstOrFail();
$component = Livewire::actingAs($this->editor(), 'staff')->test(EditPage::class, ['record' => $page->id]);
$state = $component->get('data.blocks');
$state = $component->get('data.sections');
$keys = array_keys($state);
$reordered = [$keys[3] => $state[$keys[3]], $keys[0] => $state[$keys[0]], $keys[1] => $state[$keys[1]], $keys[2] => $state[$keys[2]]];
$copy = $state[$keys[1]];
$reordered[(string) Str::uuid()] = $copy;
$reordered[(string) Str::uuid()] = $state[$keys[1]];
$component->set('data.blocks', $reordered)->call('save')->assertHasNoFormErrors();
$component->set('data.sections', $reordered)->call('save')->assertHasNoFormErrors();
$blocks = $page->fresh()->latestRevision->blocks;
$this->assertSame(['call_to_action', 'heading', 'prose', 'cards', 'prose'], array_column($blocks, 'type'));
$this->assertCount(5, array_unique(array_column($blocks, 'id')), 'Ein dupliziertes Widget erhält eine eigene Kennung.');
$revision = $page->fresh()->latestRevision;
$this->assertSame(['call_to_action', 'heading', 'prose', 'cards', 'prose'], array_column($revision->blocks, 'type'));
$this->assertCount(5, array_unique(array_column($revision->blocks, 'id')), 'Ein dupliziertes Widget erhält eine eigene Kennung.');
$this->assertCount(5, array_unique(array_column($revision->sections, 'id')), 'Ein duplizierter Abschnitt erhält eine eigene Kennung.');
}
public function test_layout_change_keeps_widgets_and_rejects_layouts_with_too_few_slots(): void
{
$page = Page::query()->where('path', '/')->firstOrFail();
$component = Livewire::actingAs($this->editor(), 'staff')->test(EditPage::class, ['record' => $page->id]);
$state = $component->get('data.sections');
$keys = array_keys($state);
// Raster wechseln: fehlende Plätze entstehen, das vorhandene Widget bleibt im ersten Platz.
$component->set("data.sections.{$keys[0]}.layout", 'u1_1_1_1');
$slots = $component->get("data.sections.{$keys[0]}.slots");
$this->assertCount(4, $slots);
$this->assertSame(['heading'], $this->widgetTypes([['slots' => $slots]]));
// Zweites Widget in Platz 2 setzen und auf zwei Plätze wechseln: leere Plätze entfallen, Widgets bleiben.
$slotKeys = array_keys($slots);
$secondWidget = $state[$keys[1]]['slots'][array_key_first($state[$keys[1]]['slots'])]['widget'];
$component->set("data.sections.{$keys[0]}.slots.{$slotKeys[1]}.widget", $secondWidget);
$component->set("data.sections.{$keys[0]}.layout", 'u2_2');
$this->assertCount(2, $component->get("data.sections.{$keys[0]}.slots"));
$this->assertSame(['heading', 'prose'], $this->widgetTypes([['slots' => $component->get("data.sections.{$keys[0]}.slots")]]));
// Ein Raster mit nur einem Platz ist gesperrt, solange zwei Widgets eingesetzt sind; kein Widget geht verloren.
$component->set("data.sections.{$keys[0]}.layout", 'u4');
$this->assertCount(2, $component->get("data.sections.{$keys[0]}.slots"));
$component->call('save')->assertHasErrors(["data.sections.{$keys[0]}.layout"]);
$component->set("data.sections.{$keys[0]}.layout", 'u2_2');
$remaining = $component->get('data.sections');
unset($remaining[$keys[1]]);
$component->set('data.sections', $remaining)->call('save')->assertHasNoFormErrors();
$sections = $page->fresh()->latestRevision->sections;
$this->assertCount(3, $sections);
$this->assertSame('u2_2', $sections[0]['layout']);
$this->assertSame(['heading', 'prose'], array_column($sections[0]['slots'], 'type'));
}
public function test_widget_too_wide_for_its_slot_is_reported_at_the_section(): void
{
$component = Livewire::actingAs($this->editor(), 'staff')
->test(CreatePage::class)
->fillForm([
'path' => '/raster-pruefung',
'sections' => [
$this->sectionState('u1_3', [
['type' => 'hero', 'data' => ['variant' => 'standard', 'data' => ['heading' => 'Zu schmal']]],
null,
], ['background' => 'accent', 'spacing' => 'large', 'divider' => 'line']),
],
])
->call('create')
->assertNotified('Nicht gespeichert');
$key = array_key_first($component->get('data.sections'));
$component->assertHasErrors(["data.sections.$key.slots"]);
$this->assertNull(Page::query()->where('path', '/raster-pruefung')->first());
}
public function test_unsafe_link_is_reported_at_the_section_and_nothing_is_saved(): void
@@ -119,11 +198,17 @@ public function test_unsafe_link_is_reported_at_the_section_and_nothing_is_saved
$revisions = $page->revisions()->count();
$component = Livewire::actingAs($this->editor(), 'staff')->test(EditPage::class, ['record' => $page->id]);
$key = array_keys($component->get('data.blocks'))[3];
$sectionKey = array_keys($component->get('data.sections'))[3];
$slotKey = array_key_first($component->get("data.sections.$sectionKey.slots"));
$widgetKey = array_key_first($component->get("data.sections.$sectionKey.slots.$slotKey.widget"));
$component->set("data.blocks.$key.data.data.url", 'javascript:alert(1)')
$component->set("data.sections.$sectionKey.slots.$slotKey.widget.$widgetKey.data.data.url", 'javascript:alert(1)')
->call('save')
->assertHasErrors(["data.blocks.$key.data.data.url"]);
->assertHasErrors([
"data.sections.$sectionKey.slots.$slotKey.widget.$widgetKey.data.data.url",
"data.sections.$sectionKey.slots",
])
->assertNotified('Nicht gespeichert');
$this->assertSame($revisions, $page->revisions()->count());
}
@@ -136,23 +221,74 @@ public function test_errors_found_only_by_the_registry_are_announced_with_the_se
$page = Page::query()->where('path', '/')->firstOrFail();
$revisions = $page->revisions()->count();
$component = Livewire::actingAs($this->editor(), 'staff')->test(EditPage::class, ['record' => $page->id]);
$state = $component->get('data.blocks');
$state[(string) Str::uuid()] = ['type' => 'hero', 'data' => ['variant' => 'standard', 'data' => ['heading' => 'Mit Bild'], 'refs' => ['image' => 'cms/bild.jpg']]];
$state = $component->get('data.sections');
$state[(string) Str::uuid()] = $this->sectionState('u4', [
['type' => 'hero', 'data' => ['variant' => 'standard', 'data' => ['heading' => 'Mit Bild'], 'refs' => ['image' => 'cms/bild.jpg']]],
]);
$component->set('data.blocks', $state)
$component->set('data.sections', $state)
->call('save')
->assertNotified('Nicht gespeichert');
$this->assertSame($revisions, $page->revisions()->count());
}
public function test_section_background_image_is_saved_and_published_from_the_public_area(): void
{
Storage::fake('media_public');
Storage::fake('cms_incoming');
Storage::disk('media_public')->put('cms/flaeche.jpg', 'bild');
Livewire::actingAs($this->editor(), 'staff')
->test(CreatePage::class)
->fillForm([
'path' => '/flaechen',
'sections' => [
$this->sectionState('u2_2', [
['type' => 'heading', 'data' => ['variant' => 'standard', 'data' => ['heading' => 'Auf Bild']]],
['type' => 'prose', 'data' => ['variant' => 'standard', 'data' => ['body' => 'Text']]],
], ['background' => 'image', 'image' => 'cms/flaeche.jpg', 'focus' => 'top', 'overlay' => 'dark']),
],
])
->call('create')
->assertHasNoFormErrors();
$style = Page::query()->where('path', '/flaechen')->firstOrFail()->latestRevision->sections[0]['style'];
$this->assertSame(['background' => 'image', 'image' => 'cms/flaeche.jpg', 'focus' => 'top', 'overlay' => 'dark'], array_intersect_key($style, array_flip(['background', 'image', 'focus', 'overlay'])));
}
public function test_page_can_be_duplicated_as_an_unpublished_draft_without_changing_the_source(): void
{
$source = Page::query()->where('path', '/praevention')->firstOrFail();
$sourceRevision = $source->latestRevision->id;
$editor = $this->editor();
Livewire::actingAs($editor, 'staff')
->test(ListPages::class)
->callAction(TestAction::make('duplicate')->table($source), ['path' => '/praevention'])
->assertHasActionErrors(['path']);
Livewire::actingAs($editor, 'staff')
->test(ListPages::class)
->callAction(TestAction::make('duplicate')->table($source), ['path' => '/neue-landingpage'])
->assertHasNoActionErrors();
$copy = Page::query()->where('path', '/neue-landingpage')->firstOrFail();
$this->assertNull($copy->published_revision_id);
$this->assertSame(
array_column($source->latestRevision->widgets(), 'type'),
array_column($copy->latestRevision->widgets(), 'type'),
);
$this->assertSame($sourceRevision, $source->fresh()->latestRevision->id, 'Die Vorlage bleibt unverändert.');
}
public function test_new_page_keeps_the_selected_pillars(): void
{
$pillar = app(PillarService::class)->create('Grenzen');
Livewire::actingAs($this->editor(), 'staff')
->test(CreatePage::class)
->fillForm(['path' => '/grenzen-thema', 'pillars' => [$pillar->id], 'blocks' => []])
->fillForm(['path' => '/grenzen-thema', 'pillars' => [$pillar->id], 'sections' => []])
->call('create')
->assertHasNoFormErrors();
@@ -163,29 +299,30 @@ public function test_duplicated_section_keeps_its_new_id_across_saves(): void
{
$page = Page::query()->where('path', '/')->firstOrFail();
$component = Livewire::actingAs($this->editor(), 'staff')->test(EditPage::class, ['record' => $page->id]);
$state = $component->get('data.blocks');
$state = $component->get('data.sections');
$state[(string) Str::uuid()] = $state[array_key_first($state)];
$component->set('data.blocks', $state)->call('save')->assertHasNoFormErrors();
$component->set('data.sections', $state)->call('save')->assertHasNoFormErrors();
$first = array_column($page->fresh()->latestRevision->blocks, 'id');
$firstSections = array_column($page->fresh()->latestRevision->sections, 'id');
$component->call('save')->assertHasNoFormErrors();
$second = array_column($page->fresh()->latestRevision->blocks, 'id');
$this->assertCount(5, array_unique($first));
$this->assertSame($first, $second);
$this->assertSame($first, array_column($page->fresh()->latestRevision->blocks, 'id'));
$this->assertSame($firstSections, array_column($page->fresh()->latestRevision->sections, 'id'));
}
public function test_invalid_or_taken_paths_are_shown_at_the_path_field(): void
{
Livewire::actingAs($this->editor(), 'staff')
->test(CreatePage::class)
->fillForm(['path' => '/praevention', 'blocks' => []])
->fillForm(['path' => '/praevention', 'sections' => []])
->call('create')
->assertHasErrors(['data.path']);
Livewire::actingAs($this->editor(), 'staff')
->test(CreatePage::class)
->fillForm(['path' => 'C:/Program Files/x', 'blocks' => []])
->fillForm(['path' => 'C:/Program Files/x', 'sections' => []])
->call('create')
->assertHasErrors(['data.path']);
@@ -215,15 +352,21 @@ public function test_block_preview_uses_the_public_widget_view_with_unsaved_stat
$this->assertStringContainsString('Karte B', $cards);
}
public function test_editor_offers_every_registered_widget_with_description(): void
public function test_editor_offers_every_registered_widget_layouts_and_section_design(): void
{
$page = Page::query()->where('path', '/')->firstOrFail();
$component = Livewire::actingAs($this->editor(), 'staff')->test(EditPage::class, ['record' => $page->id]);
$first = array_key_first($component->get('data.sections'));
Livewire::actingAs($this->editor(), 'staff')
->test(EditPage::class, ['record' => $page->id])
// Die Widget-Auswahl erscheint an jedem freien Platz.
$component->set("data.sections.$first.layout", 'u2_2')
->assertSee('Einstieg (Hero)')
->assertSee('Programm- und Modulkarten')
->assertSee('Titel und Beschreibung kommen automatisch aus den Fachdaten')
->assertSee('Braucht einen Platz ab 2 Rastereinheiten')
->assertSee('Gestaltung des Abschnitts')
->assertSee('1 + 2 + 1')
->assertSee('Widget einsetzen')
->assertSee('Entwurf speichern');
}
@@ -248,8 +391,9 @@ public function test_preview_with_device_widths_is_only_available_to_staff(): vo
->get(route('pages.preview', $revision))
->assertOk()
->assertSee('Vorschau einer unveröffentlichten Revision')
->assertSee('Registrieren')
->assertDontSee('Mitgliederbereich</a>', false);
->assertSee('<meta name="robots" content="noindex, nofollow">', false)
->assertSee('class="site-header"', false)
->assertSee('class="site-footer scope-dark"', false);
}
public function test_navigation_items_can_be_edited_hidden_reordered_and_removed(): void
@@ -299,6 +443,41 @@ private function editor(): User
return $editor;
}
/**
* Formularzustand eines Abschnitts; null steht für einen leeren Platz.
*
* @param list<array<string, mixed>|null> $widgets
* @param array<string, mixed> $style
* @return array<string, mixed>
*/
private function sectionState(string $layout, array $widgets, array $style = []): array
{
$slots = [];
foreach ($widgets as $widget) {
$slots[(string) Str::uuid()] = ['widget' => $widget === null ? [] : $this->keyed([$widget])];
}
return ['id' => null, 'layout' => $layout, 'style' => $style, 'slots' => $slots];
}
/**
* @param array<int|string, mixed> $sections
* @return list<string>
*/
private function widgetTypes(array $sections): array
{
$types = [];
foreach ($sections as $section) {
foreach ($section['slots'] ?? [] as $slot) {
foreach ($slot['widget'] ?? [] as $item) {
$types[] = $item['type'];
}
}
}
return $types;
}
/**
* @param list<array<string, mixed>> $items
* @return array<string, array<string, mixed>>
+45
View File
@@ -0,0 +1,45 @@
<?php
namespace Tests\Feature;
use App\Domain\Cms\Page;
use App\Domain\Cms\PageService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Carbon;
use Tests\TestCase;
class CmsRollbackCommandTest extends TestCase
{
use RefreshDatabase;
public function test_published_pages_return_to_their_state_before_a_deployment_only_with_apply(): void
{
$service = app(PageService::class);
$page = Page::query()->where('path', '/praevention')->firstOrFail();
$before = $page->published_revision_id;
Carbon::setTestNow('2030-01-01 12:00:00');
$new = $service->saveRevision($page, [['layout' => 'u2_2', 'style' => [], 'slots' => [
['type' => 'heading', 'v' => 1, 'data' => ['heading' => 'Neu']],
null,
]]], null, null, null);
$service->publish($page, $new);
$created = Page::query()->create(['path' => '/neu-nach-deploy']);
$service->publish($created, $service->saveRevision($created, [['type' => 'heading', 'v' => 1, 'data' => ['heading' => 'Ganz neu']]], null, null, null));
Carbon::setTestNow();
$this->artisan('cms:revert-published', ['--before' => '2030-01-01 11:00'])->assertSuccessful();
$this->assertSame($new->id, $page->fresh()->published_revision_id, 'Ohne --apply ändert sich nichts.');
$this->artisan('cms:revert-published', ['--before' => '2030-01-01 11:00', '--apply' => true])->assertSuccessful();
$this->assertSame($before, $page->fresh()->published_revision_id);
$this->assertNull($created->fresh()->published_revision_id, 'Eine erst danach angelegte Seite wird zurückgezogen.');
$this->assertNotNull($new->fresh(), 'Revisionen bleiben erhalten.');
}
public function test_missing_time_is_rejected(): void
{
$this->artisan('cms:revert-published')->assertFailed();
}
}
+259
View File
@@ -0,0 +1,259 @@
<?php
namespace Tests\Feature;
use App\Domain\Cms\NavigationItem;
use App\Domain\Cms\Page;
use App\Domain\Cms\PageService;
use App\Domain\Cms\Widgets\RenderContext;
use App\Domain\Cms\Widgets\WidgetRenderer;
use App\Jobs\PublishPublicMedia;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Queue;
use Tests\Support\BuildsCatalog;
use Tests\TestCase;
/**
* Öffentliche Darstellung der Abschnitte, globales Website-Gerüst und Rückfallweg.
*/
class CmsSectionRenderingTest extends TestCase
{
use BuildsCatalog;
use RefreshDatabase;
/**
* @return array<string, mixed>
*/
private function heading(string $text): array
{
return ['type' => 'heading', 'v' => 1, 'data' => ['heading' => $text]];
}
/**
* @return array<string, mixed>
*/
private function prose(string $text): array
{
return ['type' => 'prose', 'v' => 1, 'data' => ['body' => $text]];
}
/**
* @param list<array<string, mixed>> $sections
*/
private function publish(string $path, array $sections): Page
{
$service = app(PageService::class);
$page = Page::query()->create(['path' => $path]);
$service->publish($page, $service->saveRevision($page, $sections, null, null, null));
return $page->fresh();
}
public function test_sections_render_grid_ratios_backgrounds_and_dividers(): void
{
$this->publish('/raster', [
['layout' => 'u4', 'style' => ['background' => 'dark', 'divider' => 'accent'], 'slots' => [$this->heading('Einstieg')]],
['layout' => 'u1_3', 'style' => ['background' => 'light', 'width' => 'wide', 'divider' => 'line'], 'slots' => [$this->prose('Schmal'), $this->prose('Breit')]],
['layout' => 'u1_1_1_1', 'style' => ['background' => 'accent', 'spacing' => 'large'], 'slots' => [$this->prose('A'), $this->prose('B'), $this->prose('C'), $this->prose('D')]],
['layout' => 'u2_2', 'style' => ['divider' => 'line'], 'slots' => [$this->prose('Letzter')]],
]);
$html = $this->get('/raster')->assertOk()->getContent();
$this->assertStringContainsString('page-section section-bg-dark section-width-standard section-space-normal section-layout-u4 scope-dark', $html);
$this->assertStringContainsString('section-bg-light section-width-wide', $html);
$this->assertStringContainsString('--section-cols-lg: minmax(0, 1fr) minmax(0, 3fr); --section-cols-md: minmax(0, 1fr)', $html);
$this->assertStringContainsString('--section-cols-md: repeat(2, minmax(0, 1fr))', $html, 'Vier gleiche Plätze stehen auf dem Tablet als 2 × 2.');
$this->assertStringContainsString('section-bg-accent section-width-standard section-space-large section-layout-u1-1-1-1 scope-accent', $html);
$this->assertStringContainsString('section-divider section-divider-accent', $html);
$this->assertSame(1, substr_count($html, 'section-divider section-divider-line'), 'Nach dem letzten Abschnitt steht kein Trenner.');
$this->assertSame(1, substr_count($html, '<h1>'), 'Nur das erste Widget der Seite ist Überschrift erster Ordnung.');
$this->assertLessThan(strpos($html, 'Breit'), strpos($html, 'Schmal'), 'Lese- und Fokusreihenfolge folgt den Plätzen.');
}
public function test_empty_slots_and_empty_sections_leave_no_gaps(): void
{
$this->publish('/luecken', [
['layout' => 'u1_2_1', 'style' => [], 'slots' => [$this->prose('Links'), null, $this->prose('Rechts')]],
['layout' => 'u2_2', 'style' => ['background' => 'dark'], 'slots' => [null, null]],
['layout' => 'u1_3', 'style' => [], 'slots' => [null, $this->prose('Allein')]],
]);
$html = $this->get('/luecken')->assertOk()->getContent();
$this->assertStringContainsString('data-slots="2" style="--section-cols-lg: minmax(0, 1fr) minmax(0, 1fr)', $html, 'Die übrigen Plätze teilen sich die Breite im Verhältnis ihrer Einheiten.');
$this->assertStringContainsString('data-slots="1" style="--section-cols-lg: minmax(0, 1fr)', $html);
$this->assertStringNotContainsString('section-bg-dark', $html, 'Ein Abschnitt ohne Inhalt entfällt samt Fläche.');
}
public function test_background_image_comes_from_the_public_area_with_focus_and_overlay(): void
{
Queue::fake();
$this->publish('/bild', [
['layout' => 'u4', 'style' => ['background' => 'image', 'image' => 'cms/flaeche.jpg', 'focus' => 'top_left', 'overlay' => 'dark'], 'slots' => [$this->heading('Auf Bild')]],
['layout' => 'u4', 'style' => ['background' => 'image', 'image' => 'cms/zweites.jpg', 'overlay' => 'light'], 'slots' => [$this->prose('Hell')]],
]);
$html = $this->get('/bild')->assertOk()->getContent();
$this->assertStringContainsString('section-bg-image', $html);
$this->assertStringContainsString('section-overlay-dark scope-dark', $html);
$this->assertStringContainsString('section-overlay-light scope-light', $html);
$this->assertMatchesRegularExpression('#<img class="page-section-image" src="[^"]*cms/flaeche\.jpg" alt="" loading="eager" fetchpriority="high"[^>]*object-position: 0% 0%#', $html);
$this->assertMatchesRegularExpression('#<img class="page-section-image" src="[^"]*cms/zweites\.jpg" alt="" loading="lazy"#', $html);
Queue::assertPushed(PublishPublicMedia::class, 2);
}
public function test_preview_uses_the_same_renderer_as_the_public_page(): void
{
$page = $this->publish('/gleich', [
['layout' => 'u2_2', 'style' => ['background' => 'light'], 'slots' => [$this->heading('Links'), $this->prose('Rechts')]],
]);
$editor = User::factory()->redakteur()->create();
$public = $this->get('/gleich')->getContent();
$preview = $this->actingAs($editor, 'staff')->get(route('pages.preview', $page->published_revision_id))->getContent();
$this->assertSame($this->sectionsMarkup($public), $this->sectionsMarkup($preview));
$this->assertStringContainsString('Vorschau einer unveröffentlichten Revision', $preview);
}
public function test_public_page_is_identical_for_guests_and_members(): void
{
// Schrift-Vorabladehinweise gibt der Rahmen je Prozess nur einmal aus; sie hängen nicht vom Besucher ab.
$withoutPreload = fn (string $html): string => preg_replace('#<link rel="preload" as="font"[^>]*>\s*#', '', $html);
$guest = $withoutPreload($this->get('/praevention')->assertOk()->getContent());
$member = $withoutPreload($this->actingAs(User::factory()->create())->get('/praevention')->assertOk()->getContent());
$this->assertSame($guest, $member, 'Öffentliche Seiten hängen nicht vom Anmeldestatus ab (ADR-32).');
$this->assertStringContainsString('href="'.route('member.dashboard').'"', $guest);
$this->assertStringContainsString('Mitgliederbereich', $guest);
}
public function test_global_layout_has_header_navigation_mobile_menu_and_footer(): void
{
$html = $this->get('/praevention')->assertOk()->getContent();
$this->assertStringContainsString('<a class="skip" href="#inhalt">', $html);
$this->assertStringContainsString('class="brand" href="'.route('home').'" data-brand-status="vorlaeufig"', $html);
$this->assertStringContainsString('aria-label="Hauptnavigation"', $html);
$this->assertMatchesRegularExpression('#<a href="[^"]*/praevention"\s+aria-current="page"\s*>Prävention</a>#', $html);
$this->assertStringContainsString('data-site-menu-button', $html);
$this->assertStringContainsString('aria-controls="site-nav"', $html);
$this->assertStringContainsString('class="site-footer scope-dark"', $html);
$this->assertStringContainsString('<h2 id="fuss-footer">Service</h2>', $html);
$this->assertStringContainsString('Impressum', $html);
$this->assertStringNotContainsString('Warenkorb', $html, 'Ohne Warenkorb erscheint kein funktionsloser Kaufknopf.');
$this->assertStringNotContainsString('fonts.bunny.net', $html);
$this->assertStringNotContainsString('fonts.googleapis.com', $html);
}
public function test_cart_entry_appears_only_when_enabled(): void
{
config(['cms.cart.enabled' => true, 'cms.cart.url' => '/warenkorb']);
$this->get('/praevention')->assertSee('Warenkorb')->assertSee('href="/warenkorb"', false);
}
public function test_submenus_footer_groups_and_hidden_parents(): void
{
$parent = NavigationItem::query()->where('label', 'Prävention')->firstOrFail();
NavigationItem::query()->create(['label' => 'Grenzen', 'url' => '/themen/grenzen', 'placement' => 'header', 'parent_id' => $parent->id, 'sort_order' => 1]);
NavigationItem::query()->create(['label' => 'Kontaktformular', 'url' => '/kontakt', 'placement' => 'footer_contact', 'sort_order' => 1]);
NavigationItem::query()->create(['label' => 'Fußkind', 'url' => '/x', 'placement' => 'footer', 'parent_id' => $parent->id, 'sort_order' => 2]);
$html = $this->get('/praevention')->getContent();
$this->assertStringContainsString('site-nav-item has-children is-active-trail', $html);
$this->assertStringContainsString('aria-controls="untermenue-'.$parent->id.'"', $html);
$this->assertStringContainsString('Untermenü Prävention', $html);
$this->assertMatchesRegularExpression('#<ul class="site-subnav" id="untermenue-'.$parent->id.'">\s*<li><a href="[^"]*/themen/grenzen"\s*>Grenzen</a></li>#', $html);
$this->assertStringContainsString('<h2 id="fuss-footer_contact">Kontakt</h2>', $html);
$this->assertNull(NavigationItem::query()->where('label', 'Fußkind')->value('parent_id'), 'Untermenüs gibt es nur in der Hauptnavigation.');
$parent->update(['is_visible' => false]);
$this->assertStringNotContainsString('Grenzen', $this->get('/praevention')->getContent(), 'Mit dem Eintrag ist auch sein Untermenü ausgeblendet.');
}
public function test_deleting_a_parent_moves_its_children_to_the_top_level(): void
{
$parent = NavigationItem::query()->where('label', 'Prävention')->firstOrFail();
$child = NavigationItem::query()->create(['label' => 'Grenzen', 'url' => '/themen/grenzen', 'placement' => 'header', 'parent_id' => $parent->id]);
$parent->delete();
$this->assertNull($child->fresh()->parent_id);
$this->get('/ueber')->assertSee('Grenzen');
}
public function test_member_area_uses_the_shared_wordmark_and_tokens(): void
{
$member = User::factory()->create();
$this->actingAs($member)
->get(route('member.dashboard'))
->assertOk()
->assertSee('class="brand member-mark"', false)
->assertSee('<span class="brand-claim">Mitgliederbereich</span>', false)
->assertSee('class="member-dock"', false);
}
public function test_rollback_column_lets_the_previous_renderer_show_every_widget(): void
{
$page = $this->publish('/rueckfall', [
['layout' => 'u1_1_1_1', 'style' => ['background' => 'dark'], 'slots' => [$this->heading('Erstens'), $this->prose('Zweitens'), null, $this->prose('Viertens')]],
]);
// Darstellung wie in der Fassung vor dem Abschnittsraster: flache Liste aus der Spalte blocks.
$html = app(WidgetRenderer::class)->renderAll($page->publishedRevision->blocks, RenderContext::publicPage())->toHtml();
foreach (['Erstens', 'Zweitens', 'Viertens'] as $text) {
$this->assertStringContainsString($text, $html);
}
}
public function test_restore_copies_sections_and_rollback_column_unchanged(): void
{
$page = $this->publish('/wieder', [
['layout' => 'u2_2', 'style' => ['background' => 'light'], 'slots' => [$this->heading('Früher'), $this->prose('Stand')]],
]);
$first = $page->publishedRevision;
$service = app(PageService::class);
$service->publish($page, $service->saveRevision($page, [['layout' => 'u4', 'style' => [], 'slots' => [$this->heading('Später')]]], null, null, null));
$restored = $service->restore($page->fresh(), $first, null);
$service->publish($page->fresh(), $restored);
$this->assertSame($first->sections, $restored->fresh()->sections);
$this->assertSame($first->blocks, $restored->fresh()->blocks);
$this->get('/wieder')->assertSee('Früher')->assertDontSee('Später');
}
public function test_program_reference_in_a_narrow_slot_reads_catalog_data(): void
{
$program = $this->composition('Programm Abstand', 'programm', summary: 'Kurzbeschreibung aus den Fachdaten');
$this->publish('/programme-schmal', [
['layout' => 'u3_1', 'style' => [], 'slots' => [
$this->prose('Hauptinhalt'),
['type' => 'catalog_cards', 'v' => 1, 'variant' => 'compact', 'data' => [], 'refs' => ['items' => [['type' => 'composition', 'id' => $program->composition_id]]]],
]],
]);
$this->get('/programme-schmal')
->assertOk()
->assertSee('Programm Abstand')
->assertSee('catalog-cards catalog-cards-compact', false)
->assertSee('data-units="1"', false);
}
private function sectionsMarkup(string $html): string
{
preg_match('#<main[^>]*>(.*)</main>#s', $html, $match);
$markup = preg_replace('#<p class="preview-banner".*?</p>#s', '', $match[1] ?? '');
return trim(preg_replace('/\s+/', ' ', $markup));
}
}
+262
View File
@@ -0,0 +1,262 @@
<?php
namespace Tests\Unit;
use App\Domain\Cms\Sections\PageSections;
use App\Domain\Cms\Sections\SectionLayouts;
use App\Domain\Cms\Sections\SectionStyle;
use App\Domain\Cms\Widgets\WidgetRegistry;
use App\Filament\Support\SectionEditor;
use Illuminate\Validation\ValidationException;
use Tests\TestCase;
class PageSectionsTest extends TestCase
{
private function sections(): PageSections
{
return app(PageSections::class);
}
/**
* @param list<array<string, mixed>|null> $slots
* @param array<string, mixed> $style
* @return array<string, mixed>
*/
private function section(string $layout, array $slots, array $style = []): array
{
return ['layout' => $layout, 'style' => $style, 'slots' => $slots];
}
/**
* @return array<string, mixed>
*/
private function heading(string $text): array
{
return ['type' => 'heading', 'v' => 1, 'data' => ['heading' => $text]];
}
public function test_required_layouts_exist_with_at_most_four_units(): void
{
$this->assertSame(['u4', 'u2_2', 'u1_3', 'u3_1', 'u1_2_1', 'u1_1_1_1'], array_keys(SectionLayouts::UNITS));
foreach (SectionLayouts::UNITS as $key => $units) {
$this->assertSame(4, array_sum($units), $key);
$this->assertLessThanOrEqual(4, count($units), $key);
}
$this->assertSame('1 + 2 + 1', SectionLayouts::short('u1_2_1'));
}
public function test_columns_follow_the_units_and_stack_unequal_layouts_on_tablets(): void
{
$this->assertSame(['lg' => 'minmax(0, 1fr) minmax(0, 3fr)', 'md' => 'minmax(0, 1fr)'], SectionLayouts::columns([1, 3]));
$this->assertSame('repeat(2, minmax(0, 1fr))', SectionLayouts::columns([1, 1, 1, 1])['md']);
$this->assertSame('repeat(3, minmax(0, 1fr))', SectionLayouts::columns([1, 1, 1])['md']);
$this->assertSame('repeat(2, minmax(0, 1fr))', SectionLayouts::columns([2, 2])['md']);
$this->assertSame(['lg' => 'minmax(0, 1fr)', 'md' => 'minmax(0, 1fr)'], SectionLayouts::columns([3]));
}
public function test_sections_are_normalized_with_slots_matching_the_layout(): void
{
$stored = $this->sections()->normalize([
$this->section('u1_3', [$this->heading('Links'), $this->heading('Rechts')], ['background' => 'dark', 'divider' => 'line']),
$this->section('u1_1_1_1', [$this->heading('Eins'), null, $this->heading('Drei')]),
]);
$this->assertCount(2, $stored);
$this->assertSame('u1_3', $stored[0]['layout']);
$this->assertSame(1, $stored[0]['v']);
$this->assertSame('dark', $stored[0]['style']['background']);
$this->assertSame('line', $stored[0]['style']['divider']);
$this->assertSame('standard', $stored[0]['style']['width']);
$this->assertCount(4, $stored[1]['slots'], 'Fehlende Plätze werden als leere Plätze ergänzt.');
$this->assertNull($stored[1]['slots'][1]);
$this->assertNull($stored[1]['slots'][3]);
$this->assertNotEmpty($stored[0]['id']);
}
public function test_flat_widgets_are_taken_over_as_full_width_sections(): void
{
$stored = $this->sections()->normalize([
['type' => 'heading', 'heading' => 'Altformat'],
$this->heading('Hülle'),
]);
$this->assertSame(['u4', 'u4'], array_column($stored, 'layout'));
$this->assertSame('Altformat', $stored[0]['slots'][0]['data']['heading']);
}
public function test_more_widgets_than_slots_are_rejected_instead_of_dropped(): void
{
try {
$this->sections()->normalize([
$this->section('u2_2', [$this->heading('A'), $this->heading('B'), $this->heading('C')]),
]);
$this->fail('Überzähliges Widget wurde angenommen.');
} catch (ValidationException $exception) {
$this->assertArrayHasKey('sections.0.slots', $exception->errors());
$this->assertStringContainsString('2 Plätze', $exception->errors()['sections.0.slots'][0]);
}
}
public function test_surplus_empty_slots_are_compacted_without_losing_widgets(): void
{
$stored = $this->sections()->normalize([
$this->section('u2_2', [$this->heading('A'), null, $this->heading('C'), null]),
]);
$this->assertSame(['A', 'C'], array_map(fn ($slot) => $slot['data']['heading'], $stored[0]['slots']));
}
public function test_widget_minimum_width_is_enforced_per_slot(): void
{
$hero = ['type' => 'hero', 'v' => 1, 'data' => ['heading' => 'Einstieg']];
try {
$this->sections()->normalize([$this->section('u1_3', [$hero, null])]);
$this->fail('Einstieg im schmalen Platz wurde angenommen.');
} catch (ValidationException $exception) {
$this->assertArrayHasKey('sections.0.slots.0.units', $exception->errors());
}
$stored = $this->sections()->normalize([$this->section('u1_3', [null, $hero])]);
$this->assertSame('hero', $stored[0]['slots'][1]['type']);
$this->assertSame(2, app(WidgetRegistry::class)->get('hero')->minUnits());
}
public function test_free_style_values_and_unknown_layouts_are_rejected(): void
{
foreach ([
[['layout' => 'u5', 'slots' => []], 'sections.0.layout'],
[$this->section('u4', [], ['background' => '#ff00ff']), 'sections.0.style.background'],
[$this->section('u4', [], ['css' => 'color: red']), 'sections.0.style.css'],
[$this->section('u4', [], ['spacing' => 'riesig']), 'sections.0.style.spacing'],
] as [$section, $key]) {
try {
$this->sections()->normalize([$section]);
$this->fail('Freier Wert wurde angenommen: '.$key);
} catch (ValidationException $exception) {
$this->assertArrayHasKey($key, $exception->errors());
}
}
}
public function test_background_image_must_be_public_and_is_dropped_for_other_backgrounds(): void
{
try {
$this->sections()->normalize([$this->section('u4', [$this->heading('A')], ['background' => 'image', 'image' => 'bibliothek/standbild.jpg'])]);
$this->fail('Geschütztes Bild wurde als Hintergrund angenommen.');
} catch (ValidationException $exception) {
$this->assertArrayHasKey('sections.0.style.image', $exception->errors());
}
try {
$this->sections()->normalize([$this->section('u4', [$this->heading('A')], ['background' => 'image'])]);
$this->fail('Hintergrundbild ohne Bild wurde angenommen.');
} catch (ValidationException $exception) {
$this->assertArrayHasKey('sections.0.style.image', $exception->errors());
}
$stored = $this->sections()->normalize([
$this->section('u4', [$this->heading('A')], ['background' => 'image', 'image' => 'cms/flaeche.jpg', 'focus' => 'top', 'overlay' => 'dark']),
$this->section('u4', [$this->heading('B')], ['background' => 'light', 'image' => 'cms/flaeche.jpg']),
]);
$this->assertSame('cms/flaeche.jpg', $stored[0]['style']['image']);
$this->assertNull($stored[1]['style']['image']);
$this->assertSame(['cms/flaeche.jpg'], $this->sections()->mediaPaths($stored));
}
public function test_ids_are_unique_across_the_whole_page_after_duplicating_a_section(): void
{
$section = ['id' => 'abschnitt-a'] + $this->section('u2_2', [
['id' => 'widget-a'] + $this->heading('A'),
['id' => 'widget-b'] + $this->heading('B'),
]);
$stored = $this->sections()->normalize([$section, $section]);
$this->assertSame('abschnitt-a', $stored[0]['id']);
$this->assertNotSame('abschnitt-a', $stored[1]['id']);
$widgetIds = array_column(array_merge($stored[0]['slots'], $stored[1]['slots']), 'id');
$this->assertCount(4, array_unique($widgetIds));
$this->assertSame(['widget-a', 'widget-b'], array_slice($widgetIds, 0, 2));
}
public function test_all_errors_of_a_page_are_reported_together(): void
{
try {
$this->sections()->normalize([
$this->section('u2_2', [['type' => 'heading', 'v' => 1, 'data' => []], null]),
$this->section('u4', [['type' => 'call_to_action', 'v' => 1, 'data' => ['heading' => 'X', 'label' => 'Los', 'url' => 'javascript:alert(1)']]]),
]);
$this->fail('Fehlerhafte Seite wurde angenommen.');
} catch (ValidationException $exception) {
$this->assertArrayHasKey('sections.0.slots.0.data.heading', $exception->errors());
$this->assertArrayHasKey('sections.1.slots.0.data.url', $exception->errors());
}
}
public function test_reading_without_sections_wraps_legacy_blocks_in_single_column_sections(): void
{
$sections = $this->sections()->read(null, [
['type' => 'heading', 'heading' => 'Alt'],
['type' => 'gibt_es_nicht'],
['type' => 'prose', 'v' => 1, 'data' => ['body' => 'Text']],
]);
$this->assertCount(2, $sections);
$this->assertSame('u4', $sections[0]['layout']);
$this->assertSame('compact', $sections[0]['style']['spacing']);
$this->assertSame('Alt', $sections[0]['slots'][0]['data']['heading']);
$this->assertSame('prose', $sections[1]['slots'][0]['type']);
}
public function test_reading_is_lenient_with_unknown_stored_values(): void
{
$sections = $this->sections()->read([
['id' => 'x', 'layout' => 'u9', 'style' => ['background' => 'pink', 'width' => 'wide'], 'slots' => [['type' => 'heading', 'v' => 1, 'data' => ['heading' => 'A']]]],
]);
$this->assertSame('u4', $sections[0]['layout']);
$this->assertSame('default', $sections[0]['style']['background']);
$this->assertSame('wide', $sections[0]['style']['width']);
}
public function test_flatten_keeps_reading_order_for_the_rollback_column(): void
{
$stored = $this->sections()->normalize([
$this->section('u1_1_1_1', [$this->heading('1'), null, $this->heading('3'), $this->heading('4')]),
$this->section('u4', [$this->heading('5')]),
]);
$this->assertSame(['1', '3', '4', '5'], array_map(fn ($widget) => $widget['data']['heading'], $this->sections()->flatten($stored)));
$this->assertSame('1', $this->sections()->pageTitle($stored));
}
public function test_style_summary_names_background_and_divider(): void
{
$this->assertSame('Dunkle Markenfläche · Breit · Trenner: Dezente Linie', SectionStyle::summary(['background' => 'dark', 'width' => 'wide', 'divider' => 'line']));
}
public function test_layout_change_in_the_editor_never_drops_a_widget(): void
{
$slots = [
'a' => ['widget' => ['w1' => ['type' => 'heading']]],
'b' => ['widget' => []],
'c' => ['widget' => ['w3' => ['type' => 'prose']]],
'd' => ['widget' => []],
];
$two = SectionEditor::arrangeSlots($slots, 'u2_2');
$this->assertSame(['a', 'c'], array_keys($two));
$one = SectionEditor::arrangeSlots($two, 'u4');
$this->assertCount(2, $one, 'Passen die Widgets nicht, bleiben alle erhalten; das Speichern weist die Seite ab.');
$four = SectionEditor::arrangeSlots($two, 'u1_1_1_1');
$this->assertCount(4, $four);
$this->assertSame(['a', 'c'], array_slice(array_keys($four), 0, 2));
$this->assertSame(2, SectionEditor::filledCount($four));
}
}
+14
View File
@@ -66,6 +66,20 @@ public function test_registration_rejects_keys_that_are_not_stable_identifiers()
new WidgetRegistry([$this->customWidget('Teaser Box')]);
}
public function test_every_widget_declares_a_minimum_width_within_four_units(): void
{
foreach ($this->registry()->all() as $key => $type) {
$this->assertGreaterThanOrEqual(1, $type->minUnits(), $key);
$this->assertLessThanOrEqual($type->preferredUnits(), $type->minUnits(), $key);
$this->assertLessThanOrEqual(4, $type->preferredUnits(), $key);
$this->assertNotEmpty($type->stages(), $key);
}
$this->assertSame(2, $this->registry()->get('hero')->minUnits());
$this->assertSame(2, $this->registry()->get('image_text')->minUnits());
$this->assertSame(1, $this->registry()->get('catalog_cards')->minUnits());
}
public function test_a_new_widget_type_works_through_the_contract_alone(): void
{
$registry = new WidgetRegistry([$this->customWidget('teaser')]);