CI Feature / test (push) Successful in 5m40s
Die Marken eines Films liegen als metadata['markers'] an der Fassung. Bis eine
Fassung entsteht, gibt es einen Arbeitsstand in content_elements.marker_draft
(neue, leere Spalte, rückwärtskompatibel): { base_version, markers, saved_at }.
Mitglieder sehen ihn nie, und er wird nicht gesondert protokolliert.
- FilmMarkers prüft und vereinheitlicht (Zeit auf 0,1 s, Titel, Mindestabstand
1 s, höchstens 100) und liest gespeicherte Daten reparierend. Der Altwert
decision_seconds gilt nur, solange der Schlüssel markers fehlt; eine
gelöschte Liste bringt ihn nicht zurück.
- MarkerDraft speichert den Arbeitsstand gegen gleichzeitiges Speichern
(saved_at als Marke) und räumt nur den Stand ab, der gelesen wurde.
- ContentService übernimmt die Marken der bisherigen Fassung, wenn eine Fassung
mit Datei ohne Marken angelegt wird. Vorher ging jede Fassung aus anderem
Anlass (Text, Notiz, neue Datei) ohne Marken hervor, weil die Aufrufer die
Metadaten selbst zusammenstellen.
- ElementRevision wendet den Arbeitsstand an. Eine Änderung nur an den Marken
zählt als Änderung, ohne Datei entsteht keine Fassung nur aus Marken.
Das Formularfeld decision_seconds entfällt.
Bewusste Änderung eines Tests: test_an_uploaded_file_becomes_a_ready_version
setzte decision_seconds über das Formular; der Wert kommt jetzt als Marke aus
dem Arbeitsstand.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
138 lines
5.2 KiB
PHP
138 lines
5.2 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use App\Domain\Catalog\ContentElementVersion;
|
|
use App\Domain\Catalog\DomainRuleException;
|
|
use App\Domain\Media\FilmMarkers;
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class FilmMarkersTest extends TestCase
|
|
{
|
|
private function version(?array $metadata): ContentElementVersion
|
|
{
|
|
return new ContentElementVersion(['metadata' => $metadata]);
|
|
}
|
|
|
|
public function test_a_list_is_normalized_to_one_canonical_form(): void
|
|
{
|
|
$list = FilmMarkers::normalize([
|
|
['t' => '30', 'label' => ' Kapitel zwei ', 'stop' => false],
|
|
['t' => 10.04, 'label' => 'Entscheidung', 'stop' => true, 'prompt' => ' Was fällt auf? '],
|
|
]);
|
|
|
|
$this->assertSame([
|
|
['t' => 10.0, 'label' => 'Entscheidung', 'stop' => true, 'prompt' => 'Was fällt auf?'],
|
|
['t' => 30.0, 'label' => 'Kapitel zwei', 'stop' => false, 'prompt' => ''],
|
|
], $list);
|
|
}
|
|
|
|
public function test_the_same_time_written_differently_is_the_same_list(): void
|
|
{
|
|
$a = FilmMarkers::normalize([['t' => 42, 'label' => 'A']]);
|
|
$b = FilmMarkers::normalize([['t' => 42.0, 'label' => 'A']]);
|
|
$c = FilmMarkers::normalize([['t' => '42.04', 'label' => 'A']]);
|
|
|
|
$this->assertTrue(FilmMarkers::same($a, $b));
|
|
$this->assertTrue(FilmMarkers::same($a, $c));
|
|
$this->assertSame(json_encode($a), json_encode($b));
|
|
}
|
|
|
|
public function test_an_empty_list_is_valid_and_means_no_markers(): void
|
|
{
|
|
$this->assertSame([], FilmMarkers::normalize([]));
|
|
}
|
|
|
|
/**
|
|
* @return array<string, array{0: mixed, 1: string}>
|
|
*/
|
|
public static function invalidLists(): array
|
|
{
|
|
return [
|
|
'keine Liste' => ['abc', 'Liste'],
|
|
'negative Zeit' => [[['t' => -1, 'label' => 'A']], 'Zeit'],
|
|
'Zeit ist Text' => [[['t' => 'bald', 'label' => 'A']], 'Zeit'],
|
|
'Zeit fehlt' => [[['label' => 'A']], 'Zeit'],
|
|
'Titel fehlt' => [[['t' => 5, 'label' => ' ']], 'Titel'],
|
|
'Titel zu lang' => [[['t' => 5, 'label' => str_repeat('x', 121)]], 'Titel'],
|
|
'Text zu lang' => [[['t' => 5, 'label' => 'A', 'prompt' => str_repeat('x', 1001)]], 'Text'],
|
|
'zu dicht' => [[['t' => 10, 'label' => 'A'], ['t' => 10.5, 'label' => 'B']], 'Abstand'],
|
|
'zwei gleiche Zeiten' => [[['t' => 10, 'label' => 'A'], ['t' => 10.04, 'label' => 'B']], 'Abstand'],
|
|
'Eintrag ist keine Marke' => [['x'], 'Marke'],
|
|
];
|
|
}
|
|
|
|
#[DataProvider('invalidLists')]
|
|
public function test_invalid_lists_are_refused_with_a_reason(mixed $raw, string $word): void
|
|
{
|
|
try {
|
|
FilmMarkers::normalize($raw);
|
|
$this->fail('Die Liste hätte abgelehnt werden müssen.');
|
|
} catch (DomainRuleException $e) {
|
|
$this->assertStringContainsString($word, $e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function test_more_than_a_hundred_markers_are_refused(): void
|
|
{
|
|
$list = [];
|
|
|
|
for ($i = 0; $i < 101; $i++) {
|
|
$list[] = ['t' => $i * 2, 'label' => 'M'.$i];
|
|
}
|
|
|
|
$this->expectException(DomainRuleException::class);
|
|
FilmMarkers::normalize($list);
|
|
}
|
|
|
|
public function test_a_version_without_any_marker_data_has_none(): void
|
|
{
|
|
$this->assertSame([], FilmMarkers::ofVersion(null));
|
|
$this->assertSame([], FilmMarkers::ofVersion($this->version(null)));
|
|
$this->assertSame([], FilmMarkers::ofVersion($this->version(['file' => 'x.mp4'])));
|
|
}
|
|
|
|
public function test_the_old_decision_value_reads_as_one_stop_marker(): void
|
|
{
|
|
$this->assertSame(
|
|
[['t' => 12.0, 'label' => 'Entscheidung', 'stop' => true, 'prompt' => '']],
|
|
FilmMarkers::ofVersion($this->version(['decision_seconds' => 12])),
|
|
);
|
|
}
|
|
|
|
public function test_an_old_decision_value_of_zero_is_no_marker(): void
|
|
{
|
|
$this->assertSame([], FilmMarkers::ofVersion($this->version(['decision_seconds' => 0])));
|
|
}
|
|
|
|
public function test_the_markers_key_wins_even_when_it_is_empty(): void
|
|
{
|
|
$this->assertSame([], FilmMarkers::ofVersion($this->version(['markers' => [], 'decision_seconds' => 12])));
|
|
$this->assertCount(1, FilmMarkers::ofVersion($this->version([
|
|
'markers' => [['t' => 5, 'label' => 'A', 'stop' => false, 'prompt' => '']],
|
|
'decision_seconds' => 12,
|
|
])));
|
|
}
|
|
|
|
public function test_stored_data_that_became_unreadable_is_repaired_instead_of_breaking_the_page(): void
|
|
{
|
|
$list = FilmMarkers::ofVersion($this->version(['markers' => [
|
|
['t' => 20, 'label' => 'B', 'stop' => false],
|
|
['t' => -3, 'label' => 'kaputt'],
|
|
'müll',
|
|
['t' => 20.2, 'label' => 'zu dicht'],
|
|
['t' => 5, 'label' => 'A', 'stop' => true],
|
|
]]));
|
|
|
|
$this->assertSame(['A', 'B'], array_column($list, 'label'));
|
|
}
|
|
|
|
public function test_the_presence_of_the_markers_key_is_detectable(): void
|
|
{
|
|
$this->assertTrue(FilmMarkers::hasMarkers($this->version(['markers' => []])));
|
|
$this->assertFalse(FilmMarkers::hasMarkers($this->version(['decision_seconds' => 3])));
|
|
$this->assertFalse(FilmMarkers::hasMarkers(null));
|
|
}
|
|
}
|