> $content */ private function publish(string $path, array $content): string { $page = Page::query()->create(['path' => $path]); $service = app(PageService::class); $service->publish($page, $service->saveRevision($page, $content, null, null, null)); return $this->get($path)->assertOk()->getContent(); } /** * @param list|null> $slots * @param array $style * @return array */ private function section(string $layout, array $slots, array $style = []): array { return ['layout' => $layout, 'style' => $style, 'slots' => $slots]; } public function test_hero_from_design_iteration_one_is_upgraded_and_stays_savable(): void { $registry = app(WidgetRegistry::class); $standard = $registry->upcast(['type' => 'hero', 'v' => 1, 'variant' => 'stage', 'settings' => ['focus' => 'top_right', 'text_side' => 'left'], 'data' => ['heading' => 'Alt', 'cta2_label' => 'Zwei', 'cta2_url' => '/b']]); $this->assertSame(2, $standard['v']); $this->assertSame('photo_split', $standard['variant']); $this->assertSame([], $standard['settings'], 'Nicht mehr vorhandene Einstellungen werden entfernt.'); $this->assertSame([100, 0], [$standard['data']['focus_x'], $standard['data']['focus_y']]); $this->assertSame('/b', $standard['data']['cta2_url']); $highlight = $registry->upcast(['type' => 'hero', 'v' => 1, 'variant' => 'highlight', 'data' => ['heading' => 'Alt']]); $this->assertSame('editorial_solid', $highlight['variant']); $this->assertSame('editorial_solid', $registry->upcast(['type' => 'hero', 'v' => 1, 'variant' => 'editorial', 'data' => ['heading' => 'Alt']])['variant']); // Szenario „bestehende Seite unverändert speichern“: gespeicherte v1-Hülle geht ohne Fehler durch die Prüfung. $saved = $registry->normalize([['type' => 'hero', 'v' => 1, 'variant' => 'stage', 'settings' => ['focus' => 'left', 'text_side' => 'right'], 'data' => ['heading' => 'Alt', 'alt' => 'Bild'], 'refs' => ['image' => 'cms/alt.jpg']]]); $this->assertSame(['photo_split', 2, [0, 50]], [$saved[0]['variant'], $saved[0]['v'], [$saved[0]['data']['focus_x'], $saved[0]['data']['focus_y']]]); } public function test_image_text_from_design_iteration_one_is_upgraded_and_stays_savable(): void { $saved = app(WidgetRegistry::class)->normalize([[ 'type' => 'image_text', 'v' => 2, 'variant' => 'image_left', 'settings' => ['format' => 'portrait', 'focus' => 'bottom'], 'data' => ['title' => 'Alt', 'body' => '

Text

', 'alt' => 'Bild'], 'refs' => ['image' => 'cms/alt.jpg'], ]])[0]; $this->assertSame(3, $saved['v']); $this->assertSame([], $saved['settings']); $this->assertSame([50, 100], [$saved['data']['focus_x'], $saved['data']['focus_y']]); $this->assertSame('image_left', $saved['variant']); } public function test_premium_hero_renders_variants_heights_and_accents(): void { $html = $this->publish('/einstiege', [ $this->section('u4', [[ 'type' => 'hero', 'v' => 2, 'variant' => 'photo_split', 'settings' => ['height' => 'compact', 'accent' => 'none'], 'data' => ['eyebrow' => '', 'heading' => 'Erster Einstieg', 'alt' => 'Lara und Felix', 'focus_x' => 30, 'focus_y' => 70], 'refs' => ['image' => 'cms/park.jpg'], ]]), $this->section('u3_1', [[ 'type' => 'hero', 'v' => 2, 'variant' => 'editorial_solid', 'settings' => ['height' => 'large', 'heading_level' => 'h3', 'accent' => 'rays'], 'data' => ['heading' => 'Zweiter Einstieg', 'cta_label' => 'Konzept', 'cta_url' => '/konzept'], ], null]), ]); $this->assertStringContainsString('class="lf-hero lf-hero--photo-split lf-hero--height-compact lf-hero--accent-none"', $html); $this->assertStringContainsString('style="--lf-hero-focus-x: 30%; --lf-hero-focus-y: 70%"', $html); $this->assertStringContainsString('alt="Lara und Felix" loading="eager" fetchpriority="high" decoding="async"', $html); $this->assertStringContainsString('<script>alert(1)</script>', $html); $this->assertStringNotContainsString('', $html); $this->assertSame(1, substr_count($html, 'assertStringContainsString('

Erster Einstieg

', $html); $this->assertStringContainsString('

Zweiter Einstieg

', $html); $this->assertStringContainsString('lf-hero--editorial-solid lf-hero--height-large lf-hero--accent-rays', $html); $this->assertStringContainsString('brand-rays lf-hero__rays', $html); $this->assertSame(1, substr_count($html, 'lf-hero__title-accent'), 'Ohne Akzent keine Unterstreichung.'); $this->assertStringContainsString('widget-hero widget-variant-photo-split widget-height-compact', $html); } public function test_hero_rejects_unsafe_links_and_out_of_range_focus(): void { $cases = [ 'blocks.0.data.cta2_url' => ['heading' => 'X', 'cta2_label' => 'Böse', 'cta2_url' => 'javascript:alert(1)'], 'blocks.0.data.focus_x' => ['heading' => 'X', 'focus_x' => 150], ]; foreach ($cases as $key => $data) { try { app(WidgetRegistry::class)->normalize([['type' => 'hero', 'v' => 2, 'data' => $data]]); $this->fail("$key wurde angenommen."); } catch (ValidationException $exception) { $this->assertArrayHasKey($key, $exception->errors()); } } } public function test_premium_image_text_renders_surface_height_side_and_sanitized_body(): void { $html = $this->publish('/bild-text', [ ['type' => 'heading', 'v' => 1, 'data' => ['heading' => 'Seite']], $this->section('u4', [[ 'type' => 'image_text', 'v' => 3, 'variant' => 'image_left', 'settings' => ['surface' => 'navy', 'height' => 'spacious', 'heading_level' => 'h3'], 'data' => ['eyebrow' => 'Unser Ansatz', 'title' => 'Geschichten', 'body' => '

Text

', 'alt' => 'Park', 'cta_label' => 'Mehr', 'cta_url' => '/konzept', 'cta2_label' => 'Themen', 'cta2_url' => 'https://example.org/themen', 'focus_x' => 10, 'focus_y' => 90], 'refs' => ['image' => 'cms/park.jpg'], ]]), $this->section('u4', [['type' => 'image_text', 'v' => 3, 'data' => ['body' => '

Ohne Bild

']]]), ]); $this->assertStringContainsString('class="lf-bt lf-bt--navy lf-bt--image-left lf-bt--height-spacious"', $html); $this->assertStringContainsString('style="--bt-focus-x: 10%; --bt-focus-y: 90%"', $html); $this->assertStringContainsString('

Geschichten

', $html); $this->assertStringContainsString('

Unser Ansatz

', $html); $this->assertStringNotContainsString('', $html); $this->assertStringContainsString('Mehr ', $html); $this->assertStringContainsString('Themen', $html); $this->assertStringContainsString('lf-bt lf-bt--cream lf-bt--image-left lf-bt--height-normal lf-bt--without-image', $html); } /** * Gemeinsamer Layoutvertrag für alle Bestandswidgets: In jeder zulässigen Platzbreite wird gerendert; nicht * zulässige Breiten werden beim Speichern mit verständlicher Meldung abgewiesen. */ public function test_every_widget_renders_in_each_supported_width_and_rejects_the_others(): void { $samples = [ 'heading' => ['heading' => 'Überschrift mit einem sehr langen Wort Gewaltpräventionsfortbildungsmaßnahme'], 'prose' => ['body' => 'Fließtext mit einer langen Adresse https://example.org/'.str_repeat('a', 80)], 'cards' => ['items' => [['title' => 'Karte mit langem Titel für schmale Plätze', 'text' => 'Beschreibung', 'url' => '/a']]], 'call_to_action' => ['heading' => 'Aufruf', 'text' => 'Text', 'label' => 'Eine ausgesprochen lange Schaltflächenbeschriftung zum Prüfen', 'url' => '/a'], 'faq' => ['items' => [['question' => 'Frage?', 'answer' => 'Antwort.']]], 'hero' => ['heading' => 'Einstieg mit einer langen Überschrift, die umbrechen muss'], 'image_text' => ['title' => 'Bild und Text', 'body' => '

Text

'], ]; $registry = app(WidgetRegistry::class); $layouts = ['u4' => [4], 'u3_1' => [3, 1], 'u2_2' => [2, 2], 'u1_1_1_1' => [1, 1, 1, 1]]; $path = 0; foreach ($samples as $type => $data) { $widgetType = $registry->get($type); $widget = ['type' => $type, 'v' => $widgetType->version(), 'data' => $data]; foreach ($layouts as $layout => $units) { $slots = array_fill(0, count($units), null); $slots[0] = $widget; if ($widgetType->supportsUnits($units[0])) { $html = $this->publish('/raster-'.(++$path), [$this->section($layout, $slots)]); $this->assertStringContainsString('widget-'.str_replace('_', '-', $type), $html, "$type in $layout"); $this->assertStringContainsString('data-units="'.$units[0].'"', $html, "$type in $layout"); } else { try { app(PageService::class)->saveRevision(Page::query()->create(['path' => '/abgewiesen-'.(++$path)]), [$this->section($layout, $slots)], null, null, null); $this->fail("$type in $layout ({$units[0]} Einheiten) wurde angenommen."); } catch (ValidationException $exception) { $this->assertStringContainsString($widgetType->unitsLabel().' Rastereinheiten', $exception->errors()['sections.0.slots.0.units'][0]); } } } } $this->assertSame(['u4', 'u2_2', 'u1_3', 'u3_1', 'u1_2_1', 'u1_1_1_1'], array_keys(SectionLayouts::UNITS)); } public function test_fill_height_marks_the_widget_and_defaults_to_content_height(): void { $html = $this->publish('/fuellen', [ $this->section('u2_2', [ ['type' => 'call_to_action', 'v' => 1, 'settings' => ['height' => 'fill'], 'data' => ['heading' => 'Gleich hoch', 'label' => 'Los', 'url' => '/a']], ['type' => 'call_to_action', 'v' => 1, 'data' => ['heading' => 'Nach Inhalt', 'label' => 'Los', 'url' => '/b']], ]), ]); $this->assertStringContainsString('widget-call-to-action widget-variant-standard widget-height-fill', $html); $this->assertStringContainsString('widget-call-to-action widget-variant-standard widget-height-auto', $html); $this->assertStringNotContainsString('widget-prose widget-variant-standard widget-height', $html); } }