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
Eins
Eins eins
Zwei
Kurz fett & klar
Eins
Zwei
Lang erklärt
', ])->save(); $text = app(LibraryCatalog::class)->text($practice->fresh()); $this->assertSame('Kurz fett & klar - Eins - Zwei', $text['summary']); $this->assertSame('Lang erklärt', $text['description']); $this->assertStringContainsString('fett', $text['summary_html']); $this->assertStringContainsString('erklärt', $text['description_html']); $profile = app(EditorialProfileReader::class)->read($practice->fresh(), 'bibliothek'); $this->assertStringNotContainsString('<', (string) $profile->value('summary')); $this->assertStringContainsString('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; } }