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') ->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]) ->assertSee('Lara im Park als Titelbild') ->assertSee('Lara im Hof als Titelbild') ->assertDontSee('Vorschlag aus dem Film') ->call('adoptPicture', $first->element->id) ->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(); } 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; } }