put('inhalte/merkblatt.pdf', 'pdfbytes'); Livewire::actingAs($this->editor(), 'staff') ->test(ListContentElements::class) ->mountAction('create') ->fillForm([ 'working_title' => 'Merkblatt Abstand', 'editorial_content_kind_id' => $this->kind('merkblatt'), 'shape' => 'document', 'incoming' => ['inhalte/merkblatt.pdf'], ]) ->callMountedAction() ->assertHasNoFormErrors(); $element = ContentElement::query()->where('working_title', 'Merkblatt Abstand')->firstOrFail(); $this->assertSame('document', $element->output_class); $this->assertSame($this->kind('merkblatt'), $element->editorial_content_kind_id); $this->assertSame('Merkblatt', $this->card($element)['editorialKind']); $merkblaetter = MediaLibrary::class; $this->assertSame( ['Merkblatt Abstand'], array_column(app($merkblaetter)->cards(['arten' => MaterialKindSelection::encode(['k'.$this->kind('merkblatt')])], false), 'title'), 'Das Medium lässt sich nach der Materialart filtern.', ); } public function test_the_material_kind_is_required_when_creating_a_medium(): void { Livewire::actingAs($this->editor(), 'staff') ->test(ListContentElements::class) ->mountAction('create') ->fillForm(['working_title' => 'Ohne Art', 'shape' => 'text', 'body' => 'Wortlaut']) ->callMountedAction() ->assertHasFormErrors(['editorial_content_kind_id' => 'required']); $this->assertDatabaseMissing('content_elements', ['working_title' => 'Ohne Art']); } public function test_the_server_rejects_a_kind_that_is_not_meant_for_media_and_creates_nothing(): void { $this->actingAs($this->editor(), 'staff'); foreach (['programm' => 'nicht vorgesehen', 'uebungsabschnitt' => 'nicht vorgesehen'] as $slug => $fragment) { try { MediumForm::create(['working_title' => 'Falsch', 'shape' => 'text', 'body' => 'Text', 'editorial_content_kind_id' => $this->kind($slug)], hold: false); $this->fail('Die Materialart '.$slug.' darf für ein Medium nicht gewählt werden.'); } catch (DomainRuleException $exception) { $this->assertStringContainsString($fragment, $exception->getMessage()); } } $this->assertDatabaseMissing('content_elements', ['working_title' => 'Falsch']); } public function test_the_offered_kinds_are_the_active_medium_kinds_without_the_automatic_one(): void { $options = app(EditorialVocabulary::class)->kindOptions('medium'); $this->assertContains('Merkblatt', $options); $this->assertNotContains('Übungsabschnitt', $options); $this->assertNotContains('Programm', $options); } // ---------------------------------------------------------------- 2. Abschnitte automatisch einordnen public function test_a_section_created_in_the_exercise_editor_is_an_exercise_section_with_its_exercise(): void { $exercise = $this->exerciseComposition('Wohlfühlabstand'); Livewire::actingAs($this->editor(), 'staff') ->test(EditPractice::class, ['record' => $exercise->getKey()]) ->set('newTextTitle', 'Ablauf') ->set('newTextBody', '

Die Kinder gehen aufeinander zu.

') ->call('addText'); $element = ContentElement::query()->where('working_title', 'Ablauf')->firstOrFail(); $this->assertSame($this->kind('uebungsabschnitt'), $element->editorial_content_kind_id); $this->assertSame($exercise->getKey(), $element->origin_composition_id); $card = $this->card($element); $this->assertSame('Übungsabschnitt', $card['editorialKind']); $this->assertSame('Wohlfühlabstand', $card['exercise']['title']); $this->assertStringEndsWith('/fachuebungen/'.$exercise->getKey(), (string) $card['exercise']['url']); } public function test_a_text_created_in_a_module_stays_an_ordinary_text(): void { $module = app(ContentService::class)->createComposition('Ein Modul', CompositionKind::Uebung); Livewire::actingAs($this->editor(), 'staff') ->test(EditExercise::class, ['record' => $module->getKey()]) ->set('newTextTitle', 'Modultext') ->set('newTextBody', '

Gilt für das Modul.

