create('Stopp sagen', CompositionKind::Exercise); $component = Livewire::actingAs($this->editor(), 'staff') ->test(EditPractice::class, ['record' => $practice->getKey()]) ->assertOk(); $component->set('rich.summary', [ 'type' => 'doc', 'content' => [['type' => 'paragraph', 'content' => [['type' => 'text', 'text' => 'Fester ', 'marks' => []], ['type' => 'text', 'text' => 'Stand', 'marks' => [['type' => 'bold']]]]]], ]); $this->assertSame('

Fester Stand

', $component->get('summary')); $component->set('summary', '

Vom Server

')->assertOk(); $this->assertSame('doc', $component->get('rich.summary.type')); $this->assertSame('Vom Server', $component->get('rich.summary.content.0.content.0.text')); } public function test_legacy_plain_text_appears_formatted_but_opening_it_changes_nothing(): void { $practice = app(EditorialCatalog::class)->create('Stopp sagen', CompositionKind::Exercise); $practice->forceFill(['summary' => "Erste Zeile.\n\n- Punkt A\n- Punkt B"])->save(); $component = Livewire::actingAs($this->editor(), 'staff') ->test(EditPractice::class, ['record' => $practice->getKey()]) ->assertOk(); $this->assertSame("Erste Zeile.\n\n- Punkt A\n- Punkt B", $component->get('summary'), 'Die Eigenschaft bleibt, was gespeichert ist.'); $this->assertSame('bulletList', $component->get('rich.summary.content.1.type'), 'Der Editor zeigt die Liste.'); $this->assertFalse($component->instance()->textFieldsChanged(), 'Öffnen markiert nichts als geändert.'); $this->assertSame("Erste Zeile.\n\n- Punkt A\n- Punkt B", $practice->fresh()->summary); } public function test_saving_stores_canonical_html_and_an_untouched_legacy_field_is_not_reported_as_changed(): void { $practice = app(EditorialCatalog::class)->create('Stopp sagen', CompositionKind::Exercise); $component = Livewire::actingAs($this->editor(), 'staff') ->test(EditPractice::class, ['record' => $practice->getKey()]) ->set('summary', '

Kurz fett

') ->set('description', '

Lang

'); $this->assertTrue($component->instance()->textFieldsChanged()); $component->call('saveRedaktion'); $practice->refresh(); $this->assertSame(FormattedText::canonicalHtml('

Kurz fett

'), $practice->summary); $this->assertSame('

Lang

', $practice->description); } public function test_a_list_and_a_nested_list_pass_the_payload_depth_guard(): void { $practice = app(EditorialCatalog::class)->create('Stopp sagen', CompositionKind::Exercise); $item = fn (string $text, array $more = []): array => ['type' => 'listItem', 'content' => [['type' => 'paragraph', 'content' => [['type' => 'text', 'text' => $text]]], ...$more]]; $component = Livewire::actingAs($this->editor(), 'staff') ->test(EditPractice::class, ['record' => $practice->getKey()]) ->set('rich.summary', ['type' => 'doc', 'content' => [['type' => 'paragraph', 'content' => [['type' => 'text', 'text' => 'Davor']]], ['type' => 'bulletList', 'content' => [$item('Eins', [['type' => 'bulletList', 'content' => [$item('Eins eins')]]]), $item('Zwei')]]]]) ->assertHasNoErrors(); $this->assertSame('

Davor

', $component->get('summary')); $component->set('rich.summary.content.1.content.0.content.0.content.0.text', 'Geändert'); $this->assertStringContainsString('Geändert', $component->get('summary')); } public function test_opening_a_legacy_exercise_reports_no_unsaved_changes(): void { $exercise = $this->exercise('Altbestand'); $composition = $exercise['version']->composition; $component = Livewire::actingAs($this->editor(), 'staff') ->test(EditPractice::class, ['record' => $composition->getKey()]) ->assertOk(); $this->assertStringNotContainsString('ungespeicherte', $component->instance()->editorStatus()); $this->assertSame('Nein sagen und Abstand halten', $component->get('rich.learningGoal.content.0.content.0.text'), 'Das Lernziel steht im Editor.'); $this->assertFalse($component->instance()->textFieldsChanged()); } public function test_an_untouched_legacy_exercise_creates_no_new_version_when_released_again(): void { $exercise = $this->exercise('Altbestand'); $composition = $exercise['version']->composition; Livewire::actingAs($this->editor(), 'staff') ->test(EditPractice::class, ['record' => $composition->getKey()]) ->call('saveDraft') ->call('armRelease') ->set('releaseConsent', true) ->call('publishRevision'); $this->assertSame(1, $composition->versions()->count()); $this->assertSame('Nein sagen und Abstand halten', $composition->versions()->first()->learning_goal, 'Der Altbestand bleibt Klartext.'); } public function test_formatting_the_learning_goal_is_a_real_change_and_creates_a_version(): void { $exercise = $this->exercise('Altbestand'); $composition = $exercise['version']->composition; Livewire::actingAs($this->editor(), 'staff') ->test(EditPractice::class, ['record' => $composition->getKey()]) ->set('learningGoal', '

Nein sagen und Abstand halten

') ->call('saveDraft') ->call('armRelease') ->set('releaseConsent', true) ->call('publishRevision'); $this->assertSame(2, $composition->versions()->count()); $this->assertSame('

Nein sagen und Abstand halten

', $composition->versions()->orderByDesc('number')->first()->learning_goal); $this->assertSame('Nein sagen und Abstand halten', $composition->versions()->orderBy('number')->first()->learning_goal, 'Die frühere Fassung bleibt unverändert.'); } public function test_a_medium_keeps_its_plain_description_unless_it_is_edited_and_stores_edits_as_clean_html(): void { $content = app(ContentService::class); $element = $content->createElement('text', 'text', 'Trainerunterlage'); $content->publishElementVersion($element, 'Der Wortlaut'); $content->describe($element, 'Trainerunterlage', 'Alt und schlicht. - Punkt'); $before = IdentityChange::query()->count(); $component = Livewire::actingAs($this->editor(), 'staff') ->test(ViewContentElement::class, ['record' => $element->getKey()]) ->call('openRedaktion') ->call('saveRedaktion'); $this->assertSame('Alt und schlicht. - Punkt', $element->fresh()->description, 'Speichern ohne Änderung lässt den Altbestand, wie er ist.'); $this->assertSame($before, IdentityChange::query()->count()); $component->set('descriptionText', '

Neu fett

')->call('saveRedaktion'); $this->assertSame('

Neu fett

', $element->fresh()->description); } private function editor(): User { $editor = User::factory()->redakteur()->create(); $editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP'); return $editor; } }