Wähle eine Stelle auch aus der Website-Datei eines Films ohne Fassung als Kartenbild
Der Regler „Bild aus dem Film“ der Medienkarte blieb bei einem Film nur mit Website-Datei (zum Beispiel ein Teaser) aus, weil er eine bereitgestellte Fassung verlangte. Die Stelle kommt jetzt aus der Website-Datei (Herkunft frame:0@Sekunde, wie im Medienmanager), mit Vorschau über die Redaktionsroute und Übernahme als Bild-Medium in bis zu 1600 px Breite. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
631502c064
commit
1413e0640f
6 files changed
+247
-18
No files matched your search
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Cms\Page;
|
||||
use App\Domain\Cms\PageService;
|
||||
use App\Domain\Cms\Widgets\WidgetRegistry;
|
||||
use App\Domain\Media\FilmStill;
|
||||
use App\Domain\Media\FilmStillSource;
|
||||
use App\Domain\Media\ThumbnailDeriver;
|
||||
use App\Filament\Resources\Pages\Pages\EditPage;
|
||||
use App\Models\User;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Bild aus einem Film nur mit Website-Datei (zum Beispiel ein Teaser) für die Medienkarte: Die Stelle kommt aus der
|
||||
* Website-Datei, weil es keine bereitgestellte Fassung gibt. Die Bildextraktion (ffmpeg) ist durch einen Stub ersetzt.
|
||||
*/
|
||||
class FilmStillWebsiteFileTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/** @var object{calls: list<array{second: float, width: int}>, 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<array{second: float, width: int}> */
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user