Files
laraundfelix/tests/Feature/CmsMediaCardTextTest.php
T
LarsandClaude Sonnet 5.5 3825f53a9b
CI Feature / test (push) Successful in 1m46s
Deploy Test / test (push) Successful in 1m45s
Deploy Test / deploy (push) Successful in 36s
Wähle den Kartentext auch an der Programm- und Modulkarte und führe den Filmbild-Regler nach.
- Programm- und Modulkarte: „Text der Karte“ (Automatisch wie bisher: Teaser, sonst Kurzbeschreibung, sonst
  Lernziel; Teaser, Kurzbeschreibung, Ausführliche Beschreibung, Lernziel der Fassung). Eine ausdrückliche Wahl
  ersetzt nicht still; die Vorschau nennt, wo der Text zu pflegen ist. Das Vorschaubild des Programms oder Moduls
  lässt sich als Bild-Medium übernehmen (CompositionStill, additive Tabelle composition_still_sources).
- Filmbild im Dialog wie im Medienmanager: Regler und Zahlenfeld zeigen dieselbe Stelle, das Bild folgt dem Regler
  nach kurzer Pause, „Diese Stelle übernehmen“; das Vorschaubild des Films mit kleiner Ansicht daneben.
- Gemeinsame Meldung nach dem tatsächlichen Stand für Film- und Programmbilder.
- Test bewusst angepasst: Die Programmkarte hat jetzt eine Textwahl (vorher nur die Medienkarte).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-21 21:19:43 +01:00

