Führe eine zentrale Widget-Registry mit visuellem Seiteneditor ein.
CI Feature / test (push) Successful in 31s

- Codebasiertes Widget-Register (config/cms.php) mit Vertrag
  {id, type, v, variant, settings, data, refs}: Typkennung, Schemaversion,
  Prüfregeln, freigegebene Varianten, Editorfelder, Blade-Ansicht,
  Verweisauflösung und Medienliste je Widget-Art.
- Die sechs Bestandsbausteine bleiben als Version 1 lesbar; gespeicherte
  Revisionen werden nicht umgeschrieben, sondern beim Lesen angehoben
  (Bild und Text: Version 2 mit Titel, formatiertem Text, Bild links/rechts).
  Wiederherstellen kopiert eine Revision unverändert.
- Neue Widgets: Einstieg (Hero) und Programm-/Modulkarten. Letztere speichern
  nur Verweise; Titel und Kurzbeschreibung kommen aus den Fachdaten. Öffentlich
  erscheinen nur Programme mit Anzeigefreigabe (gleiche Regel wie /programme,
  jetzt in PublicCatalogReader); Module nur in der Redaktionsvorschau, bis
  öffentliche Profile (ADR-29) bestehen.
- Ein Renderer für öffentliche Seite, Vorschau und Blockvorschau im Editor.
- Seiteneditor als Filament-Builder: Auswahl mit Beschreibung und Schema,
  kompakte Abschnitte mit Vorschau, Bearbeitung im Dialog, Sortieren,
  Duplizieren. Speichern erzeugt nur einen Entwurf.
- Vorschau einer Revision in 390/768/1440 px; Vorschauroute nutzt den
  Personal-Guard (vorher war sie für Redakteure ohne Mitgliedersitzung
  nicht erreichbar).
- Basislayout in Komponenten (Marke, Kopf, Fuß, Seitenvorlage).
- Navigation: bearbeiten, ausblenden, löschen, per Ziehen sortieren;
  unsichere Adressen (javascript:) werden abgewiesen und nicht ausgegeben.
  Ergänzende Migration is_visible (Vorgabe sichtbar).
- Pfadfehler und doppelte Pfade erscheinen am Pfadfeld statt still zu scheitern.

Tests: BlockRegistryTest geht in WidgetRegistryTest auf (gleiche Prüfungen
plus Registrierung, Versionierung, Bereinigung). Bestandsseiten werden gegen
Textfixtures aus dem Stand vor der Umstellung geprüft.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-11-17 17:49:30 +01:00
1 parent cfdd6de0c7
commit 9d936bfa4a
76 files changed
+4237 -475

No files matched your search

