Einstellung link_style (Textlink oder Pille) und je Karte ein Linktext (leer: "Mehr erfahren", nur mit Linkziel gespeichert). Der Link trägt den gestreckten Link über die ganze Karte, der Titel ist dann kein eigener Link; ohne Einstellung bleibt alles wie zuvor. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
240 lines
13 KiB
PHP
240 lines
13 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],
|
|
['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']);
|
|
|
|
$this->assertSame(['align' => 'left', 'size' => 'medium', 'position' => 'top', 'valign' => 'top', 'distribution' => 'grow', 'divider' => false, 'brush' => false, 'hover' => false, 'link' => null], $layout);
|
|
}
|
|
|
|
public function test_unknown_values_are_rejected_when_saving(): void
|
|
{
|
|
foreach ([['distribution' => 'wild'], ['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);
|
|
// Beide Verteilungen behalten gleich breite Spalten, damit die Trennstriche in der Mitte der Lücke liegen.
|
|
$this->assertStringNotContainsString('justify-content: space-between', substr($css, (int) strpos($css, 'Redaktionelle Karten: Dachzeile')));
|
|
$this->assertStringContainsString(':is(.widget-prose, .widget-heading, .widget-cards) .prose p', $css);
|
|
$this->assertStringContainsString('prefers-reduced-motion', substr($css, (int) strpos($css, '.cards--hover .card {')));
|
|
}
|
|
|
|
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());
|
|
}
|
|
}
|