Files
laraundfelix/tests/Feature/CmsBrandSymbolsTest.php
T
LarsandClaude Sonnet 5.5 219962daff
Deploy Test / test (push) Successful in 3m5s
CI Feature / test (push) Successful in 3m5s
Deploy Test / deploy (push) Successful in 27s
Biete Symbole auf redaktionellen Karten und in der FAQ an
Etappe 2 der Angleichung aller Widgets:

- Redaktionelle Karten: je Karte ein optionales Symbol über dem Titel
  (data.items[].symbol, nur Schlüssel aus HeadingAccent::SYMBOLS). Neue
  Einstellungen: Größe der Symbole (dieselben vier Stufen, Vorgabe Mittel) und
  Ausrichtung (links, zentriert, rechts). Der Schlüssel symbol wird nur
  gespeichert, wenn ein Symbol gewählt ist, und die Listenklassen erscheinen
  nur bei Abweichung von der Vorgabe: Karten ohne Symbol bleiben in Daten und
  Ausgabe unverändert.
- FAQ: Symbol neben dem ganzen Block (Größe, senkrechte Ausrichtung), Vorgabe
  Mittel. Die Oberkante der ersten Frage stimmt am gerenderten Bild auf einen
  Bruchteil eines Pixels.
- HeadingAccent::block() und TEXT_ALIGN bündeln Ausrichtung und Größe für
  Inhalte mit Symbol über dem Text; die Merkmalszeile verwendet sie ebenfalls.
- Bewusst ohne Symbol: Themen-, Medien-, Programm- sowie Programm- und
  Modulkarten. Ihr Inhalt kommt aus Katalogobjekten, Medienkarten tragen den
  Material-Tag.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-24 09:28:15 +01:00

334 lines
22 KiB
PHP

