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:
LarsandClaude Sonnet 5.5 committed 2026-11-29 18:35:15 +01:00
1 parent 62f3a33541
commit 87de5a62d4
41 files changed
+2372 -14

No files matched your search

+270
View File
@@ -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);
}
}