Füge die zentrale Farbpalette und die Hintergrundbreite für Abschnitte hinzu (ADR-67)
- DesignPalette: bis zu zehn benannte Farben (Hintergrund und Schrift) in site_settings, stabile Kennungen, Kontrastprüfung 4,5:1 auf dem Server, Verwendungssuche - Seite Website → Design → Farben (Systemverwalter): Kacheln, Dialog mit Live-Vorschau, Kontrastwarnung mit Empfehlung, Bestätigung mit betroffenen Seiten, Entfernen gesperrt bei Verwendung - Hintergrund „Farbe aus der Palette“ als Verweis im bestehenden Feld background; farbige Kacheln im Editor - Renderer leitet Bedeutungswerte aus Hintergrund und Schrift ab; scope-dark bei heller Schrift - Hintergrundbreite: volle Browserbreite (Vorgabe) oder auf Abschnittsbreite begrenzt - Test sichert die Ausgabe aller bisherigen Varianten byte-gleich; Abnahme mit Screenshots Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
62f3a33541
commit
87de5a62d4
41 files changed
+2372
-14
No files matched your search
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Cms\Page;
|
||||
use App\Domain\Cms\PageService;
|
||||
use App\Jobs\PublishPublicMedia;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Schutz bestehender Seiten (ADR-67): Die Ausgabe aller bisherigen Gestaltungsvarianten (Flächen, Bilder mit Überlagerung
|
||||
* und Fokus, Breiten, Abstände, Trenner, Kartenoptionen) bleibt Byte für Byte gleich. Die Farbpalette und die
|
||||
* Hintergrundbreite dürfen daran nichts ändern, solange ein Abschnitt sie nicht ausdrücklich verwendet.
|
||||
*
|
||||
* Die Vorlage tests/Fixtures/section-legacy-render.html wurde vor der Erweiterung aus dem damaligen Stand erzeugt.
|
||||
* Neu erzeugen nur bewusst und mit Begründung: UPDATE_SNAPSHOT=1 php artisan test --filter=CmsSectionLegacyRenderTest
|
||||
*/
|
||||
class CmsSectionLegacyRenderTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private const FIXTURE = __DIR__.'/../Fixtures/section-legacy-render.html';
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function prose(string $text): array
|
||||
{
|
||||
return ['type' => 'prose', 'v' => 1, 'data' => ['body' => $text]];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function heading(string $text): array
|
||||
{
|
||||
return ['type' => 'heading', 'v' => 1, 'data' => ['heading' => $text]];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
private function matrix(): array
|
||||
{
|
||||
$sections = [];
|
||||
|
||||
foreach (['default' => ['narrow', 'standard', 'wide', 'full'], 'light' => ['wide'], 'dark' => ['narrow', 'standard', 'wide', 'full'], 'accent' => ['wide']] as $background => $widths) {
|
||||
foreach ($widths as $width) {
|
||||
$sections[] = [
|
||||
'layout' => 'u2_2',
|
||||
'style' => ['background' => $background, 'width' => $width],
|
||||
'slots' => [$this->heading("$background $width"), $this->prose("Text $background $width")],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
foreach (['light', 'dark', 'none'] as $overlay) {
|
||||
foreach (['center', 'top_left'] as $focus) {
|
||||
$sections[] = [
|
||||
'layout' => 'u4',
|
||||
'style' => ['background' => 'image', 'image' => 'cms/flaeche.jpg', 'focus' => $focus, 'overlay' => $overlay],
|
||||
'slots' => [$this->prose("Bild $overlay $focus")],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
foreach (['none', 'compact', 'normal', 'large'] as $spacing) {
|
||||
$sections[] = [
|
||||
'layout' => 'u1_3',
|
||||
'style' => ['background' => 'light', 'spacing_top' => $spacing, 'spacing_bottom' => $spacing, 'gap' => $spacing, 'divider' => 'line'],
|
||||
'slots' => [$this->prose("Abstand $spacing"), $this->prose('Rechts')],
|
||||
];
|
||||
}
|
||||
|
||||
$sections[] = ['layout' => 'u4', 'style' => ['background' => 'dark', 'divider' => 'accent'], 'slots' => [$this->heading('Trenner Akzent')]];
|
||||
$sections[] = ['layout' => 'u4', 'style' => ['cards_height' => 'equal', 'cards_links' => 'bottom'], 'slots' => [$this->prose('Karten gleich hoch')]];
|
||||
$sections[] = ['layout' => 'u1_1_1_1', 'style' => ['background' => 'accent'], 'slots' => [$this->prose('Eins'), null, $this->prose('Drei'), null]];
|
||||
|
||||
return $sections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zufällige Kennungen (Abschnitt, Widget) werden für den Vergleich vereinheitlicht.
|
||||
*/
|
||||
private function sectionsMarkup(string $html): string
|
||||
{
|
||||
$start = strpos($html, '<div class="page-section ');
|
||||
$end = strpos($html, '</main>');
|
||||
$markup = substr($html, $start, $end - $start);
|
||||
$markup = (string) preg_replace('/\b(id|aria-labelledby|aria-describedby|for)="([^"]*[0-9a-f]{8}-[0-9a-f]{4}-[^"]*)"/', '$1="#"', $markup);
|
||||
$markup = (string) preg_replace('/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/', 'UUID', $markup);
|
||||
|
||||
return trim($markup)."\n";
|
||||
}
|
||||
|
||||
public function test_existing_section_styles_render_exactly_as_before(): void
|
||||
{
|
||||
Queue::fake([PublishPublicMedia::class]);
|
||||
|
||||
$service = app(PageService::class);
|
||||
$page = Page::query()->create(['path' => '/legacy']);
|
||||
$service->publish($page, $service->saveRevision($page, $this->matrix(), null, null, null));
|
||||
|
||||
$markup = $this->sectionsMarkup($this->get('/legacy')->assertOk()->getContent());
|
||||
|
||||
if (getenv('UPDATE_SNAPSHOT') === '1') {
|
||||
file_put_contents(self::FIXTURE, $markup);
|
||||
}
|
||||
|
||||
$this->assertFileExists(self::FIXTURE);
|
||||
$this->assertSame(file_get_contents(self::FIXTURE), $markup, 'Die Ausgabe bestehender Abschnittsvarianten hat sich geändert.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,270 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Cms\Page;
|
||||
use App\Domain\Cms\PageService;
|
||||
use App\Domain\Cms\Sections\PageSections;
|
||||
use App\Domain\Cms\Sections\SectionStyle;
|
||||
use App\Domain\Design\DesignPalette;
|
||||
use App\Filament\Resources\Pages\Pages\EditPage;
|
||||
use App\Jobs\PublishPublicMedia;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Farbe aus der Palette und Hintergrundbreite im Abschnitt (ADR-67): Speicherformat, Darstellung, Rückfall und Wirkung einer
|
||||
* Änderung an der Palette. Die Ausgabe bisheriger Varianten sichert CmsSectionLegacyRenderTest.
|
||||
*/
|
||||
class CmsSectionPaletteTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
DesignPalette::flush();
|
||||
DesignPalette::save(null, 'Dunkelblau', '#032551', '#ffffff');
|
||||
DesignPalette::save(null, 'Helles Grün', '#e8f0de', '#032551');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $style
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function section(array $style, string $text = 'Inhalt'): array
|
||||
{
|
||||
return ['layout' => 'u4', 'style' => $style, 'slots' => [['type' => 'prose', 'v' => 1, 'data' => ['body' => $text]]]];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $style
|
||||
*/
|
||||
private function publish(string $path, array $style): Page
|
||||
{
|
||||
$page = Page::query()->create(['path' => $path]);
|
||||
$service = app(PageService::class);
|
||||
$service->publish($page, $service->saveRevision($page, [$this->section($style)], null, null, null));
|
||||
|
||||
return $page->fresh();
|
||||
}
|
||||
|
||||
private function sectionTag(string $html): string
|
||||
{
|
||||
preg_match('/<div class="page-section [^>]*>/', $html, $match);
|
||||
|
||||
return $match[0] ?? '';
|
||||
}
|
||||
|
||||
public function test_a_dark_palette_colour_renders_with_its_values_and_the_dark_scope(): void
|
||||
{
|
||||
$this->publish('/dunkel', ['background' => 'palette', 'palette_slot' => 'c1']);
|
||||
|
||||
$tag = $this->sectionTag($this->get('/dunkel')->assertOk()->getContent());
|
||||
|
||||
$this->assertStringContainsString('section-bg-palette', $tag);
|
||||
$this->assertStringContainsString('scope-dark', $tag);
|
||||
$this->assertStringContainsString('--color-surface: #032551;', $tag);
|
||||
$this->assertStringContainsString('--color-text: #ffffff;', $tag);
|
||||
$this->assertStringContainsString('--color-heading: #ffffff;', $tag);
|
||||
$this->assertStringContainsString('--color-focus: #fcd10a;', $tag);
|
||||
}
|
||||
|
||||
public function test_a_light_palette_colour_renders_without_the_dark_scope(): void
|
||||
{
|
||||
$this->publish('/hell', ['background' => 'palette', 'palette_slot' => 'c2']);
|
||||
|
||||
$tag = $this->sectionTag($this->get('/hell')->assertOk()->getContent());
|
||||
|
||||
$this->assertStringContainsString('section-bg-palette', $tag);
|
||||
$this->assertStringNotContainsString('scope-dark', $tag);
|
||||
$this->assertStringContainsString('--color-surface: #e8f0de;', $tag);
|
||||
$this->assertStringContainsString('--color-text: #032551;', $tag);
|
||||
$this->assertStringContainsString('--color-focus: #1769aa;', $tag);
|
||||
}
|
||||
|
||||
public function test_the_stored_format_holds_only_the_reference_not_the_colours(): void
|
||||
{
|
||||
$page = $this->publish('/format', ['background' => 'palette', 'palette_slot' => 'c1']);
|
||||
|
||||
$style = $page->latestRevision->sections[0]['style'];
|
||||
|
||||
$this->assertSame(['palette', 'c1'], [$style['background'], $style['palette_slot']]);
|
||||
$this->assertStringNotContainsString('#032551', json_encode($page->latestRevision->sections));
|
||||
}
|
||||
|
||||
public function test_the_reference_is_stored_only_with_the_palette_background(): void
|
||||
{
|
||||
$page = $this->publish('/andere-flaeche', ['background' => 'dark', 'palette_slot' => 'c1']);
|
||||
|
||||
$this->assertArrayNotHasKey('palette_slot', $page->latestRevision->sections[0]['style']);
|
||||
}
|
||||
|
||||
public function test_an_unknown_colour_is_refused_when_saving(): void
|
||||
{
|
||||
foreach (['c9', null, 'x'] as $slot) {
|
||||
try {
|
||||
app(PageSections::class)->normalize([$this->section(['background' => 'palette', 'palette_slot' => $slot])]);
|
||||
$this->fail('Eine unbekannte Farbe muss abgelehnt werden.');
|
||||
} catch (ValidationException $exception) {
|
||||
$this->assertArrayHasKey('sections.0.style.palette_slot', $exception->errors());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function test_a_colour_that_no_longer_exists_falls_back_to_the_default_surface_without_an_error(): void
|
||||
{
|
||||
$page = $this->publish('/verwaist', ['background' => 'palette', 'palette_slot' => 'c2']);
|
||||
$revision = $page->latestRevision;
|
||||
$revision->sections = [$this->section(['background' => 'palette', 'palette_slot' => 'c7'])];
|
||||
$revision->save();
|
||||
|
||||
$tag = $this->sectionTag($this->get('/verwaist')->assertOk()->getContent());
|
||||
|
||||
$this->assertStringContainsString('section-bg-default', $tag);
|
||||
$this->assertStringNotContainsString('style=', $tag);
|
||||
$this->assertSame('default', SectionStyle::fromStored(['background' => 'palette', 'palette_slot' => 'c7'])['background']);
|
||||
}
|
||||
|
||||
public function test_changing_a_colour_changes_published_pages_at_once_without_publishing_again(): void
|
||||
{
|
||||
$page = $this->publish('/global', ['background' => 'palette', 'palette_slot' => 'c1']);
|
||||
$revisions = $page->revisions()->count();
|
||||
$this->assertStringContainsString('--color-surface: #032551;', $this->get('/global')->getContent());
|
||||
|
||||
DesignPalette::save('c1', 'Dunkelblau', '#6b3fa0', '#ffffff');
|
||||
|
||||
$this->assertStringContainsString('--color-surface: #6b3fa0;', $this->get('/global')->getContent());
|
||||
$this->assertSame($revisions, $page->fresh()->revisions()->count(), 'Die Seite bleibt unverändert; nur die Palette wurde geändert.');
|
||||
}
|
||||
|
||||
public function test_the_preview_uses_the_same_markup_as_the_public_page(): void
|
||||
{
|
||||
$page = $this->publish('/vorschau', ['background' => 'palette', 'palette_slot' => 'c1']);
|
||||
$editor = User::factory()->redakteur()->create();
|
||||
|
||||
$public = $this->sectionTag($this->get('/vorschau')->getContent());
|
||||
$preview = $this->sectionTag($this->actingAs($editor, 'staff')->get(route('pages.preview', $page->published_revision_id))->getContent());
|
||||
|
||||
$this->assertNotSame('', $public);
|
||||
$this->assertSame($public, $preview);
|
||||
}
|
||||
|
||||
public function test_the_summary_names_the_colour_and_the_background_width(): void
|
||||
{
|
||||
$this->assertSame('Farbe „Dunkelblau“', SectionStyle::summary(['background' => 'palette', 'palette_slot' => 'c1']));
|
||||
$this->assertStringContainsString('Hintergrund auf Abschnittsbreite', SectionStyle::summary(['background' => 'light', 'background_width' => 'section']));
|
||||
$this->assertStringNotContainsString('Abschnittsbreite', SectionStyle::summary(['background' => 'light']));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------
|
||||
// Hintergrundbreite
|
||||
// ---------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public function test_the_default_background_width_adds_no_class_and_is_not_stored(): void
|
||||
{
|
||||
$page = $this->publish('/voll', ['background' => 'light', 'background_width' => 'full']);
|
||||
|
||||
$this->assertStringNotContainsString('section-bg-width-section', $this->get('/voll')->getContent());
|
||||
$this->assertArrayNotHasKey('background_width', $page->latestRevision->sections[0]['style']);
|
||||
}
|
||||
|
||||
public function test_a_limited_background_gets_its_class_for_every_kind_of_surface(): void
|
||||
{
|
||||
foreach ([
|
||||
'/b-hell' => ['background' => 'light'],
|
||||
'/b-dunkel' => ['background' => 'dark'],
|
||||
'/b-akzent' => ['background' => 'accent'],
|
||||
'/b-palette' => ['background' => 'palette', 'palette_slot' => 'c2'],
|
||||
] as $path => $style) {
|
||||
$page = $this->publish($path, $style + ['background_width' => 'section', 'width' => 'narrow']);
|
||||
|
||||
$this->assertStringContainsString('section-bg-width-section', $this->sectionTag($this->get($path)->getContent()), $path);
|
||||
$this->assertSame('section', $page->latestRevision->sections[0]['style']['background_width'], $path);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_a_limited_background_with_an_image_keeps_the_image_overlay_and_focus(): void
|
||||
{
|
||||
Queue::fake([PublishPublicMedia::class]);
|
||||
$this->publish('/bild', ['background' => 'image', 'image' => 'cms/flaeche.jpg', 'focus' => 'top_left', 'overlay' => 'dark', 'background_width' => 'section']);
|
||||
|
||||
$html = $this->get('/bild')->getContent();
|
||||
|
||||
$this->assertStringContainsString('section-bg-image', $html);
|
||||
$this->assertStringContainsString('section-overlay-dark scope-dark', $html);
|
||||
$this->assertStringContainsString('section-bg-width-section', $html);
|
||||
$this->assertMatchesRegularExpression('#<img class="page-section-image" src="[^"]*cms/flaeche\.jpg" alt="" loading="eager" fetchpriority="high"[^>]*object-position: 0% 0%#', $html);
|
||||
}
|
||||
|
||||
public function test_no_class_is_added_without_a_surface_or_with_the_full_content_width(): void
|
||||
{
|
||||
$page = $this->publish('/ohne-flaeche', ['background' => 'default', 'background_width' => 'section']);
|
||||
$this->assertStringNotContainsString('section-bg-width-section', $this->get('/ohne-flaeche')->getContent());
|
||||
$this->assertArrayNotHasKey('background_width', $page->latestRevision->sections[0]['style'], 'Ohne Fläche gibt es nichts zu begrenzen.');
|
||||
|
||||
$this->publish('/vollbreit', ['background' => 'dark', 'background_width' => 'section', 'width' => 'full']);
|
||||
$this->assertStringNotContainsString('section-bg-width-section', $this->get('/vollbreit')->getContent(), 'Bei Vollbreite gibt es keinen Unterschied.');
|
||||
}
|
||||
|
||||
public function test_an_unknown_background_width_is_refused(): void
|
||||
{
|
||||
$this->expectException(ValidationException::class);
|
||||
|
||||
app(PageSections::class)->normalize([$this->section(['background' => 'light', 'background_width' => 'schmal'])]);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------
|
||||
// Editor
|
||||
// ---------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public function test_the_editor_saves_a_palette_colour_and_the_background_width_and_an_untouched_page_stays_unchanged(): void
|
||||
{
|
||||
$editor = User::factory()->redakteur()->create();
|
||||
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
$page = Page::query()->create(['path' => '/editor']);
|
||||
app(PageService::class)->saveRevision($page, [$this->section(['background' => 'light'])], null, null, null);
|
||||
$revisions = $page->revisions()->count();
|
||||
|
||||
$component = Livewire::actingAs($editor, 'staff')->test(EditPage::class, ['record' => $page->id]);
|
||||
$key = array_key_first($component->get('data.sections'));
|
||||
|
||||
$component->assertSet("data.sections.{$key}.style.background", 'light')->assertSet("data.sections.{$key}.style.palette_slot", null);
|
||||
$component->call('save')->assertHasNoFormErrors();
|
||||
$this->assertSame($revisions, $page->revisions()->count(), 'Speichern ohne Änderung legt keine Revision an.');
|
||||
|
||||
$key = array_key_first($component->get('data.sections'));
|
||||
$component->set("data.sections.{$key}.style.palette_slot", 'c2')->set("data.sections.{$key}.style.background", 'palette')
|
||||
->set("data.sections.{$key}.style.background_width", 'section')->call('save')->assertHasNoFormErrors();
|
||||
$style = $page->fresh()->latestRevision->sections[0]['style'];
|
||||
$this->assertSame(['palette', 'c2', 'section'], [$style['background'], $style['palette_slot'], $style['background_width']]);
|
||||
|
||||
$key = array_key_first($component->get('data.sections'));
|
||||
$component->set("data.sections.{$key}.style.background", 'light')->set("data.sections.{$key}.style.palette_slot", null)
|
||||
->set("data.sections.{$key}.style.background_width", 'full')->call('save')->assertHasNoFormErrors();
|
||||
$style = $page->fresh()->latestRevision->sections[0]['style'];
|
||||
$this->assertArrayNotHasKey('palette_slot', $style, 'Der Verweis verschwindet mit der Palettenfarbe.');
|
||||
$this->assertArrayNotHasKey('background_width', $style);
|
||||
}
|
||||
|
||||
public function test_the_editor_offers_the_palette_colours_as_tiles_to_an_editor_without_access_to_the_palette(): void
|
||||
{
|
||||
$editor = User::factory()->redakteur()->create();
|
||||
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
$page = Page::query()->create(['path' => '/auswahl']);
|
||||
app(PageService::class)->saveRevision($page, [$this->section([])], null, null, null);
|
||||
|
||||
$html = Livewire::actingAs($editor, 'staff')->test(EditPage::class, ['record' => $page->id])->html();
|
||||
|
||||
$this->assertStringContainsString('luf-flaeche', $html);
|
||||
$this->assertStringContainsString('Dunkelblau', $html);
|
||||
$this->assertStringContainsString('Helles Grün', $html);
|
||||
$this->assertStringContainsString('Hintergrundbild', $html);
|
||||
$this->assertStringContainsString('Die Farbpalette pflegt die Systemverwaltung', $html);
|
||||
$this->assertStringNotContainsString('Farbpalette verwalten', $html);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Cms\Page;
|
||||
use App\Domain\Cms\PageService;
|
||||
use App\Domain\Design\DesignPalette;
|
||||
use App\Filament\Pages\DesignFarben;
|
||||
use App\Models\User;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Verwaltungsseite „Website → Design → Farben“ (ADR-67): Berechtigung, Anlegen, Bearbeiten, Wirkung auf bestehende Seiten,
|
||||
* Entfernen.
|
||||
*/
|
||||
class DesignFarbenPageTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
|
||||
DesignPalette::flush();
|
||||
}
|
||||
|
||||
private function admin(): User
|
||||
{
|
||||
$admin = User::factory()->systemverwalter()->create();
|
||||
$admin->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
|
||||
return $admin;
|
||||
}
|
||||
|
||||
private function useColour(string $path, string $slot, bool $publish = true): Page
|
||||
{
|
||||
$page = Page::query()->create(['path' => $path]);
|
||||
$service = app(PageService::class);
|
||||
$revision = $service->saveRevision($page, [['layout' => 'u4', 'style' => ['background' => 'palette', 'palette_slot' => $slot], 'slots' => [['type' => 'heading', 'v' => 1, 'data' => ['heading' => 'Seite '.$path]]]]], null, null, null);
|
||||
|
||||
if ($publish) {
|
||||
$service->publish($page, $revision);
|
||||
}
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
public function test_only_the_system_administrator_may_open_the_page(): void
|
||||
{
|
||||
$editor = User::factory()->redakteur()->create();
|
||||
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
|
||||
$this->get('/verwaltung/design/farben')->assertRedirect();
|
||||
$this->actingAs($editor, 'staff')->get('/verwaltung/design/farben')->assertForbidden();
|
||||
$this->actingAs($this->admin(), 'staff')->get('/verwaltung/design/farben')->assertOk()
|
||||
->assertSee('Farbpalette für die Abschnitte der Website')
|
||||
->assertSee('Freier Platz')
|
||||
->assertSee('Markenflächen (fest)')
|
||||
->assertSee(DesignFarben::getUrl());
|
||||
}
|
||||
|
||||
public function test_an_editor_cannot_change_the_palette_even_with_a_direct_call(): void
|
||||
{
|
||||
$editor = User::factory()->redakteur()->create();
|
||||
|
||||
Livewire::actingAs($editor, 'staff')->test(DesignFarben::class)->assertForbidden();
|
||||
$this->assertSame([], DesignPalette::slots());
|
||||
}
|
||||
|
||||
public function test_a_colour_is_created_through_the_dialog(): void
|
||||
{
|
||||
$component = Livewire::actingAs($this->admin(), 'staff')->test(DesignFarben::class)
|
||||
->call('neu')
|
||||
->assertSet('dialog.id', null)
|
||||
->assertSet('dialog.bg', '#3b7b09')
|
||||
->call('speichern', 'Markengrün', '#3b7b09', '#ffffff');
|
||||
|
||||
$component->assertSet('dialog', null)->assertSet('fehler', []);
|
||||
$this->assertSame(['Markengrün', '#3b7b09', '#ffffff'], array_values(array_intersect_key(DesignPalette::find('c1'), array_flip(['name', 'bg', 'fg']))));
|
||||
$component->assertSee('Markengrün')->assertSee('#3b7b09')->assertSee('Noch auf keiner Seite verwendet');
|
||||
}
|
||||
|
||||
public function test_too_little_contrast_and_missing_input_are_shown_at_the_field_and_nothing_is_saved(): void
|
||||
{
|
||||
$component = Livewire::actingAs($this->admin(), 'staff')->test(DesignFarben::class)
|
||||
->call('neu')
|
||||
->call('speichern', '', 'rot', '#e8f0de');
|
||||
|
||||
$this->assertSame(['name', 'bg'], array_keys($component->get('fehler')));
|
||||
$this->assertSame([], DesignPalette::slots());
|
||||
|
||||
$component->call('speichern', 'Blass', '#ffffff', '#e8f0de');
|
||||
$this->assertSame(['fg'], array_keys($component->get('fehler')));
|
||||
$component->assertSee('mindestens 4,5 : 1');
|
||||
$this->assertSame([], DesignPalette::slots());
|
||||
}
|
||||
|
||||
public function test_a_brand_surface_can_be_copied_as_a_starting_point(): void
|
||||
{
|
||||
Livewire::actingAs($this->admin(), 'staff')->test(DesignFarben::class)
|
||||
->call('neu', 'dark')
|
||||
->assertSet('dialog.name', 'Dunkle Markenfläche')
|
||||
->assertSet('dialog.bg', '#032551');
|
||||
|
||||
$this->assertSame([], DesignPalette::slots(), 'Kopieren öffnet nur den Dialog.');
|
||||
}
|
||||
|
||||
public function test_a_full_palette_offers_no_new_colour(): void
|
||||
{
|
||||
foreach (range(1, 10) as $number) {
|
||||
DesignPalette::save(null, "Farbe $number", '#032551', '#ffffff');
|
||||
}
|
||||
|
||||
Livewire::actingAs($this->admin(), 'staff')->test(DesignFarben::class)->call('neu')->assertSet('dialog', null)->assertDontSee('Freier Platz');
|
||||
}
|
||||
|
||||
public function test_renaming_an_unused_or_used_colour_saves_at_once(): void
|
||||
{
|
||||
DesignPalette::save(null, 'Grün', '#3b7b09', '#ffffff');
|
||||
$this->useColour('/live', 'c1');
|
||||
|
||||
Livewire::actingAs($this->admin(), 'staff')->test(DesignFarben::class)
|
||||
->call('bearbeiten', 'c1')
|
||||
->call('speichern', 'Waldgrün', '#3b7b09', '#ffffff')
|
||||
->assertSet('bestaetigung', null);
|
||||
|
||||
$this->assertSame('Waldgrün', DesignPalette::find('c1')['name']);
|
||||
}
|
||||
|
||||
public function test_changing_the_values_of_a_used_colour_shows_the_affected_pages_and_waits_for_confirmation(): void
|
||||
{
|
||||
DesignPalette::save(null, 'Grün', '#3b7b09', '#ffffff');
|
||||
$this->useColour('/live', 'c1');
|
||||
$this->useColour('/entwurf', 'c1', publish: false);
|
||||
|
||||
$component = Livewire::actingAs($this->admin(), 'staff')->test(DesignFarben::class)
|
||||
->call('bearbeiten', 'c1')
|
||||
->call('speichern', 'Grün', '#2f6407', '#ffffff');
|
||||
|
||||
$this->assertSame('#3b7b09', DesignPalette::find('c1')['bg'], 'Bis zur Bestätigung ist nichts gespeichert.');
|
||||
$frage = $component->get('bestaetigung');
|
||||
$this->assertSame('wirkung', $frage['aktion']);
|
||||
$this->assertStringContainsString('2 Seiten (veröffentlicht: 1, im Entwurf: 1)', $frage['text']);
|
||||
$this->assertStringContainsString('sofort, auch auf der veröffentlichten Website', $frage['text']);
|
||||
$this->assertCount(2, $frage['liste']);
|
||||
$this->assertStringContainsString('/live', implode(' ', $frage['liste']));
|
||||
$component->assertSee('Diese Änderung wirkt auf bestehende Seiten')->assertSee('Farbe ändern und sofort anwenden');
|
||||
|
||||
$component->call('confirmConfirmation')->assertSet('dialog', null)->assertSet('bestaetigung', null);
|
||||
|
||||
$this->assertSame('#2f6407', DesignPalette::find('c1')['bg']);
|
||||
$this->assertStringContainsString('--color-surface: #2f6407;', $this->get('/live')->getContent());
|
||||
}
|
||||
|
||||
public function test_cancelling_the_confirmation_keeps_the_stored_colour(): void
|
||||
{
|
||||
DesignPalette::save(null, 'Grün', '#3b7b09', '#ffffff');
|
||||
$this->useColour('/live', 'c1');
|
||||
|
||||
$component = Livewire::actingAs($this->admin(), 'staff')->test(DesignFarben::class)
|
||||
->call('bearbeiten', 'c1')
|
||||
->call('speichern', 'Grün', '#2f6407', '#ffffff')
|
||||
->call('cancelConfirmation');
|
||||
|
||||
$component->assertSet('bestaetigung', null);
|
||||
$this->assertSame('#3b7b09', DesignPalette::find('c1')['bg']);
|
||||
}
|
||||
|
||||
public function test_changing_an_unused_colour_needs_no_confirmation(): void
|
||||
{
|
||||
DesignPalette::save(null, 'Grün', '#3b7b09', '#ffffff');
|
||||
|
||||
Livewire::actingAs($this->admin(), 'staff')->test(DesignFarben::class)
|
||||
->call('bearbeiten', 'c1')
|
||||
->call('speichern', 'Grün', '#2f6407', '#ffffff')
|
||||
->assertSet('bestaetigung', null)
|
||||
->assertSet('dialog', null);
|
||||
|
||||
$this->assertSame('#2f6407', DesignPalette::find('c1')['bg']);
|
||||
}
|
||||
|
||||
public function test_a_colour_in_use_cannot_be_removed_and_the_pages_are_named(): void
|
||||
{
|
||||
DesignPalette::save(null, 'Grün', '#3b7b09', '#ffffff');
|
||||
$this->useColour('/live', 'c1');
|
||||
|
||||
$component = Livewire::actingAs($this->admin(), 'staff')->test(DesignFarben::class)->call('entfernenFragen', 'c1');
|
||||
|
||||
$this->assertSame('hinweis', $component->get('bestaetigung')['aktion']);
|
||||
$component->assertSee('lässt sich nicht entfernen')->call('confirmConfirmation');
|
||||
$this->assertNotNull(DesignPalette::find('c1'));
|
||||
}
|
||||
|
||||
public function test_an_unused_colour_is_removed_after_a_question(): void
|
||||
{
|
||||
DesignPalette::save(null, 'Grün', '#3b7b09', '#ffffff');
|
||||
|
||||
$component = Livewire::actingAs($this->admin(), 'staff')->test(DesignFarben::class)->call('entfernenFragen', 'c1');
|
||||
$this->assertSame('entfernen', $component->get('bestaetigung')['aktion']);
|
||||
$this->assertNotNull(DesignPalette::find('c1'), 'Die Frage entfernt noch nichts.');
|
||||
|
||||
$component->call('confirmConfirmation');
|
||||
|
||||
$this->assertNull(DesignPalette::find('c1'));
|
||||
$this->assertSame(10, DesignPalette::free());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Cms\Page;
|
||||
use App\Domain\Cms\PageService;
|
||||
use App\Domain\Design\DesignPalette;
|
||||
use App\Domain\Design\SiteSetting;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Zentrale Farbpalette (ADR-67): Speicherung, Prüfung, Kennungen, Verwendung und Ausfallsicherheit.
|
||||
*/
|
||||
class DesignPaletteTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
DesignPalette::flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $style
|
||||
*/
|
||||
private function page(string $path, array $style, bool $publish = true): Page
|
||||
{
|
||||
$page = Page::query()->create(['path' => $path]);
|
||||
$service = app(PageService::class);
|
||||
$revision = $service->saveRevision($page, [['layout' => 'u4', 'style' => $style, 'slots' => [['type' => 'heading', 'v' => 1, 'data' => ['heading' => 'Titel '.$path]]]]], null, null, null);
|
||||
|
||||
if ($publish) {
|
||||
$service->publish($page, $revision);
|
||||
}
|
||||
|
||||
return $page->fresh();
|
||||
}
|
||||
|
||||
public function test_the_palette_starts_empty_with_ten_free_places(): void
|
||||
{
|
||||
$this->assertSame([], DesignPalette::slots());
|
||||
$this->assertSame(10, DesignPalette::free());
|
||||
$this->assertNull(DesignPalette::find('c1'));
|
||||
}
|
||||
|
||||
public function test_a_colour_is_saved_with_a_name_and_a_normalised_pair(): void
|
||||
{
|
||||
$this->assertSame([], DesignPalette::save(null, ' Marken grün ', '#3B7B09', 'FFF'));
|
||||
|
||||
$slot = DesignPalette::slots()[0];
|
||||
$this->assertSame(['c1', 'Marken grün', '#3b7b09', '#ffffff'], [$slot['id'], $slot['name'], $slot['bg'], $slot['fg']]);
|
||||
$this->assertSame(9, DesignPalette::free());
|
||||
$this->assertSame($slot, DesignPalette::find('c1'));
|
||||
}
|
||||
|
||||
public function test_the_stored_palette_survives_a_cold_cache(): void
|
||||
{
|
||||
DesignPalette::save(null, 'Dunkelblau', '#032551', '#ffffff');
|
||||
DesignPalette::flush();
|
||||
|
||||
$this->assertSame('Dunkelblau', DesignPalette::find('c1')['name']);
|
||||
$this->assertSame(1, SiteSetting::query()->count());
|
||||
}
|
||||
|
||||
public function test_invalid_input_is_refused_with_a_message_per_field(): void
|
||||
{
|
||||
$errors = DesignPalette::save(null, '', 'rot', '#12');
|
||||
|
||||
$this->assertSame(['name', 'bg', 'fg'], array_keys($errors));
|
||||
$this->assertSame([], DesignPalette::slots());
|
||||
$this->assertSame(0, SiteSetting::query()->count());
|
||||
|
||||
$this->assertArrayHasKey('name', DesignPalette::save(null, str_repeat('x', 41), '#032551', '#ffffff'));
|
||||
}
|
||||
|
||||
public function test_a_colour_with_too_little_contrast_is_refused_and_a_suggestion_is_named(): void
|
||||
{
|
||||
$errors = DesignPalette::save(null, 'Blass', '#e8f0de', '#ffffff');
|
||||
|
||||
$this->assertSame(['fg'], array_keys($errors));
|
||||
$this->assertStringContainsString('mindestens 4,5 : 1', $errors['fg']);
|
||||
$this->assertStringContainsString('Empfehlung: #032551', $errors['fg']);
|
||||
$this->assertSame([], DesignPalette::slots());
|
||||
}
|
||||
|
||||
public function test_names_are_unique_regardless_of_case(): void
|
||||
{
|
||||
DesignPalette::save(null, 'Markengrün', '#3b7b09', '#ffffff');
|
||||
|
||||
$this->assertArrayHasKey('name', DesignPalette::save(null, 'MARKENGRÜN', '#032551', '#ffffff'));
|
||||
$this->assertSame([], DesignPalette::save('c1', 'markengrün', '#2f6407', '#ffffff'), 'Die Farbe darf ihren eigenen Namen behalten.');
|
||||
}
|
||||
|
||||
public function test_the_palette_holds_at_most_ten_colours(): void
|
||||
{
|
||||
foreach (range(1, 10) as $number) {
|
||||
$this->assertSame([], DesignPalette::save(null, "Farbe $number", '#032551', '#ffffff'));
|
||||
}
|
||||
|
||||
$this->assertSame(0, DesignPalette::free());
|
||||
$this->assertArrayHasKey('slot', DesignPalette::save(null, 'Elfte', '#032551', '#ffffff'));
|
||||
$this->assertCount(10, DesignPalette::slots());
|
||||
}
|
||||
|
||||
public function test_an_identifier_is_never_given_out_again(): void
|
||||
{
|
||||
DesignPalette::save(null, 'Eins', '#032551', '#ffffff');
|
||||
DesignPalette::save(null, 'Zwei', '#3b7b09', '#ffffff');
|
||||
$this->assertSame([], DesignPalette::remove('c2'));
|
||||
|
||||
DesignPalette::save(null, 'Drei', '#6b3fa0', '#ffffff');
|
||||
|
||||
$this->assertSame(['c1', 'c3'], array_column(DesignPalette::slots(), 'id'));
|
||||
}
|
||||
|
||||
public function test_editing_keeps_the_identifier_and_changes_the_values(): void
|
||||
{
|
||||
DesignPalette::save(null, 'Grün', '#3b7b09', '#ffffff');
|
||||
|
||||
$this->assertSame([], DesignPalette::save('c1', 'Waldgrün', '#2f6407', '#ffffff'));
|
||||
$this->assertSame(['c1', 'Waldgrün', '#2f6407'], array_values(array_intersect_key(DesignPalette::find('c1'), array_flip(['id', 'name', 'bg']))));
|
||||
$this->assertArrayHasKey('slot', DesignPalette::save('c9', 'Gibt es nicht', '#2f6407', '#ffffff'));
|
||||
}
|
||||
|
||||
public function test_usage_separates_published_pages_from_drafts(): void
|
||||
{
|
||||
DesignPalette::save(null, 'Grün', '#3b7b09', '#ffffff');
|
||||
DesignPalette::save(null, 'Blau', '#032551', '#ffffff');
|
||||
$this->page('/live', ['background' => 'palette', 'palette_slot' => 'c1']);
|
||||
$this->page('/entwurf', ['background' => 'palette', 'palette_slot' => 'c1'], publish: false);
|
||||
$this->page('/ohne', ['background' => 'dark']);
|
||||
|
||||
$usage = DesignPalette::usage();
|
||||
|
||||
$this->assertSame(['/entwurf', '/live'], array_column($usage['c1'], 'path'));
|
||||
$byPath = array_column($usage['c1'], null, 'path');
|
||||
$this->assertSame([1, 0], [$byPath['/live']['published'], $byPath['/live']['draft']]);
|
||||
$this->assertSame([0, 1], [$byPath['/entwurf']['published'], $byPath['/entwurf']['draft']]);
|
||||
$this->assertArrayNotHasKey('c2', $usage);
|
||||
}
|
||||
|
||||
public function test_a_draft_that_differs_from_the_published_state_counts_separately(): void
|
||||
{
|
||||
DesignPalette::save(null, 'Grün', '#3b7b09', '#ffffff');
|
||||
$page = $this->page('/zwei-staende', ['background' => 'dark']);
|
||||
$service = app(PageService::class);
|
||||
$service->saveRevision($page, [['layout' => 'u4', 'style' => ['background' => 'palette', 'palette_slot' => 'c1'], 'slots' => [['type' => 'heading', 'v' => 1, 'data' => ['heading' => 'Neu']]]]], null, null, null);
|
||||
|
||||
$use = DesignPalette::usage()['c1'][0];
|
||||
|
||||
$this->assertSame([0, 1], [$use['published'], $use['draft']]);
|
||||
}
|
||||
|
||||
public function test_a_colour_in_use_cannot_be_removed_but_an_unused_one_can(): void
|
||||
{
|
||||
DesignPalette::save(null, 'Grün', '#3b7b09', '#ffffff');
|
||||
DesignPalette::save(null, 'Blau', '#032551', '#ffffff');
|
||||
$this->page('/live', ['background' => 'palette', 'palette_slot' => 'c1']);
|
||||
|
||||
$this->assertArrayHasKey('slot', DesignPalette::remove('c1'));
|
||||
$this->assertNotNull(DesignPalette::find('c1'));
|
||||
$this->assertSame([], DesignPalette::remove('c2'));
|
||||
$this->assertNull(DesignPalette::find('c2'));
|
||||
$this->assertArrayHasKey('slot', DesignPalette::remove('c2'), 'Eine entfernte Farbe lässt sich nicht noch einmal entfernen.');
|
||||
}
|
||||
|
||||
public function test_damaged_data_never_breaks_reading(): void
|
||||
{
|
||||
SiteSetting::query()->create(['key' => DesignPalette::KEY, 'value' => ['next' => 'x', 'slots' => [
|
||||
['id' => 'c1', 'name' => 'Gut', 'bg' => '#3b7b09', 'fg' => '#ffffff'],
|
||||
['id' => 'c2', 'name' => '', 'bg' => '#3b7b09', 'fg' => '#ffffff'],
|
||||
['id' => 'x3', 'name' => 'Falsche Kennung', 'bg' => '#3b7b09', 'fg' => '#ffffff'],
|
||||
['id' => 'c4', 'name' => 'Kein Hex', 'bg' => 'rot', 'fg' => '#ffffff'],
|
||||
'kaputt',
|
||||
]]]);
|
||||
DesignPalette::flush();
|
||||
|
||||
$this->assertSame(['c1'], array_column(DesignPalette::slots(), 'id'));
|
||||
|
||||
DesignPalette::save(null, 'Neu', '#032551', '#ffffff');
|
||||
$this->assertSame(['c1', 'c2'], array_column(DesignPalette::slots(), 'id'), 'Die nächste Kennung folgt auf die höchste vorhandene.');
|
||||
}
|
||||
|
||||
public function test_a_missing_table_gives_an_empty_palette_instead_of_an_error(): void
|
||||
{
|
||||
Schema::drop('site_settings');
|
||||
DesignPalette::flush();
|
||||
|
||||
$this->assertSame([], DesignPalette::slots());
|
||||
$this->assertNull(DesignPalette::find('c1'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<div class="page-section section-bg-default section-width-narrow section-space-top-compact section-space-bottom-compact section-gap-normal section-layout-u2-2" id="#"><div class="page-section-inner"><div class="section-grid section-grid-tablet-columns" data-slots="2" style="--section-cols-lg: minmax(0, 2fr) minmax(0, 2fr); --section-cols-md: repeat(2, minmax(0, 1fr))"><div class="section-slot" data-units="2"><section class="block widget widget-heading widget-variant-standard" id="#"><h1>default narrow</h1></section></div><div class="section-slot" data-units="2"><section class="block widget widget-prose widget-variant-standard" id="#"><div class="prose"><p>Text default narrow</p></div></section></div></div></div></div><div class="page-section section-bg-default section-width-standard section-space-top-compact section-space-bottom-compact section-gap-normal section-layout-u2-2" id="#"><div class="page-section-inner"><div class="section-grid section-grid-tablet-columns" data-slots="2" style="--section-cols-lg: minmax(0, 2fr) minmax(0, 2fr); --section-cols-md: repeat(2, minmax(0, 1fr))"><div class="section-slot" data-units="2"><section class="block widget widget-heading widget-variant-standard" id="#"><h2>default standard</h2></section></div><div class="section-slot" data-units="2"><section class="block widget widget-prose widget-variant-standard" id="#"><div class="prose"><p>Text default standard</p></div></section></div></div></div></div><div class="page-section section-bg-default section-width-wide section-space-top-compact section-space-bottom-compact section-gap-normal section-layout-u2-2" id="#"><div class="page-section-inner"><div class="section-grid section-grid-tablet-columns" data-slots="2" style="--section-cols-lg: minmax(0, 2fr) minmax(0, 2fr); --section-cols-md: repeat(2, minmax(0, 1fr))"><div class="section-slot" data-units="2"><section class="block widget widget-heading widget-variant-standard" id="#"><h2>default wide</h2></section></div><div class="section-slot" data-units="2"><section class="block widget widget-prose widget-variant-standard" id="#"><div class="prose"><p>Text default wide</p></div></section></div></div></div></div><div class="page-section section-bg-default section-width-full section-space-top-compact section-space-bottom-compact section-gap-normal section-layout-u2-2" id="#"><div class="page-section-inner"><div class="section-grid section-grid-tablet-columns" data-slots="2" style="--section-cols-lg: minmax(0, 2fr) minmax(0, 2fr); --section-cols-md: repeat(2, minmax(0, 1fr))"><div class="section-slot" data-units="2"><section class="block widget widget-heading widget-variant-standard" id="#"><h2>default full</h2></section></div><div class="section-slot" data-units="2"><section class="block widget widget-prose widget-variant-standard" id="#"><div class="prose"><p>Text default full</p></div></section></div></div></div></div><div class="page-section section-bg-light section-width-wide section-space-top-compact section-space-bottom-compact section-gap-normal section-layout-u2-2" id="#"><div class="page-section-inner"><div class="section-grid section-grid-tablet-columns" data-slots="2" style="--section-cols-lg: minmax(0, 2fr) minmax(0, 2fr); --section-cols-md: repeat(2, minmax(0, 1fr))"><div class="section-slot" data-units="2"><section class="block widget widget-heading widget-variant-standard" id="#"><h2>light wide</h2></section></div><div class="section-slot" data-units="2"><section class="block widget widget-prose widget-variant-standard" id="#"><div class="prose"><p>Text light wide</p></div></section></div></div></div></div><div class="page-section section-bg-dark section-width-narrow section-space-top-compact section-space-bottom-compact section-gap-normal section-layout-u2-2 scope-dark" id="#"><div class="page-section-inner"><div class="section-grid section-grid-tablet-columns" data-slots="2" style="--section-cols-lg: minmax(0, 2fr) minmax(0, 2fr); --section-cols-md: repeat(2, minmax(0, 1fr))"><div class="section-slot" data-units="2"><section class="block widget widget-heading widget-variant-standard" id="#"><h2>dark narrow</h2></section></div><div class="section-slot" data-units="2"><section class="block widget widget-prose widget-variant-standard" id="#"><div class="prose"><p>Text dark narrow</p></div></section></div></div></div></div><div class="page-section section-bg-dark section-width-standard section-space-top-compact section-space-bottom-compact section-gap-normal section-layout-u2-2 scope-dark" id="#"><div class="page-section-inner"><div class="section-grid section-grid-tablet-columns" data-slots="2" style="--section-cols-lg: minmax(0, 2fr) minmax(0, 2fr); --section-cols-md: repeat(2, minmax(0, 1fr))"><div class="section-slot" data-units="2"><section class="block widget widget-heading widget-variant-standard" id="#"><h2>dark standard</h2></section></div><div class="section-slot" data-units="2"><section class="block widget widget-prose widget-variant-standard" id="#"><dLine truncated
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Domain\Design\ColorContrast;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Farbrechnung der Palette (ADR-67). Die Vergleichswerte stammen aus den dokumentierten Markenpaaren (tokens.css) und aus
|
||||
* der WCAG-Definition; dieselben Werte prüft die Browserabnahme gegen die Live-Vorschau.
|
||||
*/
|
||||
class ColorContrastTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @return array<string, array{0: mixed, 1: ?string}>
|
||||
*/
|
||||
public static function hexValues(): array
|
||||
{
|
||||
return [
|
||||
'lang' => ['#3B7B09', '#3b7b09'],
|
||||
'ohne Raute' => ['3b7b09', '#3b7b09'],
|
||||
'kurz' => ['#fa0', '#ffaa00'],
|
||||
'Leerzeichen' => [' #FFF ', '#ffffff'],
|
||||
'zu kurz' => ['#ff', null],
|
||||
'kein Hex' => ['#gggggg', null],
|
||||
'zu lang' => ['#1234567', null],
|
||||
'kein Text' => [123, null],
|
||||
'leer' => ['', null],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider('hexValues')]
|
||||
public function test_hex_values_are_normalised_or_refused(mixed $input, ?string $expected): void
|
||||
{
|
||||
$this->assertSame($expected, ColorContrast::normalize($input));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{0: string, 1: string, 2: float}>
|
||||
*/
|
||||
public static function pairs(): array
|
||||
{
|
||||
return [
|
||||
'Schwarz auf Weiß' => ['#000000', '#ffffff', 21.0],
|
||||
'gleiche Farbe' => ['#336699', '#336699', 1.0],
|
||||
'Navy auf Weiß (tokens.css: 15:1)' => ['#032551', '#ffffff', 15.0],
|
||||
'Weiß auf Markengrün (tokens.css: 5,2:1)' => ['#ffffff', '#3b7b09', 5.2],
|
||||
'Grau 777 auf Weiß (knapp unter AA)' => ['#777777', '#ffffff', 4.48],
|
||||
'Grau 767676 auf Weiß (knapp AA)' => ['#767676', '#ffffff', 4.54],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider('pairs')]
|
||||
public function test_contrast_ratio_matches_the_wcag_definition(string $a, string $b, float $expected): void
|
||||
{
|
||||
$this->assertEqualsWithDelta($expected, ColorContrast::ratio($a, $b), 0.25);
|
||||
$this->assertSame(ColorContrast::ratio($a, $b), ColorContrast::ratio($b, $a), 'Die Reihenfolge ändert den Kontrast nicht.');
|
||||
}
|
||||
|
||||
public function test_the_thresholds_decide_between_aa_large_text_and_failure(): void
|
||||
{
|
||||
$this->assertTrue(ColorContrast::passes('#767676', '#ffffff'));
|
||||
$this->assertFalse(ColorContrast::passes('#777777', '#ffffff'));
|
||||
$this->assertSame('enhanced', ColorContrast::rating(7.0));
|
||||
$this->assertSame('aa', ColorContrast::rating(4.5));
|
||||
$this->assertSame('large', ColorContrast::rating(4.49));
|
||||
$this->assertSame('large', ColorContrast::rating(3.0));
|
||||
$this->assertSame('fail', ColorContrast::rating(2.99));
|
||||
}
|
||||
|
||||
public function test_the_suggested_text_colour_is_always_readable(): void
|
||||
{
|
||||
foreach (['#ffffff', '#000000', '#3b7b09', '#fcd10a', '#808080', '#ff00ff', '#00ffff', '#7a7a2e', '#5b8625', '#e8f0de'] as $background) {
|
||||
$suggestion = ColorContrast::suggestText($background);
|
||||
|
||||
$this->assertTrue(ColorContrast::passes($suggestion, $background), "Empfehlung $suggestion auf $background");
|
||||
}
|
||||
|
||||
$this->assertSame('#ffffff', ColorContrast::suggestText('#3b7b09'), 'Auf dunklem Grün ist Weiß die Marken-Empfehlung.');
|
||||
$this->assertSame('#032551', ColorContrast::suggestText('#e8f0de'), 'Auf hellem Grün ist Dunkelblau die Marken-Empfehlung.');
|
||||
}
|
||||
|
||||
public function test_a_surface_is_dark_when_the_text_is_lighter_than_the_background(): void
|
||||
{
|
||||
$this->assertTrue(ColorContrast::isDarkSurface('#ffffff', '#032551'));
|
||||
$this->assertFalse(ColorContrast::isDarkSurface('#032551', '#e8f0de'));
|
||||
}
|
||||
|
||||
public function test_derived_surface_values_keep_their_own_contrast_rules(): void
|
||||
{
|
||||
foreach ([['#032551', '#e8f0de'], ['#ffffff', '#3b7b09'], ['#f4f6f8', '#032551'], ['#000000', '#fcd10a'], ['#ffffff', '#6b3fa0']] as [$text, $background]) {
|
||||
$values = ColorContrast::surfaceProperties($background, $text);
|
||||
$label = "$text auf $background";
|
||||
|
||||
$this->assertSame($background, $values['color-surface']);
|
||||
$this->assertSame($text, $values['color-text']);
|
||||
$this->assertTrue(ColorContrast::passes($values['color-text-muted'], $background), "Gedämpfter Text: $label");
|
||||
$this->assertTrue(ColorContrast::passes($values['color-link-hover'], $background), "Link beim Überfahren: $label");
|
||||
$this->assertGreaterThanOrEqual(3.0, ColorContrast::ratio($values['color-focus'], $background), "Fokus: $label");
|
||||
$this->assertGreaterThanOrEqual(3.0, ColorContrast::ratio($values['color-action'], $background), "Schaltfläche: $label");
|
||||
$this->assertTrue(ColorContrast::passes($values['color-action-text'], $values['color-action']), "Schaltflächentext: $label");
|
||||
}
|
||||
}
|
||||
|
||||
public function test_dark_surfaces_use_the_yellow_brand_focus_and_light_surfaces_the_blue_one(): void
|
||||
{
|
||||
$this->assertSame('#fcd10a', ColorContrast::surfaceProperties('#032551', '#ffffff')['color-focus']);
|
||||
$this->assertSame('#1769aa', ColorContrast::surfaceProperties('#e8f0de', '#032551')['color-focus']);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user