Files
laraundfelix/tests/Feature/CmsDesignIterationTest.php
LarsandClaude Opus 5.5 656f999d2c
CI Feature / test (push) Successful in 36s
Deploy Test / test (push) Successful in 32s
Deploy Test / deploy (push) Successful in 32s
Setze die Breitenstufen der Kopfzeile vor dem ersten Zeichnen.
Bei 1280 bis 1920 px zeigten die ersten Frames die volle, überlaufende
Navigation, bis das verzögert geladene Modul umschaltete. Die Messung
steht jetzt als window.lufHeaderMode inline direkt nach der Kopfzeile
(nach dem Stylesheet, vor dem Zeichnen); site-nav.js wiederholt sie bei
Größenänderungen und nach dem Laden der Schriften.

Außerdem: Widget-Vorschau ohne Scrollbalken-Reserve, feine Linie über
dem Fußbereich, wenn die Seite mit einer dunklen Fläche endet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 07:30:40 +01:00

178 lines
8.9 KiB
PHP

<?php
namespace Tests\Feature;
use App\Domain\Cms\NavigationItem;
use App\Domain\Cms\Page;
use App\Domain\Cms\PageService;
use App\Domain\Cms\Widgets\WidgetRegistry;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Validation\ValidationException;
use Tests\TestCase;
/**
* Designiteration 1: stabiler Website-Rahmen, Markenakzente und neue Widget-Varianten.
* Alle Erweiterungen sind additiv: gespeicherte Widgets bleiben gültig und werden wie bisher dargestellt.
*/
class CmsDesignIterationTest extends TestCase
{
use RefreshDatabase;
/**
* @param list<array<string, mixed>> $content Abschnitte oder Widgets
*/
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<array<string, mixed>|null> $slots
* @param array<string, string> $style
* @return array<string, mixed>
*/
private function section(string $layout, array $slots, array $style = []): array
{
return ['layout' => $layout, 'style' => $style, 'slots' => $slots];
}
public function test_header_keeps_one_box_with_compact_bar_and_sets_the_menu_mode_before_painting(): void
{
$html = $this->publish('/rahmen', [['type' => 'heading', 'v' => 1, 'data' => ['heading' => 'Rahmen']]]);
$this->assertStringContainsString('data-site-header-sentinel', $html);
$this->assertMatchesRegularExpression('#<header class="site-header" data-site-header>\s*<div class="site-header-bar">\s*<div class="site-header-inner ui-container">#', $html);
$this->assertStringContainsString('class="brand brand-lockup"', $html);
$this->assertStringContainsString('class="site-icon-link site-account-link" href="'.route('member.dashboard').'"', $html);
// Breitenstufen werden direkt nach der Kopfzeile gesetzt, vor dem ersten Zeichnen, nicht erst durch das Modul-Skript.
$this->assertMatchesRegularExpression('#</header>\s*<script>\s*window\.lufHeaderMode = function \(h\)#', $html);
$this->assertStringContainsString("window.lufHeaderMode(document.querySelector('[data-site-header]'));", $html);
}
public function test_footer_shows_legal_links_in_the_base_row_and_a_decorative_arc(): void
{
$legal = Page::query()->create(['path' => '/impressum-test']);
NavigationItem::query()->create(['label' => 'Impressum', 'page_id' => $legal->id, 'placement' => 'footer_legal', 'sort_order' => 1, 'is_visible' => true]);
$html = $this->publish('/fuss', [['type' => 'heading', 'v' => 1, 'data' => ['heading' => 'Fuß']]]);
$this->assertMatchesRegularExpression('#<div class="site-footer-base ui-container">\s*<nav aria-labelledby="fuss-footer_legal">\s*<h2 id="fuss-footer_legal" class="visually-hidden">Rechtliches</h2>#', $html);
$this->assertStringContainsString('Impressum', $html);
$this->assertMatchesRegularExpression('#<svg class="brand-arc site-footer-arc"[^>]*aria-hidden="true"#', $html);
}
public function test_hero_stored_before_this_iteration_renders_unchanged_content(): void
{
$html = $this->publish('/alt', [[
'type' => 'hero', 'v' => 1, 'variant' => 'standard',
'data' => ['heading' => 'Stark im Alltag', 'text' => 'Einstieg', 'cta_label' => 'Mehr', 'cta_url' => '/praevention', 'alt' => 'Bild'],
'refs' => ['image' => 'cms/alt.jpg'],
]]);
$this->assertStringContainsString('class="hero hero-standard hero-with-image"', $html);
$this->assertStringContainsString('<h1>Stark im Alltag</h1>', $html);
$this->assertStringContainsString('<p class="lede">Einstieg</p>', $html);
$this->assertSame(1, substr_count($html, 'class="button button-brand"'));
$this->assertStringNotContainsString('button-secondary', $html);
$this->assertStringContainsString('alt="Bild" loading="eager" fetchpriority="high" decoding="async"', $html);
$this->assertStringNotContainsString('section-bleed', $html);
}
public function test_brand_stage_bleeds_only_when_it_is_alone_in_its_section_and_has_an_image(): void
{
$stage = fn (?string $image) => [
'type' => 'hero', 'v' => 1, 'variant' => 'stage',
'settings' => ['focus' => 'left', 'text_side' => 'left'],
'data' => ['heading' => 'Bühne', 'alt' => $image ? 'Motiv' : null],
'refs' => ['image' => $image],
];
$html = $this->publish('/buehne', [
$this->section('u4', [$stage('cms/buehne.jpg')], ['width' => 'full']),
$this->section('u2_2', [$stage('cms/buehne.jpg'), ['type' => 'prose', 'v' => 1, 'data' => ['body' => '<p>Text</p>']]]),
$this->section('u4', [$stage(null)]),
]);
$this->assertSame(1, substr_count($html, 'section-bleed'));
$this->assertMatchesRegularExpression('#class="page-section [^"]*section-bleed"#', $html);
$this->assertStringContainsString('class="hero hero-stage hero-with-image hero-text-left" style="--hero-focus: 0% 50%"', $html);
$this->assertStringContainsString('<div class="hero-media">', $html);
// Nur das erste Bild der Seite wird sofort geladen.
$this->assertSame(1, substr_count($html, 'fetchpriority="high"'));
}
public function test_hero_renders_a_second_action_and_rejects_unsafe_targets(): void
{
$html = $this->publish('/zwei', [[
'type' => 'hero', 'v' => 1, 'variant' => 'editorial',
'data' => ['heading' => 'Konzept', 'cta_label' => 'Programme', 'cta_url' => '/programme', 'cta2_label' => 'Mitgliederbereich', 'cta2_url' => '/bereich'],
]]);
$this->assertStringContainsString('class="hero hero-editorial"', $html);
$this->assertStringContainsString('<a class="button button-brand" href="/programme">Programme</a>', $html);
$this->assertStringContainsString('<a class="button button-secondary" href="/bereich">Mitgliederbereich</a>', $html);
try {
app(WidgetRegistry::class)->normalize([[
'type' => 'hero', 'v' => 1, 'variant' => 'stage',
'data' => ['heading' => 'X', 'cta2_label' => 'Böse', 'cta2_url' => 'javascript:alert(1)'],
]]);
$this->fail('Unsicheres zweites Linkziel wurde angenommen.');
} catch (ValidationException $exception) {
$this->assertArrayHasKey('blocks.0.data.cta2_url', $exception->errors());
}
}
public function test_image_settings_are_enumerations_only(): void
{
$html = $this->publish('/format', [[
'type' => 'image_text', 'v' => 2, 'variant' => 'image_left',
'settings' => ['format' => 'portrait', 'focus' => 'top_right'],
'data' => ['title' => 'Hochformat', 'body' => '<p>Text</p>', 'alt' => 'Motiv'],
'refs' => ['image' => 'cms/hoch.jpg'],
]]);
$this->assertStringContainsString('class="image-text image-text-left image-format-portrait" style="--image-focus: 100% 0%"', $html);
try {
app(WidgetRegistry::class)->normalize([[
'type' => 'image_text', 'v' => 2, 'variant' => 'image_left',
'settings' => ['format' => 'panorama; color: red'],
'data' => ['body' => '<p>Text</p>'],
]]);
$this->fail('Freier Einstellungswert wurde angenommen.');
} catch (ValidationException $exception) {
$this->assertArrayHasKey('blocks.0.settings.format', $exception->errors());
}
}
public function test_featured_cards_lead_with_the_first_card_and_link_the_whole_card(): void
{
$html = $this->publish('/karten', [[
'type' => 'cards', 'v' => 1, 'variant' => 'featured',
'data' => ['items' => [
['title' => 'Erste', 'text' => 'Hervorgehoben', 'url' => '/a', 'image' => 'cms/a.jpg'],
['title' => 'Zweite', 'url' => '/b'],
['title' => 'Dritte'],
]],
]]);
$this->assertStringContainsString('<ul class="cards cards-featured">', $html);
$this->assertMatchesRegularExpression('#<li class="card card-with-image card-linked card-lead">#', $html);
$this->assertSame(1, substr_count($html, 'card-lead'));
$this->assertMatchesRegularExpression('#<h3 class="card-title">\s*<a href="/a">Erste</a>#', $html);
$this->assertMatchesRegularExpression('#<h3 class="card-title">\s*Dritte\s*</h3>#', $html, 'Karten ohne Linkziel bleiben ohne Link.');
}
public function test_unknown_variant_from_a_newer_version_falls_back_to_the_default(): void
{
$widget = app(WidgetRegistry::class)->upcast(['type' => 'cards', 'v' => 1, 'variant' => 'masonry', 'data' => ['items' => [['title' => 'Eins']]]]);
$this->assertSame('standard', $widget['variant']);
}
}