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,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