CI Feature / test (push) Successful in 5m6s
Die Verteilung erhält "Blocksatz" und "Linksbündig"; "Abstände gleichen aus" heißt jetzt "Zentriert" und bleibt in der Darstellung unverändert. Neu ist der Abstand zwischen den Karten (auch null), ADR-73. Test bewusst geändert: Das Verbot von space-between in CmsEditorialCardsTest sollte die Trennstriche in der Mitte der Lücke halten. space-between gilt nun nur für Blocksatz ohne Trennstrich; das prüft der Test. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
353 lines
19 KiB
PHP
353 lines
19 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Domain\Cms\Page;
|
|
use App\Domain\Cms\PageService;
|
|
use App\Domain\Cms\Widgets\Types\CardsWidget;
|
|
use App\Domain\Cms\Widgets\WidgetErrors;
|
|
use App\Domain\Cms\Widgets\WidgetRegistry;
|
|
use Filament\Forms\Components\Repeater;
|
|
use Filament\Forms\Components\RichEditor;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Validation\ValidationException;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Redaktionelle Karten, Version 2: Beschreibung als formatierter Text, Dachzeile, Verteilung, Lage und senkrechte Ausrichtung
|
|
* des Symbols, Pinselstrich, Trennstrich und Hervorhebung. Die bisherigen Einstellungen und die Ausgabe ohne neue
|
|
* Einstellungen bleiben unverändert.
|
|
*/
|
|
class CmsEditorialCardsTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
/**
|
|
* @param array<string, mixed> $data
|
|
* @param array<string, mixed> $settings
|
|
*/
|
|
private function publish(string $path, array $data, array $settings = [], string $variant = 'standard', int $version = 2): string
|
|
{
|
|
$page = Page::query()->create(['path' => $path]);
|
|
$service = app(PageService::class);
|
|
$sections = [['layout' => 'u4', 'style' => [], 'slots' => [['type' => 'cards', 'v' => $version, 'variant' => $variant, 'settings' => $settings, 'data' => $data]]]];
|
|
$service->publish($page, $service->saveRevision($page, $sections, null, null, null));
|
|
|
|
return $this->get($path)->assertOk()->getContent();
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
private function card(array $extra = []): array
|
|
{
|
|
return ['items' => [['title' => 'Karte', 'url' => '/a'] + $extra]];
|
|
}
|
|
|
|
public function test_version_one_texts_are_lifted_to_formatted_text_with_paragraphs_and_line_breaks(): void
|
|
{
|
|
$widget = app(WidgetRegistry::class)->upcast(['type' => 'cards', 'v' => 1, 'variant' => 'standard', 'data' => ['items' => [
|
|
['title' => 'Eins', 'text' => "Erste Zeile\nzweite Zeile\n\nNeuer Absatz & <b>nicht fett</b>"],
|
|
['title' => 'Zwei', 'text' => null],
|
|
['title' => 'Drei'],
|
|
]]]);
|
|
|
|
$this->assertSame(2, $widget['v']);
|
|
$this->assertSame('<p>Erste Zeile<br>zweite Zeile</p><p>Neuer Absatz & <b>nicht fett</b></p>', $widget['data']['items'][0]['text']);
|
|
$this->assertNull($widget['data']['items'][1]['text']);
|
|
$this->assertArrayNotHasKey('text', $widget['data']['items'][2]);
|
|
}
|
|
|
|
public function test_the_description_is_rendered_as_formatted_text_and_empty_ones_are_dropped(): void
|
|
{
|
|
$html = $this->publish('/karten-text', ['items' => [
|
|
['title' => 'Mit Text', 'text' => '<p>Ein <strong>fetter</strong> Satz.</p><p style="text-align: center">Mitte</p><ul><li>Punkt</li></ul>'],
|
|
['title' => 'Leer', 'text' => '<p></p>'],
|
|
]]);
|
|
|
|
$this->assertStringContainsString('<div class="prose card-text"><p>Ein <strong>fetter</strong> Satz.</p><p class="ta-center">Mitte</p><ul><li><p>Punkt</p></li></ul></div>', $html);
|
|
$this->assertSame(1, substr_count($html, 'card-text'), 'Eine leere Beschreibung erzeugt keinen Block.');
|
|
}
|
|
|
|
public function test_the_description_field_is_the_website_editor_and_the_eyebrow_a_short_text_field(): void
|
|
{
|
|
$fields = app(WidgetRegistry::class)->get('cards')->dataFields();
|
|
$repeater = $fields[0];
|
|
$this->assertInstanceOf(Repeater::class, $repeater);
|
|
|
|
$children = collect($repeater->getDefaultChildComponents())->keyBy(fn ($field) => $field->getName());
|
|
$this->assertInstanceOf(RichEditor::class, $children['text']);
|
|
$this->assertSame(['eyebrow', 'title', 'symbol', 'text', 'url'], $children->keys()->take(5)->all());
|
|
}
|
|
|
|
public function test_the_eyebrow_stands_above_the_title_and_is_only_stored_when_filled(): void
|
|
{
|
|
$html = $this->publish('/karten-dachzeile', ['items' => [
|
|
['title' => 'Mit', 'eyebrow' => ' Thema ', 'url' => '/a'],
|
|
['title' => 'Ohne', 'eyebrow' => ' ', 'url' => '/b'],
|
|
]]);
|
|
|
|
$this->assertMatchesRegularExpression('~<p class="card-eyebrow">Thema</p>\s*<h3 class="card-title">\s*<a href="/a">Mit</a>~', $html);
|
|
$this->assertSame(1, substr_count($html, 'card-eyebrow'));
|
|
|
|
[$clean] = app(WidgetRegistry::class)->get('cards')->clean(['items' => [['title' => 'Ohne', 'eyebrow' => '', 'text' => '', 'url' => '']]], [], new WidgetErrors);
|
|
$this->assertSame(['title' => 'Ohne', 'text' => null, 'url' => null, 'image' => null], $clean['items'][0]);
|
|
}
|
|
|
|
public function test_without_new_settings_the_list_markup_is_unchanged(): void
|
|
{
|
|
$html = $this->publish('/karten-vorgabe', $this->card(['text' => '<p>Text</p>', 'symbol' => 'buch']));
|
|
|
|
$this->assertStringContainsString('<ul class="cards cards-grid">', $html);
|
|
$this->assertStringNotContainsString('card-row', $html);
|
|
$this->assertStringNotContainsString('card-eyebrow', $html);
|
|
$this->assertStringNotContainsString('lf-card__brush', $html);
|
|
$this->assertMatchesRegularExpression('~<div class="card-body">\s*<svg[^>]*class="brand-symbol lf-card__symbol"~s', $html);
|
|
}
|
|
|
|
public function test_each_new_setting_adds_its_class_only_when_it_deviates_from_the_default(): void
|
|
{
|
|
$cases = [
|
|
['distribution' => 'space', 'cards--spaced'],
|
|
['distribution' => 'grow', null],
|
|
['distribution' => 'between', 'cards--between'],
|
|
['distribution' => 'left', 'cards--start'],
|
|
['gap' => 'none', 'cards--gap-none'],
|
|
['gap' => 'xl', 'cards--gap-xl'],
|
|
['divider' => 'line', 'cards--lines'],
|
|
['hover' => 'lift', 'cards--hover'],
|
|
['symbol_position' => 'left', 'cards--symbol-left'],
|
|
['symbol_position' => 'right', 'cards--symbol-right'],
|
|
['symbol_position' => 'top', null],
|
|
];
|
|
|
|
foreach ($cases as $index => $case) {
|
|
$class = array_pop($case);
|
|
$html = $this->publish('/karten-einstellung-'.$index, $this->card(['symbol' => 'buch']), $case);
|
|
|
|
if ($class === null) {
|
|
$this->assertStringContainsString('<ul class="cards cards-grid">', $html, json_encode($case));
|
|
} else {
|
|
$this->assertStringContainsString($class, $html, json_encode($case));
|
|
}
|
|
}
|
|
}
|
|
|
|
public function test_the_symbol_beside_the_text_wraps_symbol_and_text_in_a_row_and_aligns_vertically(): void
|
|
{
|
|
$items = ['items' => [
|
|
['title' => 'Mit', 'eyebrow' => 'Thema', 'text' => '<p>Text</p>', 'symbol' => 'buch', 'url' => '/a'],
|
|
['title' => 'Ohne', 'url' => '/b'],
|
|
]];
|
|
|
|
$html = $this->publish('/karten-links', $items, ['symbol_position' => 'left', 'symbol_align' => 'center']);
|
|
$this->assertStringContainsString('<ul class="cards cards-grid cards--symbol-left cards--symbol-v-center">', $html);
|
|
$this->assertSame(1, substr_count($html, 'card-row'), 'Nur die Karte mit Symbol hat eine Zeile.');
|
|
$this->assertMatchesRegularExpression('~<div class="card-row">\s*<svg[^>]*lf-card__symbol[^>]*>.*?</svg>\s*<div class="card-main">\s*<p class="card-eyebrow">Thema</p>\s*<h3 class="card-title">.*?<div class="prose card-text"><p>Text</p></div>\s*</div>\s*</div>\s*</div>\s*</li>~s', $html);
|
|
|
|
$unaligned = $this->publish('/karten-links-oben', $items, ['symbol_position' => 'right']);
|
|
$this->assertStringContainsString('<ul class="cards cards-grid cards--symbol-right">', $unaligned, 'Oben ist die Vorgabe und braucht keine Klasse.');
|
|
|
|
$above = $this->publish('/karten-oben-mittig', $items, ['symbol_align' => 'center']);
|
|
$this->assertStringNotContainsString('symbol-v-', $above, 'Die senkrechte Lage wirkt nur neben dem Text.');
|
|
}
|
|
|
|
public function test_a_visible_link_below_the_text_replaces_the_title_link_as_the_card_link(): void
|
|
{
|
|
$data = ['items' => [
|
|
['title' => 'Mit Link', 'text' => '<p>Text</p>', 'url' => '/a', 'link_label' => 'Zum Angebot'],
|
|
['title' => 'Standardtext', 'url' => '/b'],
|
|
['title' => 'Ohne Ziel', 'link_label' => 'Verwaist'],
|
|
]];
|
|
|
|
$text = $this->publish('/karten-link-text', $data, ['link_style' => 'text']);
|
|
$this->assertStringContainsString('<p class="card-more"><a class="card-link card-link--text" href="/a" aria-label="Zum Angebot: Mit Link">Zum Angebot</a></p>', $text);
|
|
$this->assertStringContainsString('aria-label="Mehr erfahren: Standardtext">Mehr erfahren</a>', $text);
|
|
$this->assertSame(2, substr_count($text, 'card-more'), 'Eine Karte ohne Linkziel zeigt keinen Link.');
|
|
$this->assertStringNotContainsString('Verwaist', $text, 'Ein Linktext ohne Linkziel wird verworfen.');
|
|
$this->assertDoesNotMatchRegularExpression('~<h3 class="card-title">\s*<a~', $text, 'Der Titel ist dann kein eigener Link.');
|
|
|
|
$this->assertStringContainsString('card-link card-link--pill', $this->publish('/karten-link-pille', $data, ['link_style' => 'pill']));
|
|
|
|
$without = $this->publish('/karten-link-ohne', $data);
|
|
$this->assertStringNotContainsString('card-more', $without);
|
|
$this->assertMatchesRegularExpression('~<h3 class="card-title">\s*<a href="/a">Mit Link</a>~', $without, 'Ohne Einstellung bleibt der Titel der Link der Karte.');
|
|
}
|
|
|
|
public function test_the_brush_stands_under_each_title(): void
|
|
{
|
|
$html = $this->publish('/karten-pinsel', ['items' => [['title' => 'Eins', 'url' => '/a'], ['title' => 'Zwei', 'url' => '/b']]], ['accent' => 'brush']);
|
|
|
|
$this->assertSame(2, substr_count($html, 'lf-card__brush'));
|
|
$this->assertMatchesRegularExpression('~</h3>\s*<svg[^>]*lf-heading-brush lf-card__brush~', $html);
|
|
}
|
|
|
|
public function test_the_divider_is_not_offered_to_the_compact_list(): void
|
|
{
|
|
$data = ['items' => [['title' => 'Eins'], ['title' => 'Zwei']]];
|
|
|
|
$this->assertStringContainsString('cards--lines', $this->publish('/karten-linien', $data, ['divider' => 'line']));
|
|
$this->assertStringNotContainsString('cards--lines', $this->publish('/karten-linien-liste', $data, ['divider' => 'line'], 'compact'));
|
|
}
|
|
|
|
public function test_the_layout_ignores_invalid_values(): void
|
|
{
|
|
$layout = CardsWidget::layout(['distribution' => 'wild', 'symbol_position' => 'oben', 'symbol_align' => 'mitte', 'divider' => 'dick', 'hover' => 'zoom', 'accent' => 'bunt', 'link_style' => 'knopf', 'gap' => '3px']);
|
|
|
|
$this->assertSame(['align' => 'left', 'size' => 'medium', 'position' => 'top', 'valign' => 'top', 'distribution' => 'grow', 'gap' => null, 'divider' => false, 'brush' => false, 'hover' => false, 'link' => null], $layout);
|
|
}
|
|
|
|
public function test_the_compact_list_keeps_its_lines_without_flow_and_gap_classes(): void
|
|
{
|
|
$html = $this->publish('/karten-liste-abstand', $this->card(), ['distribution' => 'left', 'gap' => 'l'], 'compact');
|
|
|
|
$this->assertStringContainsString('<ul class="cards cards-compact">', $html);
|
|
}
|
|
|
|
public function test_the_gap_applies_to_every_distribution_and_the_featured_variant(): void
|
|
{
|
|
foreach (['grow', 'space', 'between', 'left'] as $distribution) {
|
|
$html = $this->publish('/karten-abstand-'.$distribution, $this->card(), ['distribution' => $distribution, 'gap' => 's'], 'featured');
|
|
|
|
$this->assertMatchesRegularExpression('~<ul class="cards cards-featured[^"]*cards--gap-s~', $html, $distribution);
|
|
}
|
|
|
|
$this->assertSame(['distribution', 'gap', 'align'], app(WidgetRegistry::class)->get('cards')->settingGroups()['Verteilung']);
|
|
}
|
|
|
|
public function test_unknown_values_are_rejected_when_saving(): void
|
|
{
|
|
foreach ([['distribution' => 'wild'], ['gap' => 'riesig'], ['symbol_position' => 'unten'], ['symbol_align' => 'mitte'], ['hover' => 'zoom'], ['link_style' => 'knopf']] as $index => $settings) {
|
|
try {
|
|
$this->publish('/karten-falsch-'.$index, $this->card(), $settings);
|
|
$this->fail("Fall $index wurde angenommen.");
|
|
} catch (ValidationException $exception) {
|
|
$this->assertNotEmpty($exception->errors(), "Fall $index");
|
|
}
|
|
}
|
|
}
|
|
|
|
public function test_the_stylesheet_keeps_links_clickable_and_colors_readable_on_light_cards(): void
|
|
{
|
|
$css = (string) file_get_contents(resource_path('css/widgets.css'));
|
|
|
|
// Der gestreckte Titellink legt sich über die Karte; Links in der Beschreibung müssen darüber liegen.
|
|
$this->assertMatchesRegularExpression('/\.card \.prose a \{\s*position: relative;\s*z-index: 1;/', $css);
|
|
// Die Karte bleibt auf dunklen und grünen Abschnitten hell; die aufgehellten Textfarben dürfen dort nicht gelten.
|
|
$this->assertMatchesRegularExpression('/\.cards:not\(\.cards-compact, \.cards--lines\) \.card \.prose \{\s*--tc-marine: var\(--lf-navy\);/', $css);
|
|
// Mit Trennstrich bleiben die Karten gleich breite Spalten, damit die Striche in der Mitte der Lücke liegen: Die
|
|
// freie Verteilung (zentriert, Blocksatz) gilt nur ohne Trennstrich.
|
|
$this->assertSame(1, substr_count($css, 'justify-content: space-between;'."\n}\n\n:is(.cards--spaced, .cards--between):not(.cards--lines)"));
|
|
$this->assertMatchesRegularExpression('/\.cards--between:not\(\.cards--lines\) \{\s*justify-content: space-between;/', $css);
|
|
$this->assertStringContainsString('inset-inline-start: calc(var(--cards-gap) / -2);', $css);
|
|
$this->assertStringContainsString('.cards.cards--lines:is(.cards--gap-none, .cards--gap-xs)', $css);
|
|
$this->assertStringContainsString(':is(.widget-prose, .widget-heading, .widget-cards, .widget-notice) .prose p', $css);
|
|
$this->assertStringContainsString('prefers-reduced-motion', substr($css, (int) strpos($css, '.cards--hover .card {')));
|
|
}
|
|
|
|
/**
|
|
* Wertet die erzeugte Tabelle (lf-karten-verteilung.css) wie der Browser aus: je Zahl der Karten, Breite des Platzes (rem)
|
|
* und Karte die Zahl der Karten in ihrer Zeile. Spätere Regeln gewinnen bei gleicher Spezifität; die Tabelle für Symbole
|
|
* neben dem Text hat die höhere.
|
|
*
|
|
* @return array<int, int> Karte (1-basiert, ohne die hervorgehobene erste) => Karten in ihrer Zeile
|
|
*/
|
|
private function rowSizes(string $css, int $cards, float $width, bool $side, bool $featured): array
|
|
{
|
|
$current = [];
|
|
$threshold = 0.0;
|
|
|
|
foreach (preg_split('/\R/', $css) as $line) {
|
|
if (preg_match('/^@container slot \(min-width: ([\d.]+)rem\)/', $line, $match)) {
|
|
$threshold = (float) $match[1];
|
|
|
|
continue;
|
|
}
|
|
|
|
if (str_starts_with($line, '}')) {
|
|
$threshold = 0.0;
|
|
|
|
continue;
|
|
}
|
|
|
|
if (! preg_match('/^\s*(\.cards[^{]*?) > \.card:nth-child\(n\+(\d+)\) \{ --cards-c: (\d+); \}$/', $line, $match) || $threshold > $width) {
|
|
continue;
|
|
}
|
|
|
|
[, $selector, $from, $value] = $match;
|
|
$isSide = str_contains($selector, 'cards--symbol-left');
|
|
$isFeatured = str_contains($selector, '.cards.cards-featured');
|
|
|
|
if ($isFeatured !== $featured || ($isSide && ! $side) || ! str_contains($selector, ':nth-child('.($cards + ($featured ? 1 : 0)).')):not(')) {
|
|
continue;
|
|
}
|
|
|
|
for ($child = (int) $from; $child <= $cards + ($featured ? 1 : 0); $child++) {
|
|
$card = $child - ($featured ? 1 : 0);
|
|
if ($card >= 1 && (($current[$card]['side'] ?? false) <= $isSide)) {
|
|
$current[$card] = ['side' => $isSide, 'value' => (int) $value];
|
|
}
|
|
}
|
|
}
|
|
|
|
return array_map(fn (array $entry): int => $entry['value'], $current);
|
|
}
|
|
|
|
public function test_the_balance_table_gives_even_rows_for_one_to_twelve_cards_at_every_width(): void
|
|
{
|
|
$css = (string) file_get_contents(resource_path('css/components/lf-karten-verteilung.css'));
|
|
|
|
foreach ([false, true] as $featured) {
|
|
foreach ([false, true] as $side) {
|
|
$minimum = $side ? 18.0 : 15.0;
|
|
|
|
foreach ([20.0, 31.75, 36.0, 40.0, 48.5, 57.5, 65.25, 70.0, 77.25, 82.0, 98.75, 120.0] as $width) {
|
|
$columns = max(1, min(6, (int) floor(($width + 1.75) / ($minimum + 1.75))));
|
|
|
|
foreach (range(2, 12) as $cards) {
|
|
$rows = (int) ceil($cards / $columns);
|
|
$base = intdiv($cards, $rows);
|
|
$extra = $cards % $rows;
|
|
$expected = array_merge(array_fill(0, $extra * ($base + 1), $base + 1), array_fill(0, $cards - $extra * ($base + 1), $base));
|
|
|
|
$sizes = $this->rowSizes($css, $cards, $width, $side, $featured);
|
|
// Fehlende Karten: keine Regel gilt, also eine Karte je Zeile (Vorgabe --cards-c: 1).
|
|
$actual = array_map(fn (int $card): int => $sizes[$card] ?? 1, range(1, $cards));
|
|
|
|
$this->assertSame(array_values($expected), $actual, sprintf('%d Karten, Platz %srem, Symbol neben dem Text: %s, hervorgehoben: %s', $cards, $width, $side ? 'ja' : 'nein', $featured ? 'ja' : 'nein'));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function test_the_cards_wrap_at_the_minimum_width_and_stay_in_flex_rows(): void
|
|
{
|
|
$css = (string) file_get_contents(resource_path('css/widgets.css'));
|
|
|
|
$this->assertStringContainsString('min-inline-size: min(var(--card-min), 100%);', $css);
|
|
$this->assertStringContainsString('--card-min: 15rem;', $css);
|
|
$this->assertStringContainsString('--card-min: 18rem;', $css);
|
|
$this->assertMatchesRegularExpression('/\.cards-grid,\s*\.cards-featured \{[^}]*display: flex;[^}]*flex-wrap: wrap;/s', $css);
|
|
$this->assertStringContainsString("@import './components/lf-karten-verteilung.css';", (string) file_get_contents(resource_path('css/app.css')));
|
|
}
|
|
|
|
public function test_the_symbol_field_survives_duplicating_a_card(): void
|
|
{
|
|
// Beim Duplizieren wertet das Feld die Vorschau aus, bevor die Vorlage als Referenz bereitsteht (Skriptfehler
|
|
// „Cannot read properties of undefined (reading 'innerHTML')“). Der Zugriff darf deshalb nicht auf $refs.start allein beruhen.
|
|
$view = (string) file_get_contents(resource_path('views/filament/cms/symbol-feld.blade.php'));
|
|
|
|
$this->assertStringNotContainsString('this.$refs.start.innerHTML', $view);
|
|
$this->assertStringContainsString("this.\$root.querySelector('template')", $view);
|
|
}
|
|
|
|
public function test_the_summary_and_media_paths_are_unchanged(): void
|
|
{
|
|
$type = app(WidgetRegistry::class)->get('cards');
|
|
|
|
$this->assertSame('2 Karten: Eins, Zwei', $type->summary(['data' => ['items' => [['title' => 'Eins'], ['title' => 'Zwei']]]]));
|
|
$this->assertSame(2, $type->version());
|
|
}
|
|
}
|