Files
laraundfelix/tests/Feature/CatalogFollowThroughTest.php
T
LarsandCursor 5e763d15ec
Deploy Test / test (push) Successful in 17s
Deploy Test / deploy (push) Successful in 25s
Ergaenze Stammdaten, Suche, Dimensionen, Abdeckung und Ausgabenachweis
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-16 08:24:23 +01:00

91 lines
4.0 KiB
PHP

<?php
namespace Tests\Feature;
use App\Domain\Catalog\ArticleService;
use App\Domain\Catalog\ContentService;
use App\Domain\Catalog\DomainRuleException;
use App\Domain\Catalog\EditorialDimension;
use App\Domain\Catalog\EditorialDimensionValue;
use App\Domain\Catalog\IdentityDimension;
use App\Domain\Catalog\OfferService;
use App\Domain\Entitlement\GrantIssuer;
use App\Domain\Entitlement\MediaDelivery;
use App\Http\SignedLink;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class CatalogFollowThroughTest extends TestCase
{
use RefreshDatabase;
public function test_an_uncovered_program_cannot_be_activated(): void
{
$content = app(ContentService::class);
$film = $content->publishElementVersion($content->createElement('film', 'film', 'Film'), null, ['file' => 'inhalte/a.mp4']);
$sheet = $content->publishElementVersion($content->createElement('text', 'document', 'Blatt'), 'Text');
$program = $content->publishComposition($content->createComposition('Programm'), [
['role' => 'Film', 'target' => $film],
['role' => 'Blatt', 'target' => $sheet],
]);
$articles = app(ArticleService::class);
$filmArticle = $articles->create('nur-film');
$articles->publishRelease($filmArticle, $film, 'Nur der Film.');
$offers = app(OfferService::class);
$rights = $offers->createRightsProfile('Film', 'ehrenamtlich', ['film' => ['streamen']]);
$this->expectException(DomainRuleException::class);
$offers->activate($offers->create('Lückenhaft'), [
['target' => $filmArticle->fresh(), 'rights' => $rights],
], [
'grant_kind' => 'kauf',
'price_cents' => 100,
'composition_version_id' => $program->id,
]);
}
public function test_a_dimension_filters_the_library_and_a_delivery_is_recorded(): void
{
Storage::fake('media_derived');
Storage::disk('media_derived')->put('inhalte/demo.txt', 'text');
$content = app(ContentService::class);
$version = $content->publishElementVersion(
$content->createElement('text', 'text', 'Filterblatt'),
null,
['file' => 'inhalte/demo.txt'],
);
$dimension = EditorialDimension::query()->create(['slug' => 'alter', 'label' => 'Alter']);
$value = EditorialDimensionValue::query()->create([
'editorial_dimension_id' => $dimension->id,
'slug' => 'grundschule',
'label' => 'Grundschule',
]);
app(IdentityDimension::class)->assign($version->element, $value);
$articles = app(ArticleService::class);
$article = $articles->create('filter');
$release = $articles->publishRelease($article, $version, 'Eigenständig.');
$offers = app(OfferService::class);
$rights = $offers->createRightsProfile('Lesen', 'ehrenamtlich', ['text' => ['ansehen']]);
$offer = $offers->create('Filterangebot');
$offers->activate($offer, [['target' => $article->fresh(), 'rights' => $rights]], ['grant_kind' => 'auf_abruf']);
$member = User::factory()->create();
app(GrantIssuer::class)->claim($member, $offer);
$this->actingAs($member)->get(route('member.library', ['dimension' => [$value->id]]))->assertOk()->assertSee('Filterblatt');
$this->actingAs($member)->get(route('member.library', ['dimension' => [999]]))->assertOk()->assertDontSee('Filterblatt');
$url = SignedLink::temporary('member.media', now()->addMinutes(5), [
'article' => $article->id,
'release' => $release->id,
'version' => $version->id,
'action' => 'ansehen',
'reader' => $member->id,
]);
$this->actingAs($member)->get($url)->assertOk();
$this->assertSame(1, MediaDelivery::query()->count());
$this->assertSame('ansehen', MediaDelivery::query()->first()->action);
}
}