Öffentliche Leser, Shop, Medienliste und Bibliothek lesen Kurzbeschreibung, Beschreibung und Lernziel als Klartext; Mitgliederseiten zu Programm, Inhalt und Artikel zeigen die formatierte Fassung. Der Editor trägt die deutsche Bezeichnung des Felds als Namen für Hilfstechnik, der Tastaturfokus landet im Editor, und der Abgleich merkt sich nur eine Prüfsumme. ADR-50 nennt Rückfall und Suche. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
208 lines
9.7 KiB
PHP
208 lines
9.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Domain\Catalog\CompositionKind;
|
|
use App\Domain\Catalog\ContentService;
|
|
use App\Domain\Catalog\EditorialProfileReader;
|
|
use App\Domain\Catalog\FormattedText;
|
|
use App\Domain\Catalog\IdentityChange;
|
|
use App\Filament\Resources\ContentElements\Pages\ViewContentElement;
|
|
use App\Filament\Resources\Practices\Pages\EditPractice;
|
|
use App\Filament\Support\EditorialCatalog;
|
|
use App\Http\LibraryCatalog;
|
|
use App\Models\User;
|
|
use Filament\Facades\Filament;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Livewire\Livewire;
|
|
use Tests\Support\BuildsExercises;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Formatierte Textfelder im Arbeitsplatz (ADR-50): Der Editor schreibt kanonisches HTML in die Eigenschaft, Klartext des
|
|
* Altbestands erscheint formatiert, ohne dass das Öffnen etwas als geändert markiert.
|
|
*/
|
|
class FormatierteTexteEditorTest extends TestCase
|
|
{
|
|
use BuildsExercises;
|
|
use RefreshDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
|
|
}
|
|
|
|
public function test_the_editor_state_reaches_the_property_as_canonical_html_and_back(): void
|
|
{
|
|
$practice = app(EditorialCatalog::class)->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('<p>Fester <strong>Stand</strong></p>', $component->get('summary'));
|
|
|
|
$component->set('summary', '<p>Vom Server</p>')->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', '<p>Kurz <b>fett</b></p>')
|
|
->set('description', '<p>Lang</p><script>x()</script>');
|
|
|
|
$this->assertTrue($component->instance()->textFieldsChanged());
|
|
$component->call('saveRedaktion');
|
|
|
|
$practice->refresh();
|
|
$this->assertSame(FormattedText::canonicalHtml('<p>Kurz <strong>fett</strong></p>'), $practice->summary);
|
|
$this->assertSame('<p>Lang</p>', $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('<p>Davor</p><ul><li><p>Eins</p><ul><li><p>Eins eins</p></li></ul></li><li><p>Zwei</p></li></ul>', $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_a_formatted_summary_reads_as_plain_text_wherever_a_card_or_list_uses_it(): void
|
|
{
|
|
$practice = app(EditorialCatalog::class)->create('Stopp sagen', CompositionKind::Exercise);
|
|
$practice->forceFill([
|
|
'summary' => '<p>Kurz <strong>fett</strong> & klar</p><ul><li><p>Eins</p></li><li><p>Zwei</p></li></ul>',
|
|
'description' => '<p>Lang <em>erklärt</em></p>',
|
|
])->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('<strong>fett</strong>', $text['summary_html']);
|
|
$this->assertStringContainsString('<em>erklärt</em>', $text['description_html']);
|
|
|
|
$profile = app(EditorialProfileReader::class)->read($practice->fresh(), 'bibliothek');
|
|
$this->assertStringNotContainsString('<', (string) $profile->value('summary'));
|
|
$this->assertStringContainsString('<ul>', $profile->html('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', '<p>Nein sagen und <strong>Abstand</strong> halten</p>')
|
|
->call('saveDraft')
|
|
->call('armRelease')
|
|
->set('releaseConsent', true)
|
|
->call('publishRevision');
|
|
|
|
$this->assertSame(2, $composition->versions()->count());
|
|
$this->assertSame('<p>Nein sagen und <strong>Abstand</strong> halten</p>', $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', '<p>Neu <b>fett</b></p><script>x()</script>')->call('saveRedaktion');
|
|
|
|
$this->assertSame('<p>Neu <strong>fett</strong></p>', $element->fresh()->description);
|
|
}
|
|
|
|
private function editor(): User
|
|
{
|
|
$editor = User::factory()->redakteur()->create();
|
|
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
|
|
|
return $editor;
|
|
}
|
|
}
|