create('Stopp sagen', CompositionKind::Exercise); $cell = fn (string $type, string $text, array $attrs = []): array => ['type' => $type, 'attrs' => $attrs + ['colspan' => 1, 'rowspan' => 1, 'colwidth' => null], 'content' => [['type' => 'paragraph', 'content' => [['type' => 'text', 'text' => $text]]]]]; $component = Livewire::actingAs($this->editor(), 'staff') ->test(EditPractice::class, ['record' => $practice->getKey()]) ->set('rich.partBody', ['type' => 'doc', 'content' => [ ['type' => 'table', 'content' => [ ['type' => 'tableRow', 'content' => [$cell('tableHeader', 'Zeit'), $cell('tableHeader', 'Inhalt')]], ['type' => 'tableRow', 'content' => [$cell('tableCell', '10 Min.'), $cell('tableCell', 'Begrüßung')]], ]], ]]); $stored = '

Zeit

Inhalt

10 Min.

Begrüßung

'; $this->assertSame($stored, $component->get('partBody')); // Zurück in den Editor und wieder heraus: kein Verlust, keine Scheinänderung. $component->set('partBody', $stored)->assertOk(); $this->assertSame('table', $component->get('rich.partBody.content.0.type')); $this->assertSame('Begrüßung', $component->get('rich.partBody.content.0.content.1.content.1.content.0.content.0.text')); $this->assertSame($stored, FormattedText::canonical($component->get('partBody'))); } public function test_an_image_stays_a_reference_to_its_version_and_the_editor_gets_a_staff_address(): void { $image = $this->image('Stellung'); $practice = app(EditorialCatalog::class)->create('Stopp sagen', CompositionKind::Exercise); $stored = '

Davor

Stellung

Danach

'; $component = Livewire::actingAs($this->editor(), 'staff') ->test(EditPractice::class, ['record' => $practice->getKey()]) ->set('partBody', $stored) ->assertOk(); $node = $component->get('rich.partBody.content.1'); $this->assertSame('image', $node['type']); $this->assertSame((string) $image->id, (string) $node['attrs']['id']); $this->assertSame(route('content.file', ['version' => $image->id], false), $node['attrs']['src']); // Der Editor gibt die Adresse mit zurück; gespeichert wird sie nie. $component->set('rich.partBody', ['type' => 'doc', 'content' => [$node]]); $this->assertSame('Stellung', $component->get('partBody')); } public function test_the_image_tool_exists_only_in_text_editors_with_the_picker(): void { $practice = app(EditorialCatalog::class)->create('Stopp sagen', CompositionKind::Exercise); $component = Livewire::actingAs($this->editor(), 'staff') ->test(EditPractice::class, ['record' => $practice->getKey()]); $page = $component->instance(); $this->assertContains('bild', collect($page->richKomponente('partBody')->getToolbarButtons())->flatten()->all()); $this->assertContains('bild', collect($page->richKomponente('newTextBody')->getToolbarButtons())->flatten()->all()); $this->assertNotContains('bild', collect($page->richKomponente('summary')->getToolbarButtons())->flatten()->all(), 'Kurzangaben nehmen keine Bilder auf.'); foreach (['partBody', 'summary', 'learningGoal'] as $field) { $this->assertContains('table', collect($page->richKomponente($field)->getToolbarButtons())->flatten()->all(), $field.' hat dieselben Tabellenwerkzeuge.'); } } public function test_the_picker_offers_released_images_and_inserts_the_chosen_version_at_the_cursor(): void { $image = $this->image('Stellung'); $draft = app(ContentService::class)->draftElementVersion(app(ContentService::class)->createElement('bild', 'bild', 'Entwurfsbild'), null, ['file' => 'inhalte/entwurf.jpg']); $practice = app(EditorialCatalog::class)->create('Stopp sagen', CompositionKind::Exercise); $component = Livewire::actingAs($this->editor(), 'staff') ->test(EditPractice::class, ['record' => $practice->getKey()]) ->call('openTextImagePicker', 'partBody', ['type' => 'text', 'anchor' => 1, 'head' => 1]) ->assertSet('pickerOpen', true) ->assertSet('pickerPurpose', 'textbild'); $this->assertSame('Bild einfügen', $component->instance()->pickerConfirmLabel()); $this->assertSame(['bild' => 'Bilder'], $component->instance()->pickerKinds()); $component->call('markPicker', 'element:'.$image->id, true)->call('confirmPicker'); $component->assertSet('pickerOpen', false)->assertDispatched('run-rich-editor-commands'); // Eine noch nicht freigegebene Fassung lässt sich nicht in einen Text einfügen. $component->call('openTextImagePicker', 'partBody', [])->call('markPicker', 'element:'.$draft->id, true)->call('confirmPicker'); $this->assertStringContainsString('noch nicht freigegeben', (string) $component->get('deskFeedback')); } public function test_a_text_with_an_unreleased_image_cannot_be_frozen(): void { $content = app(ContentService::class); $draftImage = $content->draftElementVersion($content->createElement('bild', 'bild', 'Entwurfsbild'), null, ['file' => 'inhalte/entwurf.jpg']); $text = $content->draftElementVersion($content->createElement('text', 'text', 'Kapitel'), '

Text

'); $this->assertStringContainsString('noch nicht freigegeben', (string) $content->elementReleaseProblem($text)); $released = $content->releaseElementVersion($draftImage); $this->assertNull($content->elementReleaseProblem($text->refresh())); $this->assertSame($released->id, $draftImage->id); $content->block($released, 'Rechte'); $this->assertStringContainsString('deaktiviert', (string) $content->imageProblem($text->body)); } private function image(string $title) { $content = app(ContentService::class); return $content->publishElementVersion($content->createElement('bild', 'bild', $title), null, ['file' => 'inhalte/'.str($title)->slug().'.jpg']); } private function editor(): User { $editor = User::factory()->redakteur()->create(); $editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP'); return $editor; } }