composition('Programm Abstand', 'programm'); $editor = $this->editor(); Livewire::actingAs($editor, 'staff') ->test(CreatePage::class) ->fillForm([ 'path' => '/themen-test', 'seo_title' => 'Themenseite', 'blocks' => $this->keyed([ ['type' => 'hero', 'data' => ['variant' => 'highlight', 'data' => ['heading' => 'Stark im Alltag', 'text' => 'Einstieg']]], ['type' => 'image_text', 'data' => ['variant' => 'image_right', 'data' => ['title' => 'Worum es geht', 'body' => '
Text mit Betonung
'], 'refs' => []]], ['type' => 'cards', 'data' => ['variant' => 'compact', 'data' => ['items' => $this->keyed([['title' => 'Prävention', 'url' => '/praevention']])]]], ['type' => 'catalog_cards', 'data' => ['variant' => 'standard', 'data' => ['heading' => 'Programme'], 'refs' => ['items' => $this->keyed([['type' => 'composition', 'id' => $program->composition_id]])]]], ]), ]) ->call('create') ->assertHasNoFormErrors(); $page = Page::query()->where('path', '/themen-test')->firstOrFail(); $blocks = $page->latestRevision->blocks; $this->assertNull($page->published_revision_id); $this->assertSame(['hero', 'image_text', 'cards', 'catalog_cards'], array_column($blocks, 'type')); $this->assertSame(['highlight', 'image_right', 'compact', 'standard'], array_column($blocks, 'variant')); $this->assertSame([2], array_values(array_unique([$blocks[1]['v']]))); $this->assertStringContainsString('Betonung', $blocks[1]['data']['body']); $this->assertSame([['title' => 'Prävention', 'text' => null, 'url' => '/praevention', 'image' => null]], $blocks[2]['data']['items']); $this->assertSame([['type' => 'composition', 'id' => $program->composition_id]], $blocks[3]['refs']['items']); $this->get('/themen-test')->assertNotFound(); } public function test_existing_page_opens_in_the_editor_and_saves_without_changing_the_live_page(): void { $page = Page::query()->where('path', '/')->firstOrFail(); $live = $page->published_revision_id; $before = $this->mainText($this->get('/')->getContent()); $component = Livewire::actingAs($this->editor(), 'staff') ->test(EditPage::class, ['record' => $page->id]); $state = $component->get('data.blocks'); $this->assertSame(['heading', 'prose', 'cards', 'call_to_action'], array_column(array_values($state), 'type')); $component->call('save')->assertHasNoFormErrors(); $page->refresh(); $this->assertSame($live, $page->published_revision_id); $this->assertNotSame($live, $page->latestRevision->id); $this->assertSame(['heading', 'prose', 'cards', 'call_to_action'], array_column($page->latestRevision->blocks, 'type')); $this->assertSame($before, $this->mainText($this->get('/')->getContent())); Livewire::actingAs($this->editor(), 'staff') ->test(EditPage::class, ['record' => $page->id]) ->callAction('publish'); $this->assertSame( trim(file_get_contents(base_path('tests/Fixtures/legacy-pages/home.txt'))), $this->mainText($this->get('/')->getContent()), 'Nach dem Speichern im neuen Format zeigt die Seite denselben Text.', ); } public function test_editor_reorders_and_duplicates_sections(): void { $page = Page::query()->where('path', '/')->firstOrFail(); $component = Livewire::actingAs($this->editor(), 'staff')->test(EditPage::class, ['record' => $page->id]); $state = $component->get('data.blocks'); $keys = array_keys($state); $reordered = [$keys[3] => $state[$keys[3]], $keys[0] => $state[$keys[0]], $keys[1] => $state[$keys[1]], $keys[2] => $state[$keys[2]]]; $copy = $state[$keys[1]]; $reordered[(string) Str::uuid()] = $copy; $component->set('data.blocks', $reordered)->call('save')->assertHasNoFormErrors(); $blocks = $page->fresh()->latestRevision->blocks; $this->assertSame(['call_to_action', 'heading', 'prose', 'cards', 'prose'], array_column($blocks, 'type')); $this->assertCount(5, array_unique(array_column($blocks, 'id')), 'Ein dupliziertes Widget erhält eine eigene Kennung.'); } public function test_unsafe_link_is_reported_at_the_section_and_nothing_is_saved(): void { $page = Page::query()->where('path', '/')->firstOrFail(); $revisions = $page->revisions()->count(); $component = Livewire::actingAs($this->editor(), 'staff')->test(EditPage::class, ['record' => $page->id]); $key = array_keys($component->get('data.blocks'))[3]; $component->set("data.blocks.$key.data.data.url", 'javascript:alert(1)') ->call('save') ->assertHasErrors(["data.blocks.$key.data.data.url"]); $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') ->test(CreatePage::class) ->fillForm(['path' => '/praevention', 'blocks' => []]) ->call('create') ->assertHasErrors(['data.path']); Livewire::actingAs($this->editor(), 'staff') ->test(CreatePage::class) ->fillForm(['path' => 'C:/Program Files/x', 'blocks' => []]) ->call('create') ->assertHasErrors(['data.path']); $this->assertSame(1, Page::query()->where('path', '/praevention')->count()); } public function test_block_preview_uses_the_public_widget_view_with_unsaved_state(): void { $html = WidgetEditor::renderPreview('image_text', [ 'variant' => 'image_right', 'data' => [ 'title' => 'Ungespeichert', 'body' => ['type' => 'doc', 'content' => [['type' => 'paragraph', 'content' => [['type' => 'text', 'text' => 'Vorschautext']]]]], ], 'refs' => ['image' => null, '_upload' => []], ]); $this->assertStringContainsString('image-text image-text-right', $html); $this->assertStringContainsString('