Führe Marken an der Filmfassung und einen Arbeitsstand am Element ein
CI Feature / test (push) Successful in 5m40s
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>
This commit is contained in:
1 parent
e91c7f7ebb
commit
3c809b6cc8
10 files changed
+972
-22
No files matched your search
@@ -28,6 +28,7 @@ class ContentElement extends Model
|
||||
'thumbnail_alt',
|
||||
'thumbnail_source',
|
||||
'thumbnail_error',
|
||||
'marker_draft',
|
||||
'preview_path',
|
||||
'editorial_content_kind_id',
|
||||
'archived_at',
|
||||
@@ -40,6 +41,7 @@ protected function casts(): array
|
||||
return [
|
||||
'archived_at' => 'datetime',
|
||||
'website_released_at' => 'datetime',
|
||||
'marker_draft' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
use App\Domain\Media\FilmMarkers;
|
||||
use App\Domain\Media\MediaRendition;
|
||||
use App\Jobs\StoreContentFile;
|
||||
use App\Models\User;
|
||||
@@ -58,6 +59,7 @@ public function publishElementVersion(
|
||||
}
|
||||
|
||||
$number = ((int) $element->versions()->max('number')) + 1;
|
||||
$metadata = $this->withCarriedMarkers($element, $metadata);
|
||||
$incoming = $metadata['incoming'] ?? null;
|
||||
$version = $element->versions()->create([
|
||||
'number' => $number,
|
||||
@@ -82,6 +84,35 @@ public function publishElementVersion(
|
||||
return $version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Eine Fassung mit Datei übernimmt die Marken der bisherigen neuesten Fassung, wenn der Aufrufer keine nennt. Sonst
|
||||
* ginge jede Fassung aus anderem Anlass (Text, Notiz, neue Datei) still ohne Marken hervor, weil die Aufrufer die
|
||||
* Metadaten selbst zusammenstellen. Eine ausdrücklich genannte Liste, auch eine leere, gilt unverändert.
|
||||
* Der Altwert `decision_seconds` wird dabei einmal zu einer Marke umgesetzt und nicht erneut geschrieben.
|
||||
*
|
||||
* @param array<string, mixed> $metadata
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function withCarriedMarkers(ContentElement $element, array $metadata): array
|
||||
{
|
||||
$hasFile = (is_string($metadata['file'] ?? null) && $metadata['file'] !== '')
|
||||
|| (is_string($metadata['incoming'] ?? null) && $metadata['incoming'] !== '');
|
||||
|
||||
if (! $hasFile || array_key_exists('markers', $metadata)) {
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
$latest = $element->versions()->orderByDesc('number')->first();
|
||||
$markers = FilmMarkers::ofVersion($latest);
|
||||
|
||||
if ($markers !== [] || FilmMarkers::hasMarkers($latest)) {
|
||||
$metadata['markers'] = $markers;
|
||||
unset($metadata['decision_seconds']);
|
||||
}
|
||||
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
public function draftElementVersion(
|
||||
ContentElement $element,
|
||||
?string $body = null,
|
||||
|
||||
@@ -0,0 +1,240 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Media;
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
|
||||
/**
|
||||
* Marken eines Films: Sprungmarken und Stopps an der Filmfassung (`metadata['markers']`).
|
||||
*
|
||||
* Eine Marke: t (Sekunden, auf 0,1 gerundet), label (Titel), stop (hält die Wiedergabe an), prompt (einfacher Text,
|
||||
* optional). Kapitel sind Marken ohne stop. Eine Liste je Fassung, kein zweites Feld.
|
||||
*
|
||||
* Eine Stelle löst die Altlast auf: Der frühere Einzelwert `decision_seconds` gilt nur, solange die Fassung den
|
||||
* Schlüssel `markers` nicht hat. Hat sie ihn (auch leer), zählt er allein, damit gelöschte Marken nicht zurückkehren.
|
||||
*
|
||||
* Prüfen und Reparieren sind getrennt: `normalize` lehnt Fehler ab (Speichern), `ofVersion` repariert gespeicherte
|
||||
* Daten, damit eine beschädigte Liste nie eine Seite zerstört (Lesen).
|
||||
*/
|
||||
final class FilmMarkers
|
||||
{
|
||||
public const LEGACY_LABEL = 'Entscheidung';
|
||||
|
||||
public const MIN_GAP = 1.0;
|
||||
|
||||
public const MAX_MARKERS = 100;
|
||||
|
||||
public const MAX_LABEL = 120;
|
||||
|
||||
public const MAX_PROMPT = 1000;
|
||||
|
||||
/**
|
||||
* Prüft und vereinheitlicht eine Liste zum Speichern.
|
||||
*
|
||||
* @return list<array{t: float, label: string, stop: bool, prompt: string}>
|
||||
*
|
||||
* @throws DomainRuleException
|
||||
*/
|
||||
public static function normalize(mixed $raw): array
|
||||
{
|
||||
if (! is_array($raw)) {
|
||||
throw new DomainRuleException('Die Marken müssen als Liste vorliegen.');
|
||||
}
|
||||
|
||||
if (count($raw) > self::MAX_MARKERS) {
|
||||
throw new DomainRuleException('Ein Film kann höchstens '.self::MAX_MARKERS.' Marken haben.');
|
||||
}
|
||||
|
||||
$list = [];
|
||||
|
||||
foreach (array_values($raw) as $index => $entry) {
|
||||
$list[] = self::one($entry, $index + 1);
|
||||
}
|
||||
|
||||
usort($list, fn (array $a, array $b): int => $a['t'] <=> $b['t']);
|
||||
|
||||
for ($i = 1; $i < count($list); $i++) {
|
||||
if ($list[$i]['t'] - $list[$i - 1]['t'] < self::MIN_GAP - 1e-9) {
|
||||
throw new DomainRuleException(
|
||||
'Zwei Marken brauchen mindestens '.self::format(self::MIN_GAP).' Sekunde Abstand ('
|
||||
.self::format($list[$i - 1]['t']).' s und '.self::format($list[$i]['t']).' s).',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Marken, die zu einer Fassung gehören, so wie sie angezeigt und ausgeliefert werden.
|
||||
*
|
||||
* @return list<array{t: float, label: string, stop: bool, prompt: string}>
|
||||
*/
|
||||
public static function ofVersion(?ContentElementVersion $version): array
|
||||
{
|
||||
$metadata = is_array($version?->metadata) ? $version->metadata : [];
|
||||
|
||||
if (array_key_exists('markers', $metadata)) {
|
||||
return is_array($metadata['markers']) ? self::repair($metadata['markers']) : [];
|
||||
}
|
||||
|
||||
$legacy = $metadata['decision_seconds'] ?? null;
|
||||
|
||||
if (is_numeric($legacy) && (float) $legacy > 0) {
|
||||
return [['t' => self::round((float) $legacy), 'label' => self::LEGACY_LABEL, 'stop' => true, 'prompt' => '']];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/** Ob die Fassung die Marken ausdrücklich führt (auch als leere Liste). */
|
||||
public static function hasMarkers(?ContentElementVersion $version): bool
|
||||
{
|
||||
return is_array($version?->metadata) && array_key_exists('markers', $version->metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array<string, mixed>> $a
|
||||
* @param list<array<string, mixed>> $b
|
||||
*/
|
||||
public static function same(array $a, array $b): bool
|
||||
{
|
||||
return json_encode(self::repair($a)) === json_encode(self::repair($b));
|
||||
}
|
||||
|
||||
/**
|
||||
* Hinweis nach einer neuen Datei: Die Fassung hat eine andere Datei als davor, die Marken sind seither aber
|
||||
* unverändert und nicht leer. Sie stammen dann vom alten Film und müssen geprüft werden. Nichts davon wird
|
||||
* gespeichert, es folgt aus den Fassungen.
|
||||
*/
|
||||
public static function fileChangedWithoutMarkers(ContentElement $element): bool
|
||||
{
|
||||
$versions = $element->versions()->orderByDesc('number')->get();
|
||||
$latest = $versions->first();
|
||||
|
||||
if ($latest === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$markers = self::ofVersion($latest);
|
||||
|
||||
if ($markers === []) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($versions->values() as $position => $version) {
|
||||
$previous = $versions->get($position + 1);
|
||||
|
||||
if ($previous === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! self::same(self::ofVersion($version), $markers)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (self::fileOf($version) !== self::fileOf($previous)) {
|
||||
return self::same(self::ofVersion($previous), $markers);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zeit wie angezeigt: ohne überflüssige Nachkommastelle, mit Komma.
|
||||
*/
|
||||
public static function format(float $seconds): string
|
||||
{
|
||||
$text = number_format(self::round($seconds), 1, ',', '');
|
||||
|
||||
return str_ends_with($text, ',0') ? substr($text, 0, -2) : $text;
|
||||
}
|
||||
|
||||
public static function round(float $seconds): float
|
||||
{
|
||||
return round($seconds, 1);
|
||||
}
|
||||
|
||||
private static function fileOf(ContentElementVersion $version): ?string
|
||||
{
|
||||
$file = is_array($version->metadata) ? ($version->metadata['file'] ?? null) : null;
|
||||
|
||||
return is_string($file) && $file !== '' ? $file : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{t: float, label: string, stop: bool, prompt: string}
|
||||
*/
|
||||
private static function one(mixed $entry, int $number): array
|
||||
{
|
||||
if (! is_array($entry)) {
|
||||
throw new DomainRuleException('Marke '.$number.' ist keine gültige Marke.');
|
||||
}
|
||||
|
||||
$time = $entry['t'] ?? null;
|
||||
|
||||
if (! is_numeric($time) || ! is_finite((float) $time) || (float) $time < 0) {
|
||||
throw new DomainRuleException('Marke '.$number.': Die Zeit muss eine Zahl ab 0 Sekunden sein.');
|
||||
}
|
||||
|
||||
$label = trim((string) ($entry['label'] ?? ''));
|
||||
|
||||
if ($label === '' || mb_strlen($label) > self::MAX_LABEL) {
|
||||
throw new DomainRuleException('Marke '.$number.': Der Titel braucht 1 bis '.self::MAX_LABEL.' Zeichen.');
|
||||
}
|
||||
|
||||
$prompt = trim((string) ($entry['prompt'] ?? ''));
|
||||
|
||||
if (mb_strlen($prompt) > self::MAX_PROMPT) {
|
||||
throw new DomainRuleException('Marke '.$number.': Der Text darf höchstens '.self::MAX_PROMPT.' Zeichen haben.');
|
||||
}
|
||||
|
||||
return [
|
||||
't' => self::round((float) $time),
|
||||
'label' => $label,
|
||||
'stop' => ($entry['stop'] ?? false) === true,
|
||||
'prompt' => $prompt,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Lesen ohne Ausnahmen: Unbrauchbares entfällt, zu dichte Marken weichen der früheren.
|
||||
*
|
||||
* @param array<int|string, mixed> $raw
|
||||
* @return list<array{t: float, label: string, stop: bool, prompt: string}>
|
||||
*/
|
||||
private static function repair(array $raw): array
|
||||
{
|
||||
$valid = [];
|
||||
|
||||
foreach ($raw as $entry) {
|
||||
try {
|
||||
$valid[] = self::one($entry, 0);
|
||||
} catch (DomainRuleException) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
usort($valid, fn (array $a, array $b): int => $a['t'] <=> $b['t']);
|
||||
$result = [];
|
||||
|
||||
foreach ($valid as $marker) {
|
||||
$last = $result === [] ? null : $result[count($result) - 1];
|
||||
|
||||
if ($last !== null && self::MIN_GAP - 1e-9 > $marker['t'] - $last['t']) {
|
||||
if ($marker['stop'] && ! $last['stop']) {
|
||||
$result[count($result) - 1] = $marker;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$result[] = $marker;
|
||||
}
|
||||
|
||||
return array_slice($result, 0, self::MAX_MARKERS);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Media;
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* Arbeitsstand der Marken eines Films, bevor eine Fassung entsteht.
|
||||
*
|
||||
* Er liegt als Objekt in `content_elements.marker_draft`: { base_version, markers, saved_at }. `null` heißt: kein
|
||||
* Arbeitsstand, es gelten die Marken der neuesten Fassung. Ein Arbeitsstand mit leerer Liste heißt ausdrücklich
|
||||
* „alle Marken löschen“ und darf deshalb nie mit empty() oder filled() geprüft werden.
|
||||
*
|
||||
* Mitglieder sehen den Arbeitsstand nie. Er wird auch nicht gesondert protokolliert: Das Protokoll liefert die
|
||||
* Fassung. `saved_at` dient als Marke gegen gleichzeitiges Speichern (nicht `updated_at` des Elements, das sich bei
|
||||
* jedem Redaktionsspeichern ändert).
|
||||
*/
|
||||
class MarkerDraft
|
||||
{
|
||||
/**
|
||||
* @return array{base_version: int, markers: list<array<string, mixed>>, saved_at: string}|null
|
||||
*/
|
||||
public function current(ContentElement $element): ?array
|
||||
{
|
||||
$stored = ContentElement::query()->whereKey($element->getKey())->value('marker_draft');
|
||||
|
||||
return $this->read($stored);
|
||||
}
|
||||
|
||||
/**
|
||||
* Die Marken, mit denen die Redaktion gerade arbeitet: Arbeitsstand, sonst neueste Fassung.
|
||||
*
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
public function effective(ContentElement $element): array
|
||||
{
|
||||
$draft = $this->current($element);
|
||||
|
||||
if ($draft !== null) {
|
||||
return FilmMarkers::normalize($draft['markers']);
|
||||
}
|
||||
|
||||
return FilmMarkers::ofVersion($element->versions()->orderByDesc('number')->first());
|
||||
}
|
||||
|
||||
/**
|
||||
* Speichert den Arbeitsstand. `$token` ist das `saved_at`, das der Aufrufer zuletzt gesehen hat (null: Er hat keinen
|
||||
* Arbeitsstand gesehen). Hat inzwischen jemand anders gespeichert, wird abgelehnt.
|
||||
*
|
||||
* @return array{base_version: int, markers: list<array<string, mixed>>, saved_at: string}
|
||||
*
|
||||
* @throws DomainRuleException
|
||||
*/
|
||||
public function save(ContentElement $element, mixed $markers, ?string $token): array
|
||||
{
|
||||
$normalized = FilmMarkers::normalize($markers);
|
||||
|
||||
return DB::transaction(function () use ($element, $normalized, $token): array {
|
||||
$row = ContentElement::query()->whereKey($element->getKey())->lockForUpdate()->firstOrFail();
|
||||
$existing = $this->read($row->getRawOriginal('marker_draft'));
|
||||
|
||||
if (($existing['saved_at'] ?? null) !== $token) {
|
||||
throw new DomainRuleException('Die Marken wurden inzwischen von jemand anderem gespeichert. Lade die Seite neu und prüfe den aktuellen Stand.');
|
||||
}
|
||||
|
||||
$draft = [
|
||||
'base_version' => (int) $row->versions()->max('number'),
|
||||
'markers' => $normalized,
|
||||
'saved_at' => Carbon::now()->format('Y-m-d\TH:i:s.u'),
|
||||
];
|
||||
$row->forceFill(['marker_draft' => $draft])->save();
|
||||
$element->setAttribute('marker_draft', $draft);
|
||||
|
||||
return $draft;
|
||||
});
|
||||
}
|
||||
|
||||
public function discard(ContentElement $element): void
|
||||
{
|
||||
ContentElement::query()->whereKey($element->getKey())->update(['marker_draft' => null]);
|
||||
$element->setAttribute('marker_draft', null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Räumt den Arbeitsstand ab, aber nur den, der gelesen wurde (`saved_at`). Hat inzwischen jemand neu gespeichert,
|
||||
* bleibt dessen Stand erhalten.
|
||||
*/
|
||||
public function discardIf(ContentElement $element, string $savedAt): void
|
||||
{
|
||||
DB::transaction(function () use ($element, $savedAt): void {
|
||||
$row = ContentElement::query()->whereKey($element->getKey())->lockForUpdate()->firstOrFail();
|
||||
$existing = $this->read($row->getRawOriginal('marker_draft'));
|
||||
|
||||
if ($existing !== null && $existing['saved_at'] === $savedAt) {
|
||||
$row->forceFill(['marker_draft' => null])->save();
|
||||
$element->setAttribute('marker_draft', null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{base_version: int, markers: list<array<string, mixed>>, saved_at: string}|null
|
||||
*/
|
||||
private function read(mixed $stored): ?array
|
||||
{
|
||||
if (is_string($stored)) {
|
||||
$stored = json_decode($stored, true);
|
||||
}
|
||||
|
||||
if (! is_array($stored) || ! array_key_exists('markers', $stored) || ! is_array($stored['markers'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
'base_version' => (int) ($stored['base_version'] ?? 0),
|
||||
'markers' => $stored['markers'],
|
||||
'saved_at' => (string) ($stored['saved_at'] ?? ''),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@
|
||||
use App\Domain\Catalog\RightsProfile;
|
||||
use App\Domain\Catalog\RightsProfileVersion;
|
||||
use App\Domain\Catalog\StatusValue;
|
||||
use App\Domain\Media\FilmMarkers;
|
||||
|
||||
class CatalogReading
|
||||
{
|
||||
@@ -239,8 +240,13 @@ public function elementVersions(ContentElement $element): array
|
||||
$lines[] = 'Die Datei wird noch übernommen.';
|
||||
}
|
||||
|
||||
if (is_numeric($metadata['decision_seconds'] ?? null)) {
|
||||
$lines[] = 'Entscheidungsmarke bei '.(int) $metadata['decision_seconds'].' Sekunden';
|
||||
$markers = FilmMarkers::ofVersion($version);
|
||||
|
||||
if ($markers !== []) {
|
||||
$stops = count(array_filter($markers, fn (array $marker): bool => $marker['stop']));
|
||||
$lines[] = count($markers).(count($markers) === 1 ? ' Marke' : ' Marken')
|
||||
.($stops > 0 ? ', davon '.$stops.' mit Stopp' : '').': '
|
||||
.implode(', ', array_map(fn (array $marker): string => FilmMarkers::format($marker['t']).' s '.$marker['label'], $markers));
|
||||
}
|
||||
|
||||
if (is_string($metadata['error'] ?? null) && $metadata['error'] !== '') {
|
||||
|
||||
@@ -3,11 +3,12 @@
|
||||
namespace App\Filament\Support;
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Catalog\EmbeddedImages;
|
||||
use App\Domain\Catalog\FormattedText;
|
||||
use App\Domain\Media\FilmMarkers;
|
||||
use App\Domain\Media\MarkerDraft;
|
||||
use App\Filament\Resources\ContentElements\Pages\EditContentElement;
|
||||
use Filament\Forms\Components\Component;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
@@ -32,24 +33,31 @@ public static function publish(ContentElement $record, array $data): string
|
||||
$metadata['file'] = $previousFile;
|
||||
}
|
||||
|
||||
$decision = is_numeric($data['decision_seconds'] ?? null) ? (int) $data['decision_seconds'] : null;
|
||||
// Marken: der Arbeitsstand, sonst die der neuesten Fassung. Der Arbeitsstand wird frisch gelesen, denn der
|
||||
// Datensatz der Seite kann älter sein. Ohne Datei in der neuen Fassung gibt es keine Marken.
|
||||
$drafts = app(MarkerDraft::class);
|
||||
$draft = $drafts->current($record);
|
||||
$hasFile = array_key_exists('incoming', $metadata) || array_key_exists('file', $metadata);
|
||||
$latestMarkers = FilmMarkers::ofVersion($latest);
|
||||
$markers = $draft !== null ? FilmMarkers::normalize($draft['markers']) : $latestMarkers;
|
||||
$markersChanged = ! FilmMarkers::same($markers, $latestMarkers);
|
||||
|
||||
if ($decision !== null) {
|
||||
$metadata['decision_seconds'] = $decision;
|
||||
if ($hasFile && ($draft !== null || $markers !== [] || FilmMarkers::hasMarkers($latest))) {
|
||||
$metadata['markers'] = $markers;
|
||||
}
|
||||
|
||||
$body = is_string($data['body'] ?? null) ? (FormattedText::canonical($data['body']) ?: null) : null;
|
||||
$note = is_string($data['change_note'] ?? null) ? $data['change_note'] : null;
|
||||
$previousDecision = is_array($latest?->metadata) && is_numeric($latest->metadata['decision_seconds'] ?? null)
|
||||
? (int) $latest->metadata['decision_seconds']
|
||||
: null;
|
||||
$changed = $incoming !== null
|
||||
|| $dropFile
|
||||
|| ! FormattedText::same($body, $latest?->body)
|
||||
|| $decision !== $previousDecision
|
||||
|| $markersChanged
|
||||
|| (is_string($note) && trim($note) !== '');
|
||||
|
||||
if (! $changed) {
|
||||
// Ein Arbeitsstand, der den Marken der Fassung gleicht, ist erledigt.
|
||||
self::settle($drafts, $record, $draft, $hasFile);
|
||||
|
||||
return 'Text und Datei sind gleich geblieben, deshalb gibt es keine neue Fassung.';
|
||||
}
|
||||
|
||||
@@ -58,6 +66,7 @@ public static function publish(ContentElement $record, array $data): string
|
||||
}
|
||||
|
||||
app(ContentService::class)->publishElementVersion($record, $body, $metadata, $note);
|
||||
self::settle($drafts, $record, $draft, $hasFile || $dropFile);
|
||||
|
||||
return $incoming !== null
|
||||
? 'Die neue Fassung ist angelegt. Die Datei wird übernommen; die bisherige Fassung bleibt.'
|
||||
@@ -77,11 +86,6 @@ public static function fields(ContentElement $element): array
|
||||
Toggle::make('drop_file')
|
||||
->label('Datei in der neuen Fassung nicht mehr verwenden')
|
||||
->visible(fn (): bool => is_string(self::fileOf($element))),
|
||||
TextInput::make('decision_seconds')
|
||||
->label('Entscheidungsmarke in Sekunden')
|
||||
->numeric()
|
||||
->minValue(0)
|
||||
->default(self::decisionOf($latest)),
|
||||
TextInput::make('change_note')->label('Änderungsnotiz'),
|
||||
];
|
||||
}
|
||||
@@ -93,12 +97,16 @@ private static function fileOf(ContentElement $element): mixed
|
||||
return is_array($latest?->metadata) ? ($latest->metadata['file'] ?? null) : null;
|
||||
}
|
||||
|
||||
private static function decisionOf(?ContentElementVersion $version): ?int
|
||||
/**
|
||||
* Räumt den Arbeitsstand ab, der gerade übernommen oder als gleich erkannt wurde. Nur der Stand, der gelesen wurde:
|
||||
* Hat inzwischen jemand neu gespeichert, bleibt dessen Stand erhalten.
|
||||
*
|
||||
* @param array{base_version: int, markers: list<array<string, mixed>>, saved_at: string}|null $draft
|
||||
*/
|
||||
private static function settle(MarkerDraft $drafts, ContentElement $record, ?array $draft, bool $applies): void
|
||||
{
|
||||
if (! is_array($version?->metadata) || ! is_numeric($version->metadata['decision_seconds'] ?? null)) {
|
||||
return null;
|
||||
if ($draft !== null && $applies) {
|
||||
$drafts->discardIf($record, $draft['saved_at']);
|
||||
}
|
||||
|
||||
return (int) $version->metadata['decision_seconds'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Arbeitsstand der Marken eines Films, bevor eine Fassung entsteht. Nur ergänzend: Die freigegebenen Marken
|
||||
* liegen unverändert in `content_element_versions.metadata`.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('content_elements', function (Blueprint $table) {
|
||||
$table->json('marker_draft')->nullable()->after('thumbnail_error');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('content_elements', function (Blueprint $table) {
|
||||
$table->dropColumn('marker_draft');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,372 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\DomainRuleException;
|
||||
use App\Domain\Media\FilmMarkers;
|
||||
use App\Domain\Media\MarkerDraft;
|
||||
use App\Filament\Support\CatalogReading;
|
||||
use App\Filament\Support\ElementRevision;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Marken eines Films: Arbeitsstand am Element, Übernahme in die Fassung und vor allem: Keine Marke geht verloren,
|
||||
* wenn eine Fassung aus anderem Anlass entsteht (Text, neue Datei, Notiz).
|
||||
*/
|
||||
class FilmMarkersWorkflowTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
// Hinweis: Gespeichertes JSON verliert die Nachkommastelle (10.0 wird 10). Verglichen wird deshalb der Wert
|
||||
// (assertEquals), und FilmMarkers::same/ofVersion normalisieren beim Lesen, damit daraus keine Scheinänderung wird.
|
||||
|
||||
private const MARKERS = [
|
||||
['t' => 10.0, 'label' => 'Einstieg', 'stop' => false, 'prompt' => ''],
|
||||
['t' => 42.0, 'label' => 'Entscheidung', 'stop' => true, 'prompt' => 'Was würdest du tun?'],
|
||||
];
|
||||
|
||||
private function film(array $metadata = ['file' => 'inhalte/film.mp4'], ?string $body = null): ContentElement
|
||||
{
|
||||
$element = app(ContentService::class)->createElement('film', 'film', 'Übungsfilm');
|
||||
app(ContentService::class)->publishElementVersion($element, $body, $metadata);
|
||||
|
||||
return $element->fresh();
|
||||
}
|
||||
|
||||
private function latest(ContentElement $element): ContentElementVersion
|
||||
{
|
||||
return $element->versions()->orderByDesc('number')->firstOrFail();
|
||||
}
|
||||
|
||||
private function filmWithMarkers(): ContentElement
|
||||
{
|
||||
return $this->film(['file' => 'inhalte/film.mp4', 'markers' => self::MARKERS]);
|
||||
}
|
||||
|
||||
// ---- Keine Marke geht verloren -------------------------------------------------------------------------------
|
||||
|
||||
public function test_a_text_only_revision_keeps_file_and_markers(): void
|
||||
{
|
||||
$element = $this->filmWithMarkers();
|
||||
|
||||
ElementRevision::publish($element, ['body' => 'Neuer Begleittext', 'change_note' => 'Text']);
|
||||
|
||||
$latest = $this->latest($element);
|
||||
$this->assertSame(2, $latest->number);
|
||||
$this->assertSame('inhalte/film.mp4', $latest->metadata['file']);
|
||||
$this->assertEquals(self::MARKERS, $latest->metadata['markers']);
|
||||
}
|
||||
|
||||
public function test_the_service_carries_markers_when_a_caller_passes_the_same_file_without_them(): void
|
||||
{
|
||||
$element = $this->filmWithMarkers();
|
||||
|
||||
app(ContentService::class)->publishElementVersion($element, 'Notiz', ['file' => 'inhalte/film.mp4']);
|
||||
|
||||
$this->assertEquals(self::MARKERS, $this->latest($element)->metadata['markers']);
|
||||
}
|
||||
|
||||
public function test_the_service_respects_an_explicit_empty_list(): void
|
||||
{
|
||||
$element = $this->filmWithMarkers();
|
||||
|
||||
app(ContentService::class)->publishElementVersion($element, 'Notiz', ['file' => 'inhalte/film.mp4', 'markers' => []]);
|
||||
|
||||
$this->assertSame([], $this->latest($element)->metadata['markers']);
|
||||
}
|
||||
|
||||
public function test_a_new_file_keeps_the_markers_through_the_file_job(): void
|
||||
{
|
||||
Storage::fake('cms_incoming');
|
||||
Storage::fake('media_derived');
|
||||
Storage::disk('cms_incoming')->put('inhalte/neu.mp4', 'filmbytes');
|
||||
$element = $this->filmWithMarkers();
|
||||
|
||||
ElementRevision::publish($element, ['incoming' => ['inhalte/neu.mp4']]);
|
||||
|
||||
$latest = $this->latest($element);
|
||||
$this->assertSame(2, $latest->number);
|
||||
$this->assertNotSame('inhalte/film.mp4', $latest->metadata['file']);
|
||||
$this->assertEquals(self::MARKERS, $latest->metadata['markers']);
|
||||
}
|
||||
|
||||
public function test_dropping_the_file_drops_the_markers_and_the_draft(): void
|
||||
{
|
||||
$element = $this->filmWithMarkers();
|
||||
app(MarkerDraft::class)->save($element, [['t' => 5, 'label' => 'Neu']], null);
|
||||
|
||||
ElementRevision::publish($element->fresh(), ['body' => 'Nur Text', 'drop_file' => true]);
|
||||
|
||||
$latest = $this->latest($element);
|
||||
$this->assertArrayNotHasKey('file', $latest->metadata ?? []);
|
||||
$this->assertArrayNotHasKey('markers', $latest->metadata ?? []);
|
||||
$this->assertNull(app(MarkerDraft::class)->current($element));
|
||||
}
|
||||
|
||||
public function test_old_decision_value_becomes_a_marker_once_and_is_not_written_again(): void
|
||||
{
|
||||
$element = $this->film(['file' => 'inhalte/film.mp4', 'decision_seconds' => 12]);
|
||||
|
||||
ElementRevision::publish($element, ['body' => 'Text', 'change_note' => 'Text']);
|
||||
|
||||
$latest = $this->latest($element);
|
||||
$this->assertEquals([['t' => 12.0, 'label' => 'Entscheidung', 'stop' => true, 'prompt' => '']], $latest->metadata['markers']);
|
||||
$this->assertArrayNotHasKey('decision_seconds', $latest->metadata);
|
||||
}
|
||||
|
||||
public function test_a_deleted_marker_list_does_not_bring_the_old_decision_value_back(): void
|
||||
{
|
||||
$element = $this->film(['file' => 'inhalte/film.mp4', 'decision_seconds' => 12]);
|
||||
app(MarkerDraft::class)->save($element, [], null);
|
||||
|
||||
ElementRevision::publish($element->fresh(), []);
|
||||
ElementRevision::publish($element->fresh(), ['body' => 'Text', 'change_note' => 'x']);
|
||||
|
||||
$this->assertSame([], $this->latest($element)->metadata['markers']);
|
||||
$this->assertSame([], FilmMarkers::ofVersion($this->latest($element)));
|
||||
}
|
||||
|
||||
// ---- Arbeitsstand ---------------------------------------------------------------------------------------------
|
||||
|
||||
public function test_without_a_draft_the_effective_markers_are_those_of_the_latest_version(): void
|
||||
{
|
||||
$element = $this->filmWithMarkers();
|
||||
|
||||
$this->assertNull(app(MarkerDraft::class)->current($element));
|
||||
$this->assertSame(self::MARKERS, app(MarkerDraft::class)->effective($element));
|
||||
}
|
||||
|
||||
public function test_saving_a_draft_stores_the_normalized_list_with_its_base_and_a_token(): void
|
||||
{
|
||||
$element = $this->filmWithMarkers();
|
||||
|
||||
$draft = app(MarkerDraft::class)->save($element, [
|
||||
['t' => '50', 'label' => ' Neu ', 'stop' => true],
|
||||
['t' => 5, 'label' => 'Anfang'],
|
||||
], null);
|
||||
|
||||
$this->assertSame(1, $draft['base_version']);
|
||||
$this->assertSame(['Anfang', 'Neu'], array_column($draft['markers'], 'label'));
|
||||
$this->assertNotSame('', $draft['saved_at']);
|
||||
$this->assertEquals($draft, app(MarkerDraft::class)->current($element));
|
||||
$this->assertEquals($draft['markers'], app(MarkerDraft::class)->effective($element));
|
||||
}
|
||||
|
||||
public function test_the_draft_never_changes_what_members_see(): void
|
||||
{
|
||||
$element = $this->filmWithMarkers();
|
||||
|
||||
app(MarkerDraft::class)->save($element, [['t' => 99, 'label' => 'Nur Arbeitsstand']], null);
|
||||
|
||||
$this->assertSame(self::MARKERS, FilmMarkers::ofVersion($this->latest($element)));
|
||||
$this->assertSame(1, $element->versions()->count());
|
||||
}
|
||||
|
||||
public function test_an_invalid_draft_is_refused_and_leaves_the_stored_one_untouched(): void
|
||||
{
|
||||
$element = $this->filmWithMarkers();
|
||||
$kept = app(MarkerDraft::class)->save($element, [['t' => 5, 'label' => 'Gut']], null);
|
||||
|
||||
try {
|
||||
app(MarkerDraft::class)->save($element, [['t' => 5, 'label' => 'A'], ['t' => 5.5, 'label' => 'B']], $kept['saved_at']);
|
||||
$this->fail('Zu dichte Marken hätten abgelehnt werden müssen.');
|
||||
} catch (DomainRuleException) {
|
||||
$this->assertEquals($kept, app(MarkerDraft::class)->current($element));
|
||||
}
|
||||
}
|
||||
|
||||
public function test_saving_with_a_stale_token_is_refused(): void
|
||||
{
|
||||
$element = $this->filmWithMarkers();
|
||||
$first = app(MarkerDraft::class)->save($element, [['t' => 5, 'label' => 'A']], null);
|
||||
app(MarkerDraft::class)->save($element, [['t' => 6, 'label' => 'B']], $first['saved_at']);
|
||||
|
||||
$this->expectException(DomainRuleException::class);
|
||||
$this->expectExceptionMessage('inzwischen');
|
||||
app(MarkerDraft::class)->save($element, [['t' => 7, 'label' => 'C']], $first['saved_at']);
|
||||
}
|
||||
|
||||
public function test_creating_a_first_draft_while_another_exists_is_refused(): void
|
||||
{
|
||||
$element = $this->filmWithMarkers();
|
||||
app(MarkerDraft::class)->save($element, [['t' => 5, 'label' => 'A']], null);
|
||||
|
||||
$this->expectException(DomainRuleException::class);
|
||||
app(MarkerDraft::class)->save($element, [['t' => 6, 'label' => 'B']], null);
|
||||
}
|
||||
|
||||
public function test_an_empty_draft_is_a_draft_that_deletes_all_markers(): void
|
||||
{
|
||||
$element = $this->filmWithMarkers();
|
||||
|
||||
app(MarkerDraft::class)->save($element, [], null);
|
||||
|
||||
$this->assertNotNull(app(MarkerDraft::class)->current($element));
|
||||
$this->assertSame([], app(MarkerDraft::class)->effective($element));
|
||||
}
|
||||
|
||||
public function test_discarding_returns_to_the_markers_of_the_version(): void
|
||||
{
|
||||
$element = $this->filmWithMarkers();
|
||||
app(MarkerDraft::class)->save($element, [], null);
|
||||
|
||||
app(MarkerDraft::class)->discard($element);
|
||||
|
||||
$this->assertNull(app(MarkerDraft::class)->current($element));
|
||||
$this->assertSame(self::MARKERS, app(MarkerDraft::class)->effective($element));
|
||||
}
|
||||
|
||||
public function test_the_draft_belongs_to_the_element_only(): void
|
||||
{
|
||||
$one = $this->filmWithMarkers();
|
||||
$other = $this->filmWithMarkers();
|
||||
|
||||
app(MarkerDraft::class)->save($one, [], null);
|
||||
|
||||
$this->assertNull(app(MarkerDraft::class)->current($other));
|
||||
}
|
||||
|
||||
// ---- Übernahme in die Fassung ---------------------------------------------------------------------------------
|
||||
|
||||
public function test_creating_a_version_applies_the_draft_and_clears_it(): void
|
||||
{
|
||||
$element = $this->filmWithMarkers();
|
||||
$draft = app(MarkerDraft::class)->save($element, [['t' => 20, 'label' => 'Verschoben', 'stop' => true]], null);
|
||||
|
||||
$message = ElementRevision::publish($element->fresh(), []);
|
||||
|
||||
$latest = $this->latest($element);
|
||||
$this->assertSame(2, $latest->number);
|
||||
$this->assertEquals($draft['markers'], $latest->metadata['markers']);
|
||||
$this->assertSame('inhalte/film.mp4', $latest->metadata['file']);
|
||||
$this->assertNull(app(MarkerDraft::class)->current($element));
|
||||
$this->assertEquals(self::MARKERS, $element->versions()->where('number', 1)->firstOrFail()->metadata['markers']);
|
||||
$this->assertStringContainsString('neue Fassung', $message);
|
||||
}
|
||||
|
||||
public function test_a_change_to_the_markers_alone_counts_as_a_change(): void
|
||||
{
|
||||
$element = $this->filmWithMarkers();
|
||||
app(MarkerDraft::class)->save($element, [['t' => 11, 'label' => 'Einstieg']], null);
|
||||
|
||||
ElementRevision::publish($element->fresh(), []);
|
||||
|
||||
$this->assertSame(2, $element->versions()->count());
|
||||
}
|
||||
|
||||
public function test_a_draft_equal_to_the_version_creates_no_version_but_is_cleared(): void
|
||||
{
|
||||
$element = $this->filmWithMarkers();
|
||||
app(MarkerDraft::class)->save($element, self::MARKERS, null);
|
||||
|
||||
$message = ElementRevision::publish($element->fresh(), []);
|
||||
|
||||
$this->assertSame(1, $element->versions()->count());
|
||||
$this->assertStringContainsString('keine neue Fassung', $message);
|
||||
$this->assertNull(app(MarkerDraft::class)->current($element));
|
||||
}
|
||||
|
||||
public function test_the_same_markers_written_with_other_numbers_create_no_phantom_version(): void
|
||||
{
|
||||
$element = $this->film(['file' => 'inhalte/film.mp4', 'markers' => [['t' => 42, 'label' => 'A', 'stop' => true, 'prompt' => '']]]);
|
||||
app(MarkerDraft::class)->save($element, [['t' => '42.0', 'label' => 'A', 'stop' => true]], null);
|
||||
|
||||
ElementRevision::publish($element->fresh(), []);
|
||||
|
||||
$this->assertSame(1, $element->versions()->count());
|
||||
}
|
||||
|
||||
public function test_without_any_change_there_is_no_new_version(): void
|
||||
{
|
||||
$element = $this->filmWithMarkers();
|
||||
|
||||
$message = ElementRevision::publish($element->fresh(), []);
|
||||
|
||||
$this->assertSame(1, $element->versions()->count());
|
||||
$this->assertStringContainsString('keine neue Fassung', $message);
|
||||
}
|
||||
|
||||
public function test_markers_alone_never_make_a_version_without_text_or_file(): void
|
||||
{
|
||||
$element = app(ContentService::class)->createElement('film', 'film', 'Leer');
|
||||
app(MarkerDraft::class)->save($element, [['t' => 5, 'label' => 'A']], null);
|
||||
|
||||
try {
|
||||
ElementRevision::publish($element->fresh(), []);
|
||||
$this->fail('Ohne Text und Datei darf keine Fassung entstehen.');
|
||||
} catch (DomainRuleException $e) {
|
||||
$this->assertStringContainsString('Text oder eine Datei', $e->getMessage());
|
||||
}
|
||||
|
||||
$this->assertSame(0, $element->versions()->count());
|
||||
}
|
||||
|
||||
public function test_the_draft_is_read_fresh_when_a_version_is_created(): void
|
||||
{
|
||||
$element = $this->filmWithMarkers();
|
||||
$stale = $element->fresh();
|
||||
app(MarkerDraft::class)->save($element, [['t' => 30, 'label' => 'Später gespeichert']], null);
|
||||
|
||||
ElementRevision::publish($stale, []);
|
||||
|
||||
$this->assertSame('Später gespeichert', $this->latest($element)->metadata['markers'][0]['label']);
|
||||
$this->assertNull(app(MarkerDraft::class)->current($element));
|
||||
}
|
||||
|
||||
public function test_a_failed_version_keeps_the_draft(): void
|
||||
{
|
||||
$element = app(ContentService::class)->createElement('film', 'film', 'Leer');
|
||||
app(MarkerDraft::class)->save($element, [['t' => 5, 'label' => 'A']], null);
|
||||
|
||||
try {
|
||||
ElementRevision::publish($element->fresh(), []);
|
||||
} catch (DomainRuleException) {
|
||||
// erwartet
|
||||
}
|
||||
|
||||
$this->assertNotNull(app(MarkerDraft::class)->current($element));
|
||||
}
|
||||
|
||||
public function test_the_version_list_names_the_markers_instead_of_the_old_decision_value(): void
|
||||
{
|
||||
$element = $this->filmWithMarkers();
|
||||
$legacy = $this->film(['file' => 'inhalte/alt.mp4', 'decision_seconds' => 12]);
|
||||
|
||||
$lines = implode("\n", app(CatalogReading::class)->elementVersions($element));
|
||||
$legacyLines = implode("\n", app(CatalogReading::class)->elementVersions($legacy));
|
||||
|
||||
$this->assertStringContainsString('2 Marken, davon 1 mit Stopp: 10 s Einstieg, 42 s Entscheidung', $lines);
|
||||
$this->assertStringContainsString('1 Marke, davon 1 mit Stopp: 12 s Entscheidung', $legacyLines);
|
||||
}
|
||||
|
||||
// ---- Hinweis nach einer neuen Datei ----------------------------------------------------------------------------
|
||||
|
||||
public function test_a_new_file_with_unchanged_markers_is_reported_for_a_check(): void
|
||||
{
|
||||
$element = $this->filmWithMarkers();
|
||||
app(ContentService::class)->publishElementVersion($element, null, ['file' => 'inhalte/zweit.mp4']);
|
||||
|
||||
$this->assertTrue(FilmMarkers::fileChangedWithoutMarkers($element->fresh()));
|
||||
}
|
||||
|
||||
public function test_the_hint_is_gone_once_the_markers_were_touched(): void
|
||||
{
|
||||
$element = $this->filmWithMarkers();
|
||||
app(ContentService::class)->publishElementVersion($element, null, ['file' => 'inhalte/zweit.mp4']);
|
||||
app(MarkerDraft::class)->save($element, [['t' => 12, 'label' => 'Angepasst']], null);
|
||||
ElementRevision::publish($element->fresh(), []);
|
||||
|
||||
$this->assertFalse(FilmMarkers::fileChangedWithoutMarkers($element->fresh()));
|
||||
}
|
||||
|
||||
public function test_there_is_no_hint_for_a_film_without_markers_or_a_single_version(): void
|
||||
{
|
||||
$this->assertFalse(FilmMarkers::fileChangedWithoutMarkers($this->film()));
|
||||
$this->assertFalse(FilmMarkers::fileChangedWithoutMarkers($this->filmWithMarkers()));
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
use App\Domain\Catalog\ContentElementVersion;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Media\MarkerDraft;
|
||||
use App\Domain\Media\MediaRendition;
|
||||
use App\Domain\Media\ThumbnailDeriver;
|
||||
use App\Filament\Resources\Combinations\CombinationResource;
|
||||
@@ -75,13 +76,14 @@ public function test_an_uploaded_file_becomes_a_ready_version(): void
|
||||
$editor = User::factory()->redakteur()->create();
|
||||
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
$this->actingAs($editor, 'staff');
|
||||
// Die Entscheidungsmarke ist keine Eingabe der Fassung mehr, sondern eine Marke aus dem Arbeitsstand.
|
||||
app(MarkerDraft::class)->save($element, [['t' => 12, 'label' => 'Entscheidung', 'stop' => true]], null);
|
||||
|
||||
Livewire::test(ViewContentElement::class, ['record' => $element->getKey()])
|
||||
->callAction('revise', [
|
||||
'working_title' => 'Übungsfilm',
|
||||
'body' => 'Anleitung zum Film',
|
||||
'incoming' => ['inhalte/film.mp4'],
|
||||
'decision_seconds' => 12,
|
||||
])
|
||||
->assertHasNoFormErrors();
|
||||
|
||||
@@ -90,7 +92,10 @@ public function test_an_uploaded_file_becomes_a_ready_version(): void
|
||||
$this->assertNotNull($version);
|
||||
$this->assertSame(ContentVersionStatus::Bereit, $version->status);
|
||||
$this->assertSame('inhalte/'.$version->id.'/film.mp4', $version->metadata['file']);
|
||||
$this->assertSame(12, $version->metadata['decision_seconds']);
|
||||
$this->assertEquals(12, $version->metadata['markers'][0]['t']);
|
||||
$this->assertTrue($version->metadata['markers'][0]['stop']);
|
||||
$this->assertArrayNotHasKey('decision_seconds', $version->metadata);
|
||||
$this->assertNull(app(MarkerDraft::class)->current($element));
|
||||
$this->assertSame(MediaUploadLimit::KILOBYTES, EditContentElement::uploadField()->getMaxSize());
|
||||
$this->assertSame(MediaUploadLimit::rules(), FileUploadConfiguration::rules());
|
||||
Storage::disk('media_derived')->assertExists($version->metadata['file']);
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
<?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));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user