+274
View File
@@ -0,0 +1,274 @@
<?php
namespace Tests\Feature;
use App\Domain\Cms\NavigationItem;
use App\Domain\Cms\Page;
use App\Filament\Resources\NavigationItems\Pages\ManageNavigationItems;
use App\Filament\Resources\Pages\Pages\CreatePage;
use App\Filament\Resources\Pages\Pages\EditPage;
use App\Filament\Support\WidgetEditor;
use App\Models\User;
use Filament\Actions\Testing\TestAction;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Str;
use Livewire\Livewire;
use Tests\Support\BuildsCatalog;
use Tests\TestCase;
class CmsEditorTest extends TestCase
{
use BuildsCatalog;
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
}
public function test_editor_creates_a_page_from_registered_widgets_without_publishing_it(): void
{
$program = $this->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' => '<p>Text mit <strong>Betonung</strong></p>'], '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('<strong>Betonung</strong>', $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_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('<h2>Ungespeichert</h2>', $html);
$this->assertStringContainsString('Vorschautext', $html);
$cards = WidgetEditor::renderPreview('cards', [
'variant' => 'standard',
'data' => ['items' => [(string) Str::uuid() => ['title' => 'Karte A'], (string) Str::uuid() => ['title' => 'Karte B']]],
]);
$this->assertStringContainsString('Karte A', $cards);
$this->assertStringContainsString('Karte B', $cards);
}
public function test_editor_offers_every_registered_widget_with_description(): void
{
$page = Page::query()->where('path', '/')->firstOrFail();
Livewire::actingAs($this->editor(), 'staff')
->test(EditPage::class, ['record' => $page->id])
->assertSee('Einstieg (Hero)')
->assertSee('Programm- und Modulkarten')
->assertSee('Titel und Beschreibung kommen automatisch aus den Fachdaten')
->assertSee('Entwurf speichern');
}
public function test_preview_with_device_widths_is_only_available_to_staff(): void
{
$revision = Page::query()->where('path', '/')->firstOrFail()->latestRevision;
$this->get(route('pages.preview.devices', $revision))->assertRedirect();
$this->actingAs(User::factory()->create())->get(route('pages.preview', $revision))->assertRedirect();
$this->actingAs(User::factory()->create(), 'staff')->get(route('pages.preview', $revision))->assertForbidden();
auth('web')->logout();
$this->actingAs($this->editor(), 'staff')
->get(route('pages.preview.devices', $revision))
->assertOk()
->assertSee('data-width="390"', false)
->assertSee('data-width="768"', false)
->assertSee('data-width="1440"', false)
->assertSee(route('pages.preview', $revision), false);
$this->actingAs($this->editor(), 'staff')
->get(route('pages.preview', $revision))
->assertOk()
->assertSee('Vorschau einer unveröffentlichten Revision')
->assertSee('Registrieren')
->assertDontSee('Mitgliederbereich</a>', false);
}
public function test_navigation_items_can_be_edited_hidden_reordered_and_removed(): void
{
$editor = $this->editor();
$start = NavigationItem::query()->where('label', 'Start')->firstOrFail();
$about = NavigationItem::query()->where('label', 'Über das Projekt')->firstOrFail();
Livewire::actingAs($editor, 'staff')
->test(ManageNavigationItems::class)
->assertCanSeeTableRecords([$start, $about])
->callAction(TestAction::make('edit')->table($about), ['label' => 'Über uns'])
->assertHasNoFormErrors()
->callAction(TestAction::make('toggleVisibility')->table($start));
$this->assertSame('Über uns', $about->fresh()->label);
$this->assertFalse($start->fresh()->is_visible);
$this->get('/praevention')->assertSee('Über uns')->assertDontSee('>Start<', false);
$order = NavigationItem::query()->orderByDesc('sort_order')->pluck('id')->map(fn ($id) => (string) $id)->all();
Livewire::actingAs($editor, 'staff')->test(ManageNavigationItems::class)->call('reorderTable', $order);
$this->assertSame((int) $order[0], NavigationItem::query()->orderBy('sort_order')->first()->id);
Livewire::actingAs($editor, 'staff')
->test(ManageNavigationItems::class)
->callAction(TestAction::make('delete')->table($about));
$this->assertNull($about->fresh());
$this->assertNotNull(Page::query()->where('path', '/ueber')->first(), 'Die Seite bleibt bestehen.');
}
public function test_navigation_rejects_script_addresses(): void
{
Livewire::actingAs($this->editor(), 'staff')
->test(ManageNavigationItems::class)
->callAction('create', ['label' => 'Böse', 'placement' => 'header', 'url' => 'javascript:alert(1)', 'sort_order' => 9, 'is_visible' => true])
->assertHasFormErrors(['url']);
NavigationItem::query()->create(['label' => 'Alt', 'url' => 'javascript:alert(1)', 'placement' => 'footer', 'sort_order' => 99]);
$this->get('/praevention')->assertDontSee('javascript:alert(1)', false);
}
private function editor(): User
{
$editor = User::factory()->redakteur()->create();
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
return $editor;
}
/**
* @param list<array<string, mixed>> $items
* @return array<string, array<string, mixed>>
*/
private function keyed(array $items): array
{
$keyed = [];
foreach ($items as $item) {
$keyed[(string) Str::uuid()] = $item;
}
return $keyed;
}
private function mainText(string $html): string
{
preg_match('#<main[^>]*>(.*)</main>#s', $html, $match);
$text = html_entity_decode(strip_tags(str_replace('<', ' <', $match[1] ?? '')), ENT_QUOTES | ENT_HTML5, 'UTF-8');
return trim(preg_replace('/\s+/u', ' ', $text));
}
}
+237
View File
@@ -0,0 +1,237 @@
<?php
namespace Tests\Feature;
use App\Domain\Catalog\CompositionDisplayRelease;
use App\Domain\Cms\Page;
use App\Domain\Cms\PageService;
use App\Jobs\PublishPublicMedia;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Queue;
use Illuminate\Validation\ValidationException;
use Tests\Support\BuildsCatalog;
use Tests\TestCase;
class CmsWidgetRenderingTest extends TestCase
{
use BuildsCatalog;
use RefreshDatabase;
/**
* Die Textfolge jeder Bestandsseite entspricht der Darstellung vor Einführung der Registry
* (tests/Fixtures/legacy-pages, erzeugt aus dem Stand develop@cfdd6de).
*/
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'];
foreach ($pages as $path => $fixture) {
$html = $this->get($path)->assertOk()->getContent();
$this->assertSame(
trim(file_get_contents(base_path("tests/Fixtures/legacy-pages/$fixture.txt"))),
$this->mainText($html),
"Abweichung auf $path",
);
}
}
public function test_legacy_revisions_stored_in_the_flat_format_still_render(): void
{
$page = Page::query()->create(['path' => '/alt']);
$revision = $page->revisions()->create([
'blocks' => [
['type' => 'heading', 'heading' => 'Alte Seite', 'intro' => 'Einleitung'],
['type' => 'image_text', 'image' => 'cms/alt.jpg', 'alt' => 'Altes Bild', 'body' => "Absatz eins.\n\nAbsatz <zwei>."],
['type' => 'faq', 'items' => [['question' => 'Frage?', 'answer' => 'Antwort.']]],
['type' => 'cards', 'items' => [['title' => 'Karte', 'text' => 'Text', 'url' => '/praevention']]],
['type' => 'call_to_action', 'heading' => 'Los', 'text' => null, 'label' => 'Anmelden', 'url' => '/anmelden'],
],
]);
app(PageService::class)->publish($page, $revision);
$this->get('/alt')
->assertOk()
->assertSee('<title>Alte Seite</title>', false)
->assertSee('<h1>Alte Seite</h1>', false)
->assertSee('alt="Altes Bild"', false)
->assertSee('<p>Absatz eins.</p><p>Absatz &lt;zwei&gt;.</p>', false)
->assertSee('<dt>Frage?</dt>', false)
->assertSee('href="/praevention"', false)
->assertSee('href="/anmelden"', false);
$this->assertSame('heading', $revision->fresh()->blocks[0]['type']);
$this->assertArrayNotHasKey('v', $revision->fresh()->blocks[0], 'Die gespeicherte Altrevision bleibt unverändert.');
}
public function test_restoring_a_legacy_revision_keeps_its_stored_blocks(): void
{
$page = Page::query()->where('path', '/')->firstOrFail();
$legacy = $page->publishedRevision;
$service = app(PageService::class);
$service->saveRevision($page, [['type' => 'heading', 'v' => 1, 'data' => ['heading' => 'Neu']]], null, null, null);
$restored = $service->restore($page, $legacy, null);
$this->assertSame($legacy->blocks, $restored->blocks);
}
public function test_new_revisions_are_stored_as_widget_envelopes(): void
{
$page = Page::query()->create(['path' => '/neu']);
$revision = app(PageService::class)->saveRevision($page, [
['type' => 'prose', 'body' => 'Altes Eingabeformat'],
['type' => 'hero', 'v' => 1, 'variant' => 'highlight', 'data' => ['heading' => 'Einstieg']],
], null, null, null);
$this->assertSame(['id', 'type', 'v', 'variant', 'settings', 'data', 'refs'], array_keys($revision->blocks[0]));
$this->assertSame('prose', $revision->blocks[0]['type']);
$this->assertSame(['body' => 'Altes Eingabeformat'], $revision->blocks[0]['data']);
$this->assertSame('highlight', $revision->blocks[1]['variant']);
$this->assertNull($page->fresh()->published_revision_id, 'Speichern veröffentlicht nicht.');
}
public function test_reference_widgets_render_their_variants(): void
{
$page = Page::query()->create(['path' => '/varianten']);
$revision = app(PageService::class)->saveRevision($page, [
['type' => 'hero', 'v' => 1, 'variant' => 'highlight', 'data' => ['heading' => 'Stark im Alltag', 'text' => 'Einstieg', 'cta_label' => 'Mehr', 'cta_url' => '/praevention']],
['type' => 'image_text', 'v' => 2, 'variant' => 'image_right', 'data' => ['title' => 'Bild rechts', 'body' => '<p>Text <em>betont</em></p>', 'alt' => 'Beschreibung'], 'refs' => ['image' => 'cms/beispiel.jpg']],
['type' => 'cards', 'v' => 1, 'variant' => 'compact', 'data' => ['items' => [['title' => 'Eins', 'url' => '/a'], ['title' => 'Zwei']]]],
], null, null, null);
app(PageService::class)->publish($page, $revision);
$this->get('/varianten')
->assertOk()
->assertSee('hero hero-highlight', false)
->assertSee('<h1>Stark im Alltag</h1>', false)
->assertSee('class="button" href="/praevention"', false)
->assertSee('image-text image-text-right', false)
->assertSee('<h2>Bild rechts</h2>', false)
->assertSee('<em>betont</em>', false)
->assertSee(route('media.public', ['path' => 'cms/beispiel.jpg']), false)
->assertSee('cards cards-compact', false);
}
public function test_media_of_any_widget_are_published_through_the_queue(): void
{
Queue::fake();
$page = Page::query()->create(['path' => '/medien']);
app(PageService::class)->saveRevision($page, [
['type' => 'hero', 'v' => 1, 'data' => ['heading' => 'A', 'alt' => 'Bild'], 'refs' => ['image' => 'cms/hero.jpg']],
['type' => 'cards', 'v' => 1, 'data' => ['items' => [['title' => 'K', 'image' => 'cms/karte.jpg']]]],
], null, null, null);
Queue::assertPushed(PublishPublicMedia::class, fn ($job) => $job->path === 'cms/hero.jpg');
Queue::assertPushed(PublishPublicMedia::class, fn ($job) => $job->path === 'cms/karte.jpg');
}
public function test_catalog_cards_show_released_programs_from_the_master_data_only(): void
{
$program = $this->composition('Programm Abstand', 'programm', summary: 'Kurzbeschreibung aus den Fachdaten');
$module = $this->composition('Modul Nein sagen', 'modul');
$page = Page::query()->create(['path' => '/thema']);
$revision = app(PageService::class)->saveRevision($page, [[
'type' => 'catalog_cards',
'v' => 1,
'data' => ['heading' => 'Passende Angebote'],
'refs' => ['items' => [
['type' => 'composition', 'id' => $module->composition_id],
['type' => 'composition', 'id' => $program->composition_id],
]],
]], null, null, null);
app(PageService::class)->publish($page, $revision);
$this->assertSame(
['items' => [['type' => 'composition', 'id' => $module->composition_id], ['type' => 'composition', 'id' => $program->composition_id]]],
$revision->blocks[0]['refs'],
);
$this->assertStringNotContainsString('Programm Abstand', json_encode($revision->blocks), 'Keine Stammdaten im CMS.');
$this->get('/thema')
->assertOk()
->assertSee('Passende Angebote')
->assertSee('Programm Abstand')
->assertSee('Kurzbeschreibung aus den Fachdaten')
->assertSee(route('public.program', $program->composition_id), false)
->assertDontSee('Modul Nein sagen')
->assertDontSee('Redaktionsvorschau');
$program->composition->update(['display_title' => 'Programm „Abstand halten“']);
$this->get('/thema')->assertSee('Programm „Abstand halten“');
}
public function test_catalog_cards_show_modules_only_in_the_protected_preview(): void
{
$module = $this->composition('Modul Nein sagen', 'modul');
$page = Page::query()->create(['path' => '/modulseite']);
$revision = app(PageService::class)->saveRevision($page, [
['type' => 'heading', 'v' => 1, 'data' => ['heading' => 'Module']],
['type' => 'catalog_cards', 'v' => 1, 'data' => [], 'refs' => ['items' => [['type' => 'composition', 'id' => $module->composition_id]]]],
], null, null, null);
app(PageService::class)->publish($page, $revision);
$this->get('/modulseite')->assertOk()->assertDontSee('Modul Nein sagen')->assertDontSee('catalog-cards');
$editor = User::factory()->redakteur()->create();
$this->actingAs($editor, 'staff')
->get(route('pages.preview', $revision))
->assertOk()
->assertSee('Modul Nein sagen')
->assertSee('Nur in der Redaktionsvorschau sichtbar');
}
public function test_revoking_the_display_release_removes_the_card_without_editing_the_page(): void
{
$program = $this->composition('Programm Rückzug', 'programm');
$page = Page::query()->create(['path' => '/rueckzug']);
$revision = app(PageService::class)->saveRevision($page, [
['type' => 'heading', 'v' => 1, 'data' => ['heading' => 'Rückzug']],
['type' => 'catalog_cards', 'v' => 1, 'refs' => ['items' => [['type' => 'composition', 'id' => $program->composition_id]]]],
], null, null, null);
app(PageService::class)->publish($page, $revision);
$this->get('/rueckzug')->assertSee('Programm Rückzug');
$program->displayEvents()->update(['occurred_at' => now()->subMinute()]);
app(CompositionDisplayRelease::class)->revoke($program, User::factory()->create());
$this->get('/rueckzug')->assertOk()->assertDontSee('Programm Rückzug');
}
public function test_unreleased_or_foreign_objects_cannot_be_referenced(): void
{
$draft = $this->composition('Programm Entwurf', 'programm', released: false);
$page = Page::query()->create(['path' => '/entwurf']);
$this->expectException(ValidationException::class);
app(PageService::class)->saveRevision($page, [
['type' => 'catalog_cards', 'v' => 1, 'refs' => ['items' => [['type' => 'composition', 'id' => $draft->composition_id]]]],
], null, null, null);
}
public function test_public_program_list_uses_the_same_public_rule(): void
{
$this->composition('Programm Öffentlich', 'programm');
$this->composition('Programm Intern', 'programm', released: false);
$this->composition('Modul Freigegeben', 'modul');
$this->get('/programme')
->assertOk()
->assertSee('Programm Öffentlich')
->assertDontSee('Programm Intern')
->assertDontSee('Modul Freigegeben');
}
private function mainText(string $html): string
{
preg_match('#<main[^>]*>(.*)</main>#s', $html, $match);
$text = html_entity_decode(strip_tags(str_replace('<', ' <', $match[1] ?? '')), ENT_QUOTES | ENT_HTML5, 'UTF-8');
return trim(preg_replace('/\s+/u', ' ', $text));
}
}
+1
View File
@@ -0,0 +1 @@
Angebote Umfang, Rechte und Preise eines Angebots kommen aus dem Katalog. Sie werden hier nicht als freier Text ersetzt. Es sind noch keine Angebote veröffentlicht. Sobald ein Angebot aktiv ist, zeigt diese Seite seinen Umfang aus dem gespeicherten Stand.
@@ -0,0 +1 @@
Datenschutz Die Datenschutzerklärung wird hier gepflegt und ist noch nicht eingesetzt. Profilangaben sind standardmäßig nicht öffentlich. Geschützte Medien werden nicht über einen öffentlichen Dateipfad ausgeliefert.
+1
View File
@@ -0,0 +1 @@
Stark im Alltag Lara & Felix ist eine Plattform für Gewaltprävention, Selbstbehauptung und gewaltpräventive Bildungsarbeit. Sie unterstützt Erwachsene, die solche Angebote vorbereiten und durchführen. Die Lerninhalte richten sich unter anderem an Kinder. Kinder sind keine Benutzerinnen und Benutzer der Plattform und brauchen kein eigenes Konto. Die Filme „Lara & Felix“ sind die erste Produktreihe. Übungen, Programme und weitere Materialien lassen sich in derselben Struktur verwalten, ohne die Plattform auf eine einzelne Episode festzulegen. Prävention Worum es in der Bildungsarbeit geht. Materialien Filme und Begleitmaterial, sobald sie veröffentlicht sind. Für Trainer und Einrichtungen Wer die Plattform nutzt. Mitgliederbereich Nach der Anmeldung sehen Sie die Materialien, für die eine Berechtigung vorliegt. Anmelden
@@ -0,0 +1 @@
Impressum Die gesetzlich erforderlichen Angaben werden hier veröffentlicht, sobald sie feststehen. Diese Seite ist redaktionell pflegbar. Sie enthält noch keine Angaben zu einer verantwortlichen Stelle.
@@ -0,0 +1 @@
Filme und Lernmaterialien Hier erscheinen veröffentlichte Inhalte aus dem Katalog. Die Seite kopiert keine Produkttexte und nennt keine Preise. Solange noch kein Lizenzartikel veröffentlicht ist, bleibt diese Übersicht leer. Dieselbe Stelle zeigt später Filme, Übungen und Begleitmaterial aus den maßgeblichen Datensätzen.
@@ -0,0 +1 @@
Prävention im Alltag Die Plattform stellt Materialien bereit, mit denen Trainerinnen, Trainer und pädagogische Fachkräfte Präventionsangebote durchführen. Es geht um Selbstbehauptung, das Erkennen von Grenzverletzungen und um Handlungsfähigkeit in konkreten Situationen. Die Durchführung bleibt bei den Erwachsenen vor Ort. Eine Entscheidungspause in einem Film ist eine Markierung für den Präsenzkurs. Daraus wird kein digitales Quiz und keine eigenständige Lernanwendung für Kinder.
+1
View File
@@ -0,0 +1 @@
Für Trainer und Einrichtungen Die Plattform ist für Erwachsene, die geeignete Präventionsangebote durchführen. Dazu gehören Gewaltschutztrainer, Trainer und Übungsleiter, pädagogische Fachkräfte sowie Vereine und Bildungseinrichtungen. Ein Konto allein öffnet keine Materialien. Sichtbar wird, was eine konkrete Berechtigung erlaubt. Organisationen können später eigene Lizenzen halten. Eine persönliche Freischaltung ist keine Organisationslizenz.
+1
View File
@@ -0,0 +1 @@
Über das Projekt Lara & Felix – Stark im Alltag ist eine eigenständige Plattform für Gewaltprävention, Selbstbehauptung und gewaltpräventive Bildungsarbeit. Die erste Produktreihe sind die vorhandenen Filme. Das Fachmodell bleibt offen für weitere Medienarten, Übungen und Programme.
+36
View File
@@ -0,0 +1,36 @@
<?php
namespace Tests\Support;
use App\Domain\Catalog\CompositionDisplayRelease;
use App\Domain\Catalog\CompositionVersion;
use App\Domain\Catalog\ContentService;
use App\Domain\Catalog\EditorialContentKind;
use App\Models\User;
trait BuildsCatalog
{
/**
* Legt eine bereitgestellte Komposition mit Inhaltsart an und gibt sie auf Wunsch zur Anzeige frei.
*/
protected function composition(string $designation, string $kind, bool $released = true, ?string $summary = null): CompositionVersion
{
$content = app(ContentService::class);
$kindId = EditorialContentKind::query()->where('slug', $kind)->firstOrFail()->id;
$version = $content->publishComposition(
tap($content->createComposition($designation), function ($composition) use ($kindId, $summary): void {
$composition->editorial_content_kind_id = $kindId;
$composition->summary = $summary;
$composition->save();
}),
[['role' => 'Text', 'target' => $content->publishElementVersion($content->createElement('text', 'text', $designation.' Blatt'), 'Inhalt')]],
);
if ($released) {
app(CompositionDisplayRelease::class)->release($version, User::factory()->create());
}
return $version;
}
}
-33
View File
@@ -1,33 +0,0 @@
<?php
namespace Tests\Unit;
use App\Domain\Cms\Blocks\BlockRegistry;
use Illuminate\Validation\ValidationException;
use Tests\TestCase;
class BlockRegistryTest extends TestCase
{
public function test_image_text_requires_an_alternative_text(): void
{
$this->expectException(ValidationException::class);
app(BlockRegistry::class)->normalize([
['type' => 'image_text', 'body' => 'Text', 'image' => 'cms/bild.jpg'],
]);
}
public function test_action_links_reject_script_urls(): void
{
$this->expectException(ValidationException::class);
app(BlockRegistry::class)->normalize([
[
'type' => 'call_to_action',
'heading' => 'Weiter',
'label' => 'Öffnen',
'url' => 'javascript:alert(1)',
],
]);
}
}
+318
View File
@@ -0,0 +1,318 @@
<?php
namespace Tests\Unit;
use App\Domain\Cms\Widgets\RenderContext;
use App\Domain\Cms\Widgets\Support\RichText;
use App\Domain\Cms\Widgets\WidgetRegistry;
use App\Domain\Cms\Widgets\WidgetRenderer;
use App\Domain\Cms\Widgets\WidgetType;
use App\Filament\Support\WidgetEditor;
use Filament\Forms\Components\TextInput;
use Illuminate\Validation\ValidationException;
use InvalidArgumentException;
use Tests\TestCase;
class WidgetRegistryTest extends TestCase
{
private function registry(): WidgetRegistry
{
return app(WidgetRegistry::class);
}
public function test_all_configured_widgets_are_registered_with_complete_contract(): void
{
$types = $this->registry()->all();
$this->assertSame(
['hero', 'heading', 'prose', 'image_text', 'cards', 'catalog_cards', 'call_to_action', 'faq'],
array_keys($types),
);
foreach ($types as $key => $type) {
$this->assertSame($key, $type->key());
$this->assertNotSame('', $type->label());
$this->assertNotSame('', $type->description());
$this->assertGreaterThanOrEqual(1, $type->version());
$this->assertNotEmpty($type->variants());
$this->assertArrayHasKey($type->defaultVariant(), $type->variants());
$this->assertNotEmpty($type->dataRules());
$this->assertNotEmpty($type->editorSchema());
$this->assertTrue(view()->exists($type->view()), "Ansicht für $key fehlt");
}
}
public function test_reference_widgets_offer_at_least_two_variants(): void
{
foreach (['hero', 'image_text', 'cards', 'catalog_cards'] as $key) {
$this->assertGreaterThanOrEqual(2, count($this->registry()->get($key)->variants()), $key);
}
$this->assertSame(['image_left', 'image_right'], array_keys($this->registry()->get('image_text')->variants()));
}
public function test_registration_rejects_duplicate_and_invalid_keys(): void
{
$registry = new WidgetRegistry([$this->customWidget('teaser')]);
$this->expectException(InvalidArgumentException::class);
$registry->register($this->customWidget('teaser'));
}
public function test_registration_rejects_keys_that_are_not_stable_identifiers(): void
{
$this->expectException(InvalidArgumentException::class);
new WidgetRegistry([$this->customWidget('Teaser Box')]);
}
public function test_a_new_widget_type_works_through_the_contract_alone(): void
{
$registry = new WidgetRegistry([$this->customWidget('teaser')]);
$this->app->instance(WidgetRegistry::class, $registry);
$stored = $registry->normalize([
['type' => 'teaser', 'v' => 1, 'variant' => 'wide', 'data' => ['heading' => 'Neu']],
]);
$this->assertSame('teaser', $stored[0]['type']);
$this->assertSame('wide', $stored[0]['variant']);
$this->assertSame(['heading' => 'Neu'], $stored[0]['data']);
$html = app(WidgetRenderer::class)->renderAll($stored, RenderContext::publicPage())->toHtml();
$this->assertStringContainsString('<h1>Neu</h1>', $html);
$this->assertStringContainsString('widget-variant-wide', $html);
$block = WidgetEditor::block($registry->get('teaser'));
$this->assertSame('teaser', $block->getName());
$this->assertSame('Teaser · Breit – Neu', (string) $block->getLabel(['variant' => 'wide', 'data' => ['heading' => 'Neu']]));
}
public function test_unknown_type_and_unregistered_variant_are_rejected(): void
{
try {
$this->registry()->normalize([['type' => 'html', 'v' => 1, 'data' => ['markup' => '<script></script>']]]);
$this->fail('Unbekannte Art wurde angenommen.');
} catch (ValidationException $exception) {
$this->assertArrayHasKey('blocks.0.type', $exception->errors());
}
try {
$this->registry()->normalize([['type' => 'hero', 'v' => 1, 'variant' => 'gross-und-bunt', 'data' => ['heading' => 'X']]]);
$this->fail('Unbekannte Variante wurde angenommen.');
} catch (ValidationException $exception) {
$this->assertArrayHasKey('blocks.0.variant', $exception->errors());
}
}
public function test_free_settings_are_rejected(): void
{
$this->expectException(ValidationException::class);
$this->registry()->normalize([
['type' => 'heading', 'v' => 1, 'settings' => ['class' => 'bg-red-500'], 'data' => ['heading' => 'X']],
]);
}
public function test_image_text_requires_an_alternative_text_when_an_image_is_set(): void
{
try {
$this->registry()->normalize([
['type' => 'image_text', 'v' => 2, 'data' => ['body' => '<p>Text</p>'], 'refs' => ['image' => 'cms/bild.jpg']],
]);
$this->fail('Bild ohne Alternativtext wurde angenommen.');
} catch (ValidationException $exception) {
$this->assertArrayHasKey('blocks.0.data.alt', $exception->errors());
}
$stored = $this->registry()->normalize([
['type' => 'image_text', 'v' => 2, 'data' => ['body' => '<p>Ohne Bild</p>'], 'refs' => []],
]);
$this->assertNull($stored[0]['refs']['image']);
}
public function test_links_reject_script_urls_in_every_widget(): void
{
$cases = [
['type' => 'call_to_action', 'heading' => 'Weiter', 'label' => 'Öffnen', 'url' => 'javascript:alert(1)'],
['type' => 'cards', 'v' => 1, 'data' => ['items' => [['title' => 'A', 'url' => 'javascript:alert(1)']]]],
['type' => 'hero', 'v' => 1, 'data' => ['heading' => 'A', 'cta_label' => 'Los', 'cta_url' => '//fremd.example/x']],
];
foreach ($cases as $case) {
try {
$this->registry()->normalize([$case]);
$this->fail('Unsichere Adresse wurde angenommen: '.$case['type']);
} catch (ValidationException) {
$this->addToAssertionCount(1);
}
}
}
public function test_images_must_come_from_the_public_website_area(): void
{
$this->expectException(ValidationException::class);
$this->registry()->normalize([
['type' => 'hero', 'v' => 1, 'data' => ['heading' => 'A', 'alt' => 'Bild'], 'refs' => ['image' => 'bibliothek/geschuetzt.jpg']],
]);
}
public function test_formatted_text_is_sanitized_when_saved(): void
{
$stored = $this->registry()->normalize([[
'type' => 'image_text',
'v' => 2,
'data' => ['body' => '<p onclick="x()">Hallo <strong>Welt</strong><script>alert(1)</script> <a href="javascript:alert(1)">böse</a> <a href="/praevention">gut</a></p><iframe src="x"></iframe>'],
]]);
$body = $stored[0]['data']['body'];
$this->assertStringNotContainsString('script', $body);
$this->assertStringNotContainsString('onclick', $body);
$this->assertStringNotContainsString('javascript:', $body);
$this->assertStringNotContainsString('iframe', $body);
$this->assertStringContainsString('<strong>Welt</strong>', $body);
$this->assertStringContainsString('href="/praevention"', $body);
}
public function test_legacy_blocks_are_read_as_version_one_envelopes(): void
{
$widget = $this->registry()->upcast(['type' => 'heading', 'heading' => 'Alt', 'intro' => 'Einleitung']);
$this->assertSame([
'id' => null,
'type' => 'heading',
'v' => 1,
'variant' => 'standard',
'settings' => [],
'data' => ['heading' => 'Alt', 'intro' => 'Einleitung'],
'refs' => [],
], $widget);
}
public function test_legacy_image_text_is_upgraded_to_version_two_on_read(): void
{
$legacy = ['type' => 'image_text', 'image' => 'cms/alt.jpg', 'alt' => 'Kinder im Kreis', 'body' => "Erster Absatz & mehr.\n\nZweiter <Absatz>."];
$widget = $this->registry()->upcast($legacy);
$this->assertSame(2, $widget['v']);
$this->assertSame('image_left', $widget['variant']);
$this->assertSame(['image' => 'cms/alt.jpg'], $widget['refs']);
$this->assertSame('Kinder im Kreis', $widget['data']['alt']);
$this->assertNull($widget['data']['title']);
$this->assertSame('<p>Erster Absatz &amp; mehr.</p><p>Zweiter &lt;Absatz&gt;.</p>', $widget['data']['body']);
}
public function test_stored_version_one_envelope_is_upgraded_as_well(): void
{
$widget = $this->registry()->upcast([
'id' => 'abc', 'type' => 'image_text', 'v' => 1, 'variant' => 'standard',
'data' => ['image' => null, 'alt' => 'x', 'body' => 'Nur Text'], 'refs' => [],
]);
$this->assertSame(2, $widget['v']);
$this->assertSame('abc', $widget['id']);
$this->assertSame('image_left', $widget['variant']);
$this->assertSame('<p>Nur Text</p>', $widget['data']['body']);
}
public function test_widgets_from_a_newer_schema_cannot_be_saved(): void
{
$this->expectException(ValidationException::class);
$this->registry()->normalize([['type' => 'heading', 'v' => 99, 'data' => ['heading' => 'Zukunft']]]);
}
public function test_read_skips_unknown_types_without_failing(): void
{
$widgets = $this->registry()->read([
['type' => 'gibt_es_nicht', 'v' => 1],
['type' => 'prose', 'body' => 'Bleibt lesbar'],
]);
$this->assertCount(1, $widgets);
$this->assertSame('prose', $widgets[0]['type']);
}
public function test_ids_are_kept_and_duplicates_get_new_ids(): void
{
$stored = $this->registry()->normalize([
['id' => 'erster', 'type' => 'heading', 'v' => 1, 'data' => ['heading' => 'A']],
['id' => 'erster', 'type' => 'heading', 'v' => 1, 'data' => ['heading' => 'Kopie']],
['type' => 'prose', 'body' => 'Ohne Kennung'],
]);
$this->assertSame('erster', $stored[0]['id']);
$this->assertNotSame('erster', $stored[1]['id']);
$this->assertNotEmpty($stored[2]['id']);
$this->assertNotSame($stored[1]['id'], $stored[2]['id']);
}
public function test_only_declared_fields_are_stored(): void
{
$stored = $this->registry()->normalize([[
'type' => 'cards',
'v' => 1,
'data' => ['items' => [['title' => 'A', 'price' => '99 €', 'url' => '/a']], 'license' => 'alle'],
'refs' => ['offer' => 7],
]]);
$this->assertSame(['items' => [['title' => 'A', 'text' => null, 'url' => '/a', 'image' => null]]], $stored[0]['data']);
$this->assertSame([], $stored[0]['refs']);
}
public function test_rich_text_from_plain_text_escapes_markup(): void
{
$this->assertSame('<p>&lt;b&gt;fett&lt;/b&gt;</p>', RichText::fromPlainText('<b>fett</b>'));
$this->assertSame('', RichText::fromPlainText(" \n "));
}
private function customWidget(string $key): WidgetType
{
return new class($key) extends WidgetType
{
public function __construct(private readonly string $widgetKey) {}
public function key(): string
{
return $this->widgetKey;
}
public function label(): string
{
return 'Teaser';
}
public function description(): string
{
return 'Testwidget';
}
public function variants(): array
{
return ['standard' => 'Standard', 'wide' => 'Breit'];
}
public function dataRules(): array
{
return ['heading' => ['required', 'string', 'max:50']];
}
public function dataFields(): array
{
return [TextInput::make('heading')];
}
public function view(): string
{
return 'widgets.heading';
}
public function summary(array $widget): string
{
return (string) ($widget['data']['heading'] ?? '');
}
};
}
}