176 lines
7.7 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\Cms\Page;
use App\Domain\Cms\PageRevision;
use App\Domain\Cms\PageService;
use App\Domain\Cms\Widgets\WidgetRegistry;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Validation\ValidationException;
use Tests\Support\BuildsCatalog;
use Tests\TestCase;
/**
* Medien- und Materialkarte: Die Redaktion wählt, welcher zentrale Text (Teaser, Kurzbeschreibung, ausführliche
* Beschreibung) auf der Karte erscheint. Ohne Wahl gilt wie bisher die Kurzbeschreibung, sonst der Teaser.
*/
class CmsMediaCardTextTest extends TestCase
{
use BuildsCatalog;
use RefreshDatabase;
public function test_the_card_shows_the_text_the_editor_chose_and_the_default_stays_unchanged(): void
{
$film = $this->publicFilm();
$this->publish('/textwahl', [
$this->card($film, []),
$this->card($film, ['text_source' => 'auto']),
$this->card($film, ['text_source' => 'teaser']),
$this->card($film, ['text_source' => 'summary']),
$this->card($film, ['text_source' => 'description']),
]);
$cards = $this->cards($this->get('/textwahl')->assertOk()->getContent());
$this->assertCount(5, $cards);
$this->assertStringContainsString('KURZ-TEXT', $cards[0]);
$this->assertStringContainsString('KURZ-TEXT', $cards[1]);
$this->assertStringContainsString('TEASER-TEXT', $cards[2]);
$this->assertStringNotContainsString('KURZ-TEXT', $cards[2]);
$this->assertStringContainsString('KURZ-TEXT', $cards[3]);
$this->assertStringContainsString('LANG-TEXT', $cards[4]);
$this->assertStringContainsString('zweiter Absatz', $cards[4]);
foreach ($cards as $index => $card) {
foreach (['EINSATZ-INTERN', 'LIZENZ-INTERN'] as $internal) {
$this->assertStringNotContainsString($internal, $card, "Karte $index: Einsatzhinweis und Lizenzvermerk bleiben intern.");
}
}
foreach ([0, 1, 2, 3] as $index) {
$this->assertStringNotContainsString('LANG-TEXT', $cards[$index], 'Die ausführliche Beschreibung erscheint nur auf ausdrückliche Wahl.');
}
}
public function test_the_default_falls_back_to_the_teaser_but_an_explicit_choice_does_not(): void
{
$film = $this->publicFilm(['summary' => null]);
$revision = $this->publish('/textwahl-ersatz', [
$this->card($film, []),
$this->card($film, ['text_source' => 'summary']),
]);
$cards = $this->cards($this->get('/textwahl-ersatz')->assertOk()->getContent());
$this->assertStringContainsString('TEASER-TEXT', $cards[0], 'Vorgabe: ohne Kurzbeschreibung der Teaser, wie bisher.');
$this->assertStringNotContainsString('lf-pc__summary', $cards[1], 'Gewählte, nicht gepflegte Kurzbeschreibung: kein stiller Ersatz.');
$this->assertStringNotContainsString('TEASER-TEXT', $cards[1]);
$this->assertStringNotContainsString('Keine Kurzbeschreibung gepflegt', $this->get('/textwahl-ersatz')->getContent(), 'Hinweise erscheinen öffentlich nie.');
$this->assertStringNotContainsString('Für eine vollständige Karte', $this->get('/textwahl-ersatz')->getContent());
$preview = $this->actingAs(User::factory()->redakteur()->create(), 'staff')->get(route('pages.preview', $revision))->assertOk()->getContent();
$this->assertStringContainsString('Keine Kurzbeschreibung gepflegt (Medium bearbeiten → Kurzbeschreibung).', $preview);
}
public function test_the_own_text_of_the_card_wins_over_the_chosen_central_text(): void
{
$film = $this->publicFilm();
$this->publish('/textwahl-eigen', [
$this->card($film, ['text_source' => 'description'], ['summary' => 'EIGENER-KARTENTEXT']),
]);
$card = $this->cards($this->get('/textwahl-eigen')->assertOk()->getContent())[0];
$this->assertStringContainsString('EIGENER-KARTENTEXT', $card);
$this->assertStringNotContainsString('LANG-TEXT', $card);
}
public function test_the_choice_is_limited_to_the_three_central_texts_and_to_the_media_card(): void
{
$film = $this->publicFilm();
$registry = app(WidgetRegistry::class);
$this->assertSame(['auto', 'teaser', 'summary', 'description'], array_keys($registry->get('media_card')->settingOptions()['text_source']));
// Seit 21.11.2026 hat auch die Programm- und Modulkarte die Wahl (mit Lernziel); ein Thema hat nur einen Text.
$this->assertSame(['auto', 'teaser', 'summary', 'description', 'goal'], array_keys($registry->get('program_card')->settingOptions()['text_source']));
$this->assertArrayNotHasKey('text_source', $registry->get('topic_card')->settingOptions());
foreach (['usage_note', 'license_note', 'working_title'] as $internal) {
try {
$registry->normalize([['type' => 'media_card', 'v' => 1, 'variant' => 'adaptive', 'settings' => ['text_source' => $internal], 'data' => [], 'refs' => ['element' => $film->id]]]);
$this->fail("Der interne Text $internal wurde als Kartentext angenommen.");
} catch (ValidationException $exception) {
$this->assertArrayHasKey('blocks.0.settings.text_source', $exception->errors());
}
}
}
/**
* @param array<string, mixed> $extra
*/
private function publicFilm(array $extra = []): ContentElement
{
$content = app(ContentService::class);
$kind = fn (string $slug) => EditorialContentKind::query()->where('slug', $slug)->value('id');
$film = $content->createElement('film', 'film', 'Denkpause Rohschnitt');
$film->update($extra + [
'display_title' => 'Eine Pause, die stark macht',
'teaser' => 'TEASER-TEXT',
'summary' => 'KURZ-TEXT',
'description' => "LANG-TEXT erster Absatz\n\nzweiter Absatz",
'usage_note' => 'EINSATZ-INTERN',
'license_note' => 'LIZENZ-INTERN',
]);
$version = $content->publishElementVersion($film, 'Film');
$composition = $content->createComposition('Programm Denkpause');
$composition->editorial_content_kind_id = $kind('programm');
$composition->save();
$shown = $content->publishComposition($composition, [['role' => 'Film', 'target' => $version]]);
app(CompositionDisplayRelease::class)->release($shown, User::factory()->create());
return $film->refresh();
}
/**
* @param array<string, string> $settings
* @param array<string, mixed> $data
* @return array<string, mixed>
*/
private function card(ContentElement $film, array $settings, array $data = []): array
{
return ['layout' => 'u4', 'style' => [], 'slots' => [
['type' => 'media_card', 'v' => 1, 'variant' => 'adaptive', 'settings' => $settings, 'data' => $data, 'refs' => ['element' => $film->id]],
]];
}
/**
* @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;
}
/**
* @return list<string>
*/
private function cards(string $html): array
{
preg_match_all('#<article class="lf-pc .*?</article>#s', $html, $matches);
return $matches[0];
}
}