Der Web-Prozess hat derived/ nur lesend; das Anlegen als eigenständiges Präsentationsmedium schrieb dort selbst und scheiterte auf den Servern (die Tests fakten die Disk). Jetzt prüft PresentationFile nur und übergibt das Kopieren an StorePresentationFile; ein Fehler steht am Medium. Die Prüfung läuft vor dem Anlegen, sodass keine leere Hülle zurückbleibt, und nennt das Format (MOV und M4V sind keine Website-Dateien). Am Medium gibt es unter Website-Freigabe die Website-Datei zum nachträglichen Hochladen, auch bei einem Film mit geschützter Fassung (ungeschützter Trailer). Die Fassung bleibt unverändert. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
175 lines
7.0 KiB
PHP
175 lines
7.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Domain\Catalog\ContentElement;
|
|
use App\Domain\Catalog\ContentService;
|
|
use App\Domain\Catalog\DomainRuleException;
|
|
use App\Domain\Entitlement\Grant;
|
|
use App\Domain\Media\PresentationFile;
|
|
use App\Domain\Media\WebsiteMedia;
|
|
use App\Domain\Media\WebsiteRelease;
|
|
use App\Filament\Resources\ContentElements\Pages\ViewContentElement;
|
|
use App\Filament\Support\MediumForm;
|
|
use App\Jobs\PublishWebsiteMedia;
|
|
use App\Jobs\StorePresentationFile;
|
|
use App\Models\User;
|
|
use Filament\Facades\Filament;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Support\Facades\Queue;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Livewire\Livewire;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Website-Datei eines Films (zum Beispiel ein Trailer ohne Schutz). Der Web-Prozess hat `derived/` nur lesend
|
|
* (docker-compose.yml); die Datei muss deshalb die Warteschlange ablegen.
|
|
*/
|
|
class WebsiteFileTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
|
|
Storage::fake('cms_incoming');
|
|
Storage::fake('media_derived');
|
|
Storage::fake('media_public');
|
|
Storage::fake('media_originals');
|
|
}
|
|
|
|
public function test_the_web_process_does_not_write_to_the_derived_store_but_hands_the_copy_to_the_queue(): void
|
|
{
|
|
Queue::fake();
|
|
Storage::disk('cms_incoming')->put('inhalte/trailer.mp4', 'trailer-bytes');
|
|
$this->actingAs($this->editor(), 'staff');
|
|
|
|
$element = MediumForm::create([
|
|
'working_title' => 'Trailer',
|
|
'shape' => 'film',
|
|
'incoming' => 'inhalte/trailer.mp4',
|
|
'without_version' => true,
|
|
], hold: false);
|
|
|
|
Queue::assertPushed(StorePresentationFile::class, fn (StorePresentationFile $job): bool => $job->elementId === $element->id);
|
|
$this->assertEmpty(Storage::disk('media_derived')->allFiles());
|
|
$this->assertNull($element->fresh()->preview_path);
|
|
$this->assertSame(0, $element->versions()->count());
|
|
}
|
|
|
|
public function test_the_queue_places_the_file_and_the_film_can_then_be_released_without_a_license(): void
|
|
{
|
|
Storage::disk('cms_incoming')->put('inhalte/trailer.mp4', 'trailer-bytes');
|
|
$this->actingAs($this->editor(), 'staff');
|
|
|
|
$element = MediumForm::create([
|
|
'working_title' => 'Trailer',
|
|
'shape' => 'film',
|
|
'incoming' => 'inhalte/trailer.mp4',
|
|
'without_version' => true,
|
|
], hold: false)->fresh();
|
|
|
|
$this->assertSame('teaser/'.$element->id.'/datei.mp4', $element->preview_path);
|
|
Storage::disk('media_derived')->assertExists($element->preview_path);
|
|
Storage::disk('cms_incoming')->assertMissing('inhalte/trailer.mp4');
|
|
|
|
$this->assertNull(app(WebsiteRelease::class)->refusal($element));
|
|
app(WebsiteRelease::class)->release($element);
|
|
$this->assertNotNull(app(WebsiteMedia::class)->present($element->fresh()));
|
|
$this->assertSame(0, Grant::query()->count());
|
|
Storage::disk('media_originals')->assertDirectoryEmpty('/');
|
|
}
|
|
|
|
public function test_a_film_format_the_browser_cannot_play_is_refused_before_anything_is_created(): void
|
|
{
|
|
Storage::disk('cms_incoming')->put('inhalte/trailer.mov', 'mov-bytes');
|
|
$this->actingAs($this->editor(), 'staff');
|
|
|
|
try {
|
|
MediumForm::create([
|
|
'working_title' => 'Trailer als MOV',
|
|
'shape' => 'film',
|
|
'incoming' => 'inhalte/trailer.mov',
|
|
'without_version' => true,
|
|
], hold: false);
|
|
$this->fail('Eine MOV-Datei darf keine Website-Datei werden.');
|
|
} catch (DomainRuleException $e) {
|
|
$this->assertStringContainsString('.mov', $e->getMessage());
|
|
$this->assertStringContainsString('MP4', $e->getMessage());
|
|
}
|
|
|
|
$this->assertSame(0, ContentElement::query()->count());
|
|
}
|
|
|
|
public function test_a_failed_copy_is_shown_at_the_medium_instead_of_getting_lost(): void
|
|
{
|
|
$element = app(ContentService::class)->createElement('film', 'film', 'Trailer');
|
|
|
|
(new StorePresentationFile($element->id, 'inhalte/fehlt.mp4'))->handle(app(PresentationFile::class));
|
|
|
|
$this->assertStringContainsString('nicht im Eingang', (string) $element->fresh()->thumbnail_error);
|
|
$this->assertNull($element->fresh()->preview_path);
|
|
}
|
|
|
|
public function test_a_film_with_a_protected_version_gets_a_separate_unprotected_website_file(): void
|
|
{
|
|
Queue::fake([PublishWebsiteMedia::class]);
|
|
$content = app(ContentService::class);
|
|
$film = $content->createElement('film', 'film', 'Unterrichtsfilm');
|
|
$version = $content->publishElementVersion($film, null, ['incoming' => 'inhalte/ganz.mp4']);
|
|
$this->assertNotNull(app(WebsiteRelease::class)->refusal($film->fresh()));
|
|
|
|
$this->actingAs($this->editor(), 'staff');
|
|
Livewire::test(ViewContentElement::class, ['record' => $film->getKey()])
|
|
->set('bereich', 'website')
|
|
->set('websiteUpload', UploadedFile::fake()->create('trailer.mp4', 100, 'video/mp4'))
|
|
->call('storeWebsiteFile')
|
|
->assertSee('Die Website-Datei ist übernommen');
|
|
|
|
$film = $film->fresh();
|
|
$this->assertSame('teaser/'.$film->id.'/datei.mp4', $film->preview_path);
|
|
$this->assertSame([$version->id], $film->versions()->pluck('id')->all());
|
|
$this->assertNull(app(WebsiteRelease::class)->refusal($film));
|
|
}
|
|
|
|
public function test_the_upload_in_the_viewer_refuses_wrong_formats_and_missing_files(): void
|
|
{
|
|
$film = app(ContentService::class)->createElement('film', 'film', 'Film');
|
|
$this->actingAs($this->editor(), 'staff');
|
|
|
|
Livewire::test(ViewContentElement::class, ['record' => $film->getKey()])
|
|
->set('bereich', 'website')
|
|
->call('storeWebsiteFile')
|
|
->assertSee('Wähle zuerst eine Datei.')
|
|
->set('websiteUpload', UploadedFile::fake()->create('trailer.mov', 10))
|
|
->call('storeWebsiteFile')
|
|
->assertSee('kann der Browser nicht direkt abspielen');
|
|
|
|
$this->assertNull($film->fresh()->preview_path);
|
|
}
|
|
|
|
public function test_replacing_the_file_of_a_released_film_publishes_the_new_copy(): void
|
|
{
|
|
Storage::disk('cms_incoming')->put('inhalte/neu.mp4', 'neu');
|
|
$film = app(ContentService::class)->createElement('film', 'film', 'Trailer');
|
|
$film->website_released_at = now();
|
|
$film->save();
|
|
Queue::fake([PublishWebsiteMedia::class]);
|
|
|
|
app(PresentationFile::class)->store($film, 'inhalte/neu.mp4');
|
|
|
|
Queue::assertPushed(PublishWebsiteMedia::class, fn (PublishWebsiteMedia $job): bool => $job->elementId === $film->id && $job->action === 'release');
|
|
}
|
|
|
|
private function editor(): User
|
|
{
|
|
$editor = User::factory()->redakteur()->create();
|
|
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
|
|
|
return $editor;
|
|
}
|
|
}
|