'https://shinkan.test', 'services.shinkan.key' => 'geheim-fuer-den-test']); Filament::setCurrentPanel(Filament::getPanel('verwaltung')); } // ---------------------------------------------------------------- Abruf und Fassungen public function test_a_first_call_records_each_exercise_once_without_creating_a_local_version(): void { $this->fake([$this->document('h1')], [['source_id' => self::ID, 'change' => 'added', 'content_hash' => 'h1']], 'c1'); $run = app(ShinkanImport::class)->fetch(); $this->assertSame('ok', $run->status); $this->assertSame('c1', $run->cursor); $this->assertSame(1, $run->added); $this->assertSame(1, ExerciseSource::query()->count()); $this->assertSame(1, ExerciseSourceSnapshot::query()->count()); $this->assertSame(0, Composition::query()->count(), 'Abrufen legt keine lokale Übung an.'); } public function test_the_same_content_fetched_again_creates_nothing_new(): void { $this->fake([$this->document('h1')], [['source_id' => self::ID, 'change' => 'added', 'content_hash' => 'h1']], 'c1'); app(ShinkanImport::class)->fetch(); $this->fake([$this->document('h1')], [['source_id' => self::ID, 'change' => 'updated', 'content_hash' => 'h1']], 'c2'); app(ShinkanImport::class)->fetch(); app(ShinkanImport::class)->record($this->document('h1')); $this->assertSame(1, ExerciseSourceSnapshot::query()->count()); $this->assertSame('c2', ExerciseImportRun::query()->orderByDesc('id')->value('cursor')); } public function test_adopting_creates_one_immutable_local_version_with_the_source_fields_and_variants(): void { $snapshot = app(ShinkanImport::class)->record($this->document('h1')); $version = app(ShinkanImport::class)->adopt($snapshot); $again = app(ShinkanImport::class)->adopt($snapshot->fresh()); $this->assertSame($version->id, $again->id); $this->assertSame(1, $version->composition->versions()->count()); $this->assertSame(CompositionKind::Exercise, $version->composition->kind); $this->assertSame('uebung', $version->composition->editorialContentKind->slug); $this->assertSame('Sicher stehen und Stopp sagen', $version->composition->designation); $this->assertSame('Kurz erklärt.', $version->composition->summary); $this->assertSame('Nein sagen üben', $version->learning_goal); $this->assertSame(10, $version->duration_minutes); $this->assertSame(15, $version->duration_max); $this->assertSame('Matten, Pratzen', $version->material_note); $this->assertSame($snapshot->id, $version->source_snapshot_id); $this->assertSame([self::VARIANT_A, self::VARIANT_B], $version->variants->pluck('key')->all()); $this->assertSame(['quelle', 'quelle'], $version->variants->pluck('origin')->all()); $this->assertSame(['Vorbereitung', 'Durchführung', 'Trainerhinweise', 'Abweichung der Durchführung'], $version->members->pluck('role')->all()); $this->assertSame(['quelle'], $version->members->pluck('origin')->unique()->all()); $this->assertSame(self::VARIANT_A, $version->members->last()->variant->key); $this->assertSame($version->composition_id, ExerciseSource::query()->firstOrFail()->composition_id); } public function test_the_representative_catalog_answer_lands_in_the_documented_places(): void { $document = json_decode((string) file_get_contents(base_path('tests/Fixtures/shinkan/katalog-detail.json')), true, 512, JSON_THROW_ON_ERROR); $import = app(ShinkanImport::class); $version = $import->adopt($import->record($document)); $composition = $version->composition; $body = fn (string $role): string => (string) $version->members->firstWhere('role', $role)->contentElementVersion->body; $this->assertSame($document['title'], $composition->designation); $this->assertSame($document['summary'], $composition->summary); $this->assertSame($document['goal'], $version->learning_goal); $this->assertSame($document['equipment'], $version->material_note); $this->assertSame([10, 15], [$version->duration_minutes, $version->duration_max]); $this->assertSame($document['preparation'], $body('Vorbereitung')); $this->assertSame($document['execution'], $body('Durchführung')); $this->assertSame($document['trainer_notes'], $body('Trainerhinweise')); $this->assertSame(['Mit Partner', 'Allein vor dem Spiegel'], $version->variants->pluck('name')->all()); $this->assertSame([1, 2], $version->variants->pluck('position')->all(), 'Die Reihenfolge der Quelle bleibt.'); $this->assertSame(['Zu zweit üben, ein Kind spielt die Rolle des Gegenübers.', 'Einzelübung ohne Partner.'], $version->variants->pluck('description')->all()); $this->assertSame('Die Kinder bilden Paare und üben abwechselnd.', $body('Abweichung der Durchführung')); $this->assertCount(4, $version->members, 'Eine Variante ohne abweichende Durchführung erzeugt keinen Abschnitt.'); $preview = $import->preview(ExerciseSource::query()->firstOrFail()); $this->assertSame(['Quellvideo Sicherer Stand (video)'], $preview['media'], 'Medien bleiben Quellenangabe ohne Datei.'); } public function test_the_representative_html_answer_lands_formatted_in_the_documented_places(): void { $document = json_decode((string) file_get_contents(base_path('tests/Fixtures/shinkan/katalog-detail-html.json')), true, 512, JSON_THROW_ON_ERROR); $import = app(ShinkanImport::class); $version = $import->adopt($import->record($document)); $body = fn (string $role): string => (string) $version->members->firstWhere('role', $role)->contentElementVersion->body; $this->assertSame('

Die Kinder üben einen sicheren Stand und ein deutliches Stopp.

', $version->composition->summary); $this->assertSame('

Die Kinder können mit fester Stimme und sicherem Stand Stopp sagen.

', $version->learning_goal); $this->assertSame('Matten, Pratzen', $version->material_note); $this->assertStringContainsString('
  1. Sicheren Stand einnehmen

  2. ', $body('Durchführung')); $this->assertStringContainsString('wie sich der Stand angefühlt hat', $body('Durchführung')); $this->assertStringNotContainsString('data-shinkan', $body('Durchführung'), 'Der Verweis auf ein Quellmedium entfällt.'); $this->assertSame('

    Matten im Kreis auslegen.
    Genug Platz für Abstand zwischen den Kindern lassen.

    ', str_replace('
    ', '
    ', $body('Vorbereitung'))); $this->assertStringContainsString('