Neue optionale Auswahl refs.video am Hero (Variante Foto mit Textfläche). Gespielt wird der für die Website freigegebene Clip nach der Regel der Karte (Trailer, Vorschauclip, Website-Datei des Films); nie der vollständige Film. Start nach dem Laden, Schaltfläche zum Anhalten, Foto als Rückfall, kein Selbststart bei reduzierter Bewegung, Datensparmodus und 2G. Keine Migration. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
287 lines
12 KiB
PHP
287 lines
12 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\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\HeroVideo;
|
|
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;
|
|
|
|
/**
|
|
* Video im Einstieg (Hero): In der Variante „Foto mit Textfläche“ läuft auf der Fläche des Fotos ein stummer Clip, aber
|
|
* nur ein für die Website freigegebener (Trailer, Vorschauclip oder Website-Datei des gewählten Films). Der Film selbst
|
|
* und nicht freigegebene Clips kommen nie über den Einstieg; ohne Clip bleibt es beim Foto.
|
|
*/
|
|
class CmsHeroVideoTest 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_the_released_trailer_of_the_chosen_film_plays_on_the_hero(): void
|
|
{
|
|
$film = $this->publicFilm();
|
|
$trailer = $this->clip('Trailer Denkpause');
|
|
$image = $this->image('Foto Denkpause');
|
|
$this->assign($film, 'trailer', $trailer);
|
|
$this->release($trailer);
|
|
$this->release($image);
|
|
|
|
$this->publish('/hero-video', $this->hero($film, ['image' => $image->id]));
|
|
|
|
$html = $this->get('/hero-video')->assertOk()->getContent();
|
|
$hero = $this->heroHtml($html);
|
|
$this->assertStringContainsString('data-hero-video', $hero);
|
|
$this->assertStringContainsString('data-clip-src="'.route('website.media', $trailer).'"', $hero);
|
|
$this->assertStringContainsString('<video class="lf-hero__video" muted loop playsinline preload="none"', $hero, 'Stumm, in Schleife, nichts wird vorab geladen.');
|
|
$this->assertDoesNotMatchRegularExpression('/<video[^>]* src=/', $hero, 'Die Quelle wird erst nach dem Laden der Seite gesetzt.');
|
|
$this->assertStringNotContainsString('autoplay', $hero);
|
|
$this->assertStringContainsString('lf-hero__photo', $hero, 'Das Foto bleibt als Rückfall unter dem Video.');
|
|
$this->assertStringContainsString('aria-label="Video abspielen: Trailer Denkpause"', $hero);
|
|
$this->assertStringContainsString('data-hero-toggle', $hero, 'Es gibt immer eine Schaltfläche zum Anhalten.');
|
|
$this->assertStringNotContainsString('teaser/', $html);
|
|
$this->assertStringNotContainsString('originals/', $html);
|
|
$this->assertStringNotContainsString('freigegebenes Video', $html, 'Hinweise für die Redaktion erscheinen öffentlich nie.');
|
|
}
|
|
|
|
public function test_a_film_with_only_a_released_website_file_is_its_own_hero_video(): void
|
|
{
|
|
$teaser = $this->clip('Teaser Denkpause');
|
|
$this->release($teaser);
|
|
|
|
$this->publish('/hero-teaser', $this->hero($teaser));
|
|
|
|
$hero = $this->heroHtml($this->get('/hero-teaser')->assertOk()->getContent());
|
|
$this->assertStringContainsString('data-clip-src="'.route('website.media', $teaser).'"', $hero);
|
|
}
|
|
|
|
public function test_an_unreleased_video_is_not_played_publicly_and_explained_in_the_preview(): void
|
|
{
|
|
$teaser = $this->clip('Teaser Denkpause');
|
|
$revision = $this->publish('/hero-nicht-frei', $this->hero($teaser));
|
|
|
|
$public = $this->get('/hero-nicht-frei')->assertOk()->getContent();
|
|
$this->assertStringNotContainsString('data-hero-video', $public);
|
|
$this->assertStringNotContainsString('<video', $public);
|
|
$this->assertStringNotContainsString('freigegebenes Video', $public);
|
|
|
|
$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('kein für die Website freigegebenes Video', $preview);
|
|
}
|
|
|
|
public function test_withdrawing_the_release_takes_the_video_off_the_page(): void
|
|
{
|
|
$teaser = $this->clip('Teaser Denkpause');
|
|
$this->release($teaser);
|
|
$this->publish('/hero-zurueck', $this->hero($teaser));
|
|
$this->assertStringContainsString('data-hero-video', $this->get('/hero-zurueck')->getContent());
|
|
|
|
app(WebsiteRelease::class)->withdraw($teaser->fresh());
|
|
$this->flushScoped();
|
|
|
|
$this->assertStringNotContainsString('data-hero-video', $this->get('/hero-zurueck')->assertOk()->getContent());
|
|
}
|
|
|
|
public function test_a_film_with_versions_but_without_a_released_clip_stays_with_the_photo(): void
|
|
{
|
|
$film = $this->publicFilm();
|
|
$this->publish('/hero-film', $this->hero($film));
|
|
|
|
$this->assertStringNotContainsString('data-hero-video', $this->get('/hero-film')->assertOk()->getContent(), 'Der vollständige Film läuft nie über den Einstieg.');
|
|
}
|
|
|
|
public function test_the_brand_surface_variant_shows_no_video(): void
|
|
{
|
|
$teaser = $this->clip('Teaser Denkpause');
|
|
$this->release($teaser);
|
|
$this->publish('/hero-solid', $this->hero($teaser, [], 'editorial_solid'));
|
|
|
|
$this->assertStringNotContainsString('data-hero-video', $this->get('/hero-solid')->assertOk()->getContent());
|
|
}
|
|
|
|
public function test_a_hero_without_video_is_unchanged(): void
|
|
{
|
|
$this->publish('/hero-ohne', $this->hero(null));
|
|
|
|
$html = $this->get('/hero-ohne')->assertOk()->getContent();
|
|
$this->assertStringNotContainsString('data-hero-video', $html);
|
|
$this->assertStringNotContainsString('<video', $html);
|
|
$this->assertStringContainsString('Neue Wege', $html);
|
|
|
|
$widgets = app(WidgetRegistry::class)->normalize($this->hero(null)[0]['slots']);
|
|
$this->assertArrayNotHasKey('video', $widgets[0]['refs'], 'Ohne Wahl bleibt die gespeicherte Form wie bisher.');
|
|
}
|
|
|
|
public function test_the_choice_is_validated(): void
|
|
{
|
|
$film = $this->publicFilm();
|
|
$image = $this->image('Foto Denkpause');
|
|
$archived = $this->clip('Archiv Denkpause');
|
|
$archived->forceFill(['archived_at' => now()])->save();
|
|
$confidential = $this->publicFilm('traineranleitung');
|
|
$registry = app(WidgetRegistry::class);
|
|
|
|
$this->assertSame($film->id, $registry->normalize($this->hero($film)[0]['slots'])[0]['refs']['video']);
|
|
|
|
foreach (['kein Film' => $image->id, 'archiviert' => $archived->id, 'Traineranleitung' => $confidential->id, 'unbekannt' => 999999] as $case => $id) {
|
|
try {
|
|
$registry->normalize([['type' => 'hero', 'v' => 2, 'variant' => 'photo_split', 'settings' => [], 'data' => ['heading' => 'X'], 'refs' => ['video' => $id]]]);
|
|
$this->fail('Angenommen: '.$case);
|
|
} catch (ValidationException $exception) {
|
|
$this->assertArrayHasKey('blocks.0.refs.video', $exception->errors(), $case);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function test_the_selection_offers_only_films_and_says_whether_a_video_is_released(): void
|
|
{
|
|
$released = $this->clip('Teaser Frei');
|
|
$this->release($released);
|
|
$open = $this->clip('Teaser Offen');
|
|
$image = $this->image('Teaser Bild');
|
|
$archived = $this->clip('Teaser Archiv');
|
|
$archived->forceFill(['archived_at' => now()])->save();
|
|
|
|
$options = app(HeroVideo::class)->options('Teaser');
|
|
|
|
$this->assertStringContainsString('Video freigegeben', $options[$released->id]);
|
|
$this->assertStringContainsString('noch kein freigegebenes Video', $options[$open->id]);
|
|
$this->assertArrayNotHasKey($image->id, $options);
|
|
$this->assertArrayNotHasKey($archived->id, $options);
|
|
}
|
|
|
|
public function test_a_confidential_film_never_plays_on_the_hero_even_with_a_saved_choice(): void
|
|
{
|
|
$film = $this->publicFilm(kind: 'traineranleitung');
|
|
$trailer = $this->clip('Trailer Denkpause');
|
|
$this->assign($film, 'trailer', $trailer);
|
|
$this->release($trailer);
|
|
|
|
$resolved = app(HeroVideo::class)->resolve($film->id, false);
|
|
|
|
$this->assertNull($resolved['url']);
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $refs
|
|
* @return list<array<string, mixed>>
|
|
*/
|
|
private function hero(?ContentElement $video, array $refs = [], string $variant = 'photo_split'): array
|
|
{
|
|
return [['layout' => 'u4', 'style' => [], 'slots' => [
|
|
['type' => 'hero', 'v' => 2, 'variant' => $variant, 'settings' => [], 'data' => ['heading' => 'Neue Wege'], 'refs' => ($video !== null ? ['video' => $video->id] : []) + $refs],
|
|
]]];
|
|
}
|
|
|
|
private function heroHtml(string $html): string
|
|
{
|
|
preg_match('#<div class="lf-hero .*?<span class="lf-hero__bottom"#s', $html, $match);
|
|
|
|
return $match[0] ?? '';
|
|
}
|
|
|
|
/**
|
|
* @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 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();
|
|
}
|
|
|
|
/** 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(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);
|
|
}
|
|
}
|
|
}
|