Die Vorlage enthielt die lokale Adresse des Bildpfads; die CI hat eine andere APP_URL. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
118 lines
4.8 KiB
PHP
118 lines
4.8 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Domain\Cms\Page;
|
|
use App\Domain\Cms\PageService;
|
|
use App\Jobs\PublishPublicMedia;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Queue;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Schutz bestehender Seiten (ADR-67): Die Ausgabe aller bisherigen Gestaltungsvarianten (Flächen, Bilder mit Überlagerung
|
|
* und Fokus, Breiten, Abstände, Trenner, Kartenoptionen) bleibt Byte für Byte gleich. Die Farbpalette und die
|
|
* Hintergrundbreite dürfen daran nichts ändern, solange ein Abschnitt sie nicht ausdrücklich verwendet.
|
|
*
|
|
* Die Vorlage tests/Fixtures/section-legacy-render.html wurde vor der Erweiterung aus dem damaligen Stand erzeugt.
|
|
* Neu erzeugen nur bewusst und mit Begründung: UPDATE_SNAPSHOT=1 php artisan test --filter=CmsSectionLegacyRenderTest
|
|
*/
|
|
class CmsSectionLegacyRenderTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private const FIXTURE = __DIR__.'/../Fixtures/section-legacy-render.html';
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
private function prose(string $text): array
|
|
{
|
|
return ['type' => 'prose', 'v' => 1, 'data' => ['body' => $text]];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
private function heading(string $text): array
|
|
{
|
|
return ['type' => 'heading', 'v' => 1, 'data' => ['heading' => $text]];
|
|
}
|
|
|
|
/**
|
|
* @return list<array<string, mixed>>
|
|
*/
|
|
private function matrix(): array
|
|
{
|
|
$sections = [];
|
|
|
|
foreach (['default' => ['narrow', 'standard', 'wide', 'full'], 'light' => ['wide'], 'dark' => ['narrow', 'standard', 'wide', 'full'], 'accent' => ['wide']] as $background => $widths) {
|
|
foreach ($widths as $width) {
|
|
$sections[] = [
|
|
'layout' => 'u2_2',
|
|
'style' => ['background' => $background, 'width' => $width],
|
|
'slots' => [$this->heading("$background $width"), $this->prose("Text $background $width")],
|
|
];
|
|
}
|
|
}
|
|
|
|
foreach (['light', 'dark', 'none'] as $overlay) {
|
|
foreach (['center', 'top_left'] as $focus) {
|
|
$sections[] = [
|
|
'layout' => 'u4',
|
|
'style' => ['background' => 'image', 'image' => 'cms/flaeche.jpg', 'focus' => $focus, 'overlay' => $overlay],
|
|
'slots' => [$this->prose("Bild $overlay $focus")],
|
|
];
|
|
}
|
|
}
|
|
|
|
foreach (['none', 'compact', 'normal', 'large'] as $spacing) {
|
|
$sections[] = [
|
|
'layout' => 'u1_3',
|
|
'style' => ['background' => 'light', 'spacing_top' => $spacing, 'spacing_bottom' => $spacing, 'gap' => $spacing, 'divider' => 'line'],
|
|
'slots' => [$this->prose("Abstand $spacing"), $this->prose('Rechts')],
|
|
];
|
|
}
|
|
|
|
$sections[] = ['layout' => 'u4', 'style' => ['background' => 'dark', 'divider' => 'accent'], 'slots' => [$this->heading('Trenner Akzent')]];
|
|
$sections[] = ['layout' => 'u4', 'style' => ['cards_height' => 'equal', 'cards_links' => 'bottom'], 'slots' => [$this->prose('Karten gleich hoch')]];
|
|
$sections[] = ['layout' => 'u1_1_1_1', 'style' => ['background' => 'accent'], 'slots' => [$this->prose('Eins'), null, $this->prose('Drei'), null]];
|
|
|
|
return $sections;
|
|
}
|
|
|
|
/**
|
|
* Zufällige Kennungen (Abschnitt, Widget) werden für den Vergleich vereinheitlicht.
|
|
*/
|
|
private function sectionsMarkup(string $html): string
|
|
{
|
|
$start = strpos($html, '<div class="page-section ');
|
|
$end = strpos($html, '</main>');
|
|
$markup = substr($html, $start, $end - $start);
|
|
$markup = (string) preg_replace('/\b(id|aria-labelledby|aria-describedby|for)="([^"]*[0-9a-f]{8}-[0-9a-f]{4}-[^"]*)"/', '$1="#"', $markup);
|
|
// Die Basisadresse hängt von der Umgebung ab (APP_URL), die Pfade der Bilder nicht.
|
|
$markup = (string) preg_replace('#https?://[^/"\s]+/medien/#', 'HOST/medien/', $markup);
|
|
$markup = (string) preg_replace('/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/', 'UUID', $markup);
|
|
|
|
return trim($markup)."\n";
|
|
}
|
|
|
|
public function test_existing_section_styles_render_exactly_as_before(): void
|
|
{
|
|
Queue::fake([PublishPublicMedia::class]);
|
|
|
|
$service = app(PageService::class);
|
|
$page = Page::query()->create(['path' => '/legacy']);
|
|
$service->publish($page, $service->saveRevision($page, $this->matrix(), null, null, null));
|
|
|
|
$markup = $this->sectionsMarkup($this->get('/legacy')->assertOk()->getContent());
|
|
|
|
if (getenv('UPDATE_SNAPSHOT') === '1') {
|
|
file_put_contents(self::FIXTURE, $markup);
|
|
}
|
|
|
|
$this->assertFileExists(self::FIXTURE);
|
|
$this->assertSame(file_get_contents(self::FIXTURE), $markup, 'Die Ausgabe bestehender Abschnittsvarianten hat sich geändert.');
|
|
}
|
|
}
|