Die Abschnittshülle Version 2 kennt genau drei unabhängige Abstände mit denselben Stufen (Kein Abstand, Kompakt, Normal, Großzügig): - spacing_top / spacing_bottom: Innenabstand des Abschnitts; zwischen zwei Abschnitten addieren sich unten und oben (0 + 0 = 0). - gap: Abstand zwischen den Plätzen des Rasters, nebeneinander und gestapelt. Widget-Innenabstände bleiben im Widget. Entfallen sind „Abstand oben und unten“, die Abweichung „Abstand oben“ (same/small/none), die versteckte Regel, die oben zwischen zwei Abschnitten ohne Fläche auf null setzte, und der Trenner „Zusätzlicher Abstand“. Hüllen der Version 1 werden beim Lesen ohne Layoutänderung übersetzt (SectionStyle::migrateSpacing); gespeicherte Revisionen bleiben. Einzige Abweichung: „Gering“ hat keine eigene Stufe mehr und wird „Kompakt“. Tests bewusst angepasst (Hüllenversion 2, neue Klassen, Prüfung freier Werte über die neuen Schlüssel); neue Tests für Addition, Vorgaben und die Übersetzung aller Fälle der Version 1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
140 lines
7.6 KiB
PHP
140 lines
7.6 KiB
PHP
<?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\Filament\Resources\Pages\Pages\ListPages;
|
|
use App\Models\User;
|
|
use Filament\Facades\Filament;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Validation\ValidationException;
|
|
use Livewire\Livewire;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Nachprüfung 18.11.2026: Jede Seite ist in der Seitenliste ohne Suche auffindbar (zuletzt bearbeitete zuerst),
|
|
* und der erste Abschnitt kann ohne oder mit geringem Abstand an die Kopfzeile anschließen.
|
|
*/
|
|
class CmsPageListAndSpacingTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
Carbon::setTestNow();
|
|
|
|
parent::tearDown();
|
|
}
|
|
|
|
public function test_page_list_shows_the_most_recently_edited_page_first(): void
|
|
{
|
|
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
|
|
$editor = User::factory()->redakteur()->create();
|
|
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
|
$service = app(PageService::class);
|
|
|
|
Carbon::setTestNow('2026-11-18 08:00:00');
|
|
$pages = collect(range(1, 12))->map(fn (int $i) => Page::query()->create(['path' => '/seite-'.$i]));
|
|
|
|
// Die zuerst angelegte Seite wird zuletzt bearbeitet: Sie muss vorn stehen, obwohl sie die kleinste Kennung hat.
|
|
Carbon::setTestNow('2026-11-18 09:30:00');
|
|
$service->saveRevision($pages->first(), [['type' => 'heading', 'v' => 1, 'data' => ['heading' => 'Neu']]], null, null, $editor);
|
|
$this->assertSame('2026-11-18 09:30:00', $pages->first()->fresh()->updated_at->toDateTimeString());
|
|
|
|
Livewire::actingAs($editor, 'staff')
|
|
->test(ListPages::class)
|
|
->assertCanSeeTableRecords($pages->all())
|
|
->assertCanSeeTableRecords([$pages->first(), $pages->last()], inOrder: true)
|
|
->assertSee('18.11.2026 10:30', false)
|
|
->assertSee('Zuletzt bearbeitet');
|
|
}
|
|
|
|
public function test_publishing_also_counts_as_an_edit(): void
|
|
{
|
|
Carbon::setTestNow('2026-11-18 08:00:00');
|
|
$page = Page::query()->create(['path' => '/veroeffentlichen']);
|
|
$revision = app(PageService::class)->saveRevision($page, [['type' => 'heading', 'v' => 1, 'data' => ['heading' => 'A']]], null, null, null);
|
|
|
|
Carbon::setTestNow('2026-11-18 11:00:00');
|
|
app(PageService::class)->publish($page->fresh(), $revision);
|
|
|
|
$this->assertSame('2026-11-18 11:00:00', $page->fresh()->updated_at->toDateTimeString());
|
|
}
|
|
|
|
/**
|
|
* Drei unabhängige Abstände je Abschnitt; zwischen zwei Abschnitten addieren sich „unten“ und „oben“ (0 + 0 = 0).
|
|
*/
|
|
public function test_sections_render_three_independent_spacings(): void
|
|
{
|
|
$page = Page::query()->create(['path' => '/abstand']);
|
|
$service = app(PageService::class);
|
|
$prose = fn (string $text) => ['type' => 'prose', 'v' => 1, 'data' => ['body' => $text]];
|
|
$revision = $service->saveRevision($page, [
|
|
['layout' => 'u4', 'style' => ['spacing_top' => 'none', 'spacing_bottom' => 'none', 'gap' => 'none'], 'slots' => [['type' => 'hero', 'v' => 2, 'data' => ['heading' => 'Einstieg']]]],
|
|
['layout' => 'u3_1', 'style' => ['spacing_top' => 'none', 'spacing_bottom' => 'large', 'gap' => 'compact'], 'slots' => [$prose('Drei'), $prose('Eins')]],
|
|
['layout' => 'u4', 'style' => [], 'slots' => [$prose('Vorgabe')]],
|
|
], null, null, null);
|
|
$service->publish($page, $revision);
|
|
|
|
$html = $this->get('/abstand')->assertOk()->getContent();
|
|
$this->assertStringContainsString('section-space-top-none section-space-bottom-none section-gap-none section-layout-u4', $html);
|
|
$this->assertStringContainsString('section-space-top-none section-space-bottom-large section-gap-compact section-layout-u3-1', $html);
|
|
$this->assertStringContainsString('section-space-top-compact section-space-bottom-compact section-gap-normal section-layout-u4', $html, 'Vorgabe neuer Abschnitte: oben und unten kompakt, Widget-Abstand normal.');
|
|
$style = $revision->sections[0]['style'];
|
|
$this->assertSame(['none', 'none', 'none'], [$style['spacing_top'], $style['spacing_bottom'], $style['gap']]);
|
|
$this->assertStringContainsString('Abstand oben kein abstand, unten großzügig · Widget-Abstand kompakt', SectionStyle::summary($revision->sections[1]['style']));
|
|
}
|
|
|
|
/**
|
|
* Hüllen der Version 1 werden beim Lesen so übersetzt, dass die Darstellung gleich bleibt (gespeicherte Revision unverändert).
|
|
*/
|
|
public function test_version_one_spacing_is_translated_without_changing_the_layout(): void
|
|
{
|
|
$prose = ['type' => 'prose', 'v' => 1, 'data' => ['body' => 'Text']];
|
|
$v1 = fn (array $style, ?array $slots = null) => ['id' => null, 'v' => 1, 'layout' => 'u4', 'style' => $style + ['divider' => 'none'], 'slots' => $slots ?? [$prose]];
|
|
|
|
$sections = app(PageSections::class)->read([
|
|
$v1(['background' => 'default', 'spacing' => 'normal', 'spacing_top' => 'none']),
|
|
$v1(['background' => 'default', 'spacing' => 'normal']),
|
|
$v1(['background' => 'dark', 'spacing' => 'large']),
|
|
$v1(['background' => 'default', 'spacing' => 'compact', 'divider' => 'line']),
|
|
$v1(['background' => 'default', 'spacing' => 'normal', 'spacing_top' => 'small']),
|
|
$v1(['background' => 'default', 'spacing' => 'compact', 'divider' => 'space']),
|
|
$v1(['background' => 'default', 'spacing' => 'normal'], [null]),
|
|
$v1(['background' => 'default', 'spacing' => 'large']),
|
|
]);
|
|
|
|
$spacing = array_map(fn ($s) => [$s['style']['spacing_top'], $s['style']['spacing_bottom'], $s['style']['gap'], $s['style']['divider']], $sections);
|
|
$this->assertSame([
|
|
['none', 'normal', 'normal', 'none'], // Abweichung „kein Abstand“
|
|
['none', 'normal', 'normal', 'none'], // folgt Abschnitt ohne Fläche: bisher oben 0
|
|
['large', 'large', 'normal', 'none'], // eigene Fläche: oben wie Abstand
|
|
['compact', 'compact', 'normal', 'line'], // folgt dunkler Fläche: oben wie Abstand
|
|
['compact', 'normal', 'normal', 'none'], // nach Linientrenner keine Zusammenlegung; „Gering“ wird „Kompakt“
|
|
['none', 'normal', 'normal', 'none'], // folgt ohne Fläche: oben 0; „Zusätzlicher Abstand“ wird unten eine Stufe mehr
|
|
['none', 'normal', 'normal', 'none'], // leer, wird nicht dargestellt
|
|
['none', 'large', 'normal', 'none'], // folgt Abschnitt 5 (leerer Abschnitt dazwischen zählt nicht)
|
|
], $spacing);
|
|
$this->assertSame([2, 2], [$sections[0]['v'], $sections[7]['v']]);
|
|
$this->assertArrayNotHasKey('spacing', $sections[0]['style']);
|
|
}
|
|
|
|
public function test_spacings_accept_only_their_enumerated_values(): void
|
|
{
|
|
foreach (['spacing_top' => 'medium', 'spacing_bottom' => '0px', 'gap' => '2rem'] as $key => $value) {
|
|
try {
|
|
app(PageSections::class)->normalize([
|
|
['layout' => 'u4', 'style' => ['spacing_top' => 'none', 'spacing_bottom' => 'none', 'gap' => 'none', $key => $value], 'slots' => [['type' => 'prose', 'v' => 1, 'data' => ['body' => 'Text']]]],
|
|
]);
|
|
$this->fail("$key: $value wurde angenommen.");
|
|
} catch (ValidationException $exception) {
|
|
$this->assertArrayHasKey("sections.0.style.$key", $exception->errors());
|
|
}
|
|
}
|
|
}
|
|
}
|