Die Marken einer Fassung gehen als data-markers an das Video der Programm- und der Artikelseite, nur an Konten, die den Film streamen dürfen. player/member.js baut daraus Kapitelliste, den Schalter „Automatische Stopps“ (je Gerät gemerkt) und die Halt-Karte mit „Weiter“ und „Szene erneut“; das Anhalten nutzt dasselbe autostop.js wie die Vorschau der Redaktion. Das Vollbild geht bei Filmen mit Marken auf den Container, damit die Karte sichtbar bleibt; im nativen Videovollbild (Safari, iPhone) verlässt der Stopp das Vollbild. Verhaltensänderung: Der Altwert decision_seconds wurde nie ausgeliefert, hält Filme jetzt aber als Stoppmarke „Entscheidung“ an. CoursePlayerTest behält die Prüfung auf die entfallene Schaltfläche und belegt zusätzlich die gelieferte Marke. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
215 lines
8.6 KiB
PHP
215 lines
8.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Domain\Catalog\ArticleService;
|
|
use App\Domain\Catalog\Composition;
|
|
use App\Domain\Catalog\CompositionDisplayRelease;
|
|
use App\Domain\Catalog\ContentElementVersion;
|
|
use App\Domain\Catalog\ContentService;
|
|
use App\Domain\Catalog\EditorialContentKind;
|
|
use App\Domain\Catalog\LicenseArticle;
|
|
use App\Domain\Catalog\Offer;
|
|
use App\Domain\Catalog\OfferService;
|
|
use App\Domain\Entitlement\GrantIssuer;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Marken im Mitglieder-Player: Der Server liefert sie als `data-markers` am Video, auf beiden Wegen zum Film (Artikel- und
|
|
* Programmseite), und nur an Konten, die den Film streamen dürfen. Anzeige, Autostopp und Vollbild prüft die Abnahme im Browser.
|
|
*/
|
|
class MemberPlayerMarkersTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private const MARKERS = [
|
|
['t' => 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<int, Offer> */
|
|
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<string, mixed> $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<string> $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<array<string, mixed>>|null
|
|
*/
|
|
private function markersIn(string $html): ?array
|
|
{
|
|
if (preg_match('#<video[^>]*\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('<video', $page->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' => '"><script>alert(1)</script>', 'stop' => true, 'prompt' => "Zeile 1\nZeile 2 & <b>fett</b>"],
|
|
]]);
|
|
$member = $this->memberWith($scenario['article'], ['streamen']);
|
|
|
|
$page = $this->contentPage($scenario, $member)->assertOk();
|
|
$markers = $this->markersIn($page->getContent());
|
|
|
|
$this->assertStringNotContainsString('<script>alert(1)</script>', $page->getContent());
|
|
$this->assertSame('"><script>alert(1)</script>', $markers[0]['label'] ?? null, 'Der Text kommt unverändert an; das Skript setzt ihn nur als Text ein.');
|
|
}
|
|
}
|