Prüfe Altseiten im echten Altformat und zeige Speicherfehler am Abschnitt.
- Der Altseiten-Test schreibt die Seederdaten vor dem Vergleich im flachen Format zurück, wie sie auf Test und Produktion liegen (die Migration speichert sie inzwischen über die Registry); zusätzlich ein Rundlauf Editor -> Speichern -> Veröffentlichen. - Fehler, die erst die Registry erkennt, erscheinen als Meldung mit Abschnittsnummer und Art (Felder liegen im Dialog). - Seite anlegen übernimmt die gewählten Säulen (wurden bisher verworfen). - Nach dem Speichern wird der Editor neu befüllt, damit duplizierte Abschnitte ihre Kennung behalten. - Entwicklerdokumentation der Registry inkl. Rollback-Hinweis. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9d936bfa4a
commit
2dc479a8a4
6 files changed
+274
-8
No files matched your search
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Catalog\PillarService;
|
||||
use App\Domain\Cms\NavigationItem;
|
||||
use App\Domain\Cms\Page;
|
||||
use App\Filament\Resources\NavigationItems\Pages\ManageNavigationItems;
|
||||
@@ -12,6 +13,7 @@
|
||||
use Filament\Actions\Testing\TestAction;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Livewire\Livewire;
|
||||
use Tests\Support\BuildsCatalog;
|
||||
@@ -126,6 +128,53 @@ public function test_unsafe_link_is_reported_at_the_section_and_nothing_is_saved
|
||||
$this->assertSame($revisions, $page->revisions()->count());
|
||||
}
|
||||
|
||||
public function test_errors_found_only_by_the_registry_are_announced_with_the_section(): void
|
||||
{
|
||||
Storage::fake('media_public');
|
||||
Storage::fake('cms_incoming');
|
||||
Storage::disk('media_public')->put('cms/bild.jpg', 'bild');
|
||||
$page = Page::query()->where('path', '/')->firstOrFail();
|
||||
$revisions = $page->revisions()->count();
|
||||
$component = Livewire::actingAs($this->editor(), 'staff')->test(EditPage::class, ['record' => $page->id]);
|
||||
$state = $component->get('data.blocks');
|
||||
$state[(string) Str::uuid()] = ['type' => 'hero', 'data' => ['variant' => 'standard', 'data' => ['heading' => 'Mit Bild'], 'refs' => ['image' => 'cms/bild.jpg']]];
|
||||
|
||||
$component->set('data.blocks', $state)
|
||||
->call('save')
|
||||
->assertNotified('Nicht gespeichert');
|
||||
|
||||
$this->assertSame($revisions, $page->revisions()->count());
|
||||
}
|
||||
|
||||
public function test_new_page_keeps_the_selected_pillars(): void
|
||||
{
|
||||
$pillar = app(PillarService::class)->create('Grenzen');
|
||||
|
||||
Livewire::actingAs($this->editor(), 'staff')
|
||||
->test(CreatePage::class)
|
||||
->fillForm(['path' => '/grenzen-thema', 'pillars' => [$pillar->id], 'blocks' => []])
|
||||
->call('create')
|
||||
->assertHasNoFormErrors();
|
||||
|
||||
$this->assertSame([$pillar->id], Page::query()->where('path', '/grenzen-thema')->firstOrFail()->pillars()->pluck('pillars.id')->all());
|
||||
}
|
||||
|
||||
public function test_duplicated_section_keeps_its_new_id_across_saves(): void
|
||||
{
|
||||
$page = Page::query()->where('path', '/')->firstOrFail();
|
||||
$component = Livewire::actingAs($this->editor(), 'staff')->test(EditPage::class, ['record' => $page->id]);
|
||||
$state = $component->get('data.blocks');
|
||||
$state[(string) Str::uuid()] = $state[array_key_first($state)];
|
||||
|
||||
$component->set('data.blocks', $state)->call('save')->assertHasNoFormErrors();
|
||||
$first = array_column($page->fresh()->latestRevision->blocks, 'id');
|
||||
$component->call('save')->assertHasNoFormErrors();
|
||||
$second = array_column($page->fresh()->latestRevision->blocks, 'id');
|
||||
|
||||
$this->assertCount(5, array_unique($first));
|
||||
$this->assertSame($first, $second);
|
||||
}
|
||||
|
||||
public function test_invalid_or_taken_paths_are_shown_at_the_path_field(): void
|
||||
{
|
||||
Livewire::actingAs($this->editor(), 'staff')
|
||||
|
||||
@@ -5,11 +5,17 @@
|
||||
use App\Domain\Catalog\CompositionDisplayRelease;
|
||||
use App\Domain\Cms\Page;
|
||||
use App\Domain\Cms\PageService;
|
||||
use App\Filament\Resources\Pages\Pages\EditPage;
|
||||
use App\Jobs\PublishPublicMedia;
|
||||
use App\Models\User;
|
||||
use Database\Seeders\CmsSeeder;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Livewire\Livewire;
|
||||
use ReflectionMethod;
|
||||
use Tests\Support\BuildsCatalog;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -24,19 +30,64 @@ class CmsWidgetRenderingTest extends TestCase
|
||||
*/
|
||||
public function test_existing_pages_render_the_same_text_as_before_the_registry(): void
|
||||
{
|
||||
$pages = ['/' => 'home', '/praevention' => 'praevention', '/materialien' => 'materialien', '/angebote' => 'angebote', '/trainer' => 'trainer', '/ueber' => 'ueber', '/impressum' => 'impressum', '/datenschutz' => 'datenschutz'];
|
||||
$this->storeSeededPagesInTheLegacyFormat();
|
||||
|
||||
foreach ($pages as $path => $fixture) {
|
||||
$html = $this->get($path)->assertOk()->getContent();
|
||||
$this->assertSame('heading', Page::query()->where('path', '/')->first()->publishedRevision->blocks[0]['type']);
|
||||
$this->assertArrayNotHasKey('v', Page::query()->where('path', '/')->first()->publishedRevision->blocks[0]);
|
||||
|
||||
$this->assertSame(
|
||||
trim(file_get_contents(base_path("tests/Fixtures/legacy-pages/$fixture.txt"))),
|
||||
$this->mainText($html),
|
||||
"Abweichung auf $path",
|
||||
);
|
||||
foreach (self::LEGACY_PAGES as $path => $fixture) {
|
||||
$this->assertSame($this->fixture($fixture), $this->mainText($this->get($path)->assertOk()->getContent()), "Abweichung auf $path");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rundlauf: eine Seite im Altformat im Editor öffnen, speichern, veröffentlichen – der Text bleibt gleich.
|
||||
*/
|
||||
public function test_legacy_page_survives_a_round_trip_through_the_editor(): void
|
||||
{
|
||||
$this->storeSeededPagesInTheLegacyFormat();
|
||||
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
|
||||
$editor = User::factory()->redakteur()->create();
|
||||
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
|
||||
foreach (['/' => 'home', '/praevention' => 'praevention'] as $path => $fixture) {
|
||||
$page = Page::query()->where('path', $path)->firstOrFail();
|
||||
|
||||
Livewire::actingAs($editor, 'staff')
|
||||
->test(EditPage::class, ['record' => $page->id])
|
||||
->call('save')
|
||||
->assertHasNoErrors()
|
||||
->callAction('publish');
|
||||
|
||||
$live = $page->fresh()->publishedRevision;
|
||||
$this->assertArrayHasKey('v', $live->blocks[0], 'Die neue Revision ist im Hüllenformat gespeichert.');
|
||||
$this->assertSame($this->fixture($fixture), $this->mainText($this->get($path)->getContent()), "Abweichung nach Rundlauf auf $path");
|
||||
}
|
||||
}
|
||||
|
||||
private const LEGACY_PAGES = ['/' => 'home', '/praevention' => 'praevention', '/materialien' => 'materialien', '/angebote' => 'angebote', '/trainer' => 'trainer', '/ueber' => 'ueber', '/impressum' => 'impressum', '/datenschutz' => 'datenschutz'];
|
||||
|
||||
/**
|
||||
* Auf Test und Produktion liegen die Seiten im flachen Format vor der Registry. Die Migration ruft den
|
||||
* Seeder heute über die Registry auf; deshalb werden die veröffentlichten Revisionen hier mit den
|
||||
* unveränderten Seederdaten im Altformat überschrieben.
|
||||
*/
|
||||
private function storeSeededPagesInTheLegacyFormat(): void
|
||||
{
|
||||
$method = new ReflectionMethod(CmsSeeder::class, 'pages');
|
||||
$pages = $method->invoke(new CmsSeeder);
|
||||
|
||||
foreach ($pages as $path => $page) {
|
||||
$revisionId = Page::query()->where('path', $path)->value('published_revision_id');
|
||||
DB::table('page_revisions')->where('id', $revisionId)->update(['blocks' => json_encode($page['blocks'])]);
|
||||
}
|
||||
}
|
||||
|
||||
private function fixture(string $name): string
|
||||
{
|
||||
return trim(file_get_contents(base_path("tests/Fixtures/legacy-pages/$name.txt")));
|
||||
}
|
||||
|
||||
public function test_legacy_revisions_stored_in_the_flat_format_still_render(): void
|
||||
{
|
||||
$page = Page::query()->create(['path' => '/alt']);
|
||||
|
||||
Reference in new issue
Block a user