') ->call('addText'); $element = ContentElement::query()->where('working_title', 'Modultext')->firstOrFail(); $this->assertNull($element->editorial_content_kind_id); $this->assertNull($element->origin_composition_id); } public function test_sections_from_shinkan_are_exercise_sections_of_their_own_exercise_and_stay_so_on_repetition(): void { $import = app(ShinkanImport::class); $first = $import->adopt($import->record($this->document('6f1c1c52-0a53-4f6b-8e0e-3f0c2f6b9a11', 'Sicher stehen', 'h1'))); $second = $import->adopt($import->record($this->document('9a8b7c6d-1111-4222-8333-444455556666', 'Abstand halten', 'h2'))); $import->adopt($import->record($this->document('9a8b7c6d-1111-4222-8333-444455556666', 'Abstand halten', 'h2'))); $sections = ContentElement::query()->where('source_ref', 'like', 'shinkan:%')->get(); $this->assertCount(4, $sections, 'Zwei Übungen mit je Durchführung und Vorbereitung.'); foreach ($sections as $section) { $this->assertSame($this->kind('uebungsabschnitt'), $section->editorial_content_kind_id); $owner = str_contains((string) $section->source_ref, '6f1c1c52') ? $first : $second; $this->assertSame($owner->composition_id, $section->origin_composition_id, 'Jeder Abschnitt gehört zu seiner eigenen Übung.'); } $cards = app(MediaLibrary::class)->cards(['arten' => MaterialKindSelection::encode(['k'.$this->kind('uebungsabschnitt')])], true); $this->assertCount(4, $cards); $this->assertSame(['Abstand halten', 'Abstand halten', 'Sicher stehen', 'Sicher stehen'], collect($cards)->map(fn (array $card): string => $card['exercise']['title'])->sort()->values()->all()); } public function test_existing_texts_are_assigned_only_when_their_origin_is_proven(): void { $content = app(ContentService::class); $exercise = $this->exerciseComposition('Alte Übung'); $other = $this->exerciseComposition('Andere Übung'); $module = $content->createComposition('Ein Modul', CompositionKind::Uebung); $own = $this->section('Nur in der Übung', 'Text'); $shared = $this->section('In zwei Übungen', 'Text'); $direct = $this->section('Auch direkt im Modul', 'Text'); $classified = $this->section('Eigenes Merkblatt', 'Text'); $classified->element->forceFill(['editorial_content_kind_id' => $this->kind('merkblatt')])->save(); $film = $this->film('Demonstrationsfilm'); $film->element->forceFill(['editorial_content_kind_id' => $this->kind('merkblatt')])->save(); $loose = $this->section('Ohne Verwendung', 'Text'); $content->publishComposition($exercise, [ ['role' => 'Ablauf', 'target' => $own], ['role' => 'Geteilt', 'target' => $shared], ['role' => 'Auch direkt', 'target' => $direct], ['role' => 'Merkblatt', 'target' => $classified], ['role' => 'Film', 'target' => $film], ]); $content->publishComposition($other, [['role' => 'Geteilt', 'target' => $shared]]); $content->publishComposition($module, [['role' => 'Text', 'target' => $direct]]); $assigned = app(ExerciseSections::class)->backfill(); $this->assertSame(1, $assigned); $this->assertSame($this->kind('uebungsabschnitt'), $own->element->fresh()->editorial_content_kind_id); $this->assertSame($exercise->getKey(), $own->element->fresh()->origin_composition_id); foreach ([$shared, $direct, $loose] as $unclear) { $this->assertNull($unclear->element->fresh()->editorial_content_kind_id, 'Bei unklarer Herkunft bleibt die Einordnung bestehen: '.$unclear->element->working_title); $this->assertNull($unclear->element->fresh()->origin_composition_id); } $this->assertSame($this->kind('merkblatt'), $classified->element->fresh()->editorial_content_kind_id, 'Eine gesetzte Materialart bleibt.'); $this->assertSame($this->kind('merkblatt'), $film->element->fresh()->editorial_content_kind_id); $this->assertSame(0, app(ExerciseSections::class)->backfill(), 'Die Zuordnung ist wiederholbar.'); } public function test_shinkan_sections_of_the_existing_stock_get_their_exercise_even_if_a_kind_was_set(): void { $import = app(ShinkanImport::class); $version = $import->adopt($import->record($this->document('6f1c1c52-0a53-4f6b-8e0e-3f0c2f6b9a11', 'Sicher stehen', 'h1'))); // Stand vor der Einführung: Abschnitte ohne Zuordnung; eine Redaktion hat einen davon bewusst eingeordnet. ContentElement::query()->update(['editorial_content_kind_id' => null, 'origin_composition_id' => null]); $kept = ContentElement::query()->where('source_ref', 'like', '%:execution')->firstOrFail(); $kept->forceFill(['editorial_content_kind_id' => $this->kind('merkblatt')])->save(); app(ExerciseSections::class)->backfill(); $this->assertSame($version->composition_id, $kept->fresh()->origin_composition_id); $this->assertSame($this->kind('merkblatt'), $kept->fresh()->editorial_content_kind_id); $preparation = ContentElement::query()->where('source_ref', 'like', '%:preparation')->firstOrFail(); $this->assertSame($this->kind('uebungsabschnitt'), $preparation->editorial_content_kind_id); $this->assertSame(ExerciseSource::query()->value('composition_id'), $preparation->origin_composition_id); } // ---------------------------------------------------------------- 3. Mehrfachauswahl im Medienmanager public function test_the_start_view_shows_regular_media_and_old_entries_without_exercise_sections(): void { $this->library(); $this->assertSame( ['Alter Text ohne Art', 'Merkblatt Abstand', 'Trailer Park'], $this->titles(Livewire::actingAs($this->editor(), 'staff')->test(ListContentElements::class)), ); } public function test_switching_on_exercise_sections_shows_them_at_once_and_two_kinds_show_together(): void { $this->library(); $component = Livewire::actingAs($this->editor(), 'staff')->test(ListContentElements::class); $this->toggle($component, 'k'.$this->kind('uebungsabschnitt')); $this->assertSame(['Ablauf der Übung', 'Alter Text ohne Art', 'Merkblatt Abstand', 'Trailer Park'], $this->titles($component)); // Auf Merkblatt und Übungsabschnitt eingrenzen: Trailer und der Text ohne Art fallen weg. $this->toggle($component, MaterialKindSelection::WITHOUT); $this->toggle($component, 'k'.$this->kind('trailer')); $this->assertSame(['Ablauf der Übung', 'Merkblatt Abstand'], $this->titles($component)); // Die Suche grenzt die Treffer weiter ein, die Auswahl bleibt. $component->set('suche', 'ablauf'); $this->assertSame(['Ablauf der Übung'], $this->titles($component)); $component->assertSet('arten', fn (string $value): bool => str_contains($value, 'k'.$this->kind('merkblatt')) && str_contains($value, 'k'.$this->kind('uebungsabschnitt'))); // Kacheln zeigen dieselbe Auswahl. $component->set('suche', '')->set('ansicht', 'kacheln'); $this->assertSame(['Ablauf der Übung', 'Merkblatt Abstand'], $this->titles($component)); } public function test_the_row_names_the_exercise_and_leads_to_its_editor(): void { $this->library(); $component = Livewire::actingAs($this->editor(), 'staff')->test(ListContentElements::class); $this->toggle($component, 'k'.$this->kind('uebungsabschnitt')); $component ->assertSee('Übung: Wohlfühlabstand') ->assertSee('Zur Übung'); } public function test_select_all_includes_exercise_sections_and_texts_without_a_kind(): void { $this->library(); $component = Livewire::actingAs($this->editor(), 'staff')->test(ListContentElements::class)->call('selectAllArten'); $this->assertContains('Ablauf der Übung', $this->titles($component)); $this->assertContains('Alter Text ohne Art', $this->titles($component)); $this->assertContains(MaterialKindSelection::WITHOUT, $component->instance()->selectedArten()); $this->assertContains('k'.$this->kind('uebungsabschnitt'), $component->instance()->selectedArten()); } public function test_without_any_check_the_list_says_so_and_the_choice_stays_visible(): void { $this->library(); $component = Livewire::actingAs($this->editor(), 'staff')->test(ListContentElements::class); foreach (array_keys($component->instance()->artChoices()) as $key) { if (in_array($key, $component->instance()->selectedArten(), true)) { $this->toggle($component, $key); } } $component->assertSet('arten', MaterialKindSelection::NONE) ->assertSee('Keine Materialart ausgewählt') ->assertSee('Wähle oben mindestens eine Materialart aus') ->assertSee('Ohne Materialart') ->assertSee('Übungsabschnitt'); $this->assertSame([], $this->titles($component)); } public function test_the_old_address_with_one_kind_still_works(): void { $this->library(); $this->assertSame( ['Trailer Park'], $this->titles(Livewire::withQueryParams(['inhaltsart' => (string) $this->kind('trailer')])->actingAs($this->editor(), 'staff')->test(ListContentElements::class)), ); } // ---------------------------------------------------------------- 4. Persönlicher Standard public function test_the_personal_default_is_saved_restored_kept_across_logins_and_deleted(): void { $this->library(); $mine = $this->editor(); $other = $this->editor(); $component = Livewire::actingAs($mine, 'staff')->test(ListContentElements::class); $this->toggle($component, 'k'.$this->kind('uebungsabschnitt')); $this->toggle($component, MaterialKindSelection::WITHOUT); $component->set('suche', 'etwas Vorübergehendes') ->call('saveDefault'); $saved = UserViewDefault::filtersFor($mine->id, UserViewDefault::MEDIA); $this->assertNotNull($saved); $this->assertArrayNotHasKey('suche', $saved, 'Die Suche gehört nicht zum Standard.'); // Vorübergehend geändert, dann wiederhergestellt. $component->call('selectAllArten'); $this->toggle($component, 'k'.$this->kind('trailer')); $component->call('restoreDefault')->assertSet('suche', ''); $this->assertSame(['Ablauf der Übung', 'Merkblatt Abstand', 'Trailer Park'], $this->titles($component)); // Neue Anmeldung (neue Seite ohne Vorgaben in der Adresse): dieselbe Auswahl. $this->assertSame( ['Ablauf der Übung', 'Merkblatt Abstand', 'Trailer Park'], $this->titles(Livewire::actingAs($mine, 'staff')->test(ListContentElements::class)), ); // Ein zweites Konto sieht die allgemeine Startansicht. $this->assertSame( ['Alter Text ohne Art', 'Merkblatt Abstand', 'Trailer Park'], $this->titles(Livewire::actingAs($other, 'staff')->test(ListContentElements::class)), ); // Löschen: allgemeine Auswahl, sofort und beim nächsten Öffnen. Livewire::actingAs($mine, 'staff')->test(ListContentElements::class)->call('deleteDefault')->assertSet('arten', ''); $this->assertNull(UserViewDefault::filtersFor($mine->id, UserViewDefault::MEDIA)); $this->assertSame( ['Alter Text ohne Art', 'Merkblatt Abstand', 'Trailer Park'], $this->titles(Livewire::actingAs($mine, 'staff')->test(ListContentElements::class)), ); } public function test_an_address_with_its_own_filters_wins_over_the_personal_default(): void { $this->library(); $mine = $this->editor(); UserViewDefault::remember($mine->id, UserViewDefault::MEDIA, ['arten' => MaterialKindSelection::encode(['k'.$this->kind('trailer')]), 'ansicht' => 'kacheln']); $this->assertSame(['Trailer Park'], $this->titles(Livewire::actingAs($mine, 'staff')->test(ListContentElements::class))); $this->assertSame( ['Alter Text ohne Art', 'Merkblatt Abstand', 'Trailer Park'], $this->titles(Livewire::withQueryParams(['suche' => ''])->actingAs($mine, 'staff')->test(ListContentElements::class)->set('arten', '')), ); } public function test_the_standard_actions_that_need_a_saved_standard_are_disabled_without_one(): void { $this->library(); $mine = $this->editor(); $page = Livewire::actingAs($mine, 'staff')->test(ListContentElements::class); $this->assertFalse($page->instance()->hasSavedDefault()); $page->assertSee('Als Standard speichern')->assertSeeHtml('wire:click="restoreDefault" disabled'); $page->call('saveDefault'); $this->assertTrue($page->instance()->hasSavedDefault()); } // ---------------------------------------------------------------- Hilfen /** * Medien: ein Merkblatt, ein Trailer, ein alter Text ohne Art und ein Übungsabschnitt. */ private function library(): void { $content = app(ContentService::class); $exercise = $this->exerciseComposition('Wohlfühlabstand'); $merkblatt = $content->createElement('dokument', 'document', 'Merkblatt Abstand'); $merkblatt->forceFill(['editorial_content_kind_id' => $this->kind('merkblatt')])->save(); $trailer = $content->createElement('film', 'film', 'Trailer Park'); $trailer->forceFill(['editorial_content_kind_id' => $this->kind('trailer')])->save(); $content->createElement('text', 'text', 'Alter Text ohne Art'); $section = $content->createElement('text', 'text', 'Ablauf der Übung'); app(ExerciseSections::class)->mark($section, $exercise); } /** Ein Häkchen setzen oder entfernen, wie im Browser. */ private function toggle($component, string $key): void { $current = $component->instance()->artenAuswahl; $component->set('artenAuswahl', in_array($key, $current, true) ? array_values(array_diff($current, [$key])) : [...$current, $key]); } /** * @return list */ private function titles($component): array { return array_column($component->instance()->cards(), 'title'); } /** * @return array */ private function card(ContentElement $element): array { return app(MediaLibrary::class)->cardFor($element->fresh(), true); } private function kind(string $slug): int { return (int) EditorialContentKind::query()->where('slug', $slug)->value('id') ?: $this->makeKind($slug); } /** Testdaten für Arten, die die Migrationen nicht anlegen. */ private function makeKind(string $slug): int { return (int) EditorialContentKind::query()->create([ 'slug' => $slug, 'label' => ucfirst($slug), 'sort_order' => 50, 'is_active' => true, 'contexts' => ['medium'], ])->id; } private function editor(): User { $editor = User::factory()->redakteur()->create(); $editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP'); return $editor; } /** * @return array */ private function document(string $id, string $title, string $hash): array { return [ 'source_id' => $id, 'title' => $title, 'summary' => 'Kurzbeschreibung', 'goal' => 'Lernziel '.$hash, 'execution' => 'Durchführung der Übung '.$hash, 'preparation' => 'Vorbereitung der Übung '.$hash, 'trainer_notes' => '', 'equipment' => '', 'duration_min' => 10, 'duration_max' => 10, 'variants' => [], 'media' => [], 'content_hash' => str_repeat($hash[1], 64), ]; } }