CI Feature / test (push) Successful in 2m40s
Die Kleingrafiken des Brand-Kits sind jetzt im Redaktionsinhalt wählbar, nicht nur an Medienkarten: - Einstellung "Symbol vor der Überschrift" (settings.symbol) an Überschrift, Einstieg, Bild und Text und Handlungsaufruf. Feste Auswahl von 14 Symbolen (HeadingAccent::SYMBOLS), ein unbekannter Name wird beim Speichern abgewiesen. - Einstellung "Pinselstrich" (settings.accent = brush) am Widget Überschrift. - Neues Widget "Merkmalszeile" (features): zwei bis vier Merkmale mit Symbol, Kurztitel und Satz; die Anzahl bestimmt die Spalten. - Auf dunklen Flächen stehen die Symbole auf einer weißen Scheibe, weil sie feste Markenfarben mit viel Navy haben. - brand/symbol erzeugt keine Zeilenumbrüche mehr um das SVG, damit es im Fließtext und in Überschriften keine zusätzliche Lücke gibt. Der Test der Widget-Reihenfolge kennt das neue Widget bewusst (features nach cards). Stufe 3b (Symbole mitten im Fließtext) bleibt zurückgestellt. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
134 lines
6.9 KiB
PHP
134 lines
6.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
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;
|
|
|
|
/**
|
|
* 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"', $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_needs_two_to_four_items_with_a_known_symbol(): void
|
|
{
|
|
$item = fn (string $symbol = 'buch'): array => ['symbol' => $symbol, 'title' => 'Titel', 'text' => null];
|
|
|
|
foreach ([[$item()], array_fill(0, 5, $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--4', $this->publish('/merkmale-vier', $this->widget('features', ['items' => array_fill(0, 4, $item())])));
|
|
}
|
|
|
|
public function test_the_features_row_is_not_offered_in_a_single_unit_slot(): void
|
|
{
|
|
$this->assertFalse(app(WidgetRegistry::class)->get('features')->supportsUnits(1));
|
|
$this->assertTrue(app(WidgetRegistry::class)->get('features')->supportsUnits(2));
|
|
}
|
|
}
|