- Themenkarte: alle Säulen wählbar; nicht veröffentlichte nur in der Redaktionsvorschau. - Medienkarte: Kurzbeschreibung, Film (Filmtafel, Hinweis auf den geschützten Film) und Material (Materialsymbol) getrennt; Filmstandbild der Bibliothek nur in der Redaktionsvorschau, markiert; Entwürfe wählbar, gesperrte nicht; Traineranleitungen nie öffentlich. - Programm-/Modulkarte: Lernziel als Text, Dauer und Modulzahl; Programme/Module ohne Anzeigefreigabe für die Vorschau wählbar; Module weiterhin ohne Link. - Fehlende Inhalte nur in der Vorschau als eingeklappte Redaktionshinweise. - Tests bewusst angepasst: Medien zeigen jetzt die Kurzbeschreibung (Betreibervorgabe), unveröffentlichte Themen und Programme ohne Freigabe sind wählbar. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
475 lines
29 KiB
PHP
475 lines
29 KiB
PHP
<?php
|
||
|
||
namespace Tests\Feature;
|
||
|
||
use App\Domain\Catalog\CompositionDisplayRelease;
|
||
use App\Domain\Catalog\ContentElement;
|
||
use App\Domain\Catalog\ContentService;
|
||
use App\Domain\Catalog\EditorialContentKind;
|
||
use App\Domain\Catalog\Pillar;
|
||
use App\Domain\Catalog\PillarService;
|
||
use App\Domain\Cms\Page;
|
||
use App\Domain\Cms\PageRevision;
|
||
use App\Domain\Cms\PageService;
|
||
use App\Domain\Cms\Widgets\WidgetRegistry;
|
||
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 Filament\Forms\Components\Select;
|
||
use Filament\Forms\Components\Slider;
|
||
use Filament\Forms\Components\ToggleButtons;
|
||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||
use Illuminate\Support\Facades\Storage;
|
||
use Illuminate\Support\Str;
|
||
use Illuminate\Validation\ValidationException;
|
||
use Livewire\Livewire;
|
||
use Tests\Support\BuildsCatalog;
|
||
use Tests\TestCase;
|
||
|
||
/**
|
||
* Premium-Karten v1.7 (Themen-, Medien- und Programmkarte): Fachbezug ohne Kopien, Freigaberegeln,
|
||
* keine Bibliotheksbilder, kein Preis und keine Kaufaktion, Bearbeitung über den regulären Seiteneditor.
|
||
*/
|
||
class CmsPremiumCardsTest extends TestCase
|
||
{
|
||
use BuildsCatalog;
|
||
use RefreshDatabase;
|
||
|
||
protected function setUp(): void
|
||
{
|
||
parent::setUp();
|
||
|
||
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
|
||
}
|
||
|
||
public function test_the_three_card_types_are_registered_with_the_layout_contract(): void
|
||
{
|
||
$registry = app(WidgetRegistry::class);
|
||
|
||
foreach (['topic_card' => 'pillar', 'media_card' => 'element', 'program_card' => 'composition'] as $key => $ref) {
|
||
$type = $registry->get($key);
|
||
$this->assertSame([1, 2, 3, 4], $type->supportedUnits(), $key);
|
||
$this->assertSame(['auto', 'fill'], array_keys($type->heights()), $key);
|
||
$this->assertSame(['adaptive', 'stacked'], array_keys($type->variants()), $key);
|
||
$this->assertSame('widgets.premium_card', $type->view());
|
||
$this->assertArrayHasKey($ref, $type->refRules());
|
||
$this->assertArrayNotHasKey('url', $type->dataRules(), 'Kein freies Linkziel.');
|
||
$this->assertArrayNotHasKey('title', $type->dataRules(), 'Kein eigener Titel: der Titel kommt aus dem Fachobjekt.');
|
||
}
|
||
|
||
$this->assertArrayNotHasKey('show_kind', $registry->get('program_card')->settingOptions(), 'Programm oder Modul bleibt immer benannt.');
|
||
$this->assertArrayHasKey('show_summary', $registry->get('media_card')->settingOptions(), 'Medienkarten zeigen die Kurzbeschreibung des Mediums.');
|
||
}
|
||
|
||
public function test_topic_card_shows_a_published_theme_from_the_master_data_only(): void
|
||
{
|
||
$pillar = $this->pillar('Gefühle verstehen', 'gefuehle-verstehen', 'Geschichten und Impulse, die Kinder ins Gespräch bringen.');
|
||
|
||
$revision = $this->publish('/themenkarte', [$this->section('u2_2', [
|
||
$this->card('topic_card', ['pillar' => $pillar->id], settings: ['heading_level' => 'h2', 'show_summary' => 'yes']),
|
||
$this->card('topic_card', ['pillar' => $pillar->id], data: ['action_label' => 'Mehr zum Thema'], settings: ['show_summary' => 'no', 'show_kind' => 'no']),
|
||
])]);
|
||
|
||
$this->assertSame(['pillar' => $pillar->id, 'image' => null], $revision->sections[0]['slots'][0]['refs']);
|
||
$this->assertStringNotContainsString('Gefühle verstehen', json_encode($revision->sections), 'Keine Kopie des Themennamens im CMS.');
|
||
|
||
$html = $this->get('/themenkarte')->assertOk()->getContent();
|
||
$this->assertStringContainsString('<h2 class="lf-pc__title">Gefühle verstehen</h2>', $html);
|
||
$this->assertStringContainsString('<h3 class="lf-pc__title">Gefühle verstehen</h3>', $html);
|
||
$this->assertSame(1, substr_count($html, 'Geschichten und Impulse'), 'Kurzbeschreibung nur, wo sie angezeigt werden soll.');
|
||
$this->assertStringContainsString('href="'.route('theme', ['slug' => 'gefuehle-verstehen']).'">Thema entdecken</a>', $html);
|
||
$this->assertStringContainsString('>Mehr zum Thema</a>', $html);
|
||
$this->assertSame(1, substr_count($html, '<p class="lf-pc__kind">Thema</p>'));
|
||
|
||
$pillar->update(['name' => 'Gefühle verstehen und benennen']);
|
||
$this->get('/themenkarte')->assertSee('Gefühle verstehen und benennen');
|
||
|
||
$pillar->update(['published_at' => null]);
|
||
$this->get('/themenkarte')->assertOk()->assertDontSee('lf-pc', false)->assertDontSee('Gefühle verstehen');
|
||
}
|
||
|
||
public function test_program_card_names_its_kind_and_offers_no_price_or_purchase(): void
|
||
{
|
||
$module = $this->composition('Modul Nein sagen', 'modul', summary: 'Ein Modul');
|
||
$program = $this->composition('Programm Selbstvertrauen', 'programm', summary: 'Ein roter Faden für die Kursgestaltung.');
|
||
|
||
$revision = $this->publish('/programmkarte', [$this->section('u2_2', [
|
||
$this->card('program_card', ['composition' => $program->composition_id]),
|
||
$this->card('program_card', ['composition' => $module->composition_id]),
|
||
])]);
|
||
|
||
$html = $this->get('/programmkarte')->assertOk()->getContent();
|
||
$this->assertStringContainsString('<p class="lf-pc__kind">Programm</p>', $html);
|
||
$this->assertStringContainsString('<span class="lf-pc__panel-label">Programm</span>', $html, 'Ohne Bild trägt die Navy-Tafel die Art.');
|
||
$this->assertStringContainsString('href="'.route('public.program', $program->composition_id).'">Programm ansehen</a>', $html);
|
||
$this->assertStringContainsString('Ein roter Faden', $html);
|
||
$this->assertStringNotContainsString('Modul Nein sagen', $html, 'Module erscheinen öffentlich nicht.');
|
||
$this->assertStringNotContainsString('Modul / Programm', $html);
|
||
|
||
foreach (['€', 'EUR', 'Preis', 'kaufen', 'Warenkorb', '/bereich/angebote', 'offers'] as $commerce) {
|
||
$this->assertStringNotContainsString($commerce, $this->mainHtml($html), "Keine Kaufaktion: $commerce");
|
||
}
|
||
|
||
$preview = $this->actingAs(User::factory()->redakteur()->create(), 'staff')->get(route('pages.preview', $revision))->assertOk()->getContent();
|
||
$this->assertStringContainsString('<p class="lf-pc__kind">Modul</p>', $preview);
|
||
$this->assertStringContainsString('Nur in der Redaktionsvorschau sichtbar: Für Module gibt es noch keine öffentliche Seitenart', $preview);
|
||
$this->assertStringContainsString('lf-pc--internal', $preview);
|
||
}
|
||
|
||
public function test_program_card_lists_the_number_of_modules_of_the_shown_version(): void
|
||
{
|
||
$content = app(ContentService::class);
|
||
$moduleA = $this->composition('Modul Eins', 'modul');
|
||
$moduleB = $this->composition('Modul Zwei', 'modul');
|
||
$composition = $content->createComposition('Programm mit Modulen');
|
||
$composition->editorial_content_kind_id = EditorialContentKind::query()->where('slug', 'programm')->value('id');
|
||
$composition->save();
|
||
$version = $content->publishComposition($composition, [
|
||
['role' => 'Modul', 'target' => $moduleA],
|
||
['role' => 'Modul', 'target' => $moduleB],
|
||
]);
|
||
app(CompositionDisplayRelease::class)->release($version, User::factory()->create());
|
||
|
||
$this->publish('/programm-module', [$this->section('u4', [$this->card('program_card', ['composition' => $composition->id])])]);
|
||
|
||
$this->get('/programm-module')->assertOk()->assertSee('<li>2 Module</li>', false);
|
||
}
|
||
|
||
public function test_media_card_is_public_only_as_part_of_a_public_program_and_never_releases_the_medium(): void
|
||
{
|
||
$content = app(ContentService::class);
|
||
$kind = fn (string $slug) => EditorialContentKind::query()->where('slug', $slug)->value('id');
|
||
$film = $content->createElement('film', 'film', 'Denkpause Rohschnitt');
|
||
$film->update(['display_title' => 'Eine Pause, die stark macht', 'summary' => 'Gemeinsam innehalten und über gute nächste Schritte sprechen.', 'description' => 'Interne Beschreibung für die Bibliothek', 'usage_note' => 'Einsatzhinweis intern', 'license_note' => 'Lizenzvermerk intern', 'thumbnail_path' => 'vorschau/denkpause.jpg']);
|
||
$filmVersion = $content->publishElementVersion($film, 'Filmbeschreibung');
|
||
$sheet = $content->createElement('text', 'pdf', 'Merkblatt Grenzen');
|
||
$sheet->update(['editorial_content_kind_id' => $kind('merkblatt'), 'summary' => 'Ein Blatt für Eltern.']);
|
||
$sheetVersion = $content->publishElementVersion($sheet, 'Inhalt');
|
||
$guide = $content->createElement('text', 'text', 'Traineranleitung Abstand');
|
||
$guide->update(['editorial_content_kind_id' => $kind('traineranleitung')]);
|
||
$guideVersion = $content->publishElementVersion($guide, 'Vertraulich');
|
||
$loose = $content->createElement('text', 'pdf', 'Arbeitsblatt ohne Programm');
|
||
$content->publishElementVersion($loose, 'Inhalt');
|
||
|
||
$composition = $content->createComposition('Programm Denkpause');
|
||
$composition->editorial_content_kind_id = $kind('programm');
|
||
$composition->save();
|
||
$version = $content->publishComposition($composition, [
|
||
['role' => 'Film', 'target' => $filmVersion],
|
||
['role' => 'Merkblatt', 'target' => $sheetVersion],
|
||
['role' => 'Anleitung', 'target' => $guideVersion],
|
||
]);
|
||
app(CompositionDisplayRelease::class)->release($version, User::factory()->create());
|
||
|
||
$revision = $this->publish('/medienkarte', [
|
||
$this->section('u2_2', [
|
||
$this->card('media_card', ['element' => $film->id], data: ['note' => 'Für die nächste Kursstunde.']),
|
||
$this->card('media_card', ['element' => $sheet->id]),
|
||
]),
|
||
$this->section('u2_2', [
|
||
$this->card('media_card', ['element' => $guide->id]),
|
||
$this->card('media_card', ['element' => $loose->id]),
|
||
]),
|
||
]);
|
||
|
||
$main = $this->mainHtml($this->get('/medienkarte')->assertOk()->getContent());
|
||
// Film: Medienkarte mit Filmtafel, Kurzbeschreibung, Medientyp, Programmbezug und Hinweis auf den geschützten Film.
|
||
$this->assertStringContainsString('lf-pc lf-pc--media', $main);
|
||
$this->assertStringContainsString('lf-pc__panel lf-pc__panel--film', $main);
|
||
$this->assertStringContainsString('Eine Pause, die stark macht', $main);
|
||
$this->assertStringContainsString('Gemeinsam innehalten und über gute nächste Schritte sprechen.', $main);
|
||
$this->assertStringContainsString('<li>Im Programm „Programm Denkpause“</li>', $main);
|
||
$this->assertStringContainsString('<li>Vollständiger Film nur mit Lizenz im Mitgliederbereich</li>', $main);
|
||
$this->assertStringContainsString('href="'.route('public.program', $composition->id).'">Im Programm ansehen</a>', $main);
|
||
$this->assertStringContainsString('Für die nächste Kursstunde.', $main);
|
||
// Material: eigene Darstellung mit Materialsymbol.
|
||
$this->assertStringContainsString('lf-pc lf-pc--material', $main);
|
||
$this->assertStringContainsString('lf-pc__panel lf-pc__panel--material', $main);
|
||
$this->assertStringContainsString('<p class="lf-pc__kind">Merkblatt</p>', $main);
|
||
$this->assertStringContainsString('Ein Blatt für Eltern.', $main);
|
||
// Vertraulich und nicht öffentlich genannt: öffentlich nicht sichtbar.
|
||
$this->assertStringNotContainsString('Traineranleitung Abstand', $main, 'Traineranleitungen erscheinen nie öffentlich.');
|
||
$this->assertStringNotContainsString('Arbeitsblatt ohne Programm', $main);
|
||
|
||
foreach (['vorschau/denkpause.jpg', '/bereich/', '/redaktion/', '/ausgabe/', '<video', 'download', 'Filmbeschreibung', 'Interne Beschreibung', 'Einsatzhinweis intern', 'Lizenzvermerk intern', 'Bibliotheksbild', 'Für eine vollständige Karte', 'preview-note'] as $protected) {
|
||
$this->assertStringNotContainsString($protected, $main, "Keine geschützte oder redaktionelle Ausgabe über die Karte: $protected");
|
||
}
|
||
|
||
$preview = $this->actingAs(User::factory()->redakteur()->create(), 'staff')->get(route('pages.preview', $revision))->assertOk()->getContent();
|
||
// Redaktionsvorschau: Filmstandbild der Bibliothek, deutlich als nicht öffentlich markiert, und Hinweise auf Fehlendes.
|
||
$this->assertStringContainsString('src="'.route('editorial.card', ['kind' => 'element', 'subject' => $film->id]).'"', $preview);
|
||
$this->assertStringContainsString('Bibliotheksbild · nur Vorschau', $preview);
|
||
$this->assertStringContainsString('Das Vorschaubild der Bibliothek ist nicht für die Website freigegeben', $preview);
|
||
$this->assertStringContainsString('Laufzeit: in den Mediendaten nicht erfasst.', $preview);
|
||
$this->assertStringContainsString('Traineranleitung Abstand', $preview);
|
||
$this->assertStringContainsString('Traineranleitungen erscheinen nie öffentlich.', $preview);
|
||
$this->assertStringContainsString('Arbeitsblatt ohne Programm', $preview);
|
||
$this->assertStringContainsString('Das Medium gehört zu keinem öffentlich gezeigten Programm', $preview);
|
||
|
||
$film->update(['archived_at' => now()]);
|
||
$this->get('/medienkarte')->assertOk()->assertDontSee('Eine Pause, die stark macht');
|
||
}
|
||
|
||
public function test_draft_media_and_unreleased_compositions_can_be_prepared_but_stay_private(): void
|
||
{
|
||
$content = app(ContentService::class);
|
||
$draftFilm = $content->createElement('film', 'film', 'Felix beim Onkel');
|
||
$content->draftElementVersion($draftFilm, 'Entwurf');
|
||
$programComposition = $content->createComposition('Programm ohne Freigabe');
|
||
$programComposition->forceFill(['editorial_content_kind_id' => EditorialContentKind::query()->where('slug', 'programm')->value('id'), 'thumbnail_path' => 'vorschau/programm.jpg'])->save();
|
||
$program = $content->publishComposition(
|
||
$programComposition,
|
||
[['role' => 'Text', 'target' => $content->publishElementVersion($content->createElement('text', 'text', 'Programmblatt'), 'Inhalt')]],
|
||
didactic: ['learning_goal' => 'Kinder erkennen eigene Grenzen.', 'duration_minutes' => 25],
|
||
);
|
||
$module = $this->composition('Modul Grenzen', 'modul');
|
||
|
||
$revision = $this->publish('/vorbereitet', [$this->section('u1_1_2', [
|
||
$this->card('media_card', ['element' => $draftFilm->id]),
|
||
$this->card('program_card', ['composition' => $module->composition_id]),
|
||
$this->card('program_card', ['composition' => $program->composition_id]),
|
||
])]);
|
||
|
||
$this->get('/vorbereitet')->assertOk()->assertDontSee('lf-pc', false);
|
||
|
||
$preview = $this->actingAs(User::factory()->redakteur()->create(), 'staff')->get(route('pages.preview', $revision))->assertOk()->getContent();
|
||
$this->assertStringContainsString('Felix beim Onkel', $preview);
|
||
$this->assertStringContainsString('Das Medium hat noch keine bereitgestellte Fassung.', $preview);
|
||
$this->assertStringContainsString('Das Programm hat keine Anzeigefreigabe.', $preview);
|
||
$this->assertStringContainsString('Kinder erkennen eigene Grenzen.', $preview, 'Ohne Kurzbeschreibung zeigt die Karte das Lernziel.');
|
||
$this->assertStringContainsString('<li>Dauer 25 Min.</li>', $preview);
|
||
$this->assertStringContainsString('src="'.route('editorial.card', ['kind' => 'komposition', 'subject' => $program->composition_id]).'"', $preview);
|
||
$this->assertStringContainsString('Für Module gibt es noch keine öffentliche Seitenart', $preview);
|
||
$this->assertStringNotContainsString(route('public.program', $module->composition_id), $preview, 'Module erhalten keinen künstlichen Link.');
|
||
}
|
||
|
||
public function test_unpublished_themes_are_selectable_and_shown_only_in_the_preview(): void
|
||
{
|
||
$theme = app(PillarService::class)->create('Meine Grenzen – Ich darf Nein sagen');
|
||
$type = app(WidgetRegistry::class)->get('topic_card');
|
||
$search = (new \ReflectionMethod($type, 'searchSubjects'))->invoke($type, null);
|
||
$this->assertSame([$theme->id => 'Meine Grenzen – Ich darf Nein sagen · Thema · nicht veröffentlicht, nur Redaktionsvorschau'], $search);
|
||
|
||
$revision = $this->publish('/thema-vorbereitet', [$this->section('u2_2', [
|
||
$this->card('topic_card', ['pillar' => $theme->id]),
|
||
null,
|
||
])]);
|
||
|
||
$this->get('/thema-vorbereitet')->assertOk()->assertDontSee('Meine Grenzen')->assertDontSee('lf-pc', false);
|
||
$preview = $this->actingAs(User::factory()->redakteur()->create(), 'staff')->get(route('pages.preview', $revision))->assertOk()->getContent();
|
||
$this->assertStringContainsString('Meine Grenzen – Ich darf Nein sagen', $preview);
|
||
$this->assertStringContainsString('Das Thema ist nicht veröffentlicht', $preview);
|
||
$this->assertStringContainsString('Kein Text für die Website gepflegt', $preview);
|
||
|
||
app(PillarService::class)->present($theme->refresh(), $theme->name, 'meine-grenzen', 'Kinder lernen, ihre Grenzen zu spüren.', true, 1);
|
||
$this->get('/thema-vorbereitet')->assertOk()
|
||
->assertSee('Kinder lernen, ihre Grenzen zu spüren.')
|
||
->assertSee(route('theme', ['slug' => 'meine-grenzen']), false)
|
||
->assertDontSee('nicht veröffentlicht');
|
||
}
|
||
|
||
public function test_cards_reject_unpublished_or_unreleased_objects_and_require_alt_text_for_images(): void
|
||
{
|
||
Storage::fake('media_public');
|
||
Storage::disk('media_public')->put('cms/karte.jpg', 'bild');
|
||
$archivedProgram = $this->composition('Programm Archiv', 'programm');
|
||
$archivedProgram->composition->update(['archived_at' => now()]);
|
||
$archived = app(ContentService::class)->createElement('film', 'film', 'Ohne Fassung');
|
||
$published = $this->pillar('Grenzen', 'grenzen', null);
|
||
|
||
$cases = [
|
||
[$this->card('topic_card', ['pillar' => 999999]), 'refs.pillar'],
|
||
[$this->card('program_card', ['composition' => $archivedProgram->composition_id]), 'refs.composition'],
|
||
[$this->card('media_card', ['element' => $archived->id]), 'refs.element'],
|
||
[$this->card('topic_card', ['pillar' => $published->id, 'image' => 'cms/karte.jpg']), 'data.alt'],
|
||
[$this->card('topic_card', ['pillar' => $published->id], settings: ['format' => 'panorama']), 'settings.format'],
|
||
[$this->card('topic_card', []), 'refs.pillar'],
|
||
];
|
||
|
||
foreach ($cases as [$card, $key]) {
|
||
try {
|
||
app(PageService::class)->saveRevision(Page::query()->create(['path' => '/fehler-'.Str::random(6)]), [$this->section('u4', [$card])], null, null, null);
|
||
$this->fail("Erwarteter Fehler: $key");
|
||
} catch (ValidationException $exception) {
|
||
$this->assertArrayHasKey("sections.0.slots.0.$key", $exception->errors(), json_encode($exception->errors()));
|
||
}
|
||
}
|
||
}
|
||
|
||
public function test_mixed_card_grids_use_the_section_grid_with_equal_height_and_image_options(): void
|
||
{
|
||
Storage::fake('media_public');
|
||
Storage::disk('media_public')->put('cms/karte.jpg', 'bild');
|
||
$pillar = $this->pillar('Hilfe holen', 'hilfe-holen', str_repeat('Ein sehr langer Text, der umbrechen muss. ', 12));
|
||
$program = $this->composition('Programm Lang', 'programm', summary: 'Kurz');
|
||
|
||
$this->publish('/kartenraster', [
|
||
$this->section('u1_1_2', [
|
||
$this->card('topic_card', ['pillar' => $pillar->id, 'image' => 'cms/karte.jpg'], data: ['alt' => 'Lara und Felix im Park', 'focus_x' => 30, 'focus_y' => 70], settings: ['height' => 'fill', 'format' => 'portrait', 'fit' => 'contain']),
|
||
$this->card('program_card', ['composition' => $program->composition_id], settings: ['height' => 'fill']),
|
||
$this->card('topic_card', ['pillar' => $pillar->id], variant: 'stacked'),
|
||
]),
|
||
$this->section('u2_2', [
|
||
$this->card('program_card', ['composition' => $program->composition_id, 'image' => 'cms/karte.jpg'], data: ['alt' => 'Kursraum']),
|
||
$this->card('topic_card', ['pillar' => $pillar->id], settings: ['show_action' => 'no', 'show_meta' => 'no']),
|
||
]),
|
||
]);
|
||
|
||
$html = $this->get('/kartenraster')->assertOk()->getContent();
|
||
$this->assertStringContainsString('section-layout-u1-1-2', $html);
|
||
$this->assertStringContainsString('--section-cols-lg: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 2fr)', $html);
|
||
$this->assertStringNotContainsString('lf-pc-grid', $html, 'Kein zweites Kartenraster.');
|
||
$this->assertSame(2, substr_count($html, 'widget-height-fill'));
|
||
$this->assertStringContainsString('lf-pc lf-pc--editorial lf-pc--portrait lf-pc--contain', $html);
|
||
$this->assertStringContainsString('--pc-focus-x: 30%; --pc-focus-y: 70%', $html);
|
||
$this->assertStringContainsString('alt="Lara und Felix im Park"', $html);
|
||
$this->assertStringContainsString('lf-pc--stacked lf-pc--without-visual', $html);
|
||
$this->assertStringContainsString('lf-pc lf-pc--catalog lf-pc--landscape lf-pc--cover"', $html, 'Programmkarte mit Bild zeigt das Bild statt der Tafel.');
|
||
$this->assertSame(2, substr_count($html, 'Thema entdecken'), 'Drei Themenkarten, auf einer ist die Aktion ausgeblendet.');
|
||
$this->assertStringContainsString(str_repeat('Ein sehr langer Text, der umbrechen muss. ', 11), html_entity_decode($html), 'Lange Texte werden nicht gekürzt.');
|
||
}
|
||
|
||
public function test_editor_inserts_configures_saves_and_reopens_all_three_cards(): void
|
||
{
|
||
Storage::fake('media_public');
|
||
Storage::fake('cms_incoming');
|
||
Storage::disk('media_public')->put('cms/karte.jpg', 'bild');
|
||
$pillar = $this->pillar('Gefühle', 'gefuehle', 'Kurz');
|
||
$program = $this->composition('Programm Abstand', 'programm');
|
||
$element = ContentElement::query()->where('working_title', 'Programm Abstand Blatt')->firstOrFail();
|
||
|
||
Livewire::actingAs($this->editor(), 'staff')
|
||
->test(CreatePage::class)
|
||
->fillForm([
|
||
'path' => '/karten-editor',
|
||
'sections' => [
|
||
$this->sectionState('u1_1_2', [
|
||
['type' => 'topic_card', 'data' => ['variant' => 'adaptive', 'settings' => ['height' => 'fill', 'format' => 'square', 'heading_level' => 'h2'], 'data' => ['action_label' => 'Zum Thema', 'alt' => 'Park', 'focus_x' => 20, 'focus_y' => 80], 'refs' => ['pillar' => $pillar->id, 'image' => 'cms/karte.jpg']]],
|
||
['type' => 'media_card', 'data' => ['variant' => 'stacked', 'settings' => ['height' => 'fill', 'show_meta' => 'no'], 'data' => ['note' => 'Hinweis'], 'refs' => ['element' => $element->id]]],
|
||
['type' => 'program_card', 'data' => ['variant' => 'adaptive', 'settings' => ['height' => 'fill', 'fit' => 'contain'], 'data' => [], 'refs' => ['composition' => $program->composition_id]]],
|
||
]),
|
||
],
|
||
])
|
||
->call('create')
|
||
->assertHasNoFormErrors();
|
||
|
||
$page = Page::query()->where('path', '/karten-editor')->firstOrFail();
|
||
$this->assertNull($page->published_revision_id, 'Entwurf, nicht veröffentlicht.');
|
||
[$topic, $media, $programCard] = $page->latestRevision->sections[0]['slots'];
|
||
$this->assertSame(['topic_card', 'adaptive', ['height' => 'fill', 'format' => 'square', 'heading_level' => 'h2']], [$topic['type'], $topic['variant'], $topic['settings']]);
|
||
$this->assertSame(['pillar' => $pillar->id, 'image' => 'cms/karte.jpg'], $topic['refs']);
|
||
$this->assertSame(['Zum Thema', 20, 80], [$topic['data']['action_label'], $topic['data']['focus_x'], $topic['data']['focus_y']]);
|
||
$this->assertSame(['media_card', 'stacked', $element->id], [$media['type'], $media['variant'], $media['refs']['element']]);
|
||
$this->assertSame(['program_card', $program->composition_id], [$programCard['type'], $programCard['refs']['composition']]);
|
||
|
||
// Wieder öffnen: Dialog zeigt Inhalt (Fachobjekt), Medien (Bild, Fokus) und Darstellung (Variante, Höhe, Optionen).
|
||
$component = Livewire::actingAs($this->editor(), 'staff')->test(EditPage::class, ['record' => $page->id]);
|
||
$sectionKey = array_key_first($component->get('data.sections'));
|
||
$slotKey = array_key_first($component->get("data.sections.$sectionKey.slots"));
|
||
$itemKey = array_key_first($component->get("data.sections.$sectionKey.slots.$slotKey.widget"));
|
||
$this->assertSame($pillar->id, (int) $component->get("data.sections.$sectionKey.slots.$slotKey.widget.$itemKey.data.refs.pillar"));
|
||
|
||
$component->mountAction(TestAction::make('edit')->schemaComponent("sections.$sectionKey.slots.$slotKey.widget")->arguments(['item' => $itemKey]))
|
||
->assertFormFieldExists('refs.pillar', fn ($field) => $field instanceof Select && $field->isRequired())
|
||
->assertFormFieldExists('data.action_label')
|
||
->assertFormFieldExists('data.note')
|
||
->assertFormFieldExists('refs.image')
|
||
->assertFormFieldExists('data.alt')
|
||
->assertFormFieldExists('data.focus_x', fn ($field) => $field instanceof Slider)
|
||
->assertFormFieldExists('variant', fn ($field) => $field instanceof ToggleButtons && array_keys($field->getOptions()) === ['adaptive', 'stacked'])
|
||
->assertFormFieldExists('settings.height', fn ($field) => $field instanceof ToggleButtons && array_keys($field->getOptions()) === ['auto', 'fill'])
|
||
->assertFormFieldExists('settings.format')
|
||
->assertFormFieldExists('settings.fit')
|
||
->assertFormFieldExists('settings.show_summary')
|
||
->assertFormFieldExists('settings.show_action');
|
||
|
||
// Live-Vorschau des Dialogs mit derselben Ansicht wie die öffentliche Seite.
|
||
$preview = WidgetEditor::renderPreview('topic_card', $component->get("data.sections.$sectionKey.slots.$slotKey.widget.$itemKey.data"));
|
||
$this->assertStringContainsString('lf-pc lf-pc--editorial lf-pc--square', htmlspecialchars_decode($preview));
|
||
|
||
// Speichern ohne Änderung bleibt fehlerfrei; Veröffentlichen zeigt die Karten öffentlich.
|
||
$component->call('save')->assertHasNoFormErrors();
|
||
app(PageService::class)->publish($page->refresh(), $page->latestRevision);
|
||
$html = $this->get('/karten-editor')->assertOk()->getContent();
|
||
$this->assertStringContainsString('<h2 class="lf-pc__title">Gefühle</h2>', $html);
|
||
$this->assertStringContainsString('>Zum Thema</a>', $html);
|
||
$this->assertStringContainsString('Programm Abstand', $html);
|
||
$this->assertStringContainsString('Programm Abstand Blatt', $html, 'Ein Element eines öffentlichen Programms erscheint öffentlich.');
|
||
$this->assertStringContainsString('lf-pc lf-pc--material lf-pc--landscape lf-pc--cover lf-pc--stacked', $html, 'Ein Textmaterial erscheint als Materialkarte.');
|
||
$this->assertStringNotContainsString('Im Programm „Programm Abstand“', $html, 'Zusatzangaben ausgeblendet.');
|
||
}
|
||
|
||
private function pillar(string $name, string $slug, ?string $summary): Pillar
|
||
{
|
||
$pillar = app(PillarService::class)->create($name);
|
||
app(PillarService::class)->present($pillar, $name, $slug, $summary, true, 10);
|
||
|
||
return $pillar->refresh();
|
||
}
|
||
|
||
/**
|
||
* @param array<string, mixed> $refs
|
||
* @param array<string, mixed> $data
|
||
* @param array<string, string> $settings
|
||
* @return array<string, mixed>
|
||
*/
|
||
private function card(string $type, array $refs, array $data = [], array $settings = [], string $variant = 'adaptive'): array
|
||
{
|
||
return ['type' => $type, 'v' => 1, 'variant' => $variant, 'settings' => $settings, 'data' => $data, 'refs' => $refs];
|
||
}
|
||
|
||
/**
|
||
* @param list<array<string, mixed>|null> $slots
|
||
* @return array<string, mixed>
|
||
*/
|
||
private function section(string $layout, array $slots): array
|
||
{
|
||
return ['layout' => $layout, 'style' => [], 'slots' => $slots];
|
||
}
|
||
|
||
/**
|
||
* @param list<array<string, mixed>> $sections
|
||
*/
|
||
private function publish(string $path, array $sections): PageRevision
|
||
{
|
||
$page = Page::query()->create(['path' => $path]);
|
||
$service = app(PageService::class);
|
||
$revision = $service->saveRevision($page, $sections, null, null, null);
|
||
$service->publish($page, $revision);
|
||
|
||
return $revision;
|
||
}
|
||
|
||
private function mainHtml(string $html): string
|
||
{
|
||
preg_match('#<main[^>]*>(.*)</main>#s', $html, $match);
|
||
|
||
return $match[1] ?? '';
|
||
}
|
||
|
||
private function editor(): User
|
||
{
|
||
$editor = User::factory()->redakteur()->create();
|
||
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||
|
||
return $editor;
|
||
}
|
||
|
||
/**
|
||
* @param list<array<string, mixed>|null> $widgets
|
||
* @return array<string, mixed>
|
||
*/
|
||
private function sectionState(string $layout, array $widgets): array
|
||
{
|
||
$slots = [];
|
||
foreach ($widgets as $widget) {
|
||
$slots[(string) Str::uuid()] = ['widget' => $widget === null ? [] : [(string) Str::uuid() => $widget]];
|
||
}
|
||
|
||
return ['id' => null, 'layout' => $layout, 'style' => [], 'slots' => $slots];
|
||
}
|
||
}
|