10, 'label' => 'Einstieg', 'stop' => false, 'prompt' => ''], ['t' => 42, 'label' => 'Entscheidung', 'stop' => true, 'prompt' => 'Was würdest du jetzt tun?'], ]; private ContentService $content; private ArticleService $articles; private OfferService $offers; /** @var array */ private array $offerOf = []; protected function setUp(): void { parent::setUp(); $this->content = app(ContentService::class); $this->articles = app(ArticleService::class); $this->offers = app(OfferService::class); } /** * @param array $metadata * @return array{film: ContentElementVersion, program: Composition, article: LicenseArticle} */ private function scenario(array $metadata, string $output = 'film'): array { $film = $this->content->publishElementVersion( $this->content->createElement($output, $output, 'Lara im Park'), null, ['file' => 'inhalte/park.mp4'] + $metadata, ); $kind = EditorialContentKind::query()->where('slug', 'programm')->firstOrFail(); $program = $this->content->publishComposition( tap($this->content->createComposition('Grenzen erkennen'), function (Composition $item) use ($kind): void { $item->editorial_content_kind_id = $kind->id; $item->save(); }), [['role' => 'Film', 'target' => $film]], ); app(CompositionDisplayRelease::class)->release($program, User::factory()->create()); $article = $this->articles->create('programm-b'); $this->articles->publishRelease($article, $program, 'Programm.'); return ['film' => $film, 'program' => $program->composition, 'article' => $article->fresh()]; } /** * @param list $actions */ private function memberWith(LicenseArticle $article, array $actions, string $class = 'film'): User { $rights = $this->offers->createRightsProfile('Recht '.implode('-', $actions), 'ehrenamtlich', [$class => $actions]); $offer = $this->offers->create('Angebot '.implode('-', $actions)); $this->offers->activate($offer, [['target' => $article, 'rights' => $rights]], ['grant_kind' => 'auf_abruf']); $member = User::factory()->create(); app(GrantIssuer::class)->claim($member, $offer); return $member; } /** * Die Marken aus dem Attribut `data-markers` des (einzigen) Videos der Seite, oder null ohne Attribut. * * @return list>|null */ private function markersIn(string $html): ?array { if (preg_match('#]*\sdata-markers="([^"]*)"#', $html, $match) !== 1) { return null; } return json_decode(html_entity_decode($match[1], ENT_QUOTES), true); } private function contentPage(array $scenario, User $member) { return $this->actingAs($member)->get(route('member.content', [ 'composition' => $scenario['program']->id, 'version' => $scenario['film']->id, ])); } public function test_the_program_page_delivers_the_markers_to_a_member_who_may_stream(): void { $scenario = $this->scenario(['markers' => self::MARKERS]); $member = $this->memberWith($scenario['article'], ['streamen']); $page = $this->contentPage($scenario, $member)->assertOk(); $this->assertEquals(self::MARKERS, $this->markersIn($page->getContent())); } public function test_the_article_page_delivers_the_markers_to_a_member_who_may_stream(): void { $scenario = $this->scenario(['markers' => self::MARKERS]); $member = $this->memberWith($scenario['article'], ['streamen']); $page = $this->actingAs($member)->get(route('member.article', $scenario['article']))->assertOk(); $this->assertEquals(self::MARKERS, $this->markersIn($page->getContent())); } public function test_the_legacy_decision_value_arrives_as_one_stop_marker(): void { $scenario = $this->scenario(['decision_seconds' => 12]); $member = $this->memberWith($scenario['article'], ['streamen']); $expected = [['t' => 12, 'label' => 'Entscheidung', 'stop' => true, 'prompt' => '']]; $this->assertEquals($expected, $this->markersIn($this->contentPage($scenario, $member)->getContent())); $this->assertEquals($expected, $this->markersIn($this->actingAs($member)->get(route('member.article', $scenario['article']))->getContent())); } public function test_an_explicitly_empty_list_delivers_nothing_even_with_a_legacy_value(): void { $scenario = $this->scenario(['markers' => [], 'decision_seconds' => 12]); $member = $this->memberWith($scenario['article'], ['streamen']); $this->assertNull($this->markersIn($this->contentPage($scenario, $member)->assertOk()->getContent())); $this->assertNull($this->markersIn($this->actingAs($member)->get(route('member.article', $scenario['article']))->getContent())); } public function test_a_film_without_markers_has_no_attribute(): void { $scenario = $this->scenario([]); $member = $this->memberWith($scenario['article'], ['streamen']); $page = $this->contentPage($scenario, $member)->assertOk(); $this->assertStringContainsString('getContent()); $this->assertStringNotContainsString('data-markers', $page->getContent()); } public function test_a_member_without_the_right_to_stream_gets_no_label_and_no_prompt(): void { $scenario = $this->scenario(['markers' => self::MARKERS]); // Nur Herunterladen: kein Streamen, also weder Player noch Marken. $member = $this->memberWith($scenario['article'], ['laden']); $program = $this->contentPage($scenario, $member); $article = $this->actingAs($member)->get(route('member.article', $scenario['article'])); foreach ([$program, $article] as $page) { $page->assertDontSee('Entscheidung') ->assertDontSee('Was würdest du jetzt tun?') ->assertDontSee('Einstieg'); $this->assertStringNotContainsString('data-markers', $page->getContent()); } } public function test_a_stranger_gets_no_markers(): void { $scenario = $this->scenario(['markers' => self::MARKERS]); $page = $this->contentPage($scenario, User::factory()->create()); $page->assertForbidden()->assertDontSee('Was würdest du jetzt tun?'); $this->assertStringNotContainsString('data-markers', $page->getContent()); } public function test_audio_never_carries_markers(): void { $scenario = $this->scenario(['markers' => self::MARKERS], 'audio'); $member = $this->memberWith($scenario['article'], ['streamen'], 'audio'); $page = $this->contentPage($scenario, $member)->assertOk(); $this->assertStringNotContainsString('data-markers', $page->getContent()); $page->assertDontSee('Was würdest du jetzt tun?'); } public function test_texts_of_markers_cannot_break_out_of_the_attribute(): void { $scenario = $this->scenario(['markers' => [ ['t' => 5, 'label' => '">', 'stop' => true, 'prompt' => "Zeile 1\nZeile 2 & fett"], ]]); $member = $this->memberWith($scenario['article'], ['streamen']); $page = $this->contentPage($scenario, $member)->assertOk(); $markers = $this->markersIn($page->getContent()); $this->assertStringNotContainsString('', $page->getContent()); $this->assertSame('">', $markers[0]['label'] ?? null, 'Der Text kommt unverändert an; das Skript setzt ihn nur als Text ein.'); } }