Biete einen Film nur mit Website-Datei auf der Medienkarte zur Auswahl an

Ein Medium ohne Inhaltsfassung, etwa ein freigegebener Teaser, fehlte im Dropdown der
Medienkarte und wurde beim Speichern als archiviert oder gesperrt abgelehnt, weil die
Auswahl mindestens eine Fassung verlangte. Ein Film mit Website-Datei ist jetzt wählbar.
Öffentlich erscheint die Karte, sobald die Datei freigegeben ist, ohne Programmseite und
ohne Aktion; ohne Freigabe nur in der Redaktionsvorschau, mit Hinweis in der Auswahl.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-22 07:24:03 +01:00
1 parent 5e28538551
commit 437bb394b2
3 files changed
+222 -10

No files matched your search

@@ -0,0 +1,167 @@
<?php
namespace Tests\Feature;
use App\Domain\Catalog\ContentElement;
use App\Domain\Catalog\ContentService;
use App\Domain\Cms\Catalog\PublicMaterialReader;
use App\Domain\Cms\Page;
use App\Domain\Cms\PageRevision;
use App\Domain\Cms\PageService;
use App\Domain\Cms\Widgets\Support\CardClip;
use App\Domain\Cms\Widgets\Support\WebsiteImage;
use App\Domain\Cms\Widgets\WidgetRegistry;
use App\Domain\Media\PresentationFile;
use App\Domain\Media\WebsiteMedia;
use App\Domain\Media\WebsiteRelease;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
/**
* Ein Film, der nur aus einer Website-Datei besteht (Medium ohne Inhaltsfassung, z. B. ein Teaser), ist auf der
* Medienkarte wählbar. Öffentlich erscheint die Karte erst, wenn die Datei für die Website freigegeben ist; ein
* Programm ist dafür nicht nötig, die Karte hat dann keine Aktion.
*/
class CmsWebsiteOnlyFilmCardTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
Storage::fake('cms_incoming');
Storage::fake('media_derived');
Storage::fake('media_public');
Storage::fake('media_originals');
}
public function test_a_film_with_only_a_website_file_is_offered_in_the_card_dropdown(): void
{
$teaser = $this->websiteFilm('Teaser Denkpause');
$options = app(PublicMaterialReader::class)->search('Teaser Denk');
$this->assertArrayHasKey($teaser->id, $options);
$this->assertStringContainsString('Website-Datei nicht freigegeben', $options[$teaser->id]);
$this->assertArrayHasKey($teaser->id, app(PublicMaterialReader::class)->search(null), 'Auch ohne Suchbegriff.');
$this->assertTrue(app(PublicMaterialReader::class)->isSelectable($teaser));
}
public function test_the_dropdown_label_says_when_the_file_is_released(): void
{
$teaser = $this->websiteFilm('Teaser Denkpause');
$this->release($teaser);
$options = app(PublicMaterialReader::class)->search('Teaser Denk');
$this->assertStringContainsString('öffentlich mit Website-Datei', $options[$teaser->id]);
}
public function test_the_card_endpoint_accepts_such_a_film_as_its_medium(): void
{
$teaser = $this->websiteFilm('Teaser Denkpause');
$widget = app(WidgetRegistry::class)->get('media_card');
$options = (new \ReflectionMethod($widget, 'rejectSubject'))->invoke($widget, $teaser->id);
$this->assertNull($options, 'Die Auswahl wird nicht mit „archiviert oder gesperrt“ abgelehnt.');
}
public function test_a_released_website_film_shows_publicly_with_its_clip_and_without_an_action(): void
{
$teaser = $this->websiteFilm('Teaser Denkpause');
$this->release($teaser);
$this->publish('/teaser-karte', $teaser);
$html = $this->get('/teaser-karte')->assertOk()->getContent();
$this->assertStringContainsString('Teaser Denkpause', $html);
$this->assertStringContainsString('data-clip-src="'.route('website.media', $teaser).'"', $html, 'Das freigegebene Video ist der Clip der Karte.');
$this->assertStringNotContainsString('lf-pc__cta', $html, 'Ohne Programmseite gibt es keine Aktion.');
$this->assertStringNotContainsString('teaser/', $html);
$this->assertStringNotContainsString('originals/', $html);
}
public function test_an_unreleased_website_film_stays_out_of_the_public_page_but_shows_in_the_preview(): void
{
$teaser = $this->websiteFilm('Teaser Denkpause');
$this->publish('/teaser-nicht-frei', $teaser);
$this->get('/teaser-nicht-frei')->assertOk()->assertDontSee('Teaser Denkpause');
$subject = app(PublicMaterialReader::class)->subject($teaser->id, includeNonPublic: true);
$this->assertNotNull($subject);
$this->assertFalse($subject->public);
$this->assertStringContainsString('nicht für die Website freigegeben', (string) $subject->notice);
}
public function test_withdrawing_the_release_takes_the_card_off_the_public_page(): void
{
$teaser = $this->websiteFilm('Teaser Denkpause');
$this->release($teaser);
$this->publish('/teaser-zurueck', $teaser);
$this->get('/teaser-zurueck')->assertSee('Teaser Denkpause');
app(WebsiteRelease::class)->withdraw($teaser->fresh());
$this->flushScoped();
$this->get('/teaser-zurueck')->assertOk()->assertDontSee('Teaser Denkpause');
}
public function test_an_archived_website_film_is_never_offered(): void
{
$archived = $this->websiteFilm('Archiv Denkpause');
$archived->forceFill(['archived_at' => now()])->save();
$this->assertArrayNotHasKey($archived->id, app(PublicMaterialReader::class)->search('Archiv'));
}
public function test_an_image_without_a_version_is_not_offered_as_medium(): void
{
$path = 'inhalte/bild.jpg';
Storage::disk('cms_incoming')->put($path, 'bild-bytes');
$image = app(ContentService::class)->createElement('bild', 'bild', 'Bild Denkpause');
app(PresentationFile::class)->store($image, $path);
$this->assertArrayNotHasKey($image->id, app(PublicMaterialReader::class)->search('Bild Denk'), 'Nur Filme ohne Fassung zählen als Medium der Karte.');
}
private function websiteFilm(string $title): ContentElement
{
$path = 'inhalte/'.md5($title).'.mp4';
Storage::disk('cms_incoming')->put($path, '0123456789abcdefghij');
$element = app(ContentService::class)->createElement('film', 'film', $title);
$element->display_title = $title;
$element->save();
app(PresentationFile::class)->store($element, $path);
return $element->fresh();
}
private function release(ContentElement $element): void
{
app(WebsiteRelease::class)->release($element->fresh());
$this->flushScoped();
}
private function flushScoped(): void
{
foreach ([WebsiteImage::class, CardClip::class, WebsiteMedia::class, PublicMaterialReader::class] as $class) {
$this->app->forgetInstance($class);
}
}
private function publish(string $path, ContentElement $film): PageRevision
{
$page = Page::query()->create(['path' => $path]);
$service = app(PageService::class);
$revision = $service->saveRevision($page, [['layout' => 'u4', 'style' => [], 'slots' => [
['type' => 'media_card', 'v' => 1, 'variant' => 'adaptive', 'settings' => [], 'data' => [], 'refs' => ['element' => $film->id]],
]]], null, null, null);
$service->publish($page, $revision);
return $revision;
}
}