<?php
namespace Tests\Feature;
use App\Domain\Cms\Page;
use App\Domain\Cms\PageService;
use App\Domain\Cms\Widgets\Types\FeaturesWidget;
use App\Domain\Cms\Widgets\WidgetRegistry;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Validation\ValidationException;
use Tests\TestCase;
/**
* Kleingrafiken des Brand-Kits im Redaktionsinhalt: Symbol vor der Überschrift (Überschrift, Einstieg, Bild und Text,
* Handlungsaufruf), Pinselstrich unter der Überschrift und die Merkmalszeile.
*/
class CmsBrandSymbolsTest extends TestCase
{
use RefreshDatabase;
/**
* @param array<string, mixed> $widget
* @return array<string, mixed>
*/
private function widget(string $type, array $data, array $settings = [], string $variant = 'standard'): array
{
$registry = app(WidgetRegistry::class);
return ['type' => $type, 'v' => $registry->get($type)->version(), 'variant' => $variant, 'settings' => $settings, 'data' => $data];
}
/**
* @param array<string, mixed> $widget
*/
private function publish(string $path, array $widget, string $layout = 'u4'): string
{
$page = Page::query()->create(['path' => $path]);
$service = app(PageService::class);
$content = [['type' => 'heading', 'v' => 1, 'data' => ['heading' => 'Seite']], ['layout' => $layout, 'style' => [], 'slots' => [$widget]]];
$service->publish($page, $service->saveRevision($page, $content, null, null, null));
return $this->get($path)->assertOk()->getContent();
}
public function test_a_heading_shows_its_symbol_inside_the_heading_and_the_brush_below(): void
{
$html = $this->publish('/symbol', $this->widget('heading', ['heading' => 'Filme', 'intro' => 'Kurz erklärt'], ['symbol' => 'filmklappe', 'accent' => 'brush']));
$this->assertMatchesRegularExpression('~<h2><svg[^>]*aria-hidden="true"[^>]*class="brand-symbol lf-heading-symbol"[^>]*>.*?</svg>Filme</h2>~s', $html);
$this->assertMatchesRegularExpression('~<svg[^>]*class="brand-symbol lf-heading-brush"~', $html);
$this->assertStringNotContainsString('motif-title', $html, 'Die Kit-ID darf nie auf der Seite stehen.');
}
public function test_without_settings_the_heading_is_unchanged(): void
{
$html = $this->publish('/ohne', $this->widget('heading', ['heading' => 'Filme']));
$this->assertStringContainsString('<h2>Filme</h2>', $html);
$this->assertStringNotContainsString('lf-heading-symbol', $html);
$this->assertStringNotContainsString('lf-heading-brush', $html);
}
public function test_hero_image_text_and_call_to_action_show_the_symbol_too(): void
{
$hero = $this->publish('/hero', $this->widget('hero', ['heading' => 'Einstieg'], ['symbol' => 'schutzschild'], 'editorial_solid'));
$this->assertMatchesRegularExpression('~class="lf-hero__title"><svg[^>]*lf-heading-symbol~', $hero);
$imageText = $this->publish('/bild-text', $this->widget('image_text', ['title' => 'Ansatz', 'body' => '<p>Text</p>'], ['symbol' => 'buch'], 'image_left'));
$this->assertMatchesRegularExpression('~class="lf-bt__headline"><svg[^>]*lf-heading-symbol~', $imageText);
$cta = $this->publish('/aufruf', $this->widget('call_to_action', ['heading' => 'Jetzt', 'label' => 'Los', 'url' => '/angebote'], ['symbol' => 'paket']));
$this->assertMatchesRegularExpression('~<h2><svg[^>]*lf-heading-symbol~', $cta);
}
public function test_an_image_text_without_a_symbol_keeps_its_exact_headline_markup(): void
{
$html = $this->publish('/bild-text-ohne', $this->widget('image_text', ['title' => 'Geschichten', 'body' => '<p>Text</p>'], [], 'image_left'));
$this->assertStringContainsString('<h2 class="lf-bt__headline">Geschichten</h2>', $html);
}
public function test_unknown_symbols_and_accents_are_rejected_when_saving(): void
{
foreach ([['symbol' => '../../.env'], ['symbol' => 'signalstrahlen'], ['symbol' => 'gelbe-unterstreichung'], ['accent' => 'rays']] as $settings) {
try {
$this->publish('/abgelehnt-'.md5(json_encode($settings)), $this->widget('heading', ['heading' => 'Filme'], $settings));
$this->fail('Angenommen: '.json_encode($settings));
} catch (ValidationException $exception) {
$this->assertStringContainsString('nicht freigegeben', implode(' ', array_merge(...array_values($exception->errors()))));
}
}
}
public function test_the_features_row_renders_symbols_titles_and_text_with_one_column_per_item(): void
{
$items = [
['symbol' => 'filmklappe', 'title' => 'Film', 'text' => 'Kurz erklärt'],
['symbol' => 'uebungsblatt', 'title' => 'Übung', 'text' => null],
['symbol' => 'merkblatt', 'title' => 'Merkblatt', 'text' => 'Zum Mitnehmen'],
];
$html = $this->publish('/merkmale', $this->widget('features', ['items' => $items]));
$this->assertStringContainsString('class="lf-features lf-features--3 lf-features--left lf-features--size-medium"', $html, 'Vorgaben: linksbündig, mittlere Symbole, kein Strich.');
$this->assertStringNotContainsString('lf-features--lines', $html);
$this->assertSame(3, substr_count($html, 'class="lf-features__item"'));
$this->assertSame(3, preg_match_all('~<svg[^>]*aria-hidden="true"[^>]*class="brand-symbol lf-features__symbol"~', $html));
$this->assertStringContainsString('<p class="lf-features__title">Übung</p>', $html);
$this->assertStringContainsString('<p class="lf-features__text">Zum Mitnehmen</p>', $html);
$this->assertSame(2, substr_count($html, 'lf-features__text'), 'Ohne Satz gibt es keinen leeren Absatz.');
$this->assertStringNotContainsString('motif-title', $html);
}
public function test_the_features_row_takes_one_to_twelve_items_with_a_known_symbol(): void
{
$item = fn (string $symbol = 'buch'): array => ['symbol' => $symbol, 'title' => 'Titel', 'text' => null];
foreach ([[], array_fill(0, 13, $item()), [$item(), $item('nicht-vorhanden')], [$item(), ['symbol' => 'buch', 'title' => '', 'text' => null]]] as $index => $items) {
try {
$this->publish('/merkmale-falsch-'.$index, $this->widget('features', ['items' => $items]));
$this->fail("Fall $index wurde angenommen.");
} catch (ValidationException $exception) {
$this->assertNotEmpty($exception->errors(), "Fall $index");
}
}
$this->assertStringContainsString('lf-features--2', $this->publish('/merkmale-zwei', $this->widget('features', ['items' => [$item(), $item('gruppe')]])));
$this->assertStringContainsString('lf-features--1', $this->publish('/merkmale-eins', $this->widget('features', ['items' => [$item()]])));
$this->assertStringContainsString('lf-features--4', $this->publish('/merkmale-vier', $this->widget('features', ['items' => array_fill(0, 4, $item())])));
$zwoelf = $this->publish('/merkmale-zwoelf', $this->widget('features', ['items' => array_fill(0, 12, $item())]));
$this->assertStringContainsString('lf-features--12', $zwoelf);
$this->assertSame(12, substr_count($zwoelf, 'class="lf-features__item"'));
}
public function test_a_symbol_beside_the_paragraph_has_a_size_and_a_vertical_alignment(): void
{
$html = $this->publish('/gross', $this->widget('heading', ['heading' => 'Filme', 'intro' => 'Kurz erklärt'], ['symbol' => 'filmklappe', 'symbol_size' => 'large']));
$this->assertMatchesRegularExpression('~<div class="lf-lead lf-lead--large lf-lead--top"><svg[^>]*class="brand-symbol lf-lead__symbol"[^>]*>.*?</svg><div class="lf-lead__body">\s*<h2>Filme</h2>\s*<p class="lede">Kurz erklärt</p>\s*</div></div>~s', $html);
$this->assertStringNotContainsString('lf-heading-symbol', $html, 'Das kleine Symbol entfällt, sonst stünde es doppelt.');
foreach ([['medium', 'center'], ['xlarge', 'bottom']] as [$size, $align]) {
$this->assertStringContainsString(
'<div class="lf-lead lf-lead--'.$size.' lf-lead--'.$align.'">',
$this->publish("/gross-$size", $this->widget('heading', ['heading' => 'Filme'], ['symbol' => 'buch', 'symbol_size' => $size, 'symbol_align' => $align])),
);
}
$cta = $this->publish('/gross-aufruf', $this->widget('call_to_action', ['heading' => 'Jetzt', 'text' => 'Alles in einem.', 'label' => 'Los', 'url' => '/angebote'], ['symbol' => 'paket', 'symbol_size' => 'large', 'symbol_align' => 'center']));
$this->assertMatchesRegularExpression('~<div class="cta">\s*<div class="lf-lead lf-lead--large lf-lead--center"><svg[^>]*lf-lead__symbol.*?<h2>Jetzt</h2>.*?<a class="button" href="/angebote">Los</a>\s*</div></div>\s*</div>~s', $cta);
}
public function test_an_unknown_alignment_is_rejected_when_saving(): void
{
try {
$this->publish('/ausrichtung-falsch', $this->widget('heading', ['heading' => 'Filme'], ['symbol' => 'buch', 'symbol_size' => 'large', 'symbol_align' => 'diagonal']));
$this->fail('Eine unbekannte Ausrichtung wurde angenommen.');
} catch (ValidationException $exception) {
$this->assertStringContainsString('nicht freigegeben', implode(' ', array_merge(...array_values($exception->errors()))));
}
}
public function test_hero_and_image_text_put_the_symbol_beside_their_whole_text_block(): void
{
$hero = $this->publish('/hero-gross', $this->widget('hero', ['eyebrow' => 'Label', 'heading' => 'Einstieg', 'text' => 'Beschreibung'], ['symbol' => 'schutzschild', 'symbol_size' => 'xlarge', 'symbol_align' => 'bottom'], 'editorial_solid'));
$this->assertMatchesRegularExpression('~<div class="lf-hero__copy">.*?<div class="lf-lead lf-lead--xlarge lf-lead--bottom"><svg[^>]*lf-lead__symbol.*?<div class="lf-lead__body">\s*<p class="lf-hero__eyebrow">Label</p>\s*<h2 class="lf-hero__title">Einstieg</h2>.*?Beschreibung.*?</div></div>~s', $hero);
$this->assertStringNotContainsString('lf-heading-symbol', $hero);
$imageText = $this->publish('/bild-text-gross', $this->widget('image_text', ['title' => 'Ansatz', 'body' => '<p>Text</p>'], ['symbol' => 'buch', 'symbol_size' => 'small', 'symbol_align' => 'center'], 'image_left'));
$this->assertMatchesRegularExpression('~<div class="lf-bt__copy">\s*<div class="lf-lead lf-lead--small lf-lead--center"><svg[^>]*lf-lead__symbol.*?<h2 class="lf-bt__headline">Ansatz</h2>.*?<div class="lf-bt__body"><p>Text</p></div>\s*</div></div>\s*</div>~s', $imageText);
$this->assertStringNotContainsString('lf-heading-symbol', $imageText);
$this->assertStringNotContainsString('lf-lead', $this->publish('/hero-klein', $this->widget('hero', ['heading' => 'Einstieg'], ['symbol' => 'schutzschild'], 'editorial_solid')), 'Ohne Größe bleibt das Symbol klein in der Überschrift.');
}
public function test_the_prose_widget_takes_a_symbol_beside_the_text_with_medium_as_default(): void
{
$plain = $this->publish('/fliesstext-ohne', $this->widget('prose', ['body' => "Erster Absatz.\n\nZweiter Absatz."]));
$this->assertStringNotContainsString('lf-lead', $plain);
$this->assertStringContainsString('<div class="prose">', $plain);
$medium = $this->publish('/fliesstext-symbol', $this->widget('prose', ['body' => 'Text.'], ['symbol' => 'buch']));
$this->assertMatchesRegularExpression('~<div class="lf-lead lf-lead--medium lf-lead--top"><svg[^>]*lf-lead__symbol.*?<div class="lf-lead__body">\s*<div class="prose">\s*<p>Text\.</p>\s*</div>\s*</div></div>~s', $medium);
$this->assertStringContainsString('lf-lead--xlarge lf-lead--center', $this->publish('/fliesstext-gross', $this->widget('prose', ['body' => 'Text.'], ['symbol' => 'buch', 'symbol_size' => 'xlarge', 'symbol_align' => 'center'])));
$this->assertStringNotContainsString('lf-lead', $this->publish('/fliesstext-nur-groesse', $this->widget('prose', ['body' => 'Text.'], ['symbol_size' => 'large'])), 'Ohne Symbol nie ein Absatzlayout.');
}
public function test_editorial_cards_can_carry_a_symbol_with_size_and_alignment(): void
{
$items = [
['title' => 'Mit Symbol', 'text' => 'Text', 'url' => '/a', 'symbol' => 'buch'],
['title' => 'Ohne Symbol', 'text' => null, 'url' => null],
];
$plain = $this->publish('/karten-ohne', $this->widget('cards', ['items' => [['title' => 'Eins', 'text' => null, 'url' => null]]]));
$this->assertStringContainsString('<ul class="cards cards-grid">', $plain, 'Ohne Einstellungen bleibt die Liste unverändert.');
$this->assertStringNotContainsString('lf-card__symbol', $plain);
$html = $this->publish('/karten-symbol', $this->widget('cards', ['items' => $items], ['symbol_size' => 'large', 'align' => 'center']));
$this->assertStringContainsString('<ul class="cards cards-grid cards--center cards--size-large">', $html);
$this->assertSame(1, substr_count($html, 'lf-card__symbol'), 'Nur die Karte mit Symbol zeigt eins.');
$this->assertMatchesRegularExpression('~<div class="card-body">\s*<svg[^>]*aria-hidden="true"[^>]*class="brand-symbol lf-card__symbol"[^>]*>.*?</svg>\s*<h3 class="card-title">\s*<a href="/a">Mit Symbol</a>~s', $html);
$this->assertStringContainsString('<ul class="cards cards-grid cards--right">', $this->publish('/karten-rechts', $this->widget('cards', ['items' => $items], ['align' => 'right'])));
}
public function test_editorial_cards_reject_unknown_symbols_and_layout_values(): void
{
$card = fn (array $extra): array => ['items' => [['title' => 'Karte', 'text' => null, 'url' => null] + $extra]];
foreach ([[$card(['symbol' => '../../.env']), []], [$card(['symbol' => 'signalstrahlen']), []], [$card([]), ['symbol_size' => 'huge']], [$card([]), ['align' => 'justify']]] as $index => [$data, $settings]) {
try {
$this->publish('/karten-falsch-'.$index, $this->widget('cards', $data, $settings));
$this->fail("Fall $index wurde angenommen.");
} catch (ValidationException $exception) {
$this->assertNotEmpty($exception->errors(), "Fall $index");
}
}
}
public function test_the_faq_takes_a_symbol_beside_all_questions(): void
{
$data = ['items' => [['question' => 'Warum?', 'answer' => 'Darum.']]];
$plain = $this->publish('/faq-ohne', $this->widget('faq', $data));
$this->assertStringNotContainsString('lf-lead', $plain);
$this->assertStringContainsString('<dl class="faq">', $plain);
$html = $this->publish('/faq-symbol', $this->widget('faq', $data, ['symbol' => 'sprechblase-fragezeichen']));
$this->assertMatchesRegularExpression('~<div class="lf-lead lf-lead--medium lf-lead--top"><svg[^>]*lf-lead__symbol.*?<div class="lf-lead__body">\s*<dl class="faq">\s*<dt>Warum\?</dt>\s*<dd>Darum\.</dd>\s*</dl>\s*</div></div>~s', $html);
$this->assertStringContainsString('lf-lead--small lf-lead--bottom', $this->publish('/faq-klein', $this->widget('faq', $data, ['symbol' => 'buch', 'symbol_size' => 'small', 'symbol_align' => 'bottom'])));
}
public function test_the_call_to_action_can_underline_its_heading_with_the_brush(): void
{
$html = $this->publish('/aufruf-pinsel', $this->widget('call_to_action', ['heading' => 'Jetzt', 'label' => 'Los', 'url' => '/angebote'], ['accent' => 'brush']));
$this->assertMatchesRegularExpression('~<h2>Jetzt</h2>\s*<svg[^>]*class="brand-symbol lf-heading-brush"~', $html);
$this->assertStringNotContainsString('lf-heading-brush', $this->publish('/aufruf-ohne', $this->widget('call_to_action', ['heading' => 'Jetzt', 'label' => 'Los', 'url' => '/angebote'])));
}
public function test_the_large_size_does_nothing_without_a_symbol_and_is_checked_when_saving(): void
{
$this->assertStringNotContainsString('lf-lead', $this->publish('/gross-ohne', $this->widget('heading', ['heading' => 'Filme'], ['symbol_size' => 'large'])));
$this->assertStringContainsString('<h2>Filme</h2>', $this->publish('/gross-ohne-2', $this->widget('heading', ['heading' => 'Filme'], ['symbol_size' => 'large'])));
try {
$this->publish('/gross-falsch', $this->widget('heading', ['heading' => 'Filme'], ['symbol' => 'buch', 'symbol_size' => 'huge']));
$this->fail('Eine unbekannte Größe wurde angenommen.');
} catch (ValidationException $exception) {
$this->assertStringContainsString('nicht freigegeben', implode(' ', array_merge(...array_values($exception->errors()))));
}
}
public function test_feature_links_are_small_text_by_default_and_a_pill_on_request(): void
{
$items = [
['symbol' => 'filmklappe', 'title' => 'Film', 'text' => null, 'url' => '/materialien', 'link_label' => 'Alle Filme'],
['symbol' => 'buch', 'title' => 'Buch', 'text' => null, 'url' => 'https://example.org/buch', 'link_label' => null],
['symbol' => 'gruppe', 'title' => 'Gruppe', 'text' => null],
];
$text = $this->publish('/links-text', $this->widget('features', ['items' => $items]));
$this->assertStringContainsString('<a class="lf-features__link lf-features__link--text" href="/materialien" aria-label="Alle Filme: Film">Alle Filme</a>', $text);
$this->assertStringContainsString('<a class="lf-features__link lf-features__link--text" href="https://example.org/buch" aria-label="Mehr erfahren: Buch">Mehr erfahren</a>', $text);
$this->assertSame(2, substr_count($text, 'class="lf-features__more"'), 'Ohne Link gibt es keinen leeren Absatz.');
$pill = $this->publish('/links-pille', $this->widget('features', ['items' => $items], ['link_style' => 'pill']));
$this->assertSame(2, substr_count($pill, 'lf-features__link--pill'));
$this->assertStringNotContainsString('lf-features__link--text', $pill);
}
public function test_feature_links_must_be_safe_and_a_label_without_a_link_is_dropped(): void
{
$item = fn (array $extra): array => ['symbol' => 'buch', 'title' => 'Titel', 'text' => null] + $extra;
foreach (['javascript:alert(1)', 'data:text/html,x', '//evil.example'] as $url) {
try {
$this->publish('/link-unsicher-'.md5($url), $this->widget('features', ['items' => [$item(['url' => $url]), $item([])]]));
$this->fail("Die Adresse $url wurde angenommen.");
} catch (ValidationException $exception) {
$this->assertNotEmpty($exception->errors(), $url);
}
}
$html = $this->publish('/link-ohne-ziel', $this->widget('features', ['items' => [$item(['link_label' => 'Versteckt']), $item([])]]));
$this->assertStringNotContainsString('Versteckt', $html);
$this->assertStringNotContainsString('lf-features__link', $html);
try {
$this->publish('/pille-falsch', $this->widget('features', ['items' => [$item([]), $item([])]], ['link_style' => 'button']));
$this->fail('Eine unbekannte Link-Darstellung wurde angenommen.');
} catch (ValidationException $exception) {
$this->assertStringContainsString('nicht freigegeben', implode(' ', array_merge(...array_values($exception->errors()))));
}
}
public function test_the_features_row_takes_alignment_symbol_size_and_divider_from_its_settings(): void
{
$items = [['symbol' => 'buch', 'title' => 'Eins', 'text' => null], ['symbol' => 'gruppe', 'title' => 'Zwei', 'text' => null]];
$html = $this->publish('/merkmale-layout', $this->widget('features', ['items' => $items], ['align' => 'center', 'symbol_size' => 'xlarge', 'divider' => 'line']));
$this->assertStringContainsString('class="lf-features lf-features--2 lf-features--center lf-features--size-xlarge lf-features--lines"', $html);
$right = $this->publish('/merkmale-rechts', $this->widget('features', ['items' => $items], ['align' => 'right', 'symbol_size' => 'small']));
$this->assertStringContainsString('class="lf-features lf-features--2 lf-features--right lf-features--size-small"', $right);
$this->assertStringNotContainsString('lf-features--lines', $right);
}
public function test_unknown_layout_values_of_the_features_row_are_rejected_and_fall_back_to_the_defaults(): void
{
foreach ([['align' => 'justify'], ['symbol_size' => 'huge'], ['divider' => 'double']] as $index => $settings) {
try {
$this->publish('/merkmale-layout-falsch-'.$index, $this->widget('features', ['items' => [['symbol' => 'buch', 'title' => 'Eins', 'text' => null], ['symbol' => 'buch', 'title' => 'Zwei', 'text' => null]]], $settings));
$this->fail('Angenommen: '.json_encode($settings));
} catch (ValidationException $exception) {
$this->assertStringContainsString('nicht freigegeben', implode(' ', array_merge(...array_values($exception->errors()))));
}
}
// Schon gespeicherte, später ungültig gewordene Werte dürfen die Ausgabe nicht brechen.
$this->assertSame(['align' => 'left', 'size' => 'medium', 'divider' => false], FeaturesWidget::layout(['align' => ['x'], 'symbol_size' => 'huge', 'divider' => 'double']));
$this->assertSame(['align' => 'right', 'size' => 'large', 'divider' => true], FeaturesWidget::layout(['align' => 'right', 'symbol_size' => 'large', 'divider' => 'line']));
}
public function test_the_features_row_fits_every_slot_width(): void
{
foreach ([1, 2, 3, 4] as $units) {
$this->assertTrue(app(WidgetRegistry::class)->get('features')->supportsUnits($units), "$units Einheiten");
}
}
}