Ergänze die gemeinsame redaktionelle Basis an den Fachobjekten.
CI Feature / test (push) Successful in 54s
Deploy Test / test (push) Successful in 47s
Deploy Test / deploy (push) Successful in 24s

Texte, Materialart und Präsentationsmedien bleiben am Medium, Modul, Programm und Lizenzartikel und werden von Verwaltung und Karten aus derselben Quelle gelesen, ohne Fassung oder Lizenz zu verändern.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-11-19 07:54:36 +01:00
1 parent c4be6ed8dc
commit f29ea58fd5
40 files changed
+2311 -20

No files matched your search

+530
View File
@@ -0,0 +1,530 @@
<?php
namespace Tests\Feature;
use App\Domain\Catalog\ArticleRelease;
use App\Domain\Catalog\ArticleService;
use App\Domain\Catalog\CompositionDisplayRelease;
use App\Domain\Catalog\CompositionKind;
use App\Domain\Catalog\CompositionMember;
use App\Domain\Catalog\ContentElement;
use App\Domain\Catalog\ContentService;
use App\Domain\Catalog\DomainRuleException;
use App\Domain\Catalog\EditorialContentKind;
use App\Domain\Catalog\EditorialDimension;
use App\Domain\Catalog\EditorialDimensionValue;
use App\Domain\Catalog\EditorialProfileReader;
use App\Domain\Catalog\IdentityDimension;
use App\Domain\Catalog\IdentityDimensionValue;
use App\Domain\Catalog\Offer;
use App\Domain\Catalog\PresentationAssignment;
use App\Domain\Catalog\PresentationMedia;
use App\Domain\Catalog\ReleaseStatus;
use App\Domain\Cms\Page;
use App\Domain\Cms\PageRevision;
use App\Domain\Cms\PageService;
use App\Domain\Cms\Widgets\Support\WebsiteImage;
use App\Domain\Media\MediaRendition;
use App\Domain\Media\WebsiteMedia;
use App\Domain\Media\WebsiteRelease;
use App\Filament\Resources\ContentElements\Pages\ViewContentElement;
use App\Filament\Resources\Courses\Pages\EditCourse;
use App\Filament\Resources\Exercises\Pages\EditExercise;
use App\Filament\Resources\LicenseArticles\Pages\ViewLicenseArticle;
use App\Filament\Support\MediaLibrary;
use App\Models\User;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Storage;
use Livewire\Livewire;
use Tests\Support\BuildsCatalog;
use Tests\TestCase;
class EditorialDeskTest extends TestCase
{
use BuildsCatalog;
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
Storage::fake('media_derived');
Storage::fake('media_public');
Storage::fake('media_originals');
}
public function test_a_film_keeps_its_version_when_editorial_text_and_presentation_change(): void
{
$content = app(ContentService::class);
$film = $content->createElement('film', 'film', 'Lara im Park');
$version = $content->publishElementVersion($film, 'Filmfassung');
$cover = $this->image('Titel Park');
$trailer = $this->trailer('Trailer Park');
$editor = $this->editor();
$this->actingAs($editor, 'staff');
Livewire::test(ViewContentElement::class, ['record' => $film->getKey()])
->set('bereich', 'beschreibung')
->set('displayTitle', 'Lara im Park')
->set('teaser', 'Ein Nachmittag im Park.')
->set('summary', 'Lara übt, ihre Grenze zu sagen.')
->set('descriptionText', 'Ausführlich: die Szene im Park und was sie zeigt.')
->set('searchTerms', 'park, grenze')
->set('kindId', $this->kind('unterrichtsfilm'))
->call('saveEditorial')
->assertSee('Es gibt keine neue Fassung.');
$film->refresh();
$this->assertSame(1, $film->versions()->count());
$this->assertSame($version->id, $film->versions()->first()->id);
$this->assertSame('Ein Nachmittag im Park.', $film->teaser);
$this->assertSame($this->kind('unterrichtsfilm'), $film->editorial_content_kind_id);
$purpose = $this->dimensionValue('verwendungszweck', 'training');
$audience = $this->dimensionValue('zielgruppe', 'kinder');
app(IdentityDimension::class)->assign($film, $purpose);
app(IdentityDimension::class)->assign($film, $audience);
Livewire::test(ViewContentElement::class, ['record' => $film->getKey()])
->set('bereich', 'praesentation')
->set('presentationRole', 'titelbild')
->set('presentationPick', 'element:'.$cover->versions()->first()->id)
->call('assignPickedPresentation')
->set('presentationRole', 'trailer')
->set('presentationPick', 'element:'.$trailer->versions()->first()->id)
->set('bindToVersion', true)
->call('assignPickedPresentation')
->assertSee('Titel Park')
->assertSee('Trailer Park')
->assertSee('Standard-Titelbild')
->call('releaseAssigned', $trailer->id)
->assertSee('Für die Website freigegeben');
$film->refresh();
$trailer->refresh();
$this->assertSame(1, $film->versions()->count());
$this->assertSame($version->id, $film->versions()->value('id'));
$this->assertNotNull($trailer->website_released_at);
$this->assertNotNull(app(WebsiteMedia::class)->present($trailer));
Livewire::test(ViewContentElement::class, ['record' => $film->getKey()])
->call('withdrawAssigned', $trailer->id);
$this->assertNull($trailer->fresh()->website_released_at);
$this->assertNull(app(WebsiteMedia::class)->present($trailer));
$this->assertSame(2, PresentationAssignment::query()->where('subject_id', $film->id)->count());
}
public function test_a_module_description_does_not_version_the_composition_or_create_a_text_medium(): void
{
$content = app(ContentService::class);
$film = $content->publishElementVersion($content->createElement('film', 'film', 'Lara im Park'), 'Film');
$module = $content->createComposition('Eigene Grenzen erkennen');
$module->editorial_content_kind_id = $this->kind('modul');
$module->save();
$version = $content->publishComposition(
$module,
[['role' => 'Film', 'target' => $film]],
didactic: ['learning_goal' => 'Eine Grenze erkennen und sagen.'],
);
$textsBefore = ContentElement::query()->where('output_class', 'text')->count();
$this->actingAs($this->editor(), 'staff');
Livewire::test(EditExercise::class, ['record' => $module->getKey()])
->set('teaser', 'Kurz in das Modul.')
->set('summary', 'Kinder benennen eine eigene Grenze.')
->set('description', 'Ausführliche Modulbeschreibung, kein Lehrtext.')
->set('dimensionIds', [$this->dimensionValue('zielgruppe', 'kinder')->id])
->call('saveDisplay')
->assertSee('Die Fassung bleibt unverändert.');
$module->refresh();
$version->refresh();
$this->assertSame(1, $module->versions()->count());
$this->assertSame('Eine Grenze erkennen und sagen.', $version->learning_goal);
$this->assertSame('Kurz in das Modul.', $module->teaser);
$this->assertTrue(
CompositionMember::query()->where('composition_version_id', $version->id)->where('content_element_version_id', $film->id)->exists()
);
$this->assertSame($textsBefore, ContentElement::query()->where('output_class', 'text')->count());
$cover = $this->image('Modulbild');
app(PresentationMedia::class)->assign($module, 'titelbild', $cover->id, null, $this->editor());
$this->assertSame(1, $module->fresh()->versions()->count());
$this->assertSame(
1,
CompositionMember::query()->where('composition_version_id', $version->id)->count()
);
}
public function test_a_program_keeps_its_own_cover_trailer_and_gallery_order(): void
{
$content = app(ContentService::class);
$program = $content->createComposition('Stark im Alltag', CompositionKind::Kurs);
$program->editorial_content_kind_id = $this->kind('programm');
$program->save();
$content->publishComposition($program, [[
'role' => 'Text',
'target' => $content->publishElementVersion($content->createElement('text', 'text', 'Blatt'), 'Inhalt'),
]]);
$cover = $this->image('Programmcover');
$trailer = $this->trailer('Programmtrailer');
$first = $this->image('Galerie eins');
$second = $this->image('Galerie zwei');
$third = $this->image('Galerie drei');
$media = app(PresentationMedia::class);
$actor = $this->editor();
$media->assign($program, 'titelbild', $cover->id, null, $actor);
$media->assign($program, 'trailer', $trailer->id, $trailer->versions()->first()->id, $actor);
$media->assign($program, 'galerie', $first->id, null, $actor);
$media->assign($program, 'galerie', $second->id, null, $actor);
$media->assign($program, 'galerie', $third->id, null, $actor);
$gallery = PresentationAssignment::query()
->where('subject_id', $program->id)
->whereHas('role', fn ($query) => $query->where('slug', 'galerie'))
->orderBy('position')
->pluck('content_element_id')
->all();
$this->assertSame([$first->id, $second->id, $third->id], $gallery);
$firstAssignment = PresentationAssignment::query()->where('content_element_id', $first->id)->where('subject_id', $program->id)->first();
$media->move($program, $firstAssignment->id, 1, $actor);
$gallery = PresentationAssignment::query()
->where('subject_id', $program->id)
->whereHas('role', fn ($query) => $query->where('slug', 'galerie'))
->orderBy('position')
->pluck('content_element_id')
->all();
$this->assertSame([$second->id, $first->id, $third->id], $gallery);
$this->assertSame(1, $program->fresh()->versions()->count());
app(IdentityDimension::class)->assign($program, $this->dimensionValue('zielgruppe', 'eltern'));
$found = app(MediaLibrary::class)->cards([
'suche' => '',
'inhaltsart' => '',
], false);
$this->assertNotContains('Stark im Alltag', array_column($found, 'title'));
$this->actingAs($actor, 'staff');
Livewire::test(EditCourse::class, ['record' => $program->getKey()])
->assertSee('Programmcover')
->assertSee('Galerie zwei')
->assertSee('Standard-Titelbild');
}
public function test_a_license_article_overrides_only_its_own_presentation(): void
{
$content = app(ContentService::class);
$film = $content->createElement('film', 'film', 'Lara im Park');
$film->display_title = 'Lara im Park';
$film->teaser = 'Teaser der Fassung';
$film->summary = 'Kurz aus dem Film';
$film->description = 'Lang aus dem Film';
$film->save();
$version = $content->publishElementVersion($film, 'Film');
$articles = app(ArticleService::class);
$article = $articles->create('LARA-PARK', 'Alltag');
$release = $articles->publishRelease($article, $version, 'Derselbe Unterrichtsfilm');
$offers = Offer::query()->count();
$note = $release->classification_note;
$number = $release->number;
$keeper = User::factory()->katalogverwalter()->create();
$keeper->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
$this->actingAs($keeper, 'staff');
$profile = app(EditorialProfileReader::class)->read($article->fresh(), 'artikel');
$this->assertSame('quelle', $profile->origin('summary'));
$this->assertSame('Kurz aus dem Film', $profile->value('summary'));
$this->assertSame('Lara im Park', $profile->value('display_title'));
Livewire::test(ViewLicenseArticle::class, ['record' => $article->getKey()])
->set('summary', 'Eigene Artikelbeschreibung')
->call('saveLicenseEditorial')
->assertSee('Stand, Preis und Rechte bleiben unverändert.')
->assertSee('Übernommen von Lara im Park')
->assertSee('Eigene Angabe');
$article->refresh();
$release->refresh();
$this->assertSame('Eigene Artikelbeschreibung', $article->summary);
$this->assertNull($article->teaser);
$again = app(EditorialProfileReader::class)->read($article, 'artikel');
$this->assertSame('eigen', $again->origin('summary'));
$this->assertSame('Eigene Artikelbeschreibung', $again->value('summary'));
$this->assertSame('quelle', $again->origin('teaser'));
$this->assertSame('Teaser der Fassung', $again->value('teaser'));
$this->assertSame($number, $release->number);
$this->assertSame($note, $release->classification_note);
$this->assertSame(ReleaseStatus::Veroeffentlicht, $release->status);
$this->assertSame($offers, Offer::query()->count());
$this->assertSame(1, $film->fresh()->versions()->count());
$cover = $this->image('Artikelbild');
app(PresentationMedia::class)->assign($article, 'titelbild', $cover->id, null, $keeper);
$this->assertSame($release->id, $article->fresh()->current_release_id);
$this->assertSame(1, ArticleRelease::query()->count());
$ambiguous = $articles->create('UNDEUTIG');
$program = $content->createComposition('Zweite Wurzel', CompositionKind::Kurs);
$programVersion = $content->publishComposition($program, [['role' => 'Film', 'target' => $version]]);
$ambiguous->releases()->create([
'number' => 1,
'classification_note' => 'zwei Wurzeln',
'status' => ReleaseStatus::Entwurf,
'root_element_version_id' => $version->id,
'root_composition_version_id' => $programVersion->id,
]);
$ambiguous->current_release_id = $ambiguous->releases()->value('id');
$ambiguous->save();
$this->assertNull(app(EditorialProfileReader::class)->sourceOf($ambiguous->fresh()));
$this->assertSame('leer', app(EditorialProfileReader::class)->read($ambiguous->fresh())->origin('summary'));
}
public function test_classification_is_filterable_and_does_not_change_use_or_release(): void
{
$content = app(ContentService::class);
$lesson = $content->createElement('film', 'film', 'Unterricht');
$lesson->editorial_content_kind_id = $this->kind('unterrichtsfilm');
$lesson->teaser = 'sucht-den-unterricht';
$lesson->save();
$content->publishElementVersion($lesson, 'Film');
$clip = $content->createElement('film', 'film', 'Nur Trailer');
$clip->editorial_content_kind_id = $this->kind('trailer');
$clip->save();
$content->publishElementVersion($clip, 'Clip');
$picture = $content->createElement('bild', 'bild', 'Keyvisual');
$picture->editorial_content_kind_id = $this->kind('titelbild');
$picture->thumbnail_path = 'vorschau/key.jpg';
$picture->save();
$content->publishElementVersion($picture, null, ['file' => 'inhalte/key.jpg']);
$backdrop = $content->createElement('bild', 'bild', 'Hintergrund');
$backdrop->editorial_content_kind_id = $this->kind('hintergrundbild');
$backdrop->save();
$content->publishElementVersion($backdrop, null, ['file' => 'inhalte/hintergrund.jpg']);
app(IdentityDimension::class)->assign($lesson, $this->dimensionValue('verwendungszweck', 'training'));
app(IdentityDimension::class)->assign($lesson, $this->dimensionValue('verwendungszweck', 'website'));
app(IdentityDimension::class)->assign($clip, $this->dimensionValue('verwendungszweck', 'website'));
$releasedAt = null;
$lesson->website_released_at = null;
$lesson->save();
$library = app(MediaLibrary::class);
$lessons = array_column($library->cards(['inhaltsart' => (string) $this->kind('unterrichtsfilm')], false), 'title');
$clips = array_column($library->cards(['inhaltsart' => (string) $this->kind('trailer')], false), 'title');
$pictures = array_column($library->cards(['art' => 'bild', 'inhaltsart' => (string) $this->kind('titelbild')], false), 'title');
$backs = array_column($library->cards(['inhaltsart' => (string) $this->kind('hintergrundbild')], false), 'title');
$this->assertSame(['Unterricht'], $lessons);
$this->assertSame(['Nur Trailer'], $clips);
$this->assertSame(['Keyvisual'], $pictures);
$this->assertSame(['Hintergrund'], $backs);
$this->assertNotContains('Nur Trailer', $lessons);
$byPurpose = array_column($library->cards([
'einordnung' => (string) $this->dimensionValue('verwendungszweck', 'training')->id,
'nutzung' => 'unbenutzt',
], false), 'title');
$this->assertContains('Unterricht', $byPurpose);
$this->assertNotContains('Nur Trailer', $byPurpose);
$bySearch = array_column($library->cards(['suche' => 'sucht-den-unterricht'], false), 'title');
$this->assertSame(['Unterricht'], $bySearch);
$lesson->editorial_content_kind_id = $this->kind('interview');
$lesson->save();
$lesson->refresh();
$this->assertSame($releasedAt, $lesson->website_released_at);
$this->assertSame(0, CompositionMember::query()->where('content_element_version_id', $lesson->versions()->first()->id)->count());
$this->assertSame(2, IdentityDimensionValue::query()->where('subject_type', $lesson->getMorphClass())->where('subject_id', $lesson->id)->count());
}
public function test_the_program_card_uses_central_text_and_only_a_released_cover(): void
{
$content = app(ContentService::class);
$program = $content->createComposition('Programm Karte', CompositionKind::Kurs);
$program->editorial_content_kind_id = $this->kind('programm');
$program->display_title = 'Zentraler Programmname';
$program->teaser = 'Zentraler Teaser';
$program->summary = 'Zentrale Kurzbeschreibung';
$program->description = 'Interne Langfassung';
$program->save();
$version = $content->publishComposition($program, [[
'role' => 'Text',
'target' => $content->publishElementVersion($content->createElement('text', 'text', 'Blatt'), 'Inhalt'),
]]);
app(CompositionDisplayRelease::class)->release($version, User::factory()->create());
$cover = $this->image('Öffentliches Cover');
Storage::disk('media_derived')->put('vorschau/oeffentlich.jpg', 'cover-bytes');
$cover->thumbnail_path = 'vorschau/oeffentlich.jpg';
$cover->website_alt = 'Lara auf der Wiese';
$cover->save();
app(WebsiteRelease::class)->release($cover);
app(PresentationMedia::class)->assign($program, 'titelbild', $cover->id, null);
$guide = $content->createElement('text', 'text', 'Geheime Traineranleitung');
$guide->editorial_content_kind_id = $this->kind('traineranleitung');
$guide->description = 'Nur für Trainer, nicht öffentlich.';
$guide->save();
$content->publishElementVersion($guide, 'Interner Lehrtext');
$this->publish('/redaktion-karte', [[
'layout' => 'u2_2',
'style' => [],
'slots' => [
$this->card('program_card', ['composition' => $program->id]),
$this->card('program_card', ['composition' => $program->id], ['heading' => 'Nur diese Karte']),
],
]]);
$html = $this->get('/redaktion-karte')->assertOk()->getContent();
$this->assertStringContainsString('Zentraler Programmname', $html);
$this->assertStringContainsString('Zentraler Teaser', $html);
$this->assertStringContainsString('Nur diese Karte', $html);
$this->assertStringNotContainsString('Interne Langfassung', $html);
$this->assertStringNotContainsString('Nur für Trainer', $html);
$this->assertStringContainsString('/website-medien/'.$cover->id, $html);
$this->assertStringNotContainsString('editorial.card', $html);
$this->assertStringNotContainsString('originals/', $html);
$program->teaser = 'Teaser nach der Änderung';
$program->save();
$this->get('/redaktion-karte')->assertOk()
->assertSee('Teaser nach der Änderung')
->assertSee('Nur diese Karte')
->assertSee('Zentraler Programmname');
app(WebsiteRelease::class)->withdraw($cover->fresh());
$this->assertNull($cover->fresh()->website_released_at);
// WebsiteImage ist je Prozess gebunden. Ein neuer HTTP-Request im selben Testprozess
// bekommt sonst noch die vorherige Freigabe. Auf dem Server endet der Scope mit der Anfrage.
$this->app->forgetInstance(WebsiteImage::class);
$after = $this->get('/redaktion-karte')->assertOk()->getContent();
$this->assertStringNotContainsString('/website-medien/'.$cover->id, $after);
$this->assertStringContainsString('Teaser nach der Änderung', $after);
$this->assertStringContainsString('Nur diese Karte', $after);
$this->assertStringNotContainsString('cover-bytes', $after);
$this->assertSame('Zentraler Programmname', $program->fresh()->display_title);
}
public function test_a_bound_clip_stays_on_its_version_and_a_medium_cannot_present_itself(): void
{
$content = app(ContentService::class);
$film = $content->createElement('film', 'film', 'Lara im Park');
$first = $content->publishElementVersion($film, 'Fassung 1');
$trailer = $this->trailer('Ausschnitt');
$media = app(PresentationMedia::class);
$media->assign($film, 'vorschauclip', $trailer->id, $first->id);
$second = $content->publishElementVersion($film, 'Fassung 2');
$rows = $media->rows($film->fresh());
$this->assertTrue($rows[0]['binding']['stale']);
$this->assertSame($first->id, PresentationAssignment::query()->value('source_version_id'));
$this->assertNotSame($second->id, PresentationAssignment::query()->value('source_version_id'));
$this->expectException(DomainRuleException::class);
$media->assign($film, 'titelbild', $film->id, null);
}
public function test_a_kachel_variant_does_not_replace_the_central_teaser(): void
{
$program = app(ContentService::class)->createComposition('Variante', CompositionKind::Kurs);
$program->editorial_content_kind_id = $this->kind('programm');
$program->teaser = 'Zentral';
$program->save();
app(ContentService::class)->publishComposition($program, [[
'role' => 'Text',
'target' => app(ContentService::class)->publishElementVersion(app(ContentService::class)->createElement('text', 'text', 'Blatt'), 'Inhalt'),
]]);
app(EditorialProfileReader::class)->putVariant($program, 'teaser', 'kachel', 'Nur die Kachel', $this->editor());
$profile = app(EditorialProfileReader::class)->read($program->fresh(), 'kachel');
$plain = app(EditorialProfileReader::class)->read($program->fresh());
$this->assertSame('Nur die Kachel', $profile->value('teaser'));
$this->assertSame('variante', $profile->origin('teaser'));
$this->assertSame('Zentral', $plain->value('teaser'));
$this->assertSame('Zentral', $program->fresh()->teaser);
}
private function image(string $title): ContentElement
{
$content = app(ContentService::class);
$element = $content->createElement('bild', 'bild', $title);
$element->thumbnail_path = 'vorschau/'.md5($title).'.jpg';
$element->save();
Storage::disk('media_derived')->put($element->thumbnail_path, 'bild');
$content->publishElementVersion($element, null, ['file' => 'inhalte/'.md5($title).'.jpg']);
return $element->fresh();
}
private function trailer(string $title): ContentElement
{
$content = app(ContentService::class);
$element = $content->createElement('film', 'film', $title);
$version = $content->publishElementVersion($element, 'Teaser');
$path = 'teaser/'.md5($title).'.mp4';
MediaRendition::query()->create([
'content_element_version_id' => $version->id,
'role' => 'preview',
'label' => 'teaser',
'path' => $path,
]);
Storage::disk('media_derived')->put($path, 'teaser-bytes');
return $element->fresh();
}
private function kind(string $slug): int
{
return (int) EditorialContentKind::query()->where('slug', $slug)->value('id');
}
private function dimensionValue(string $dimension, string $slug): EditorialDimensionValue
{
$id = EditorialDimension::query()->where('slug', $dimension)->value('id');
return EditorialDimensionValue::query()
->where('editorial_dimension_id', $id)
->where('slug', $slug)
->firstOrFail();
}
private function editor(): User
{
$editor = User::factory()->redakteur()->create();
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
return $editor;
}
/**
* @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;
}
/**
* @param array<string, mixed> $refs
* @param array<string, mixed> $data
* @return array<string, mixed>
*/
private function card(string $type, array $refs, array $data = []): array
{
return ['type' => $type, 'v' => 1, 'variant' => 'adaptive', 'settings' => [], 'data' => $data, 'refs' => $refs];
}
}
+1 -1
View File
@@ -234,7 +234,7 @@ public function test_pillar_and_classification_filters_narrow_the_same_library()
$content->publishElementVersion($other, 'Text');
$pillar = app(PillarService::class)->create('Meine Grenzen');
app(PillarService::class)->assign($film, [$pillar->id]);
$dimension = EditorialDimension::query()->create(['slug' => 'zielgruppe', 'label' => 'Zielgruppe']);
$dimension = EditorialDimension::query()->where('slug', 'zielgruppe')->firstOrFail();
$value = $dimension->values()->create(['slug' => 'grundschule', 'label' => 'Grundschule']);
app(IdentityDimension::class)->assign($film, $value);