Kopf, Fuß und verknüpfte Sektionen als Blockdokumente (Paket G, Teil 1)
Migration 20260912001000 legt die Tabelle partial an: Blockdokumente, die keine Seiten sind. Kopf- und Fußbereich je einmal, wiederverwendbare Sektionen beliebig viele - im selben Editor gestaltbar wie eine Seite, weil der Editor seine Schnittstelle aus einem Datenattribut nimmt statt sie fest zu kennen. Im Template steht keine Marke und keine Navigation mehr. Ein neuer Block menu zeigt einen Menüplatz; die Einträge bleiben in der Menüverwaltung. Eine Seite braucht genau eine Hauptüberschrift, ein geteilter Bereich keine - sonst hätte jede Seite, die ihn trägt, zwei. Geteilte Bereiche haben keinen Entwurf und keine Veröffentlichung: sie sind überall sichtbar, gespeichert heißt live. Verknüpft statt kopiert: partialref speichert nur die Adresse, die Blöcke bleiben im Bereich, und eine Änderung erreicht jede Seite, die sie einbindet. Zyklen abgewiesen, Verschachtelung auf drei Ebenen begrenzt, eine entfernte Sektion hinterlässt keine Lücke und der Verweis bleibt erhalten. Die Abschnittsvorlagen kopieren weiterhin. Ein echter Fehler kam dabei heraus, der jede dunkle Sektion mit Spalten betraf: .block-column>.block-text:first-child setzt eine Farbe für helle Hintergründe und gewinnt auf Spezifität gegen .tone-ink - gemessen 1,87:1. Geprüft: 165 PHP-Tests / 660 Assertions unter PHP 8.2.12 und 8.4.22, 15 JavaScript-Modelltests, Editortest mit axe ohne Verstöße, öffentliche Browserprüfung, Migration nach Backup angewendet. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
33e4ac0c54
commit
d0938eec69
26 files changed
+955
-56
No files matched your search
@@ -7,6 +7,7 @@ use App\Content\DocumentValidator;
|
||||
use App\Content\MediaLibrary;
|
||||
use App\Content\MenuRepository;
|
||||
use App\Content\PageRepository;
|
||||
use App\Content\PartialRepository;
|
||||
use App\Content\PostRepository;
|
||||
use App\Content\RedirectRepository;
|
||||
use App\Content\SiteSettings;
|
||||
@@ -27,6 +28,7 @@ use DoctrineMigrations\Version20260912000600;
|
||||
use DoctrineMigrations\Version20260912000700;
|
||||
use DoctrineMigrations\Version20260912000800;
|
||||
use DoctrineMigrations\Version20260912000900;
|
||||
use DoctrineMigrations\Version20260912001000;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\NullLogger;
|
||||
@@ -42,6 +44,7 @@ final class CmsTest extends TestCase
|
||||
private SiteSettings $site;
|
||||
private RedirectRepository $redirects;
|
||||
private Theme $themes;
|
||||
private PartialRepository $partials;
|
||||
private string $path;
|
||||
|
||||
protected function setUp(): void
|
||||
@@ -57,6 +60,7 @@ final class CmsTest extends TestCase
|
||||
(new Version20260912000700($this->db, new NullLogger()))->up($schema);
|
||||
(new Version20260912000800($this->db, new NullLogger()))->up($schema);
|
||||
(new Version20260912000900($this->db, new NullLogger()))->up($schema);
|
||||
(new Version20260912001000($this->db, new NullLogger()))->up($schema);
|
||||
foreach ($schema->toSql($this->db->getDatabasePlatform()) as $sql) {
|
||||
$this->db->executeStatement($sql);
|
||||
}
|
||||
@@ -73,6 +77,11 @@ final class CmsTest extends TestCase
|
||||
$this->site = new SiteSettings($this->db);
|
||||
$this->redirects = new RedirectRepository($this->db);
|
||||
$this->themes = new Theme($this->db);
|
||||
$this->partials = new PartialRepository($this->db, new DocumentValidator());
|
||||
// A real installation has a header and a footer; the navigation lives in the header area.
|
||||
foreach (DemoContent::areas() as $kind => $area) {
|
||||
$this->partials->create($kind, 'default', $area['name'], $area['document']);
|
||||
}
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
@@ -1419,6 +1428,123 @@ final class CmsTest extends TestCase
|
||||
self::assertSame($before, $this->site->load()['homePath']);
|
||||
}
|
||||
|
||||
public function testHeaderAndFooterAreEditableDocumentsThatReachEveryPage(): void
|
||||
{
|
||||
$this->pages->publish('page-1', $this->pages->saveDraft('page-1', DemoContent::pages()['home'], 0), 1);
|
||||
$second = $this->publishedPage('zweite', 'Zweite Seite');
|
||||
self::assertNotNull($this->pages->findForEditor($second));
|
||||
|
||||
// The seeded areas render as ordinary blocks, and the navigation block shows the menu.
|
||||
$this->menus->save('header', 'Hauptnavigation', [
|
||||
['label' => 'Start', 'type' => 'page', 'pageId' => 'page-1', 'anchor' => '', 'children' => []],
|
||||
], 0);
|
||||
$html = $this->request('/')->getContent();
|
||||
self::assertStringContainsString('<header class="site-header">', $html);
|
||||
self::assertStringContainsString('<p id="area-header-name" class="block-text">kant cms</p>', $html);
|
||||
self::assertStringContainsString('aria-label="Hauptnavigation"', $html);
|
||||
self::assertStringContainsString('>Start</a>', $html);
|
||||
|
||||
// Changing the header reaches every page at once, because it is one shared document.
|
||||
$header = $this->partials->findByKind('header');
|
||||
$document = $header['document'];
|
||||
$document['blocks'][0]['children'][0]['children'][0]['children'][0]['props']['text'] = 'Neue Wortmarke';
|
||||
$this->partials->save($header['id'], $document, $header['version']);
|
||||
foreach (['/', '/zweite'] as $path) {
|
||||
self::assertStringContainsString('Neue Wortmarke', $this->request($path)->getContent(), $path);
|
||||
self::assertStringNotContainsString('kant cms', $this->request($path)->getContent(), $path);
|
||||
}
|
||||
|
||||
// An emptied area renders nothing rather than leaving a broken shell behind.
|
||||
$footer = $this->partials->findByKind('footer');
|
||||
$this->partials->save($footer['id'], [...$footer['document'], 'blocks' => []], $footer['version']);
|
||||
self::assertStringContainsString('<footer class="site-footer">', $this->request('/')->getContent());
|
||||
self::assertStringNotContainsString('Viele Möglichkeiten', $this->request('/')->getContent());
|
||||
}
|
||||
|
||||
public function testALinkedSectionChangesOnEveryPageThatEmbedsIt(): void
|
||||
{
|
||||
$sectionId = $this->partials->create('section', 'aufruf', 'Aufruf-Band', [
|
||||
'schemaVersion' => 11, 'title' => 'Aufruf-Band', 'description' => 'Wiederverwendbar.',
|
||||
'blocks' => [['id' => 'cta-section', 'type' => 'section', 'children' => [
|
||||
['id' => 'cta-heading', 'type' => 'heading', 'props' => ['text' => 'Bereit?', 'level' => 2]],
|
||||
]]],
|
||||
]);
|
||||
|
||||
$withRef = static function (string $title): array {
|
||||
$document = DemoContent::starter($title);
|
||||
$document['schemaVersion'] = 11;
|
||||
$document['blocks'][] = ['id' => 'ref', 'type' => 'partialref', 'props' => ['partial' => 'aufruf']];
|
||||
|
||||
return $document;
|
||||
};
|
||||
$this->pages->publish('page-1', $this->pages->saveDraft('page-1', $withRef('Erste'), 0), 1);
|
||||
$other = $this->pages->createPage('zweite', null, 'page', $withRef('Zweite'));
|
||||
$page = $this->pages->findForEditor($other);
|
||||
$this->pages->publish($other, $page['draft_revision_id'], $page['version']);
|
||||
|
||||
foreach (['/', '/zweite'] as $path) {
|
||||
self::assertStringContainsString('Bereit?', $this->request($path)->getContent(), $path);
|
||||
}
|
||||
// The page documents carry only the address, never the section's blocks.
|
||||
self::assertSame(['partial' => 'aufruf'], $this->pages->findPublished('zweite')['document']['blocks'][2]['props']);
|
||||
|
||||
// One change in the section reaches both pages.
|
||||
$section = $this->partials->find($sectionId);
|
||||
$document = $section['document'];
|
||||
$document['blocks'][0]['children'][0]['props']['text'] = 'Jetzt anfragen';
|
||||
$this->partials->save($sectionId, $document, $section['version']);
|
||||
foreach (['/', '/zweite'] as $path) {
|
||||
self::assertStringContainsString('Jetzt anfragen', $this->request($path)->getContent(), $path);
|
||||
self::assertStringNotContainsString('Bereit?', $this->request($path)->getContent(), $path);
|
||||
}
|
||||
self::assertSame(['/home', '/zweite'], $this->partials->usedBy('aufruf'));
|
||||
|
||||
// Removing the section leaves both pages intact; the reference stays stored.
|
||||
$this->partials->delete($sectionId);
|
||||
$stripped = $this->request('/');
|
||||
self::assertSame(200, $stripped->getStatusCode());
|
||||
self::assertStringContainsString('<!-- Verknüpfte Sektion aufruf ist nicht vorhanden. -->', $stripped->getContent());
|
||||
self::assertSame('aufruf', $this->pages->findPublished('home')['document']['blocks'][2]['props']['partial']);
|
||||
}
|
||||
|
||||
public function testSharedAreasRefuseAMainHeadingAndSectionsRefuseToContainThemselves(): void
|
||||
{
|
||||
// A page brings its own main heading; an area appearing on every page must not add one.
|
||||
try {
|
||||
$this->partials->create('section', 'mit-h1', 'Mit H1', [
|
||||
'schemaVersion' => 11, 'title' => 'Mit H1', 'description' => 'x',
|
||||
'blocks' => [['id' => 'h', 'type' => 'heading', 'props' => ['text' => 'Titel', 'level' => 1]]],
|
||||
]);
|
||||
self::fail('Expected a main heading in a shared area to be refused.');
|
||||
} catch (InvalidDocument) {
|
||||
}
|
||||
|
||||
$id = $this->partials->create('section', 'selbst', 'Selbstbezug', [
|
||||
'schemaVersion' => 11, 'title' => 'Selbstbezug', 'description' => 'x',
|
||||
'blocks' => [['id' => 's', 'type' => 'section', 'children' => []]],
|
||||
]);
|
||||
$cyclic = ['schemaVersion' => 11, 'title' => 'Selbstbezug', 'description' => 'x', 'blocks' => [
|
||||
['id' => 's', 'type' => 'partialref', 'props' => ['partial' => 'selbst']],
|
||||
]];
|
||||
try {
|
||||
$this->partials->save($id, $cyclic, $this->partials->find($id)['version']);
|
||||
self::fail('Expected a section containing itself to be refused.');
|
||||
} catch (InvalidPage) {
|
||||
}
|
||||
// Nothing was written, so the section still holds its original block.
|
||||
self::assertSame('section', $this->partials->find($id)['document']['blocks'][0]['type']);
|
||||
|
||||
// Only one header and one footer.
|
||||
try {
|
||||
$this->partials->create('header', 'zweiter', 'Zweiter Kopf', ['schemaVersion' => 11, 'title' => 'x', 'description' => 'x', 'blocks' => []]);
|
||||
self::fail('Expected a second header to be refused.');
|
||||
} catch (InvalidPage) {
|
||||
}
|
||||
// And they cannot be deleted, only emptied.
|
||||
$this->expectException(InvalidPage::class);
|
||||
$this->partials->delete($this->partials->findByKind('header')['id']);
|
||||
}
|
||||
|
||||
private function request(string $url, string $method = 'GET'): Response
|
||||
{
|
||||
$previous = [];
|
||||
|
||||
Reference in new issue
Block a user