Themenbereiche
diff --git a/tests/Feature/CmsPageListAndSpacingTest.php b/tests/Feature/CmsPageListAndSpacingTest.php
index 750ec18..5b4e350 100644
--- a/tests/Feature/CmsPageListAndSpacingTest.php
+++ b/tests/Feature/CmsPageListAndSpacingTest.php
@@ -65,32 +65,75 @@ public function test_publishing_also_counts_as_an_edit(): void
$this->assertSame('2026-11-18 11:00:00', $page->fresh()->updated_at->toDateTimeString());
}
- public function test_first_section_can_start_directly_below_the_header_without_changing_other_spacing(): void
+ /**
+ * 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);
- $hero = ['type' => 'hero', 'v' => 2, 'data' => ['heading' => 'Einstieg']];
+ $prose = fn (string $text) => ['type' => 'prose', 'v' => 1, 'data' => ['body' => $text]];
$revision = $service->saveRevision($page, [
- ['layout' => 'u4', 'style' => ['spacing_top' => 'none', 'spacing' => 'large'], 'slots' => [$hero]],
- ['layout' => 'u4', 'style' => ['spacing_top' => 'small'], 'slots' => [['type' => 'prose', 'v' => 1, 'data' => ['body' => 'Text']]]],
- ['layout' => 'u4', 'style' => [], 'slots' => [['type' => 'prose', 'v' => 1, 'data' => ['body' => 'Weiter']]]],
+ ['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->assertMatchesRegularExpression('#class="page-section section-bg-default section-width-standard section-space-large section-space-top-none section-layout-u4"#', $html);
- $this->assertStringContainsString('section-space-normal section-space-top-small section-layout-u4', $html);
- $this->assertSame(2, substr_count($html, 'section-space-top-'), 'Ohne Angabe gilt der normale Abstand; keine zusätzliche Klasse.');
- $this->assertSame('same', $revision->sections[2]['style']['spacing_top']);
- $this->assertStringContainsString('oben kein abstand', SectionStyle::summary($revision->sections[0]['style']));
+ $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']));
}
- public function test_top_spacing_accepts_only_its_enumerated_values(): void
+ /**
+ * 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
{
- $this->expectException(ValidationException::class);
+ $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]];
- app(PageSections::class)->normalize([
- ['layout' => 'u4', 'style' => ['spacing_top' => '0px'], 'slots' => [['type' => 'prose', 'v' => 1, 'data' => ['body' => 'Text']]]],
+ $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());
+ }
+ }
}
}
diff --git a/tests/Feature/CmsSectionRenderingTest.php b/tests/Feature/CmsSectionRenderingTest.php
index 38c6fe6..a8bbd23 100644
--- a/tests/Feature/CmsSectionRenderingTest.php
+++ b/tests/Feature/CmsSectionRenderingTest.php
@@ -61,11 +61,12 @@ public function test_sections_render_grid_ratios_backgrounds_and_dividers(): voi
$html = $this->get('/raster')->assertOk()->getContent();
- $this->assertStringContainsString('page-section section-bg-dark section-width-standard section-space-normal section-layout-u4 scope-dark', $html);
+ $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.');
- $this->assertStringContainsString('section-bg-accent section-width-standard section-space-large section-layout-u1-1-1-1 scope-accent', $html);
+ // 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, ''), 'Nur das erste Widget der Seite ist Überschrift erster Ordnung.');
diff --git a/tests/Unit/PageSectionsTest.php b/tests/Unit/PageSectionsTest.php
index 2006a7e..a8505f6 100644
--- a/tests/Unit/PageSectionsTest.php
+++ b/tests/Unit/PageSectionsTest.php
@@ -65,7 +65,7 @@ public function test_sections_are_normalized_with_slots_matching_the_layout(): v
$this->assertCount(2, $stored);
$this->assertSame('u1_3', $stored[0]['layout']);
- $this->assertSame(1, $stored[0]['v']);
+ $this->assertSame(2, $stored[0]['v'], 'Hülle Version 2: drei unabhängige Abstände.');
$this->assertSame('dark', $stored[0]['style']['background']);
$this->assertSame('line', $stored[0]['style']['divider']);
$this->assertSame('standard', $stored[0]['style']['width']);
@@ -141,7 +141,9 @@ public function test_free_style_values_and_unknown_layouts_are_rejected(): void
[['layout' => 'u5', 'slots' => []], 'sections.0.layout'],
[$this->section('u4', [], ['background' => '#ff00ff']), 'sections.0.style.background'],
[$this->section('u4', [], ['css' => 'color: red']), 'sections.0.style.css'],
- [$this->section('u4', [], ['spacing' => 'riesig']), 'sections.0.style.spacing'],
+ [$this->section('u4', [], ['spacing_top' => 'riesig']), 'sections.0.style.spacing_top'],
+ [$this->section('u4', [], ['spacing_bottom' => '0px']), 'sections.0.style.spacing_bottom'],
+ [$this->section('u4', [], ['gap' => '3rem']), 'sections.0.style.gap'],
] as [$section, $key]) {
try {
$this->sections()->normalize([$section]);
@@ -218,7 +220,8 @@ public function test_reading_without_sections_wraps_legacy_blocks_in_single_colu
$this->assertCount(2, $sections);
$this->assertSame('u4', $sections[0]['layout']);
- $this->assertSame('compact', $sections[0]['style']['spacing']);
+ $this->assertSame(['compact', 'compact', 'normal'], [$sections[0]['style']['spacing_top'], $sections[0]['style']['spacing_bottom'], $sections[0]['style']['gap']]);
+ $this->assertSame('none', $sections[1]['style']['spacing_top'], 'Wie bisher steht zwischen zwei Altbausteinen nur einmal der kompakte Abstand.');
$this->assertSame('Alt', $sections[0]['slots'][0]['data']['heading']);
$this->assertSame('prose', $sections[1]['slots'][0]['type']);
}