$data * @param array $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 */ 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 & nicht fett"], ['title' => 'Zwei', 'text' => null], ['title' => 'Drei'], ]]]); $this->assertSame(2, $widget['v']); $this->assertSame('

Erste Zeile
zweite Zeile

Neuer Absatz & <b>nicht fett</b>

', $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' => '

Ein fetter Satz.

Mitte

'], ['title' => 'Leer', 'text' => '

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

Ein fetter Satz.

Mitte

  • Punkt

', $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('~

Thema

\s*

\s*Mit~', $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' => '

Text

', 'symbol' => 'buch'])); $this->assertStringContainsString('
    ', $html); $this->assertStringNotContainsString('card-row', $html); $this->assertStringNotContainsString('card-eyebrow', $html); $this->assertStringNotContainsString('lf-card__brush', $html); $this->assertMatchesRegularExpression('~
    \s*]*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('
      ', $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' => '

      Text

      ', 'symbol' => 'buch', 'url' => '/a'], ['title' => 'Ohne', 'url' => '/b'], ]]; $html = $this->publish('/karten-links', $items, ['symbol_position' => 'left', 'symbol_align' => 'center']); $this->assertStringContainsString('
        ', $html); $this->assertSame(1, substr_count($html, 'card-row'), 'Nur die Karte mit Symbol hat eine Zeile.'); $this->assertMatchesRegularExpression('~
        \s*]*lf-card__symbol[^>]*>.*?\s*
        \s*

        Thema

        \s*

        .*?

        Text

        \s*

        \s*
        \s*
    \s*~s', $html); $unaligned = $this->publish('/karten-links-oben', $items, ['symbol_position' => 'right']); $this->assertStringContainsString('
      ', $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_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('~

\s*]*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']); $this->assertSame(['align' => 'left', 'size' => 'medium', 'position' => 'top', 'valign' => 'top', 'distribution' => 'grow', 'divider' => false, 'brush' => false, 'hover' => false], $layout); } public function test_unknown_values_are_rejected_when_saving(): void { foreach ([['distribution' => 'wild'], ['symbol_position' => 'unten'], ['symbol_align' => 'mitte'], ['hover' => 'zoom']] 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()); } }