, fail: bool} */ private object $extractor; protected function setUp(): void { parent::setUp(); Storage::fake('cms_incoming'); Storage::fake('media_derived'); Storage::fake('media_public'); Storage::fake('media_originals'); Filament::setCurrentPanel(Filament::getPanel('verwaltung')); $this->extractor = new class($this->jpeg()) extends ThumbnailDeriver { /** @var list */ public array $calls = []; public bool $fail = false; public function __construct(private readonly string $jpeg) {} public function websiteFileJpeg(ContentElement $element, float $seconds, int $width): ?string { $this->calls[] = ['second' => $seconds, 'width' => $width]; return $this->fail ? null : $this->jpeg; } }; $this->app->instance(ThumbnailDeriver::class, $this->extractor); } public function test_a_frame_of_the_website_file_becomes_one_image_medium(): void { $film = $this->teaser(); $editor = User::factory()->redakteur()->create(); $still = app(FilmStill::class)->fromSecond($film, 7.5, $editor)->refresh(); $this->assertSame('bild', $still->output_class); $this->assertSame('Standbild: Teaser Denkpause (Website-Datei, 7,5 s)', $still->display_title); $this->assertSame('Szene aus dem Film „Teaser Denkpause“', $still->website_alt); $this->assertSame(0, $still->versions()->count(), 'Es entsteht keine Inhaltsfassung.'); $this->assertSame([['second' => 7.5, 'width' => FilmStill::WIDTH]], $this->extractor->calls); $this->assertSame('frame:0@7.5', FilmStillSource::query()->where('film_element_id', $film->id)->value('source_key')); $this->assertSame($still->id, FilmStillSource::query()->value('still_element_id')); } public function test_the_same_frame_of_the_website_file_is_never_extracted_twice(): void { $film = $this->teaser(); $first = app(FilmStill::class)->fromSecond($film, 3); $again = app(FilmStill::class)->fromSecond($film, 3.0); $this->assertSame($first->id, $again->id); $this->assertCount(1, $this->extractor->calls); } public function test_a_film_with_neither_a_version_nor_a_website_file_is_refused(): void { $film = app(ContentService::class)->createElement('film', 'film', 'Leer'); $this->assertNull(app(FilmStill::class)->websiteFile($film)); $this->expectException(DomainRuleException::class); $this->expectExceptionMessage('weder eine bereitgestellte Fassung noch eine Website-Datei'); app(FilmStill::class)->fromSecond($film, 3); } public function test_a_frame_that_cannot_be_extracted_creates_nothing(): void { $film = $this->teaser(); $this->extractor->fail = true; $before = ContentElement::query()->count(); try { app(FilmStill::class)->fromSecond($film, 3); $this->fail('Ohne Bild darf nichts angelegt werden.'); } catch (DomainRuleException $exception) { $this->assertStringContainsString('Website-Datei', $exception->getMessage()); } $this->assertSame($before, ContentElement::query()->count()); } public function test_the_editor_adopts_a_frame_of_the_website_file_into_the_card_image(): void { $film = $this->teaser(); $editor = User::factory()->redakteur()->create(); $editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP'); $page = Page::query()->create(['path' => '/teaser-bild']); app(PageService::class)->saveRevision($page, [ ['layout' => 'u4', 'style' => [], 'slots' => [['type' => 'media_card', 'v' => 1, 'variant' => 'adaptive', 'settings' => [], 'data' => [], 'refs' => ['element' => $film->id]]]], ], null, null, null); $component = Livewire::actingAs($editor, 'staff')->test(EditPage::class, ['record' => $page->id]); $component->call('adoptFilmFrame', 'data.ziel.image', $film->id, '7.5'); $still = ContentElement::query()->where('output_class', 'bild')->latest('id')->firstOrFail(); $this->assertSame($still->id, $component->get('data.ziel.image')); $component->assertNotified('Im Medienmanager angelegt: „Standbild: Teaser Denkpause (Website-Datei, 7,5 s)“'); } public function test_the_card_field_offers_the_slider_with_the_website_file_for_such_a_film(): void { $film = $this->teaser(); $widget = app(WidgetRegistry::class)->get('media_card'); $data = (new \ReflectionMethod($widget, 'filmFieldData'))->invoke($widget, $film); $this->assertNull($data['filmVersionId']); $this->assertSame(route('content.website-frame', ['element' => $film]), $data['filmWebsiteFrameUrl'], 'Der Regler zeigt Stellen der Website-Datei.'); $this->assertSame('0', $data['filmStartSecond']); } private function teaser(): ContentElement { $film = app(ContentService::class)->createElement('film', 'film', 'Teaser Denkpause'); $film->forceFill(['preview_path' => 'teaser/'.$film->id.'/datei.mp4'])->save(); Storage::disk('media_derived')->put($film->preview_path, 'x'); return $film->fresh(); } private function jpeg(): string { $image = imagecreatetruecolor(1600, 900); imagefill($image, 0, 0, imagecolorallocate($image, 40, 120, 90)); ob_start(); imagejpeg($image); return (string) ob_get_clean(); } }