exercise(); $inner = $this->moduleWith('Modul innen', $exercise['version'], ['a']); $outer = $this->moduleWith('Programm außen', $inner, null, CompositionKind::Kurs); $articles = app(ArticleService::class); $article = $articles->create('programm-aussen'); $first = $articles->publishRelease($article, $outer, 'Erster Stand.'); $second = $articles->publishRelease($article->fresh(), $outer, 'Zweiter Stand.'); $direct = $articles->publishRelease($articles->create('modul-innen'), $inner, 'Modul allein.'); $usage = app(ExerciseUsage::class)->forComposition($exercise['version']->composition); $this->assertCount(1, $usage); $this->assertSame(['Modul innen', 'Programm außen'], array_map(fn (array $host): string => $host['composition']->designation, $usage[0]['hosts'])); $this->assertSame([['a'], null], array_map(fn (array $host) => $host['selection'], $usage[0]['hosts'])); $stands = collect($usage[0]['releases']); $this->assertEqualsCanonicalizing([$first->id, $second->id, $direct->id], $stands->map(fn (array $row): int => $row['release']->id)->all()); $this->assertSame('1-1', $stands->first(fn (array $row): bool => $row['release']->id === $first->id)['path'], 'Zwei Ebenen tief.'); $this->assertSame('1', $stands->first(fn (array $row): bool => $row['release']->id === $direct->id)['path']); $this->assertSame('abgeloest_verfuegbar', $first->fresh()->status->value); } public function test_the_impact_of_a_block_names_stand_variant_and_usage(): void { $exercise = $this->exercise(); $withFilm = $this->moduleWith('Mit Film', $exercise['version'], ['a']); $withoutFilm = $this->moduleWith('Ohne Film', $exercise['version'], ['b']); $articles = app(ArticleService::class); $articles->publishRelease($articles->create('mit-film'), $withFilm, 'Film.'); $articles->publishRelease($articles->create('ohne-film'), $withoutFilm, 'Ohne Film.'); $film = app(ExerciseUsage::class)->blockImpact($exercise['filmA']); $this->assertCount(1, $film); $this->assertSame('mit-film', $film[0]['article']->code); $this->assertSame('a', $film[0]['variant']); $this->assertStringContainsString('nicht mehr vollständig durchführbar', $film[0]['effect']); $sheet = app(ExerciseUsage::class)->blockImpact($exercise['sheetB']); $this->assertSame('ergaenzend', $sheet[0]['requirement']); $this->assertStringContainsString('Nur dieses ergänzende Medium entfällt', $sheet[0]['effect']); $this->assertSame([], app(ExerciseUsage::class)->blockImpact($this->film('Unbenutzt'))); } public function test_a_block_changes_neither_the_frozen_stand_nor_the_usage(): void { $exercise = $this->exercise(); $module = $this->moduleWith('Modul', $exercise['version'], ['a']); $articles = app(ArticleService::class); $release = $articles->publishRelease($articles->create('modul'), $module, 'Modul.'); $before = $release->contents->pluck('content_element_version_id')->all(); app(ContentService::class)->block($exercise['filmA'], 'Rechte zurückgezogen.'); $this->assertSame($before, $release->fresh()->contents->pluck('content_element_version_id')->all()); $this->assertSame('veroeffentlicht', $release->fresh()->status->value); $this->assertCount(1, app(ExerciseUsage::class)->blockImpact($exercise['filmA'])); } public function test_an_offer_with_a_blocked_part_is_not_activated_and_names_it(): void { $exercise = $this->exercise(); $module = $this->moduleWith('Modul', $exercise['version'], ['a']); $articles = app(ArticleService::class); $article = $articles->create('modul-angebot'); $articles->publishRelease($article, $module, 'Modul.'); app(ContentService::class)->block($exercise['filmA'], 'Rechte zurückgezogen.'); $offers = app(OfferService::class); $rights = $offers->createRightsProfile('Film', 'ehrenamtlich', ['film' => ['streamen'], 'text' => ['ansehen']]); $this->expectException(DomainRuleException::class); $this->expectExceptionMessage('gesperrte Bestandteile'); $offers->activate($offers->create('Angebot'), [['target' => $article->fresh(), 'rights' => $rights]], [ 'grant_kind' => 'auf_abruf', 'composition_version_id' => $module->id, ]); } public function test_the_preview_picture_of_a_blocked_medium_is_not_served_any_more(): void { $exercise = $this->exercise(); $element = $exercise['filmA']->element; $element->thumbnail_path = 'vorschau/film-a.jpg'; $element->save(); $module = $this->moduleWith('Modul', $exercise['version'], ['a']); $articles = app(ArticleService::class); $article = $articles->create('modul-bild'); $articles->publishRelease($article, $module, 'Modul.'); $offers = app(OfferService::class); $offer = $offers->create('Bild'); $offers->activate($offer, [['target' => $article->fresh(), 'rights' => $offers->createRightsProfile('Film', 'ehrenamtlich', ['film' => ['streamen']])]], ['grant_kind' => 'auf_abruf']); $member = User::factory()->create(); app(GrantIssuer::class)->claim($member, $offer); $url = route('member.thumbnail', ['kind' => 'element', 'subject' => $element->id]); // Erlaubt, aber die Datei fehlt in diesem Test. $this->actingAs($member)->get($url)->assertNotFound(); app(ContentService::class)->block($exercise['filmA'], 'Rechte zurückgezogen.'); $this->actingAs($member)->get($url)->assertForbidden(); } public function test_two_versions_of_an_exercise_run_in_parallel_stands(): void { $content = app(ContentService::class); $exercise = $this->exercise(); $first = $this->moduleWith('Modul alt', $exercise['version'], ['a']); $revised = $content->publishElementVersion($exercise['textA']->element, 'Neuer Wortlaut.'); $second = $content->publishComposition($exercise['version']->composition, [ ['role' => 'Durchführung A', 'target' => $revised, 'variant' => 'a'], ['role' => 'Film A', 'target' => $exercise['filmA'], 'variant' => 'a'], ], null, null, [], [['key' => 'a', 'name' => 'Mit Film']]); $newer = $this->moduleWith('Modul neu', $second, ['a']); $articles = app(ArticleService::class); $articles->publishRelease($articles->create('alt'), $first, 'Alt.'); $articles->publishRelease($articles->create('neu'), $newer, 'Neu.'); $usage = app(ExerciseUsage::class)->forComposition($exercise['version']->composition); $this->assertCount(2, $usage); $this->assertSame(['alt'], collect($usage[0]['releases'])->map(fn (array $row) => $row['article']->code)->all()); $this->assertSame(['neu'], collect($usage[1]['releases'])->map(fn (array $row) => $row['article']->code)->all()); $this->assertInstanceOf(ArticleRelease::class, $usage[0]['releases'][0]['release']); } }