Phase 4: Seiten mit Pagebuilder, Redaktion und Freigaben
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m56s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m56s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m2s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m9s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m40s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 2m35s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m29s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m38s
CI / Build-Artefakte aktuell (pull_request) Successful in 55s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m56s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m56s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m2s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m9s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m40s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 2m35s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m29s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m38s
CI / Build-Artefakte aktuell (pull_request) Successful in 55s
- Seiten-Plugin: Seitenbaum mit Adressen, Seitennavigation, Brotkrumen und optional Hauptnavigation; Sichtbarkeit vererbt sich auf Unterseiten - Pagebuilder (Block-Registry im Kern, Plugins tragen Blöcke bei): Abschnitt, Spalten, Tabs, Akkordeon, Box, Überschrift, Text (TipTap), Zitat, Schaltflächen, Symbolliste, Tabelle, Trennlinie, Abstand, Bild, Galerie, Video (erst nach Klick), Titelbild, Ansprechpartner, Downloads, Unterseiten, Neuigkeiten, Termine; Sichtbarkeit je Block; Bereinigung beim Speichern - Editor im Portal: Ziehen und Ablegen, Autospeichern als Entwurf, Rückgängig, Gerätevorschau, Versionen, Zeitsteuerung, Bearbeitungssperre, Freigabe anfordern - Rechte „inkl. Unterseiten“ werden im Rechte-Cache aufgelöst - Neuigkeiten: Schreiben im Portal, Freigabe-Workflow mit Benachrichtigungen - Bereich „Redaktion“, Benachrichtigungen im Portal - storage/.migrations-fingerprint nicht mehr ausliefern Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
6269d3302c
commit
f3987e8386
328 changed files with 10618 additions and 389 deletions
156
tests/Feature/Pages/PagebuilderContentTest.php
Normal file
156
tests/Feature/Pages/PagebuilderContentTest.php
Normal file
|
|
@ -0,0 +1,156 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Pages;
|
||||
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use App\Pagebuilder\Blocks;
|
||||
use App\Pagebuilder\BlockType;
|
||||
use App\Pagebuilder\Content;
|
||||
use App\Pagebuilder\Field;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use RuntimeException;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PagebuilderContentTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private function content(): Content
|
||||
{
|
||||
return app(Content::class);
|
||||
}
|
||||
|
||||
public function test_unknown_blocks_and_fields_are_dropped_and_defaults_filled(): void
|
||||
{
|
||||
$clean = $this->content()->sanitize(['blocks' => [
|
||||
['id' => 'abc12345', 'type' => 'heading', 'data' => ['text' => ' Willkommen ', 'level' => '9', 'evil' => 'x']],
|
||||
['type' => 'unbekannt', 'data' => []],
|
||||
'kein Array',
|
||||
]]);
|
||||
|
||||
$this->assertCount(1, $clean['blocks']);
|
||||
$this->assertSame(['id' => 'abc12345', 'type' => 'heading', 'data' => ['text' => 'Willkommen', 'level' => '2', 'align' => 'left']], $clean['blocks'][0]);
|
||||
}
|
||||
|
||||
public function test_html_and_links_are_made_safe(): void
|
||||
{
|
||||
$clean = $this->content()->sanitize(['blocks' => [
|
||||
['type' => 'text', 'data' => ['html' => '<p onclick="x()">Hallo <script>alert(1)</script><a href="javascript:alert(1)">Link</a> <strong>fett</strong></p><iframe src="https://evil"></iframe>']],
|
||||
['type' => 'buttons', 'data' => ['buttons' => [
|
||||
['label' => 'Böse', 'url' => 'javascript:alert(1)'],
|
||||
['label' => 'Intern', 'url' => '/seiten/mav'],
|
||||
['label' => 'Ohne Schema', 'url' => 'www.example.org/x'],
|
||||
]]],
|
||||
['type' => 'image', 'data' => ['path' => '../../.env']],
|
||||
]]);
|
||||
|
||||
$html = $clean['blocks'][0]['data']['html'];
|
||||
$this->assertStringNotContainsString('script', $html);
|
||||
$this->assertStringNotContainsString('onclick', $html);
|
||||
$this->assertStringNotContainsString('javascript:', $html);
|
||||
$this->assertStringNotContainsString('iframe', $html);
|
||||
$this->assertStringContainsString('<strong>fett</strong>', $html);
|
||||
|
||||
$this->assertSame(['', '/seiten/mav', 'https://www.example.org/x'], array_column($clean['blocks'][1]['data']['buttons'], 'url'));
|
||||
$this->assertNull($clean['blocks'][2]['data']['path']);
|
||||
}
|
||||
|
||||
public function test_columns_follow_the_layout_without_losing_content(): void
|
||||
{
|
||||
$text = fn (string $t) => ['type' => 'heading', 'data' => ['text' => $t]];
|
||||
|
||||
$clean = $this->content()->sanitize(['blocks' => [[
|
||||
'type' => 'columns',
|
||||
'data' => ['layout' => '1-1'],
|
||||
'items' => [['blocks' => [$text('A')]], ['blocks' => [$text('B')]], ['blocks' => [$text('C')]]],
|
||||
]]]);
|
||||
|
||||
$columns = $clean['blocks'][0]['items'];
|
||||
$this->assertCount(2, $columns);
|
||||
$this->assertSame(['B', 'C'], array_map(fn ($b) => $b['data']['text'], $columns[1]['blocks']));
|
||||
|
||||
$grown = $this->content()->sanitize(['blocks' => [['type' => 'columns', 'data' => ['layout' => '1-1-1-1'], 'items' => []]]]);
|
||||
$this->assertCount(4, $grown['blocks'][0]['items']);
|
||||
}
|
||||
|
||||
public function test_nesting_depth_is_limited(): void
|
||||
{
|
||||
$block = ['type' => 'heading', 'data' => ['text' => 'tief']];
|
||||
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
$block = ['type' => 'section', 'items' => [['blocks' => [$block]]]];
|
||||
}
|
||||
|
||||
$clean = $this->content()->sanitize(['blocks' => [$block]]);
|
||||
$depth = 0;
|
||||
$current = $clean['blocks'];
|
||||
|
||||
while ($current !== []) {
|
||||
$depth++;
|
||||
$current = $current[0]['items'][0]['blocks'] ?? [];
|
||||
}
|
||||
|
||||
$this->assertSame(Content::MAX_DEPTH, $depth);
|
||||
}
|
||||
|
||||
public function test_blocks_can_be_limited_to_audiences(): void
|
||||
{
|
||||
$mav = Role::query()->create(['name' => 'MAV']);
|
||||
$member = User::factory()->withRoles([$mav])->create();
|
||||
$nurse = User::factory()->create(['department' => 'Pflege']);
|
||||
$other = User::factory()->create(['department' => 'Verwaltung']);
|
||||
|
||||
$content = $this->content()->sanitize(['blocks' => [
|
||||
['type' => 'heading', 'data' => ['text' => 'Für alle']],
|
||||
['type' => 'heading', 'data' => ['text' => 'Nur MAV oder Pflege'], 'visibility' => ['role' => [(string) $mav->id], 'department' => ['Pflege']]],
|
||||
]]);
|
||||
|
||||
$texts = fn (User $user) => array_map(fn ($b) => $b['data']['text'], $this->content()->render($content, $user)['blocks']);
|
||||
|
||||
$this->assertSame(['Für alle', 'Nur MAV oder Pflege'], $texts($member));
|
||||
$this->assertSame(['Für alle', 'Nur MAV oder Pflege'], $texts($nurse));
|
||||
$this->assertSame(['Für alle'], $texts($other));
|
||||
$this->assertArrayNotHasKey('visibility', $this->content()->render($content, $member)['blocks'][1], 'Zielgruppen gehen nicht an den Browser.');
|
||||
}
|
||||
|
||||
public function test_a_failing_plugin_block_does_not_break_the_page(): void
|
||||
{
|
||||
app(Blocks::class)->add(BlockType::make('kaputt', 'Kaputt', 'box', 'dynamic')
|
||||
->fields([Field::text('title', 'Titel')])
|
||||
->resolveUsing(fn () => throw new RuntimeException('Fehler im Plugin')));
|
||||
|
||||
$content = $this->content()->sanitize(['blocks' => [
|
||||
['type' => 'kaputt', 'data' => ['title' => 'x']],
|
||||
['type' => 'heading', 'data' => ['text' => 'Bleibt']],
|
||||
]]);
|
||||
|
||||
$rendered = $this->content()->render($content, User::factory()->create());
|
||||
|
||||
$this->assertSame(['heading'], array_column($rendered['blocks'], 'type'));
|
||||
}
|
||||
|
||||
public function test_video_urls_become_privacy_friendly_embeds(): void
|
||||
{
|
||||
$content = $this->content()->sanitize(['blocks' => [
|
||||
['type' => 'video', 'data' => ['url' => 'https://www.youtube.com/watch?v=dQw4w9WgXcQ']],
|
||||
['type' => 'video', 'data' => ['url' => 'https://vimeo.com/76979871']],
|
||||
['type' => 'video', 'data' => ['url' => 'https://example.org/irgendwas']],
|
||||
]]);
|
||||
|
||||
$embeds = array_map(fn ($b) => $b['props']['embed'], $this->content()->render($content, null)['blocks']);
|
||||
|
||||
$this->assertSame('https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ?rel=0', $embeds[0]['src']);
|
||||
$this->assertSame('Vimeo', $embeds[1]['provider']);
|
||||
$this->assertNull($embeds[2]);
|
||||
}
|
||||
|
||||
public function test_plain_text_is_extracted_for_search(): void
|
||||
{
|
||||
$content = $this->content()->sanitize(['blocks' => [
|
||||
['type' => 'tabs', 'items' => [['title' => 'Wahl', 'blocks' => [['type' => 'text', 'data' => ['html' => '<p>Die <strong>MAV-Wahl</strong> findet statt.</p>']]]]]],
|
||||
]]);
|
||||
|
||||
$this->assertStringContainsString('Wahl Die MAV-Wahl findet statt.', $this->content()->plainText($content));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue