Files
laraundfelix/tests/Feature/EditorialEditorTest.php
T
LarsandCursor c73207f2c3
Deploy Test / test (push) Successful in 26s
Deploy Test / deploy (push) Successful in 30s
Halte ungenutzte Medien bearbeitbar und lege Dateien direkt im Modul an.
Eine Fassung wird erst unveränderlich, wenn sie freigegeben und verwendet wird. Das Auge am Listeneintrag öffnet die Vorschau.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-17 10:34:42 +01:00

655 lines
30 KiB
PHP

<?php
namespace Tests\Feature;
use App\Domain\Catalog\Composition;
use App\Domain\Catalog\CompositionDisplayRelease;
use App\Domain\Catalog\CompositionKind;
use App\Domain\Catalog\ContentElement;
use App\Domain\Catalog\ContentElementVersion;
use App\Domain\Catalog\ContentService;
use App\Domain\Catalog\ContentVersionStatus;
use App\Filament\Pages\EditorialDesk;
use App\Filament\Resources\ContentElements\ContentElementResource;
use App\Filament\Resources\Courses\CourseResource;
use App\Filament\Resources\Courses\Pages\EditCourse;
use App\Filament\Resources\Exercises\ExerciseResource;
use App\Filament\Resources\Exercises\Pages\EditExercise;
use App\Models\User;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Livewire\Livewire;
use Tests\TestCase;
class EditorialEditorTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
}
public function test_the_desk_finds_a_program_and_a_module_by_name(): void
{
$content = app(ContentService::class);
$sheet = $content->publishElementVersion($content->createElement('text', 'text', 'Blatt'), 'Hinweis');
$module = $content->publishComposition(
$content->createComposition('Modul Abstand', CompositionKind::Uebung),
[['role' => 'Unterlage', 'target' => $sheet]],
);
$content->publishComposition(
$content->createComposition('Programm Abstand', CompositionKind::Kurs),
[['role' => 'Modul', 'target' => $module]],
);
$editor = $this->editor();
Livewire::actingAs($editor, 'staff')
->test(EditorialDesk::class)
->assertSee('Programm Abstand')
->assertSee('Modul Abstand')
->set('query', 'Programm')
->assertSee('Programm Abstand')
->assertDontSee('Modul Abstand')
->set('query', 'kein-treffer')
->assertSee('Nichts gefunden');
}
public function test_display_data_does_not_create_a_version_and_a_module_works_without_a_film(): void
{
$editor = $this->editor();
$module = app(ContentService::class)->createComposition('Ohne Film', CompositionKind::Uebung);
Livewire::actingAs($editor, 'staff')
->test(EditExercise::class, ['record' => $module->id])
->assertSee('Ein Film ist nicht nötig')
->set('displayTitle', 'Sichtbar ohne Film')
->set('summary', 'Nur eine Beschreibung')
->call('saveDisplay')
->assertSet('feedback', 'Die Anzeige ist gespeichert. Die Fassung bleibt unverändert.')
->set('learningGoal', 'Den Abstand erklären')
->call('publishRevision')
->assertSet('feedback', 'Eine Fassung braucht mindestens einen Bestandteil. Anzeige und Kurzbeschreibung kannst du schon speichern.')
->set('newTextTitle', 'Hinweis ohne Film')
->set('newTextBody', 'Zuerst den Abstand ansprechen.')
->call('addText')
->call('publishRevision');
$module->refresh();
$this->assertSame('Sichtbar ohne Film', $module->display_title);
$this->assertSame(1, $module->versions()->count());
$this->assertSame('Den Abstand erklären', $module->versions()->first()->learning_goal);
$this->assertSame(1, $module->versions()->first()->members()->count());
}
public function test_reordering_reuses_a_medium_and_keeps_the_released_version(): void
{
$content = app(ContentService::class);
$sheet = $content->publishElementVersion(
$content->createElement('text', 'text', 'Trainerunterlage Abstand'),
'Im Kurs zuerst den Abstand ansprechen.',
);
$film = $content->publishElementVersion(
$content->createElement('film', 'film', 'Lara im Park'),
'Film',
);
$firstModule = $content->publishComposition(
$content->createComposition('Modul Abstand', CompositionKind::Uebung),
[
['role' => 'Unterlage', 'target' => $sheet],
['role' => 'Film', 'target' => $film],
],
null,
null,
['learning_goal' => 'Abstand halten', 'duration_minutes' => 15],
);
$secondModule = $content->publishComposition(
$content->createComposition('Modul Hilfe', CompositionKind::Uebung),
[['role' => 'Unterlage', 'target' => $sheet]],
);
$programVersion = $content->publishComposition(
$content->createComposition('Programm Abstand', CompositionKind::Kurs),
[
['role' => 'Modul', 'target' => $firstModule],
['role' => 'Modul', 'target' => $secondModule],
],
);
$editor = $this->editor();
app(CompositionDisplayRelease::class)->release($programVersion, $editor);
app(CompositionDisplayRelease::class)->release($firstModule, $editor);
$component = Livewire::actingAs($editor, 'staff')
->test(EditCourse::class, ['record' => $programVersion->composition_id])
->assertSee('Modul Abstand')
->assertSee('Modul Hilfe');
$members = $component->get('members');
$component->set('members', array_reverse($members))
->call('publishRevision')
->assertSet('feedback', 'Die neue Fassung ist übernommen. Die bisherige Fassung bleibt erhalten.');
$versions = $programVersion->composition->versions()->with('members')->orderBy('number')->get();
$this->assertCount(2, $versions);
$this->assertSame($firstModule->id, $versions[0]->members[0]->nested_composition_version_id);
$this->assertSame($secondModule->id, $versions[1]->members[0]->nested_composition_version_id);
$this->assertTrue(app(CompositionDisplayRelease::class)->isReleased($versions[0]));
$this->assertFalse(app(CompositionDisplayRelease::class)->isReleased($versions[1]));
$this->assertSame($sheet->id, $firstModule->members()->first()->content_element_version_id);
$this->assertSame('Im Kurs zuerst den Abstand ansprechen.', $sheet->fresh()->body);
Livewire::actingAs($editor, 'staff')
->test(EditCourse::class, ['record' => $programVersion->composition_id])
->call('releaseDisplay');
$this->assertTrue(app(CompositionDisplayRelease::class)->isReleased($versions[0]->fresh()));
$this->assertTrue(app(CompositionDisplayRelease::class)->isReleased($versions[1]->fresh()));
$this->assertSame(1, $film->element->versions()->count());
$this->actingAs($editor, 'staff')
->get(route('editorial.preview', ['composition' => $programVersion->composition, 'version' => $versions[1]]))
->assertOk()
->assertSee('Vorschau für die Redaktion')
->assertSee('Modul Hilfe')
->assertSee('Lara im Park')
->assertSee('Trainerunterlage Abstand');
}
public function test_a_new_module_returns_into_the_program(): void
{
$content = app(ContentService::class);
$sheet = $content->publishElementVersion($content->createElement('text', 'text', 'Blatt'), 'Hinweis');
$program = $content->publishComposition(
$content->createComposition('Programm Abstand', CompositionKind::Kurs),
[['role' => 'Unterlage', 'target' => $sheet]],
);
$editor = $this->editor();
$programUrl = CourseResource::getUrl('edit', ['record' => $program->composition]);
$created = Livewire::actingAs($editor, 'staff')
->test(EditCourse::class, ['record' => $program->composition_id])
->set('newModuleName', 'UX-Prüfung Modul')
->call('startModule');
$module = Composition::query()->where('designation', 'UX-Prüfung Modul')->firstOrFail();
$this->assertSame(CompositionKind::Uebung, $module->kind);
$this->actingAs($editor, 'staff')
->get(ExerciseResource::getUrl('edit', ['record' => $module]).'?zurueck='.urlencode('http://example.test/verwaltung/kurse/1'))
->assertOk()
->assertSee('Zurück und einbinden');
Livewire::actingAs($editor, 'staff')
->test(EditExercise::class, ['record' => $module->id])
->set('returnUrl', $programUrl)
->set('newTextTitle', 'UX-Prüfung Text')
->set('newTextBody', 'Nur für die Bedienprüfung.')
->call('addText')
->call('returnAndInclude')
->assertRedirect();
$version = $module->versions()->firstOrFail();
$this->actingAs($editor, 'staff')
->get($programUrl.'?uebernehmen=composition:'.$version->id)
->assertOk()
->assertSee('UX-Prüfung Modul')
->assertSee('ist in den Aufbau übernommen');
$this->assertSame(1, $program->composition->versions()->count());
$this->assertSame($sheet->id, $program->fresh()->members()->first()->content_element_version_id);
}
public function test_a_role_change_stays_on_the_selected_part_when_the_order_changes(): void
{
$content = app(ContentService::class);
$sheet = $content->publishElementVersion($content->createElement('text', 'text', 'Blatt'), 'Hinweis');
$film = $content->publishElementVersion($content->createElement('film', 'film', 'Lara im Park'), 'Film');
$program = $content->publishComposition(
$content->createComposition('Programm Abstand', CompositionKind::Kurs),
[
['role' => 'Unterlage', 'target' => $sheet],
['role' => 'Film', 'target' => $film],
],
);
Livewire::actingAs($this->editor(), 'staff')
->test(EditCourse::class, ['record' => $program->composition_id])
->call('selectPart', 1)
->set('roleDraft', 'Film zum Einstieg')
->assertSet('members.0.role', 'Unterlage')
->assertSet('members.1.role', 'Film zum Einstieg')
->call('movePart', 1, -1)
->call('publishRevision')
->assertSet('feedback', 'Die neue Fassung ist übernommen. Die bisherige Fassung bleibt erhalten.');
$versions = $program->composition->versions()->with('members')->orderBy('number')->get();
$this->assertCount(2, $versions);
$this->assertSame('Unterlage', $versions[0]->members[0]->role);
$this->assertSame('Film', $versions[0]->members[1]->role);
$this->assertSame('Film zum Einstieg', $versions[1]->members[0]->role);
$this->assertSame($film->id, $versions[1]->members[0]->content_element_version_id);
$this->assertSame('Unterlage', $versions[1]->members[1]->role);
$this->assertSame($sheet->id, $versions[1]->members[1]->content_element_version_id);
}
public function test_saving_a_draft_ten_times_creates_one_version_only_when_released(): void
{
$editor = $this->editor();
$module = app(ContentService::class)->createComposition('Entwurf Modul', CompositionKind::Uebung);
$component = Livewire::actingAs($editor, 'staff')
->test(EditExercise::class, ['record' => $module->id])
->set('newTextTitle', 'Hinweis')
->set('newTextBody', 'Erst der Entwurf.')
->call('addText');
for ($i = 1; $i <= 10; $i++) {
$component->set('learningGoal', 'Durchgang '.$i)->call('saveDraft');
}
$module->refresh();
$this->assertSame(0, $module->versions()->count());
$this->assertSame('Durchgang 10', $module->working_draft['learning_goal']);
Livewire::actingAs($editor, 'staff')
->test(EditExercise::class, ['record' => $module->id])
->assertSet('learningGoal', 'Durchgang 10')
->call('publishRevision')
->assertSet('feedback', 'Die neue Fassung ist übernommen. Die bisherige Fassung bleibt erhalten.');
$module->refresh();
$this->assertSame(1, $module->versions()->count());
$this->assertSame('Durchgang 10', $module->versions()->first()->learning_goal);
$this->assertNull($module->working_draft);
Livewire::actingAs($editor, 'staff')
->test(EditExercise::class, ['record' => $module->id])
->set('learningGoal', 'Nur Entwurf')
->call('saveDraft');
$module->refresh();
$this->assertSame(1, $module->versions()->count());
$this->assertSame('Durchgang 10', $module->versions()->first()->fresh()->learning_goal);
$this->assertSame('Nur Entwurf', $module->working_draft['learning_goal']);
}
public function test_the_picker_finds_a_film_by_title(): void
{
$content = app(ContentService::class);
$content->publishElementVersion($content->createElement('film', 'film', 'Lara im Park'), 'Film');
$module = $content->createComposition('Picker Modul', CompositionKind::Uebung);
Livewire::actingAs($this->editor(), 'staff')
->test(EditExercise::class, ['record' => $module->id])
->call('openPicker')
->set('pickerQuery', 'Lara')
->assertSee('Lara im Park')
->assertSee('Neuen Text erstellen');
}
public function test_guests_cannot_open_the_trainer_preview(): void
{
$content = app(ContentService::class);
$sheet = $content->publishElementVersion($content->createElement('text', 'text', 'Blatt'), 'Hinweis');
$version = $content->publishComposition(
$content->createComposition('Programm Abstand', CompositionKind::Kurs),
[['role' => 'Unterlage', 'target' => $sheet]],
);
$this->get(route('editorial.preview', ['composition' => $version->composition, 'version' => $version]))
->assertRedirect();
}
public function test_catalog_cards_show_text_status_and_a_single_film_suggestion(): void
{
Storage::fake('media_derived');
$content = app(ContentService::class);
$film = $this->filmWithPicture($content, 'Lara im Park');
$withFilm = $content->publishComposition(
$content->createComposition('Modul mit Film', CompositionKind::Uebung),
[['role' => 'Film', 'target' => $film]],
);
$withFilm->composition->summary = 'Kinder erkennen eine Grenze, bevor sie jemanden um Hilfe bitten.';
$withFilm->composition->save();
$plain = $content->createComposition('Modul ohne Bild', CompositionKind::Uebung);
$plain->summary = str_repeat('Ausführliche Kartenbeschreibung. ', 12);
$plain->save();
$editor = $this->editor();
app(CompositionDisplayRelease::class)->release($withFilm, $editor);
Livewire::actingAs($editor, 'staff')
->test(EditorialDesk::class)
->assertSee('Kinder erkennen eine Grenze')
->assertSee('Vorschlag aus dem Film Lara im Park')
->assertSee('In der Mitgliederbibliothek')
->assertSee('Kein Titelbild')
->assertSee('Ausführliche Kartenbeschreibung')
->assertSee('Nicht auf der Website')
->assertSee('Kein aktives Angebot')
->assertDontSee('Zur Anzeige freigeben')
->set('visibility', 'entwurf')
->assertSee('Modul ohne Bild')
->assertDontSee('Modul mit Film');
Livewire::actingAs($editor, 'staff')
->test(EditExercise::class, ['record' => $withFilm->composition_id])
->assertSee('In Mitgliederbibliothek anzeigen')
->assertSee('Vorschlag aus dem Film Lara im Park')
->assertSee('Katalogvorschau')
->assertSee('Modul bearbeiten')
->assertDontSee('Anzeige speichern')
->assertDontSee('Zur Anzeige freigeben');
}
public function test_a_chosen_picture_and_description_do_not_create_a_version(): void
{
Storage::fake('media_derived');
$content = app(ContentService::class);
$first = $this->filmWithPicture($content, 'Lara im Park');
$second = $this->filmWithPicture($content, 'Lara im Hof');
$version = $content->publishComposition(
$content->createComposition('Modul mit zwei Filmen', CompositionKind::Uebung),
[
['role' => 'Film', 'target' => $first],
['role' => 'Weiterer Film', 'target' => $second],
],
);
$editor = $this->editor();
Livewire::actingAs($editor, 'staff')
->test(EditExercise::class, ['record' => $version->composition_id])
->call('openModule')
->set('moduleTab', 'titelbild')
->assertSee('Aus Film')
->assertSee('Vorhandenes Bild')
->assertSee('Hochladen')
->assertSee('Lara im Park')
->assertSee('Lara im Hof')
->assertDontSee('Anzeige speichern')
->assertDontSee('Titelbild speichern')
->assertSee('Vorschlag aus dem Film Lara im Park')
->call('adoptPicture', $first->element->id)
->assertDontSee('Vorschlag aus dem Film')
->assertSet('feedback', 'Das Vorschaubild ist gespeichert. Die Fassung bleibt unverändert.')
->set('description', 'Eine fachliche Beschreibung für die Bibliothek.')
->set('summary', 'Kurzer Kartentext')
->call('saveDisplay')
->assertSet('feedback', 'Die Anzeige ist gespeichert. Die Fassung bleibt unverändert.');
$composition = $version->composition->fresh();
$this->assertSame(1, $composition->versions()->count());
$this->assertSame('vorschau/komposition-'.$composition->id.'.jpg', $composition->thumbnail_path);
$this->assertSame('element:'.$first->element->id, $composition->thumbnail_source);
$this->assertSame('Eine fachliche Beschreibung für die Bibliothek.', $composition->description);
Storage::disk('media_derived')->assertExists($composition->thumbnail_path);
$this->get('/medien/'.$composition->thumbnail_path)->assertNotFound();
}
public function test_the_module_dialog_saves_text_without_a_new_version(): void
{
$content = app(ContentService::class);
$sheet = $content->publishElementVersion($content->createElement('text', 'text', 'Blatt'), 'Hinweis');
$version = $content->publishComposition(
$content->createComposition('Dialog Modul', CompositionKind::Uebung),
[['role' => 'Unterlage', 'target' => $sheet]],
);
$editor = $this->editor();
Livewire::actingAs($editor, 'staff')
->test(EditExercise::class, ['record' => $version->composition_id])
->assertDontSee('Anzeige speichern')
->call('openModule')
->assertSee('Beschreibung')
->assertSee('Didaktik')
->assertSee('Einordnung')
->assertSee('Titelbild')
->set('description', 'Weg damit')
->call('closeModule')
->assertSet('description', '');
Livewire::actingAs($editor, 'staff')
->test(EditExercise::class, ['record' => $version->composition_id])
->set('description', 'Ausführlicher Dialogtext')
->set('summary', 'Kurzer Dialogtext')
->call('saveModule')
->assertSet('moduleOpen', false)
->assertSee('Es entsteht keine neue Fassung');
$composition = $version->composition->fresh();
$this->assertSame(1, $composition->versions()->count());
$this->assertSame('Ausführlicher Dialogtext', $composition->description);
$this->assertNull($composition->working_draft);
Livewire::actingAs($editor, 'staff')
->test(EditExercise::class, ['record' => $version->composition_id])
->set('learningGoal', 'Nur im Entwurf')
->set('durationMinutes', '9')
->call('saveModule');
$composition->refresh();
$this->assertSame(1, $composition->versions()->count());
$this->assertSame(ContentVersionStatus::Bereit, $composition->versions()->first()->status);
$this->assertSame('Nur im Entwurf', $composition->working_draft['learning_goal']);
$this->assertSame(9, $composition->working_draft['duration_minutes']);
}
public function test_the_picker_groups_versions_and_adopts_the_chosen_one(): void
{
$content = app(ContentService::class);
$element = $content->createElement('film', 'film', 'Lara im Park');
$first = $content->publishElementVersion($element, 'Erste Stelle');
$second = $content->publishElementVersion($element, 'Zweite Stelle');
$module = $content->createComposition('Fassungswahl', CompositionKind::Uebung);
$component = Livewire::actingAs($this->editor(), 'staff')
->test(EditExercise::class, ['record' => $module->id])
->call('openPicker')
->set('pickerQuery', 'Lara')
->set('pickerSelected', 'element:'.$second->id);
$items = $component->instance()->pickerResult()['items'];
$this->assertCount(1, $items);
$this->assertSame('element:'.$second->id, $items[0]['target']);
$component
->assertSee('Fassung 1')
->assertSee('aktueller Stand')
->set('pickerSelected', 'element:'.$first->id)
->call('addPart', 'element:'.$first->id);
$module->refresh();
$this->assertSame(0, $module->versions()->count());
$this->assertSame('element:'.$first->id, $module->working_draft['members'][0]['target']);
}
public function test_the_part_dialog_saves_a_role_without_a_new_version(): void
{
$content = app(ContentService::class);
$sheet = $content->publishElementVersion($content->createElement('text', 'text', 'Blatt'), 'Hinweis');
$version = $content->publishComposition(
$content->createComposition('Rollendialog', CompositionKind::Uebung),
[['role' => 'Unterlage', 'target' => $sheet]],
);
Livewire::actingAs($this->editor(), 'staff')
->test(EditExercise::class, ['record' => $version->composition_id])
->call('openPart', 0)
->assertSee('Bestandteil bearbeiten')
->set('roleDraft', 'Einstieg')
->call('savePart')
->assertSet('partOpen', false)
->assertSee('Es entsteht keine neue Fassung');
$composition = $version->composition->fresh();
$this->assertSame(1, $composition->versions()->count());
$this->assertSame('Unterlage', $composition->versions()->first()->members()->first()->role);
$this->assertSame('Einstieg', $composition->working_draft['members'][0]['role']);
}
public function test_a_missing_film_frame_does_not_create_a_version(): void
{
Storage::fake('media_derived');
$content = app(ContentService::class);
$element = $content->createElement('film', 'film', 'Lara im Park');
$film = $content->publishElementVersion($element, null, ['file' => 'inhalte/lara.mp4']);
$version = $content->publishComposition(
$content->createComposition('Rahmen Modul', CompositionKind::Uebung),
[['role' => 'Film', 'target' => $film]],
);
$editor = $this->editor();
$this->get(route('editorial.frame', ['version' => $film, 'sekunde' => '4.5']))
->assertRedirect();
$this->actingAs($editor, 'staff')
->get(route('editorial.frame', ['version' => $film, 'sekunde' => '4.5']))
->assertNotFound();
$this->actingAs($editor, 'staff')
->get(route('editorial.frame', ['version' => $film, 'sekunde' => 'nein']))
->assertNotFound();
Livewire::actingAs($editor, 'staff')
->test(EditExercise::class, ['record' => $version->composition_id])
->call('openModule')
->set('imageMode', 'film')
->set('frameVersionId', $film->id)
->set('frameSecond', '4.5')
->call('saveModule')
->assertSet('moduleOpen', true);
$composition = $version->composition->fresh();
$film->refresh();
$this->assertSame(1, $composition->versions()->count());
$this->assertNull($composition->thumbnail_path);
$this->assertNotNull($composition->thumbnail_error);
$this->assertSame('inhalte/lara.mp4', $film->metadata['file']);
Storage::disk('media_derived')->assertMissing('inhalte/lara.mp4');
}
public function test_a_placement_note_waits_for_release_and_keeps_the_old_version(): void
{
$content = app(ContentService::class);
$sheet = $content->publishElementVersion($content->createElement('text', 'text', 'Blatt'), 'Hinweis');
$version = $content->publishComposition(
$content->createComposition('Stellenmodul', CompositionKind::Uebung),
[['role' => 'Unterlage', 'target' => $sheet]],
);
Livewire::actingAs($this->editor(), 'staff')
->test(EditExercise::class, ['record' => $version->composition_id])
->call('openPart', 0)
->assertSee('Beschreibung an dieser Stelle')
->set('noteDraft', 'Hier zuerst den Abstand ansprechen.')
->call('savePart')
->assertSee('Es entsteht keine neue Fassung')
->call('publishRevision');
$composition = $version->composition->fresh();
$this->assertSame(2, $composition->versions()->count());
$this->assertNull($version->fresh()->members()->first()->placement_note);
$released = $composition->versions()->where('number', 2)->first();
$this->assertSame('Hier zuerst den Abstand ansprechen.', $released->members()->first()->placement_note);
$this->assertSame(ContentVersionStatus::Bereit, $released->status);
}
public function test_a_module_text_stays_editable_until_it_is_released_and_used(): void
{
$editor = $this->editor();
$module = app(ContentService::class)->createComposition('Text im Modul', CompositionKind::Uebung);
$component = Livewire::actingAs($editor, 'staff')
->test(EditExercise::class, ['record' => $module->id])
->set('newTextTitle', 'Hinweis')
->set('newTextBody', 'Erster Wortlaut')
->call('addText')
->assertSee('Vorschau: Hinweis')
->assertSee('das Auge öffnet eine Vorschau')
->assertDontSee('Das Stiftsymbol öffnet die Bearbeitung')
->call('openPart', 0)
->assertSee('dieselbe Fassung fort')
->set('partBody', 'Geänderter Wortlaut')
->call('savePart')
->assertSee('derselben Fassung');
$element = ContentElement::query()->where('working_title', 'Hinweis')->firstOrFail();
$version = $element->versions()->sole();
$this->assertSame(ContentVersionStatus::Entwurf, $version->status);
$this->assertSame('Geänderter Wortlaut', $version->body);
$this->assertSame(1, $element->versions()->count());
$this->actingAs($editor, 'staff')
->get(ContentElementResource::getUrl('index'))
->assertOk()
->assertSee('Hinweis')
->assertSee('Entwurf');
$component->call('publishRevision');
$this->assertSame(ContentVersionStatus::Bereit, $version->fresh()->status);
$this->assertSame($version->id, $module->fresh()->versions()->first()->members()->first()->content_element_version_id);
$component
->call('openPart', 0)
->set('partBody', 'Nach der Freigabe')
->call('savePart')
->assertSee('neuen Fassung');
$this->assertSame(2, $element->fresh()->versions()->count());
$this->assertSame('Geänderter Wortlaut', $version->fresh()->body);
$this->assertSame($version->id, $module->fresh()->versions()->first()->members()->first()->content_element_version_id);
$this->assertSame('element:'.$element->versions()->orderByDesc('number')->first()->id, $module->fresh()->working_draft['members'][0]['target']);
}
public function test_a_file_can_be_created_inside_the_module(): void
{
Storage::fake('cms_incoming');
Storage::fake('media_derived');
$editor = $this->editor();
$module = app(ContentService::class)->createComposition('Datei im Modul', CompositionKind::Uebung);
Livewire::actingAs($editor, 'staff')
->test(EditExercise::class, ['record' => $module->id])
->set('newFileTitle', 'Merkblatt')
->set('incomingFile', UploadedFile::fake()->create('merkblatt.pdf', 12, 'application/pdf'))
->call('addFile')
->assertSee('Merkblatt')
->call('publishRevision');
$element = ContentElement::query()->where('working_title', 'Merkblatt')->firstOrFail();
$version = $element->versions()->sole();
$this->assertSame('document', $element->output_class);
$this->assertSame(ContentVersionStatus::Bereit, $version->status);
$this->assertIsString($version->metadata['file'] ?? null);
Storage::disk('media_derived')->assertExists($version->metadata['file']);
$this->assertSame($version->id, $module->fresh()->versions()->first()->members()->first()->content_element_version_id);
}
private function filmWithPicture(ContentService $content, string $title): ContentElementVersion
{
$element = $content->createElement('film', 'film', $title);
$version = $content->publishElementVersion($element, 'Film');
$element->thumbnail_path = 'vorschau/element-'.$element->id.'.jpg';
$element->thumbnail_alt = $title;
$element->save();
$image = imagecreatetruecolor(8, 8);
ob_start();
imagepng($image);
Storage::disk('media_derived')->put($element->thumbnail_path, ob_get_clean());
imagedestroy($image);
return $version->fresh();
}
private function editor(): User
{
$editor = User::factory()->redakteur()->create();
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
return $editor;
}
}