Setze Symbole vor Absätze, Nummern in Kreise und Symbole statt Aufzählungspunkte im Text (ADR-69)
CI Feature / test (push) Successful in 7m17s
Deploy Test / test (push) Successful in 6m48s
Deploy Test / deploy (push) Successful in 41s

Zwei Werkzeuge im Texteditor (Symbol vor dem Absatz, Listenstil); gespeichert
werden nur Schlüssel, Bild und Farbe setzt die Ausgabe ein. Kreisfarben aus
der Palette, Verwendung wird mitgezählt.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-30 18:58:10 +01:00
1 parent 67764c3e4f
commit e904b500fb
24 files changed
+814 -14

No files matched your search

+165
View File
@@ -0,0 +1,165 @@
<?php
namespace Tests\Feature;
use App\Domain\Catalog\FormattedText;
use App\Domain\Cms\Page;
use App\Domain\Cms\PageService;
use App\Domain\Cms\Widgets\Support\RichText;
use App\Domain\Cms\Widgets\Support\TextMarkers;
use App\Domain\Design\DesignPalette;
use App\Support\Brand\SymbolCatalog;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
/**
* Zeichen im formatierten Text (ADR-69): Symbol vor dem Absatz, Nummern im Kreis, Symbol statt Aufzählungspunkt.
* Gespeichert werden nur Schlüssel; Bilder und Farben setzt erst die Ausgabe ein.
*/
class CmsTextMarkersTest extends TestCase
{
use RefreshDatabase;
protected function tearDown(): void
{
DesignPalette::flush();
parent::tearDown();
}
private function symbol(int $index = 0): string
{
return SymbolCatalog::keys()[$index];
}
public function test_valid_markers_survive_the_canonical_form_in_the_site_profile(): void
{
$symbol = $this->symbol();
$html = '<p data-symbol="'.$symbol.'">Absatz</p><ol data-marker="circle" data-tone="accent"><li><p>Eins</p></li></ol><ul data-marker="symbol" data-symbol="'.$symbol.'"><li><p>Punkt</p></li></ul>';
$canonical = FormattedText::canonical($html, true);
$this->assertSame($html, $canonical);
$this->assertSame($canonical, FormattedText::canonical($canonical, true), 'Die kanonische Form ist stabil.');
}
public function test_invalid_values_and_misplaced_markers_are_dropped(): void
{
$symbol = $this->symbol();
$this->assertSame('<p>A</p>', FormattedText::canonical('<p data-symbol="gibt-es-nicht">A</p>', true));
$this->assertSame('<p>A</p>', FormattedText::canonical('<p data-symbol="../x&quot; onclick=&quot;y">A</p>', true));
// Kreise gehören zur Nummerierung, Symbole zur Aufzählung; unbekannte Farbe entfällt, die Nummerierung bleibt im Kreis.
$this->assertSame('<ol data-marker="circle"><li><p>Eins</p></li></ol>', FormattedText::canonical('<ol data-marker="circle" data-tone="gibt-es-nicht"><li>Eins</li></ol>', true));
$this->assertSame('<ul><li><p>Punkt</p></li></ul>', FormattedText::canonical('<ul data-marker="circle"><li>Punkt</li></ul>', true));
$this->assertSame('<ul><li><p>Punkt</p></li></ul>', FormattedText::canonical('<ul data-marker="symbol"><li>Punkt</li></ul>', true), 'Ohne Symbol kein Symbolmarker.');
$this->assertSame('<ol><li><p>Eins</p></li></ol>', FormattedText::canonical('<ol data-marker="symbol" data-symbol="'.$symbol.'"><li>Eins</li></ol>', true));
$this->assertSame('<p data-symbol="'.$symbol.'">A</p>', FormattedText::canonical('<p data-symbol="'.$symbol.'" onclick="x()" data-fremd="1">A</p>', true), 'Fremde Attribute entfallen.');
}
public function test_a_symbol_stays_only_on_a_top_level_paragraph(): void
{
$symbol = $this->symbol();
$this->assertSame('<ul><li><p>Punkt</p></li></ul>', FormattedText::canonical('<ul><li><p data-symbol="'.$symbol.'">Punkt</p></li></ul>', true));
$this->assertSame('<blockquote><p>Zitat</p></blockquote>', FormattedText::canonical('<blockquote><p data-symbol="'.$symbol.'">Zitat</p></blockquote>', true));
$this->assertStringNotContainsString('data-symbol', FormattedText::canonical('<table><tbody><tr><td><p data-symbol="'.$symbol.'">Zelle</p></td></tr></tbody></table>', true));
}
public function test_the_catalog_profiles_know_no_markers(): void
{
$symbol = $this->symbol();
$this->assertSame('<p>A</p>', FormattedText::canonical('<p data-symbol="'.$symbol.'">A</p>'));
$this->assertSame('<ol><li><p>E</p></li></ol>', FormattedText::canonical('<ol data-marker="circle"><li>E</li></ol>'));
}
public function test_the_output_inserts_symbols_and_circles_and_leaves_plain_text_alone(): void
{
$symbol = $this->symbol();
$this->assertSame([], DesignPalette::save(null, 'Sand', '#f3e9d2', '#15243a'));
$plain = '<p>Nur Text</p><ul><li><p>A</p></li></ul>';
$this->assertSame($plain, TextMarkers::decorate($plain), 'Ein Text ohne Zeichen bleibt Byte für Byte gleich.');
$html = TextMarkers::decorate(
'<p data-symbol="'.$symbol.'">Mit Symbol</p>'
.'<ol data-marker="circle" data-tone="c1"><li><p>Eins</p></li><li><p>Zwei</p></li></ol>'
.'<ul data-marker="symbol" data-symbol="'.$symbol.'"><li><p>A</p></li><li><p>B</p></li></ul>',
);
$this->assertStringContainsString('<p data-symbol="'.$symbol.'" class="has-symbol"><span class="text-symbol" aria-hidden="true"><svg', $html);
$this->assertStringContainsString('class="text-list-circle"', $html);
$this->assertStringContainsString('--tone-bg: #f3e9d2; --tone-fg: #15243a', $html);
$this->assertSame(2, substr_count($html, 'text-list-symbol__mark'), 'Ein Symbol je Aufzählungspunkt.');
}
public function test_a_colour_that_no_longer_exists_falls_back_to_the_default(): void
{
$html = TextMarkers::decorate('<ol data-marker="circle" data-tone="c99"><li><p>Eins</p></li></ol>');
$this->assertStringContainsString('--tone-bg: #032551', $html);
}
public function test_bild_und_text_keeps_the_markers_and_drops_invalid_ones(): void
{
$symbol = $this->symbol();
$kept = RichText::sanitize('<p data-symbol="'.$symbol.'">A</p><ol data-marker="circle" data-tone="dark"><li>E</li></ol>');
$this->assertStringContainsString('data-symbol="'.$symbol.'"', $kept);
$this->assertStringContainsString('data-marker="circle"', $kept);
$dropped = RichText::sanitize('<p data-symbol="gibt-es-nicht" data-x="1">A</p><ul data-marker="circle"><li>E</li></ul>');
$this->assertStringNotContainsString('data-', $dropped);
}
public function test_the_published_page_shows_the_markers_in_text_and_in_bild_und_text(): void
{
$symbol = $this->symbol();
$body = '<p data-symbol="'.$symbol.'">Erster Absatz</p><ol data-marker="circle" data-tone="dark"><li><p>Eins</p></li></ol>';
$page = Page::query()->create(['path' => '/zeichen']);
$service = app(PageService::class);
$service->publish($page, $service->saveRevision($page, [
['layout' => 'u4', 'style' => [], 'slots' => [['type' => 'prose', 'v' => 2, 'settings' => [], 'data' => ['body' => $body]]]],
['layout' => 'u4', 'style' => [], 'slots' => [['type' => 'image_text', 'v' => 2, 'settings' => [], 'data' => ['title' => 'Bild', 'body' => $body]]]],
], null, null, null));
$html = $this->get('/zeichen')->assertOk()->getContent();
$this->assertSame(2, substr_count($html, 'class="has-symbol"'));
$this->assertSame(2, substr_count($html, 'class="text-list-circle"'));
}
public function test_a_colour_used_in_a_text_is_in_use(): void
{
$this->assertSame([], DesignPalette::save(null, 'Sand', '#f3e9d2', '#15243a'));
$page = Page::query()->create(['path' => '/farbe-im-text']);
$service = app(PageService::class);
$service->saveRevision($page, [
['layout' => 'u4', 'style' => [], 'slots' => [['type' => 'prose', 'v' => 2, 'settings' => [], 'data' => ['body' => '<ol data-marker="circle" data-tone="c1"><li><p>Eins</p></li></ol>']]]],
], null, null, null);
$uses = DesignPalette::usage();
$this->assertArrayHasKey('c1', $uses);
$this->assertSame('/farbe-im-text', $uses['c1'][0]['path']);
$this->assertNotSame([], DesignPalette::remove('c1'), 'Eine Farbe, die ein Text verwendet, lässt sich nicht entfernen.');
}
public function test_every_widget_with_formatted_text_shows_the_markers(): void
{
$symbol = $this->symbol();
$body = '<p data-symbol="'.$symbol.'">Absatz</p><ol data-marker="circle" data-tone="accent"><li><p>Eins</p></li></ol>';
$one = fn (array $widget): array => ['layout' => 'u4', 'style' => [], 'slots' => [$widget]];
$page = Page::query()->create(['path' => '/alle-widgets']);
$service = app(PageService::class);
$service->publish($page, $service->saveRevision($page, [
$one(['type' => 'heading', 'v' => 2, 'settings' => [], 'data' => ['heading' => 'Titel', 'intro' => $body]]),
$one(['type' => 'cards', 'v' => 2, 'variant' => 'standard', 'settings' => ['link_style' => 'text'], 'data' => ['items' => [['title' => 'K', 'text' => $body]]]]),
$one(['type' => 'notice', 'v' => 1, 'settings' => [], 'data' => ['title' => 'Hinweis', 'text' => $body]]),
], null, null, null));
$html = $this->get('/alle-widgets')->assertOk()->getContent();
$this->assertSame(3, substr_count($html, 'class="has-symbol"'), 'Überschrift, Karten und Hinweis zeigen das Symbol.');
$this->assertSame(3, substr_count($html, 'class="text-list-circle"'));
}
}