Die Schaltfläche mit Text verdeckte bei kleinen Karten viel vom Video und wiederholte die Art-Marke Film. Sie ist jetzt ein 30-px-Symbol (44 px Trefferfläche, Beschriftung nur für Hilfstechnik). Ein Klick oder Tipp startet den Trailer mit Ton, einmal ohne Schleife; während der stummen Vorschau beim Überfahren schaltet er den Ton zu. Das Überfahren selbst bleibt stumm, weil Browser dafür keinen Ton erlauben. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
391 lines
17 KiB
PHP
391 lines
17 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Domain\Catalog\Composition;
|
|
use App\Domain\Catalog\CompositionDisplayRelease;
|
|
use App\Domain\Catalog\ContentElement;
|
|
use App\Domain\Catalog\ContentService;
|
|
use App\Domain\Catalog\EditorialContentKind;
|
|
use App\Domain\Catalog\PresentationAssignment;
|
|
use App\Domain\Catalog\PresentationRole;
|
|
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 App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Validation\ValidationException;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Trailer auf Medien-, Programm- und Modulkarte: Die Karte spielt beim Überfahren oder Antippen nur einen für die
|
|
* Website freigegebenen Clip ab (Präsentationsrolle „Trailer“, sonst „Vorschauclip“, bei einem Film ersatzweise sein
|
|
* freigegebener Teaser). Ohne freigegebenen Clip bleibt es beim Bild; der Film selbst kommt nie über die Karte.
|
|
*/
|
|
class CmsCardTrailerTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private const BYTES = '0123456789abcdefghij';
|
|
|
|
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_released_trailer_is_offered_on_the_public_media_card(): void
|
|
{
|
|
$film = $this->publicFilm();
|
|
$trailer = $this->clip('Trailer Denkpause');
|
|
$this->assign($film, 'trailer', $trailer);
|
|
$this->release($trailer);
|
|
|
|
$this->publish('/trailer', [$this->mediaCard($film)]);
|
|
|
|
$card = $this->card($this->get('/trailer')->assertOk()->getContent());
|
|
$this->assertStringContainsString('data-card-clip', $card);
|
|
$this->assertStringContainsString('data-clip-src="'.route('website.media', $trailer).'"', $card);
|
|
$this->assertStringContainsString('<video class="lf-pc__clip" muted loop playsinline preload="none"', $card, 'Stumm, nur Schleife, nichts wird vorab geladen.');
|
|
$this->assertDoesNotMatchRegularExpression('/<video[^>]* src=/', $card, 'Die Quelle wird erst beim ersten Start gesetzt.');
|
|
$this->assertStringNotContainsString('autoplay', $card);
|
|
$this->assertStringContainsString('aria-label="Trailer abspielen: Trailer Denkpause"', $card);
|
|
$this->assertStringNotContainsString('lf-pc__clip-label', $card, 'Nur ein kleines Symbol: die Art-Marke „Film“ steht schon am Bild.');
|
|
$this->assertStringContainsString('lf-pc__visual--panel', $card, 'Ohne Kartenbild liegt der Clip über der Filmtafel.');
|
|
$this->assertStringNotContainsString('originals/', $card);
|
|
$this->assertStringNotContainsString('teaser/', $card);
|
|
$this->assertStringNotContainsString('Der Trailer', $card, 'Hinweise für die Redaktion erscheinen öffentlich nie.');
|
|
}
|
|
|
|
public function test_the_trailer_lies_over_the_card_image_when_there_is_one(): void
|
|
{
|
|
$film = $this->publicFilm();
|
|
$trailer = $this->clip('Trailer Denkpause');
|
|
$image = $this->image('Kartenbild Denkpause');
|
|
$this->assign($film, 'trailer', $trailer);
|
|
$this->release($trailer);
|
|
$this->release($image);
|
|
|
|
$this->publish('/trailer-bild', [$this->mediaCard($film, ['image' => $image->id])]);
|
|
|
|
$card = $this->card($this->get('/trailer-bild')->assertOk()->getContent());
|
|
$this->assertStringContainsString('<img class="lf-pc__image" src="'.route('website.media', $image).'"', $card);
|
|
$this->assertStringContainsString('data-clip-src="'.route('website.media', $trailer).'"', $card);
|
|
$this->assertStringNotContainsString('lf-pc__visual--panel', $card);
|
|
}
|
|
|
|
public function test_an_unreleased_trailer_is_not_played_publicly_and_explained_in_the_preview(): void
|
|
{
|
|
$film = $this->publicFilm();
|
|
$trailer = $this->clip('Trailer ohne Freigabe');
|
|
$this->assign($film, 'trailer', $trailer);
|
|
|
|
$revision = $this->publish('/trailer-offen', [$this->mediaCard($film)]);
|
|
|
|
$public = $this->get('/trailer-offen')->assertOk()->getContent();
|
|
$this->assertStringNotContainsString('data-card-clip', $public);
|
|
$this->assertStringNotContainsString('<video', $public);
|
|
$this->assertStringNotContainsString('Trailer ohne Freigabe', $public);
|
|
$this->get(route('website.media', $trailer))->assertNotFound();
|
|
|
|
$preview = $this->actingAs(User::factory()->redakteur()->create(), 'staff')->get(route('pages.preview', $revision))->assertOk()->getContent();
|
|
$this->assertStringNotContainsString('<video', $preview, 'Auch die Redaktionsvorschau spielt keinen nicht freigegebenen Clip.');
|
|
$this->assertStringContainsString('Der Trailer „Trailer ohne Freigabe“ ist nicht für die Website freigegeben', $preview);
|
|
}
|
|
|
|
public function test_withdrawing_the_release_removes_the_trailer_from_the_page(): void
|
|
{
|
|
$film = $this->publicFilm();
|
|
$trailer = $this->clip('Trailer Denkpause');
|
|
$this->assign($film, 'trailer', $trailer);
|
|
$this->release($trailer);
|
|
$this->publish('/trailer-zurueck', [$this->mediaCard($film)]);
|
|
|
|
$this->assertStringContainsString('data-card-clip', $this->get('/trailer-zurueck')->getContent());
|
|
|
|
app(WebsiteRelease::class)->withdraw($trailer->fresh());
|
|
$this->flushScoped();
|
|
|
|
$this->assertStringNotContainsString('data-card-clip', $this->get('/trailer-zurueck')->assertOk()->getContent());
|
|
$this->get(route('website.media', $trailer))->assertNotFound();
|
|
}
|
|
|
|
public function test_the_trailer_role_wins_over_the_preview_clip_and_the_film_teaser_is_the_last_resort(): void
|
|
{
|
|
$film = $this->publicFilm();
|
|
$clip = $this->clip('Vorschauclip Denkpause');
|
|
$trailer = $this->clip('Trailer Denkpause');
|
|
$this->assign($film, 'vorschauclip', $clip);
|
|
$this->assign($film, 'trailer', $trailer);
|
|
$this->release($clip);
|
|
$this->release($trailer);
|
|
$this->publish('/trailer-rollen', [$this->mediaCard($film)]);
|
|
|
|
$this->assertStringContainsString('data-clip-src="'.route('website.media', $trailer).'"', $this->get('/trailer-rollen')->getContent());
|
|
|
|
app(WebsiteRelease::class)->withdraw($trailer->fresh());
|
|
$this->flushScoped();
|
|
$this->assertStringContainsString('data-clip-src="'.route('website.media', $clip).'"', $this->get('/trailer-rollen')->getContent(), 'Ohne freigegebenen Trailer gilt der Vorschauclip.');
|
|
|
|
PresentationAssignment::query()->delete();
|
|
$this->flushScoped();
|
|
$this->assertStringNotContainsString('data-card-clip', $this->get('/trailer-rollen')->getContent());
|
|
}
|
|
|
|
public function test_a_film_released_for_the_website_is_its_own_teaser_clip(): void
|
|
{
|
|
$film = $this->publicFilm();
|
|
$film->forceFill(['preview_path' => 'teaser/film-'.$film->id.'.mp4'])->save();
|
|
Storage::disk('media_derived')->put($film->preview_path, self::BYTES);
|
|
$this->release($film);
|
|
|
|
$this->publish('/trailer-teaser', [$this->mediaCard($film)]);
|
|
|
|
$this->assertStringContainsString('data-clip-src="'.route('website.media', $film).'"', $this->get('/trailer-teaser')->assertOk()->getContent(), 'Ersatzweise der eigene freigegebene Teaser des Films.');
|
|
}
|
|
|
|
public function test_other_roles_and_images_never_become_a_clip(): void
|
|
{
|
|
$film = $this->publicFilm();
|
|
$interview = $this->clip('Interview Denkpause');
|
|
$image = $this->image('Bild als Trailer');
|
|
$this->assign($film, 'interview', $interview);
|
|
$this->assign($film, 'trailer', $image);
|
|
$this->release($interview);
|
|
$this->release($image);
|
|
|
|
$this->publish('/trailer-falsch', [$this->mediaCard($film)]);
|
|
|
|
$this->assertStringNotContainsString('data-card-clip', $this->get('/trailer-falsch')->assertOk()->getContent());
|
|
}
|
|
|
|
public function test_the_editor_can_switch_the_trailer_off_per_card_and_the_choice_is_validated(): void
|
|
{
|
|
$film = $this->publicFilm();
|
|
$trailer = $this->clip('Trailer Denkpause');
|
|
$this->assign($film, 'trailer', $trailer);
|
|
$this->release($trailer);
|
|
|
|
$this->publish('/trailer-aus', [[
|
|
'layout' => 'u1_1_1_1',
|
|
'style' => [],
|
|
'slots' => [
|
|
$this->mediaCard($film, [], ['clip' => 'yes'])['slots'][0],
|
|
$this->mediaCard($film, [], ['clip' => 'no'])['slots'][0],
|
|
$this->mediaCard($film)['slots'][0],
|
|
],
|
|
]]);
|
|
|
|
$cards = $this->cards($this->get('/trailer-aus')->assertOk()->getContent());
|
|
$this->assertCount(3, $cards);
|
|
$this->assertStringContainsString('data-card-clip', $cards[0]);
|
|
$this->assertStringNotContainsString('data-card-clip', $cards[1], 'Ausgeschaltet bleibt es beim Bild.');
|
|
$this->assertStringContainsString('data-card-clip', $cards[2], 'Vorgabe: Abspielen, auch für schon gespeicherte Karten ohne Wahl.');
|
|
|
|
$registry = app(WidgetRegistry::class);
|
|
$this->assertSame(['yes', 'no'], array_keys($registry->get('media_card')->settingOptions()['clip']));
|
|
$this->assertSame(['yes', 'no'], array_keys($registry->get('program_card')->settingOptions()['clip']));
|
|
$this->assertArrayNotHasKey('clip', $registry->get('topic_card')->settingOptions(), 'Ein Thema hat keinen Trailer.');
|
|
|
|
try {
|
|
$registry->normalize([['type' => 'media_card', 'v' => 1, 'variant' => 'adaptive', 'settings' => ['clip' => 'immer'], 'data' => [], 'refs' => ['element' => $film->id]]]);
|
|
$this->fail('Eine unbekannte Trailer-Wahl wurde angenommen.');
|
|
} catch (ValidationException $exception) {
|
|
$this->assertArrayHasKey('blocks.0.settings.clip', $exception->errors());
|
|
}
|
|
}
|
|
|
|
public function test_the_program_card_plays_the_trailer_of_the_program(): void
|
|
{
|
|
$program = $this->program('Programm Mut');
|
|
$trailer = $this->clip('Trailer Mut');
|
|
$this->assign($program, 'trailer', $trailer);
|
|
$this->release($trailer);
|
|
|
|
$this->publish('/trailer-programm', [['layout' => 'u4', 'style' => [], 'slots' => [
|
|
['type' => 'program_card', 'v' => 1, 'variant' => 'adaptive', 'settings' => [], 'data' => [], 'refs' => ['composition' => $program->id]],
|
|
]]]);
|
|
|
|
$card = $this->card($this->get('/trailer-programm')->assertOk()->getContent());
|
|
$this->assertStringContainsString('data-clip-src="'.route('website.media', $trailer).'"', $card);
|
|
$this->assertStringContainsString('lf-pc__visual--panel', $card);
|
|
}
|
|
|
|
public function test_a_confidential_film_never_offers_a_trailer(): void
|
|
{
|
|
$film = $this->publicFilm(kind: 'traineranleitung');
|
|
$trailer = $this->clip('Trailer Denkpause');
|
|
$this->assign($film, 'trailer', $trailer);
|
|
$this->release($trailer);
|
|
|
|
$this->publish('/trailer-vertraulich', [$this->mediaCard($film)]);
|
|
|
|
$html = $this->get('/trailer-vertraulich')->assertOk()->getContent();
|
|
$this->assertStringNotContainsString('data-card-clip', $html);
|
|
$this->assertStringNotContainsString('Denkpause', $html, 'Die Karte einer Traineranleitung erscheint öffentlich nie.');
|
|
}
|
|
|
|
public function test_the_media_route_serves_byte_ranges_for_clips(): void
|
|
{
|
|
$trailer = $this->clip('Trailer Denkpause');
|
|
$this->release($trailer);
|
|
$url = route('website.media', $trailer);
|
|
|
|
$whole = $this->get($url)->assertOk();
|
|
$this->assertSame('bytes', $whole->headers->get('Accept-Ranges'));
|
|
$whole->assertStreamedContent(self::BYTES);
|
|
|
|
$part = $this->get($url, ['Range' => 'bytes=2-5'])->assertStatus(206);
|
|
$this->assertSame('bytes 2-5/20', $part->headers->get('Content-Range'));
|
|
$this->assertSame('4', $part->headers->get('Content-Length'));
|
|
$part->assertStreamedContent('2345');
|
|
|
|
$this->get($url, ['Range' => 'bytes=15-'])->assertStatus(206)->assertStreamedContent('fghij');
|
|
$this->get($url, ['Range' => 'bytes=-3'])->assertStatus(206)->assertStreamedContent('hij');
|
|
$this->get($url, ['Range' => 'bytes=0-999'])->assertStatus(206)->assertStreamedContent(self::BYTES);
|
|
|
|
$unsatisfiable = $this->get($url, ['Range' => 'bytes=40-50'])->assertStatus(416);
|
|
$this->assertSame('bytes */20', $unsatisfiable->headers->get('Content-Range'));
|
|
$this->get($url, ['Range' => 'bytes=abc'])->assertStatus(416);
|
|
|
|
app(WebsiteRelease::class)->withdraw($trailer->fresh());
|
|
$this->get($url, ['Range' => 'bytes=0-3'])->assertNotFound();
|
|
}
|
|
|
|
public function test_images_ignore_range_requests(): void
|
|
{
|
|
$image = $this->image('Bild ohne Bereich');
|
|
$this->release($image);
|
|
|
|
$this->get(route('website.media', $image), ['Range' => 'bytes=0-3'])->assertOk();
|
|
}
|
|
|
|
private function publicFilm(string $kind = 'unterrichtsfilm'): ContentElement
|
|
{
|
|
$content = app(ContentService::class);
|
|
$film = $content->createElement('film', 'film', 'Denkpause Rohschnitt');
|
|
$film->update(['display_title' => 'Eine Pause, die stark macht', 'summary' => 'KURZ-TEXT']);
|
|
$film->forceFill(['editorial_content_kind_id' => EditorialContentKind::query()->where('slug', $kind)->value('id')])->save();
|
|
$version = $content->publishElementVersion($film, 'Film');
|
|
$composition = $content->createComposition('Programm Denkpause');
|
|
$composition->editorial_content_kind_id = EditorialContentKind::query()->where('slug', 'programm')->value('id');
|
|
$composition->save();
|
|
$shown = $content->publishComposition($composition, [['role' => 'Film', 'target' => $version]]);
|
|
app(CompositionDisplayRelease::class)->release($shown, User::factory()->create());
|
|
|
|
return $film->refresh();
|
|
}
|
|
|
|
private function program(string $designation): Composition
|
|
{
|
|
$content = app(ContentService::class);
|
|
$composition = $content->createComposition($designation);
|
|
$composition->forceFill(['editorial_content_kind_id' => EditorialContentKind::query()->where('slug', 'programm')->value('id'), 'summary' => 'KURZ-TEXT'])->save();
|
|
$version = $content->publishComposition(
|
|
$composition,
|
|
[['role' => 'Text', 'target' => $content->publishElementVersion($content->createElement('text', 'text', $designation.' Blatt'), 'Inhalt')]],
|
|
);
|
|
app(CompositionDisplayRelease::class)->release($version, User::factory()->create());
|
|
|
|
return $composition->refresh();
|
|
}
|
|
|
|
/** Ein kurzer Clip als eigenes Medium ohne Fassung, wie ihn die Präsentation anlegt. */
|
|
private function clip(string $title): ContentElement
|
|
{
|
|
return $this->presentation('film', $title, self::BYTES, 'mp4');
|
|
}
|
|
|
|
private function image(string $title): ContentElement
|
|
{
|
|
return $this->presentation('bild', $title, 'bild-bytes', 'jpg');
|
|
}
|
|
|
|
private function presentation(string $output, string $title, string $bytes, string $extension): ContentElement
|
|
{
|
|
$path = 'inhalte/'.md5($title).'.'.$extension;
|
|
Storage::disk('cms_incoming')->put($path, $bytes);
|
|
$element = app(ContentService::class)->createElement($output, $output, $title);
|
|
$element->display_title = $title;
|
|
$element->save();
|
|
app(PresentationFile::class)->store($element, $path);
|
|
|
|
return $element->fresh();
|
|
}
|
|
|
|
private function assign(Composition|ContentElement $subject, string $role, ContentElement $clip): void
|
|
{
|
|
PresentationAssignment::query()->create([
|
|
'subject_type' => $subject->getMorphClass(),
|
|
'subject_id' => $subject->getKey(),
|
|
'content_element_id' => $clip->id,
|
|
'presentation_role_id' => PresentationRole::query()->where('slug', $role)->value('id'),
|
|
'position' => 1,
|
|
]);
|
|
}
|
|
|
|
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] as $class) {
|
|
$this->app->forgetInstance($class);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $refs
|
|
* @param array<string, string> $settings
|
|
* @return array<string, mixed>
|
|
*/
|
|
private function mediaCard(ContentElement $film, array $refs = [], array $settings = []): array
|
|
{
|
|
return ['layout' => 'u4', 'style' => [], 'slots' => [
|
|
['type' => 'media_card', 'v' => 1, 'variant' => 'adaptive', 'settings' => $settings, 'data' => [], 'refs' => ['element' => $film->id] + $refs],
|
|
]];
|
|
}
|
|
|
|
/**
|
|
* @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 card(string $html): string
|
|
{
|
|
return $this->cards($html)[0] ?? '';
|
|
}
|
|
|
|
/**
|
|
* @return list<string>
|
|
*/
|
|
private function cards(string $html): array
|
|
{
|
|
preg_match_all('#<article class="lf-pc .*?</article>#s', $html, $matches);
|
|
|
|
return $matches[0];
|
|
}
|
|
}
|