Files
laraundfelix/tests/Feature/CmsSectionRenderingTest.php
T
LarsandClaude Sonnet 5.5 2e6260acca Gestalte den Mitgliederbereich nach Brand-UI-Kit 14 neu
Eine Navigation (Meine Bibliothek, Programme, Meine Lizenzen, Konto-Menü) mit der freigegebenen Wortmarke,
Startseite ohne erfundene Inhalte, Bibliothek mit Inhaltsart-Filter und einer Karte je Medienidentität
(„Verwendet in“), Programm-/Moduldetail, Film und Material im Zusammenhang mit Begleitmaterial und Weg zurück,
Lizenzübersicht mit Detailseite je Berechtigung. Alle Größen aus der Größenskala (ADR-44, neues Token --card-min).

Tests bewusst angepasst: Der Film spielt auf der Kontextseite statt eingebettet im Programm, Download-Links tragen
ein Symbol, der Platzhalter ist ein dekoratives Element, die Wortmarke ist das freigegebene Logo. Die Vorschau der
Bibliothekskarte in der Verwaltung nutzt dieselbe Komponente.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-22 17:56:16 +01:00

270 lines
14 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace Tests\Feature;
use App\Domain\Cms\NavigationItem;
use App\Domain\Cms\Page;
use App\Domain\Cms\PageService;
use App\Domain\Cms\Widgets\RenderContext;
use App\Domain\Cms\Widgets\WidgetRenderer;
use App\Jobs\PublishPublicMedia;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Queue;
use Tests\Support\BuildsCatalog;
use Tests\TestCase;
/**
* Öffentliche Darstellung der Abschnitte, globales Website-Gerüst und Rückfallweg.
*/
class CmsSectionRenderingTest extends TestCase
{
use BuildsCatalog;
use RefreshDatabase;
/**
* @return array<string, mixed>
*/
private function heading(string $text): array
{
return ['type' => 'heading', 'v' => 1, 'data' => ['heading' => $text]];
}
/**
* @return array<string, mixed>
*/
private function prose(string $text): array
{
return ['type' => 'prose', 'v' => 1, 'data' => ['body' => $text]];
}
/**
* @param list<array<string, mixed>> $sections
*/
private function publish(string $path, array $sections): Page
{
$service = app(PageService::class);
$page = Page::query()->create(['path' => $path]);
$service->publish($page, $service->saveRevision($page, $sections, null, null, null));
return $page->fresh();
}
public function test_sections_render_grid_ratios_backgrounds_and_dividers(): void
{
$this->publish('/raster', [
['layout' => 'u4', 'style' => ['background' => 'dark', 'divider' => 'accent'], 'slots' => [$this->heading('Einstieg')]],
['layout' => 'u1_3', 'style' => ['background' => 'light', 'width' => 'wide', 'divider' => 'line'], 'slots' => [$this->prose('Schmal'), $this->prose('Breit')]],
['layout' => 'u1_1_1_1', 'style' => ['background' => 'accent', 'spacing' => 'large'], 'slots' => [$this->prose('A'), $this->prose('B'), $this->prose('C'), $this->prose('D')]],
['layout' => 'u2_2', 'style' => ['divider' => 'line'], 'slots' => [$this->prose('Letzter')]],
]);
$html = $this->get('/raster')->assertOk()->getContent();
$this->assertStringContainsString('page-section section-bg-dark section-width-standard section-space-top-compact section-space-bottom-compact section-gap-normal section-layout-u4 scope-dark', $html);
$this->assertStringContainsString('section-bg-light section-width-wide', $html);
$this->assertStringContainsString('--section-cols-lg: minmax(0, 1fr) minmax(0, 3fr); --section-cols-md: minmax(0, 1fr)', $html);
$this->assertStringContainsString('--section-cols-md: repeat(2, minmax(0, 1fr))', $html, 'Vier gleiche Plätze stehen auf dem Tablet als 2 × 2.');
// Eingabe im Format der Version 1 („spacing“): oben und unten großzügig, Widget-Abstand wie bisher normal.
$this->assertStringContainsString('section-bg-accent section-width-standard section-space-top-large section-space-bottom-large section-gap-normal section-layout-u1-1-1-1 scope-accent', $html);
$this->assertStringContainsString('section-divider section-divider-accent', $html);
$this->assertSame(1, substr_count($html, 'section-divider section-divider-line'), 'Nach dem letzten Abschnitt steht kein Trenner.');
$this->assertSame(1, substr_count($html, '<h1>'), 'Nur das erste Widget der Seite ist Überschrift erster Ordnung.');
$this->assertLessThan(strpos($html, 'Breit'), strpos($html, 'Schmal'), 'Lese- und Fokusreihenfolge folgt den Plätzen.');
}
public function test_empty_slots_and_empty_sections_leave_no_gaps(): void
{
$this->publish('/luecken', [
['layout' => 'u1_2_1', 'style' => [], 'slots' => [$this->prose('Links'), null, $this->prose('Rechts')]],
['layout' => 'u2_2', 'style' => ['background' => 'dark'], 'slots' => [null, null]],
['layout' => 'u1_3', 'style' => [], 'slots' => [null, $this->prose('Allein')]],
]);
$html = $this->get('/luecken')->assertOk()->getContent();
$this->assertStringContainsString('data-slots="2" style="--section-cols-lg: minmax(0, 1fr) minmax(0, 1fr)', $html, 'Die übrigen Plätze teilen sich die Breite im Verhältnis ihrer Einheiten.');
$this->assertStringContainsString('data-slots="1" style="--section-cols-lg: minmax(0, 1fr)', $html);
$this->assertStringNotContainsString('section-bg-dark', $html, 'Ein Abschnitt ohne Inhalt entfällt samt Fläche.');
}
public function test_background_image_comes_from_the_public_area_with_focus_and_overlay(): void
{
Queue::fake();
$this->publish('/bild', [
['layout' => 'u4', 'style' => ['background' => 'image', 'image' => 'cms/flaeche.jpg', 'focus' => 'top_left', 'overlay' => 'dark'], 'slots' => [$this->heading('Auf Bild')]],
['layout' => 'u4', 'style' => ['background' => 'image', 'image' => 'cms/zweites.jpg', 'overlay' => 'light'], 'slots' => [$this->prose('Hell')]],
]);
$html = $this->get('/bild')->assertOk()->getContent();
$this->assertStringContainsString('section-bg-image', $html);
$this->assertStringContainsString('section-overlay-dark scope-dark', $html);
$this->assertStringContainsString('section-overlay-light scope-light', $html);
$this->assertMatchesRegularExpression('#<img class="page-section-image" src="[^"]*cms/flaeche\.jpg" alt="" loading="eager" fetchpriority="high"[^>]*object-position: 0% 0%#', $html);
$this->assertMatchesRegularExpression('#<img class="page-section-image" src="[^"]*cms/zweites\.jpg" alt="" loading="lazy"#', $html);
Queue::assertPushed(PublishPublicMedia::class, 2);
}
public function test_preview_uses_the_same_renderer_as_the_public_page(): void
{
$page = $this->publish('/gleich', [
['layout' => 'u2_2', 'style' => ['background' => 'light'], 'slots' => [$this->heading('Links'), $this->prose('Rechts')]],
]);
$editor = User::factory()->redakteur()->create();
$public = $this->get('/gleich')->getContent();
$preview = $this->actingAs($editor, 'staff')->get(route('pages.preview', $page->published_revision_id))->getContent();
$this->assertSame($this->sectionsMarkup($public), $this->sectionsMarkup($preview));
$this->assertStringContainsString('Vorschau einer unveröffentlichten Revision', $preview);
}
public function test_public_page_is_identical_for_guests_and_members(): void
{
// Schrift-Vorabladehinweise gibt der Rahmen je Prozess nur einmal aus; sie hängen nicht vom Besucher ab.
$withoutPreload = fn (string $html): string => preg_replace('#<link rel="preload" as="font"[^>]*>\s*#', '', $html);
$guest = $withoutPreload($this->get('/praevention')->assertOk()->getContent());
$member = $withoutPreload($this->actingAs(User::factory()->create())->get('/praevention')->assertOk()->getContent());
$this->assertSame($guest, $member, 'Öffentliche Seiten hängen nicht vom Anmeldestatus ab (ADR-32).');
$this->assertStringContainsString('href="'.route('member.dashboard').'"', $guest);
$this->assertStringContainsString('Mitgliederbereich', $guest);
}
public function test_global_layout_has_header_navigation_mobile_menu_and_footer(): void
{
// Der Warenkorb gehört zum Shop (Etappe 1, nur Testzahlung). Ohne aktiven Shop erscheint kein Kaufknopf.
config(['services.payment.driver' => 'unbekannt']);
$html = $this->get('/praevention')->assertOk()->getContent();
$this->assertStringContainsString('<a class="skip" href="#inhalt">', $html);
// Seit 18.11.2026: freigegebene Wortmarke als Bild statt vorläufigem Schriftzug (Brand-UI-Kit 08).
$this->assertStringContainsString('class="brand brand-logo" href="'.route('home').'" data-brand-status="freigegeben"', $html);
$this->assertStringContainsString('images/brand/lara-felix-logo-kompakt-128.webp', $html);
$this->assertStringContainsString('aria-label="Hauptnavigation"', $html);
$this->assertMatchesRegularExpression('#<a href="[^"]*/praevention"\s+aria-current="page"\s*>Prävention</a>#', $html);
$this->assertStringContainsString('data-site-menu-button', $html);
$this->assertStringContainsString('aria-controls="site-nav"', $html);
$this->assertStringContainsString('class="site-footer scope-dark"', $html);
$this->assertStringContainsString('<h2 id="fuss-footer">Service</h2>', $html);
$this->assertStringContainsString('Impressum', $html);
$this->assertStringNotContainsString('Warenkorb', $html, 'Ohne aktiven Shop erscheint kein Kaufknopf.');
$this->assertStringNotContainsString('fonts.bunny.net', $html);
$this->assertStringNotContainsString('fonts.googleapis.com', $html);
}
public function test_cart_entry_appears_only_when_the_shop_is_enabled(): void
{
// Seit Etappe 1 ist der Warenkorb umgesetzt: Der Eintrag folgt dem Shop (Testzahlung, nie Produktion)
// statt der früheren Vorbereitung über cms.cart.*.
$this->get('/praevention')->assertSee('Warenkorb')->assertSee('href="'.route('cart').'"', false);
config(['services.payment.driver' => 'unbekannt']);
$this->get('/praevention')->assertDontSee('Warenkorb');
}
public function test_submenus_footer_groups_and_hidden_parents(): void
{
$parent = NavigationItem::query()->where('label', 'Prävention')->firstOrFail();
NavigationItem::query()->create(['label' => 'Grenzen', 'url' => '/themen/grenzen', 'placement' => 'header', 'parent_id' => $parent->id, 'sort_order' => 1]);
NavigationItem::query()->create(['label' => 'Kontaktformular', 'url' => '/kontakt', 'placement' => 'footer_contact', 'sort_order' => 1]);
NavigationItem::query()->create(['label' => 'Fußkind', 'url' => '/x', 'placement' => 'footer', 'parent_id' => $parent->id, 'sort_order' => 2]);
$html = $this->get('/praevention')->getContent();
$this->assertStringContainsString('site-nav-item has-children is-active-trail', $html);
$this->assertStringContainsString('aria-controls="untermenue-'.$parent->id.'"', $html);
$this->assertStringContainsString('Untermenü Prävention', $html);
$this->assertMatchesRegularExpression('#<ul class="site-subnav" id="untermenue-'.$parent->id.'">\s*<li><a href="[^"]*/themen/grenzen"\s*>Grenzen</a></li>#', $html);
$this->assertStringContainsString('<h2 id="fuss-footer_contact">Kontakt</h2>', $html);
$this->assertNull(NavigationItem::query()->where('label', 'Fußkind')->value('parent_id'), 'Untermenüs gibt es nur in der Hauptnavigation.');
$parent->update(['is_visible' => false]);
$this->assertStringNotContainsString('Grenzen', $this->get('/praevention')->getContent(), 'Mit dem Eintrag ist auch sein Untermenü ausgeblendet.');
}
public function test_deleting_a_parent_moves_its_children_to_the_top_level(): void
{
$parent = NavigationItem::query()->where('label', 'Prävention')->firstOrFail();
$child = NavigationItem::query()->create(['label' => 'Grenzen', 'url' => '/themen/grenzen', 'placement' => 'header', 'parent_id' => $parent->id]);
$parent->delete();
$this->assertNull($child->fresh()->parent_id);
$this->get('/ueber')->assertSee('Grenzen');
}
public function test_member_area_uses_the_shared_wordmark_and_tokens(): void
{
$member = User::factory()->create();
$this->actingAs($member)
->get(route('member.dashboard'))
->assertOk()
// Seit Kit 14 trägt der Mitgliederbereich die freigegebene Wortmarke der Website und eine einzige Navigation.
->assertSee('class="brand brand-logo mb-brand"', false)
->assertSee('data-brand-status="freigegeben"', false)
->assertSee('class="mb-nav"', false)
->assertSee('class="mb-dock"', false);
}
public function test_rollback_column_lets_the_previous_renderer_show_every_widget(): void
{
$page = $this->publish('/rueckfall', [
['layout' => 'u1_1_1_1', 'style' => ['background' => 'dark'], 'slots' => [$this->heading('Erstens'), $this->prose('Zweitens'), null, $this->prose('Viertens')]],
]);
// Darstellung wie in der Fassung vor dem Abschnittsraster: flache Liste aus der Spalte blocks.
$html = app(WidgetRenderer::class)->renderAll($page->publishedRevision->blocks, RenderContext::publicPage())->toHtml();
foreach (['Erstens', 'Zweitens', 'Viertens'] as $text) {
$this->assertStringContainsString($text, $html);
}
}
public function test_restore_copies_sections_and_rollback_column_unchanged(): void
{
$page = $this->publish('/wieder', [
['layout' => 'u2_2', 'style' => ['background' => 'light'], 'slots' => [$this->heading('Früher'), $this->prose('Stand')]],
]);
$first = $page->publishedRevision;
$service = app(PageService::class);
$service->publish($page, $service->saveRevision($page, [['layout' => 'u4', 'style' => [], 'slots' => [$this->heading('Später')]]], null, null, null));
$restored = $service->restore($page->fresh(), $first, null);
$service->publish($page->fresh(), $restored);
$this->assertSame($first->sections, $restored->fresh()->sections);
$this->assertSame($first->blocks, $restored->fresh()->blocks);
$this->get('/wieder')->assertSee('Früher')->assertDontSee('Später');
}
public function test_program_reference_in_a_narrow_slot_reads_catalog_data(): void
{
$program = $this->composition('Programm Abstand', 'programm', summary: 'Kurzbeschreibung aus den Fachdaten');
$this->publish('/programme-schmal', [
['layout' => 'u3_1', 'style' => [], 'slots' => [
$this->prose('Hauptinhalt'),
['type' => 'catalog_cards', 'v' => 1, 'variant' => 'compact', 'data' => [], 'refs' => ['items' => [['type' => 'composition', 'id' => $program->composition_id]]]],
]],
]);
$this->get('/programme-schmal')
->assertOk()
->assertSee('Programm Abstand')
->assertSee('catalog-cards catalog-cards-compact', false)
->assertSee('data-units="1"', false);
}
private function sectionsMarkup(string $html): string
{
preg_match('#<main[^>]*>(.*)</main>#s', $html, $match);
$markup = preg_replace('#<p class="preview-banner".*?</p>#s', '', $match[1] ?? '');
return trim(preg_replace('/\s+/', ' ', $markup));
}
}