buildProduct(); } public function test_the_kind_values_are_the_ones_this_program_state_knows(): void { $this->assertSame(['kombination', 'uebung', 'kurs', 'exercise'], CompositionKind::values()); $this->assertNotContains(self::FOREIGN, CompositionKind::values()); } public function test_a_composition_of_an_unknown_kind_does_not_crash_loading_and_stays_hidden(): void { $this->assertSame( ['Modul mit Übung'], Composition::query()->orderBy('designation')->pluck('designation')->all(), ); $this->assertNull(CompositionVersion::query()->with('composition')->findOrFail($this->exercise->id)->composition); $this->assertNull(Composition::query()->find($this->exercise->composition_id)); $this->assertSame(1, DB::table('compositions')->where('kind', self::FOREIGN)->count(), 'Die Zeile bleibt unverändert erhalten.'); } public function test_the_member_area_neither_crashes_nor_shows_what_it_cannot_present(): void { $this->actingAs($this->member) ->get(route('member.library')) ->assertOk() ->assertSee('Modul mit Übung'); $this->actingAs($this->member) ->get(route('member.program', $this->module->composition_id)) ->assertOk() ->assertSee('Modul mit Übung') ->assertDontSee('Übung neuerer Stand') ->assertDontSee('Einstiegsfilm') ->assertDontSee('Alternativfilm') ->assertDontSee('Durchführungstext'); $this->actingAs($this->member) ->get(route('member.program', $this->exercise->composition_id)) ->assertNotFound(); } public function test_only_the_selected_variant_is_delivered_from_the_frozen_stand(): void { $this->actingAs($this->member) ->get(route('member.article', $this->article)) ->assertOk() ->assertSee('Einstiegsfilm') ->assertDontSee('Alternativfilm'); $link = fn (ContentElementVersion $version): string => SignedLink::temporary('member.media', now()->addMinutes(10), [ 'article' => $this->article->id, 'release' => $this->release->id, 'version' => $version->id, 'action' => 'ansehen', 'reader' => $this->member->id, ]); $this->actingAs($this->member)->get($link($this->filmB))->assertForbidden(); } public function test_the_previous_state_refuses_to_publish_what_it_cannot_resolve(): void { try { app(ArticleService::class)->publishRelease($this->article->fresh(), $this->module, 'Neuer Stand im alten Programmstand.'); $this->fail('Ein Stand mit unbekanntem Bestandteil darf hier nicht entstehen.'); } catch (DomainRuleException $exception) { $this->assertStringContainsString('Programmstand', $exception->getMessage()); } $this->assertSame(1, $this->article->releases()->count()); $other = app(ContentService::class)->createComposition('Anderes Modul', CompositionKind::Uebung); $this->expectException(DomainRuleException::class); app(ContentService::class)->publishComposition($other, [['role' => 'Übung', 'target' => $this->exercise]]); } public function test_an_offer_is_not_activated_for_a_structure_with_an_unknown_part(): void { $offers = app(OfferService::class); $rights = $offers->createRightsProfile('Film', 'ehrenamtlich', ['film' => ['streamen']]); $offer = $offers->create('Angebot mit Übung'); $this->expectException(DomainRuleException::class); $this->expectExceptionMessage('Programmstand'); $offers->activate($offer, [['target' => $this->article->fresh(), 'rights' => $rights]], [ 'grant_kind' => 'auf_abruf', 'composition_version_id' => $this->module->id, ]); } public function test_the_editor_of_a_structure_with_an_unknown_part_is_read_only_and_loses_nothing(): void { $module = Composition::query()->findOrFail($this->module->composition_id); $versions = $module->versions()->count(); $members = DB::table('composition_members')->where('composition_version_id', $this->module->id)->count(); $component = Livewire::actingAs($this->editor(), 'staff') ->test(EditExercise::class, ['record' => $module->getKey()]) ->assertOk() ->assertSee('neueren Programmversion'); $this->assertNotNull($component->instance()->schreibschutz()); $component->call('saveDraft'); $this->assertNull($module->fresh()->working_draft, 'Es wird kein Entwurf geschrieben, der den Bestandteil auslässt.'); $component->call('armRelease')->assertSet('releaseArmed', false); $this->assertFalse($component->instance()->publishRevision()); $component->call('discardDraft'); $this->assertSame($versions, $module->versions()->count()); $this->assertSame($members, DB::table('composition_members')->where('composition_version_id', $this->module->id)->count()); } public function test_an_editor_with_only_known_parts_still_saves(): void { $content = app(ContentService::class); $film = $content->publishElementVersion($content->createElement('film', 'film', 'Kurzfilm'), null, ['file' => 'inhalte/kurz.mp4']); $plain = $content->createComposition('Normales Modul', CompositionKind::Uebung); $content->publishComposition($plain, [['role' => 'Film', 'target' => $film]]); $component = Livewire::actingAs($this->editor(), 'staff') ->test(EditExercise::class, ['record' => $plain->getKey()]) ->assertOk(); $this->assertNull($component->instance()->schreibschutz()); $component->call('saveDraft'); $this->assertNotNull($plain->fresh()->working_draft); } public function test_the_staff_pages_around_the_structure_render_without_naming_the_unknown_part(): void { Livewire::actingAs($this->editor(), 'staff') ->test(ViewContentElement::class, ['record' => $this->filmA->content_element_id]) ->assertOk() ->assertDontSee('Übung neuerer Stand'); $keeper = User::factory()->katalogverwalter()->create(); $keeper->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP'); Livewire::actingAs($keeper, 'staff') ->test(ViewLicenseArticle::class, ['record' => $this->article->getKey()]) ->assertOk() ->assertDontSee('Übung neuerer Stand'); } public function test_the_public_site_does_not_know_the_unknown_composition(): void { $this->get(route('public.program', $this->exercise->composition_id))->assertNotFound(); $this->get(route('public.programs'))->assertOk()->assertDontSee('Übung neuerer Stand'); } /** * Ein Modul mit einer verschachtelten Übung, deren Fassung zwei Filmvarianten und einen Text enthält. Veröffentlicht * wird nur die Variante A samt Text. Danach bekommt die Übung den Wert, den erst der neue Stand schreibt. */ private function buildProduct(): void { $content = app(ContentService::class); $this->filmA = $content->publishElementVersion($content->createElement('film', 'film', 'Einstiegsfilm'), null, ['file' => 'inhalte/a.mp4']); $this->filmB = $content->publishElementVersion($content->createElement('film', 'film', 'Alternativfilm'), null, ['file' => 'inhalte/b.mp4']); $this->text = $content->publishElementVersion($content->createElement('text', 'text', 'Durchführungstext'), 'Erst aufwärmen, dann üben.'); $this->exercise = $content->publishComposition( $content->createComposition('Übung neuerer Stand', CompositionKind::Kombination), [ ['role' => 'Einstieg Variante A', 'target' => $this->filmA], ['role' => 'Einstieg Variante B', 'target' => $this->filmB], ['role' => 'Durchführung', 'target' => $this->text], ], null, null, ['learning_goal' => 'Nein sagen üben'], ); $kind = EditorialContentKind::query()->where('slug', 'modul')->firstOrFail(); $module = $content->createComposition('Modul mit Übung', CompositionKind::Uebung); $module->editorial_content_kind_id = $kind->id; $module->save(); $this->module = $content->publishComposition($module, [['role' => 'Übung', 'target' => $this->exercise]]); $articles = app(ArticleService::class); $this->article = $articles->create('modul-mit-uebung'); $this->release = $articles->publishRelease($this->article, $this->module, 'Modul mit Übung.'); // Gewählt ist nur Variante A: Der Stand schreibt Film B nicht fest. DB::table('release_contents') ->where('article_release_id', $this->release->id) ->where('content_element_version_id', $this->filmB->id) ->delete(); $offers = app(OfferService::class); $rights = $offers->createRightsProfile('Film und Text', 'ehrenamtlich', ['film' => ['streamen', 'laden'], 'text' => ['ansehen']]); $offer = $offers->create('Zugang'); $offers->activate($offer, [['target' => $this->article->fresh(), 'rights' => $rights]], ['grant_kind' => 'auf_abruf']); $this->member = User::factory()->create(); app(GrantIssuer::class)->claim($this->member, $offer); app(CompositionDisplayRelease::class)->release($this->module, $this->member); DB::table('compositions')->where('id', $this->exercise->composition_id)->update(['kind' => self::FOREIGN]); } private function editor(): User { $editor = User::factory()->redakteur()->create(); $editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP'); return $editor; } }