94 lines
4.0 KiB
PHP
94 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Domain\Catalog\CompositionDisplayRelease;
|
|
use App\Domain\Catalog\CompositionStructureReader;
|
|
use App\Domain\Catalog\ContentService;
|
|
use App\Domain\Catalog\DomainRuleException;
|
|
use App\Domain\Catalog\EditorialContentKind;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class CompositionStructureAndDisplayTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_structure_reader_resolves_explicit_version_independent_of_display_release(): void
|
|
{
|
|
$content = app(ContentService::class);
|
|
$film = $content->publishElementVersion($content->createElement('film', 'film', 'Film A'), null, ['file' => 'inhalte/a.mp4']);
|
|
$programm = EditorialContentKind::query()->where('slug', 'programm')->firstOrFail();
|
|
$composition = $content->publishComposition(
|
|
tap($content->createComposition('Programm A'), function ($item) use ($programm): void {
|
|
$item->editorial_content_kind_id = $programm->id;
|
|
$item->save();
|
|
}),
|
|
[['role' => 'Film', 'target' => $film]],
|
|
);
|
|
$compositionModel = $composition->composition;
|
|
|
|
$composition->load('composition.editorialContentKind');
|
|
$tree = app(CompositionStructureReader::class)->tree($composition);
|
|
|
|
$this->assertSame('Programm', $composition->composition->editorialContentKind?->label);
|
|
$this->assertCount(1, $tree);
|
|
$this->assertSame('Film A', $tree[0]->title);
|
|
$this->assertFalse(app(CompositionDisplayRelease::class)->isReleased($composition));
|
|
}
|
|
|
|
public function test_display_release_and_revoke_are_version_bound_and_auditable(): void
|
|
{
|
|
$content = app(ContentService::class);
|
|
$composition = $content->publishComposition(
|
|
$content->createComposition('Modul A'),
|
|
[['role' => 'Text', 'target' => $content->publishElementVersion($content->createElement('text', 'text', 'Text'), 'Inhalt')]],
|
|
);
|
|
$actor = User::factory()->create();
|
|
$releases = app(CompositionDisplayRelease::class);
|
|
|
|
$releases->release($composition, $actor, 'Erstfreigabe');
|
|
$this->assertTrue($releases->isReleased($composition));
|
|
$composition->displayEvents()->update(['occurred_at' => now()->subMinute()]);
|
|
|
|
$releases->revoke($composition, $actor, 'Korrektur');
|
|
$this->assertFalse($releases->isReleased($composition->fresh()));
|
|
|
|
$this->assertCount(2, $composition->fresh()->displayEvents);
|
|
$this->assertSame($actor->id, $composition->displayEvents()->orderByDesc('id')->first()->actor_id);
|
|
}
|
|
|
|
public function test_revoke_without_release_fails(): void
|
|
{
|
|
$content = app(ContentService::class);
|
|
$composition = $content->publishComposition(
|
|
$content->createComposition('Leer'),
|
|
[['role' => 'Text', 'target' => $content->publishElementVersion($content->createElement('text', 'text', 'Text'), 'Inhalt')]],
|
|
);
|
|
|
|
$this->expectException(DomainRuleException::class);
|
|
app(CompositionDisplayRelease::class)->revoke($composition, User::factory()->create());
|
|
}
|
|
|
|
public function test_highest_released_version_picks_latest_number(): void
|
|
{
|
|
$content = app(ContentService::class);
|
|
$element = $content->createComposition('Prog');
|
|
$v1 = $content->publishComposition($element, [
|
|
['role' => 'Text', 'target' => $content->publishElementVersion($content->createElement('text', 'text', 'Eins'), '1')],
|
|
]);
|
|
$actor = User::factory()->create();
|
|
app(CompositionDisplayRelease::class)->release($v1, $actor);
|
|
|
|
$v2 = $content->publishComposition($element, [
|
|
['role' => 'Text', 'target' => $content->publishElementVersion($content->createElement('text', 'text', 'Zwei'), '2')],
|
|
]);
|
|
app(CompositionDisplayRelease::class)->release($v2, $actor);
|
|
|
|
$highest = app(CompositionDisplayRelease::class)->highestReleasedVersion($element);
|
|
|
|
$this->assertSame(2, $highest?->number);
|
|
}
|
|
}
|