Schreibe die Einleitung der Überschrift im Editor des Fließtexts
Das Widget Überschrift und Einleitung (jetzt Version 2) nimmt die Einleitung als formatierten Text: Absätze, Zeilenumbrüche, Auszeichnungen, Schriftgröße, -farbe und Ausrichtung wie im Fließtext. Die Regeln für .prose gelten auch für die Überschrift. Klartext der Version 1 wird beim Lesen zu Absätzen mit Zeilenumbrüchen angehoben. Drei Tests erwarteten das alte Markup der Einleitung und wurden bewusst angepasst. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bd91104970
commit
00b7ce9b3f
13 files changed
+249
-48
No files matched your search
@@ -161,7 +161,7 @@ public function test_a_symbol_beside_the_paragraph_has_a_size_and_a_vertical_ali
|
||||
{
|
||||
$html = $this->publish('/gross', $this->widget('heading', ['heading' => 'Filme', 'intro' => 'Kurz erklärt'], ['symbol' => 'filmklappe', 'symbol_size' => 'large']));
|
||||
|
||||
$this->assertMatchesRegularExpression('~<div class="lf-lead lf-lead--large lf-lead--top"><svg[^>]*class="brand-symbol lf-lead__symbol"[^>]*>.*?</svg><div class="lf-lead__body">\s*<h2>Filme</h2>\s*<p class="lede">Kurz erklärt</p>\s*</div></div>~s', $html);
|
||||
$this->assertMatchesRegularExpression('~<div class="lf-lead lf-lead--large lf-lead--top"><svg[^>]*class="brand-symbol lf-lead__symbol"[^>]*>.*?</svg><div class="lf-lead__body">\s*<h2>Filme</h2>\s*<div class="prose lede"><p>Kurz erklärt</p></div>\s*</div></div>~s', $html);
|
||||
$this->assertStringNotContainsString('lf-heading-symbol', $html, 'Das kleine Symbol entfällt, sonst stünde es doppelt.');
|
||||
|
||||
foreach ([['medium', 'center'], ['xlarge', 'bottom']] as [$size, $align]) {
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Cms\Page;
|
||||
use App\Domain\Cms\PageService;
|
||||
use App\Domain\Cms\Widgets\WidgetRegistry;
|
||||
use Filament\Forms\Components\RichEditor;
|
||||
use Filament\Schemas\Concerns\InteractsWithSchemas;
|
||||
use Filament\Schemas\Contracts\HasSchemas;
|
||||
use Filament\Schemas\Schema;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Component;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Überschrift und Einleitung: Die Einleitung wird im Editor des Fließtexts geschrieben und genauso dargestellt
|
||||
* (Absätze, Zeilenumbrüche, Auszeichnungen, Schriftgröße, -farbe, Ausrichtung). Version 1 (Klartext) wird angehoben.
|
||||
*/
|
||||
class CmsHeadingIntroTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private const EDITOR = '<p style="text-align: center">Erste Zeile<br>Zweite Zeile mit <strong>fett</strong> und <span class="color" data-color="rot">rot</span></p><p><span data-size="large">Groß</span> im zweiten Absatz mit <a href="/materialien">Link</a>.</p><ul><li><p>Eins</p></li></ul>';
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @param array<string, mixed> $settings
|
||||
*/
|
||||
private function publish(string $path, array $data, int $version = 2, array $settings = []): string
|
||||
{
|
||||
$page = Page::query()->create(['path' => $path]);
|
||||
$service = app(PageService::class);
|
||||
$sections = [['layout' => 'u4', 'style' => [], 'slots' => [['type' => 'heading', 'v' => $version, 'settings' => $settings, 'data' => $data]]]];
|
||||
$service->publish($page, $service->saveRevision($page, $sections, null, null, null));
|
||||
|
||||
return $this->get($path)->assertOk()->getContent();
|
||||
}
|
||||
|
||||
public function test_the_intro_field_is_the_website_editor_of_the_prose_widget(): void
|
||||
{
|
||||
$fields = collect(app(WidgetRegistry::class)->get('heading')->dataFields())->keyBy(fn ($field) => $field->getName());
|
||||
|
||||
$field = $fields['intro'];
|
||||
$this->assertInstanceOf(RichEditor::class, $field);
|
||||
|
||||
$livewire = new class extends Component implements HasSchemas
|
||||
{
|
||||
use InteractsWithSchemas;
|
||||
|
||||
public function render(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
};
|
||||
$field->container(Schema::make($livewire));
|
||||
|
||||
$this->assertFalse($field->isRequired());
|
||||
|
||||
$buttons = array_merge(...$field->getToolbarButtons());
|
||||
$this->assertSame([], array_values(array_diff(['bold', 'italic', 'link', 'bulletList', 'table', 'fontSize', 'textColor', 'alignCenter', 'alignEnd'], $buttons)));
|
||||
$this->assertArrayHasKey('rot', $field->getTextColors());
|
||||
}
|
||||
|
||||
public function test_the_intro_keeps_paragraphs_line_breaks_and_formatting_on_the_page(): void
|
||||
{
|
||||
$html = $this->publish('/einleitung-reich', ['heading' => 'Titel', 'intro' => self::EDITOR]);
|
||||
|
||||
$this->assertStringContainsString('<div class="prose lede"><p class="ta-center">Erste Zeile<br>Zweite Zeile mit <strong>fett</strong> und <span class="color" data-color="rot">rot</span></p><p><span data-size="large">Groß</span> im zweiten Absatz mit <a href="/materialien" rel="noopener noreferrer">Link</a>.</p><ul><li><p>Eins</p></li></ul></div>', $html);
|
||||
$this->assertStringNotContainsString('style="text-align', $html, 'Die Ausrichtung ist eine Klasse, kein Inline-Stil.');
|
||||
}
|
||||
|
||||
public function test_the_intro_is_sanitized_when_saving_and_empty_text_is_dropped(): void
|
||||
{
|
||||
$registry = app(WidgetRegistry::class);
|
||||
|
||||
$stored = $registry->normalize([['type' => 'heading', 'v' => 2, 'data' => ['heading' => 'T', 'intro' => '<p onclick="x()">Hallo<script>alert(1)</script> <a href="javascript:alert(1)">böse</a></p>']]]);
|
||||
$intro = $stored[0]['data']['intro'];
|
||||
|
||||
$this->assertStringNotContainsString('script', $intro);
|
||||
$this->assertStringNotContainsString('onclick', $intro);
|
||||
$this->assertStringNotContainsString('javascript:', $intro);
|
||||
|
||||
$empty = $registry->normalize([['type' => 'heading', 'v' => 2, 'data' => ['heading' => 'T', 'intro' => '<p></p>']]]);
|
||||
$this->assertArrayNotHasKey('intro', $empty[0]['data']);
|
||||
}
|
||||
|
||||
public function test_plain_text_of_version_one_becomes_paragraphs_with_line_breaks_and_stays_escaped(): void
|
||||
{
|
||||
$widget = app(WidgetRegistry::class)->get('heading')->upgrade(['type' => 'heading', 'v' => 1, 'data' => ['heading' => 'T', 'intro' => "Erste Zeile\nZweite Zeile\n\nNeuer Absatz mit <b>Markup</b> & mehr"]], 1);
|
||||
|
||||
$this->assertSame('<p>Erste Zeile<br>Zweite Zeile</p><p>Neuer Absatz mit <b>Markup</b> & mehr</p>', $widget['data']['intro']);
|
||||
|
||||
$html = $this->publish('/einleitung-alt', ['heading' => 'Titel', 'intro' => "Eins\nZwei\n\nDrei"], 1);
|
||||
$this->assertStringContainsString('<div class="prose lede"><p>Eins<br>Zwei</p><p>Drei</p></div>', $html);
|
||||
}
|
||||
|
||||
public function test_a_heading_without_intro_renders_no_intro_and_the_reading_width_applies(): void
|
||||
{
|
||||
$html = $this->publish('/ohne-einleitung', ['heading' => 'Nur Titel']);
|
||||
$this->assertStringNotContainsString('lede', $html);
|
||||
|
||||
$reading = $this->publish('/lesebreite', ['heading' => 'Titel', 'intro' => '<p>Text</p>'], 2, ['text_width' => 'reading']);
|
||||
$this->assertStringContainsString('<div class="prose lede lf-reading prose--reading"><p>Text</p></div>', $reading);
|
||||
}
|
||||
|
||||
public function test_the_stylesheet_formats_the_intro_like_the_prose_widget(): void
|
||||
{
|
||||
$css = (string) file_get_contents(resource_path('css/widgets.css'));
|
||||
|
||||
foreach (["span[data-size='xlarge']", "span.color[data-color='gruen']", '.ta-center', 'blockquote', 'p {', 'h3,'] as $needle) {
|
||||
$this->assertStringContainsString(':is(.widget-prose, .widget-heading) .prose '.$needle, $css, $needle);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_the_summary_and_page_title_are_still_the_heading(): void
|
||||
{
|
||||
$type = app(WidgetRegistry::class)->get('heading');
|
||||
|
||||
$this->assertSame('Titel', $type->summary(['data' => ['heading' => 'Titel', 'intro' => self::EDITOR]]));
|
||||
$this->assertSame('Titel', $type->pageTitle(['data' => ['heading' => 'Titel']]));
|
||||
}
|
||||
}
|
||||
@@ -138,14 +138,14 @@ public function test_the_editor_field_is_the_shared_rich_editor(): void
|
||||
public function test_heading_and_prose_use_the_full_width_unless_the_reading_width_is_chosen(): void
|
||||
{
|
||||
$full = $this->publish('/breite-voll', [['layout' => 'u4', 'style' => [], 'slots' => [['type' => 'heading', 'v' => 1, 'data' => ['heading' => 'Eine Überschrift', 'intro' => 'Einleitung']]]], ['layout' => 'u4', 'style' => [], 'slots' => [['type' => 'prose', 'v' => 2, 'data' => ['body' => '<p>Text</p>']]]]]);
|
||||
$this->assertStringContainsString('<p class="lede">Einleitung</p>', $full);
|
||||
$this->assertStringContainsString('<div class="prose lede"><p>Einleitung</p></div>', $full);
|
||||
$this->assertStringContainsString('<div class="prose"><p>Text</p></div>', $full);
|
||||
$this->assertStringNotContainsString('lf-reading', $full);
|
||||
$this->assertStringNotContainsString('prose--reading', $full);
|
||||
|
||||
$reading = $this->publish('/breite-lesen', [['layout' => 'u4', 'style' => [], 'slots' => [['type' => 'heading', 'v' => 1, 'settings' => ['text_width' => 'reading'], 'data' => ['heading' => 'Eine Überschrift', 'intro' => 'Einleitung']]]], ['layout' => 'u4', 'style' => [], 'slots' => [['type' => 'prose', 'v' => 2, 'settings' => ['text_width' => 'reading'], 'data' => ['body' => '<p>Text</p>']]]]]);
|
||||
$this->assertStringContainsString('<h1 class="lf-reading">', $reading, 'Das erste Widget der Seite ist die H1.');
|
||||
$this->assertStringContainsString('<p class="lede lf-reading">Einleitung</p>', $reading);
|
||||
$this->assertStringContainsString('<div class="prose lede lf-reading prose--reading"><p>Einleitung</p></div>', $reading);
|
||||
$this->assertStringContainsString('<div class="prose prose--reading">', $reading);
|
||||
}
|
||||
|
||||
|
||||
@@ -291,10 +291,10 @@ public function test_legacy_blocks_are_read_as_version_one_envelopes(): void
|
||||
$this->assertSame([
|
||||
'id' => null,
|
||||
'type' => 'heading',
|
||||
'v' => 1,
|
||||
'v' => 2,
|
||||
'variant' => 'standard',
|
||||
'settings' => [],
|
||||
'data' => ['heading' => 'Alt', 'intro' => 'Einleitung'],
|
||||
'data' => ['heading' => 'Alt', 'intro' => '<p>Einleitung</p>'],
|
||||
'refs' => [],
|
||||
], $widget);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user