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

- 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:
Friederich Loheide 2026-09-26 08:52:19 +00:00
parent 6269d3302c
commit f3987e8386
328 changed files with 10618 additions and 389 deletions

View file

@ -0,0 +1,188 @@
<?php
namespace Tests\Feature\News;
use App\Models\Role;
use App\Models\User;
use App\Notifications\PortalNotification;
use App\Pagebuilder\Content;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\Storage;
use Inertia\Testing\AssertableInertia as Assert;
use Inhaus\Plugins\News\Models\NewsCategory;
use Inhaus\Plugins\News\Models\NewsPost;
use Tests\TestCase;
/**
* Redaktion im Portal: Die MAV schreibt in „MAV-Info“, die Redaktion gibt frei.
*/
class NewsWorkflowTest extends TestCase
{
use RefreshDatabase;
private NewsCategory $mavInfo;
private NewsCategory $company;
private User $author;
private User $editor;
protected function setUp(): void
{
parent::setUp();
Storage::fake('uploads');
$this->mavInfo = NewsCategory::factory()->create(['name' => 'MAV-Info', 'slug' => 'mav-info']);
$this->company = NewsCategory::factory()->create(['name' => 'Unternehmen', 'slug' => 'unternehmen']);
$writers = Role::query()->create(['name' => 'MAV']);
$writers->grants()->create(['ability' => 'news.post.create', 'resource_type' => 'news_category', 'resource_id' => $this->mavInfo->id]);
$this->author = User::factory()->withRoles([$writers])->create(['first_name' => 'Maria', 'last_name' => 'Autorin']);
$publishers = Role::query()->create(['name' => 'Redaktion']);
$publishers->grants()->create(['ability' => 'news.post.create', 'resource_type' => 'news_category', 'resource_id' => null]);
$publishers->grants()->create(['ability' => 'news.post.publish', 'resource_type' => 'news_category', 'resource_id' => $this->mavInfo->id]);
$this->editor = User::factory()->withRoles([$publishers])->create(['first_name' => 'Rita', 'last_name' => 'Redaktion']);
}
private function payload(array $overrides = []): array
{
return array_merge([
'title' => 'Mitarbeiterversammlung',
'teaser' => 'Einladung für alle.',
'body' => '<p>Am <strong>Freitag</strong> <script>alert(1)</script></p>',
'category_id' => $this->mavInfo->id,
'action' => 'draft',
], $overrides);
}
public function test_author_writes_submits_and_editor_approves(): void
{
Notification::fake();
$employee = User::factory()->create();
$this->actingAs($this->author)->get('/neuigkeiten')->assertInertia(fn (Assert $p) => $p->where('canWrite', true));
$this->get('/redaktion/neuigkeiten/neu')->assertOk()->assertInertia(fn (Assert $p) => $p
->component('news::Editor')
->where('categories', [['id' => $this->mavInfo->id, 'name' => 'MAV-Info', 'can_publish' => false]]));
$this->post('/redaktion/neuigkeiten', $this->payload(['cover' => UploadedFile::fake()->image('foto.jpg', 1600, 900)]))->assertRedirect();
$post = NewsPost::query()->sole();
$this->assertSame(NewsPost::DRAFT, $post->status);
$this->assertSame($this->author->id, $post->author_id);
$this->assertStringNotContainsString('script', $post->body_html);
$this->assertNotNull($post->cover_path);
// Veröffentlichen darf die MAV nicht selbst.
$this->put('/redaktion/neuigkeiten/'.$post->id, $this->payload(['action' => 'publish']))->assertSessionHasErrors('action');
$this->assertSame(NewsPost::DRAFT, $post->fresh()->status);
$this->put('/redaktion/neuigkeiten/'.$post->id, $this->payload(['action' => 'submit']))->assertSessionHas('status', fn ($s) => str_contains($s, 'Zur Freigabe eingereicht'));
$this->assertSame(NewsPost::PENDING, $post->fresh()->status);
Notification::assertSentTo($this->editor, PortalNotification::class, fn ($n) => str_contains($n->title, 'Mitarbeiterversammlung'));
Notification::assertNotSentTo($this->author, PortalNotification::class);
$this->actingAs($employee)->get('/neuigkeiten/'.$post->slug)->assertNotFound();
$this->actingAs($this->editor)->get('/redaktion')->assertInertia(fn (Assert $p) => $p
->where('sections.0.key', 'news')
->where('sections.0.props.review.0.title', 'Mitarbeiterversammlung'));
$this->post('/redaktion/neuigkeiten/'.$post->id.'/freigeben')->assertRedirect('/redaktion');
$post->refresh();
$this->assertTrue($post->isPublished());
$this->assertSame($this->editor->id, $post->reviewed_by);
Notification::assertSentTo($this->author, PortalNotification::class, fn ($n) => str_starts_with($n->title, 'Beitrag veröffentlicht'));
$this->actingAs($employee)->get('/neuigkeiten/'.$post->slug)->assertOk();
// Veröffentlichte Beiträge ändert die MAV nicht mehr ohne Freigabe.
$this->actingAs($this->author)->put('/redaktion/neuigkeiten/'.$post->id, $this->payload(['title' => 'Heimlich geändert']))->assertForbidden();
$this->get('/neuigkeiten/'.$post->slug)->assertInertia(fn (Assert $p) => $p->where('editUrl', route('news.editor.edit', $post)));
}
public function test_editor_returns_a_post_with_a_note(): void
{
Notification::fake();
$post = NewsPost::factory()->draft()->create(['category_id' => $this->mavInfo->id, 'author_id' => $this->author->id]);
$post->forceFill(['status' => NewsPost::PENDING, 'submitted_at' => now()])->save();
$this->actingAs($this->editor)->post('/redaktion/neuigkeiten/'.$post->id.'/zurueckgeben', ['note' => ''])->assertSessionHasErrors('note');
$this->post('/redaktion/neuigkeiten/'.$post->id.'/zurueckgeben', ['note' => 'Bitte Ort ergänzen.'])->assertRedirect('/redaktion');
$post->refresh();
$this->assertSame(NewsPost::DRAFT, $post->status);
$this->assertSame('Bitte Ort ergänzen.', $post->review_note);
Notification::assertSentTo($this->author, PortalNotification::class, fn ($n) => str_contains($n->body, 'Bitte Ort ergänzen.'));
$this->actingAs($this->author)->get('/redaktion')->assertInertia(fn (Assert $p) => $p->where('sections.0.props.mine.0.review_note', 'Bitte Ort ergänzen.'));
$this->post('/redaktion/neuigkeiten/'.$post->id.'/freigeben')->assertForbidden();
}
public function test_publishers_can_schedule_and_feature(): void
{
$this->actingAs($this->editor)->post('/redaktion/neuigkeiten', $this->payload([
'action' => 'publish',
'published_at' => now()->addDays(2)->toIso8601String(),
'is_featured' => '1',
]))->assertSessionHas('status', 'Beitrag geplant.');
$post = NewsPost::query()->sole();
$this->assertTrue($post->isScheduled());
$this->assertTrue($post->is_featured);
$this->assertFalse($post->isPublished());
$this->get('/redaktion')->assertInertia(fn (Assert $p) => $p->where('sections.0.props.mine.0.status_label', 'Geplant'));
$this->travel(3)->days();
$this->assertTrue($post->fresh()->isPublished());
}
public function test_authors_cannot_write_in_foreign_categories(): void
{
$this->actingAs($this->author)->post('/redaktion/neuigkeiten', $this->payload(['category_id' => $this->company->id]))->assertSessionHasErrors('category_id');
$this->post('/redaktion/neuigkeiten', $this->payload(['category_id' => null]))->assertSessionHasErrors('category_id');
$foreign = NewsPost::factory()->draft()->create(['category_id' => $this->company->id]);
$this->get('/redaktion/neuigkeiten/'.$foreign->id)->assertForbidden();
$this->actingAs(User::factory()->create())->get('/redaktion/neuigkeiten/neu')->assertForbidden();
$this->get('/redaktion')->assertForbidden();
}
public function test_inline_images_are_uploaded_for_the_body(): void
{
$url = $this->actingAs($this->author)->postJson('/redaktion/neuigkeiten/bilder', ['image' => UploadedFile::fake()->image('bild.png', 800, 600)])->assertOk()->json('url');
$this->assertStringContainsString('news/inline/', $url);
$this->actingAs(User::factory()->create())->postJson('/redaktion/neuigkeiten/bilder', ['image' => UploadedFile::fake()->image('x.png')])->assertForbidden();
}
public function test_news_block_lists_visible_posts_in_pages(): void
{
NewsPost::factory()->create(['category_id' => $this->mavInfo->id, 'title' => 'Aus der MAV']);
NewsPost::factory()->create(['category_id' => $this->company->id, 'title' => 'Quartalszahlen']);
NewsPost::factory()->draft()->create(['category_id' => $this->mavInfo->id, 'title' => 'Entwurf']);
$content = app(Content::class);
$rendered = $content->render($content->sanitize(['blocks' => [['type' => 'news.latest', 'data' => ['category' => 'mav-info', 'count' => 5]]]]), User::factory()->create());
$this->assertSame(['Aus der MAV'], array_column($rendered['blocks'][0]['props']['posts'], 'title'));
$this->assertSame('/neuigkeiten?kategorie=mav-info', $rendered['blocks'][0]['props']['more_url']);
}
public function test_admin_form_keeps_status_in_sync(): void
{
$post = NewsPost::factory()->draft()->create();
$this->assertSame(NewsPost::DRAFT, $post->status);
$post->update(['published_at' => now()]);
$this->assertSame(NewsPost::PUBLISHED, $post->fresh()->status);
$post->update(['published_at' => null]);
$this->assertSame(NewsPost::DRAFT, $post->fresh()->status);
}
}

View 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));
}
}

View file

@ -0,0 +1,67 @@
<?php
namespace Tests\Feature\Pages;
use App\Models\Grant;
use App\Models\Role;
use App\Models\User;
use App\Support\Permissions\Audiences;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Inhaus\Plugins\Pages\Filament\Resources\ContentPages\Pages\CreateContentPage;
use Inhaus\Plugins\Pages\Filament\Resources\ContentPages\Pages\EditContentPage;
use Inhaus\Plugins\Pages\Filament\Resources\ContentPages\Pages\ListContentPages;
use Inhaus\Plugins\Pages\Models\Page;
use Livewire\Livewire;
use Tests\TestCase;
class PagesAdminTest extends TestCase
{
use RefreshDatabase;
public function test_admin_sets_up_the_mav_page_with_rights_and_visibility(): void
{
$this->actingAs(User::factory()->admin()->create());
$mav = Role::query()->create(['name' => 'MAV']);
User::factory()->create(['department' => 'Pflege']);
Livewire::test(CreateContentPage::class)
->fillForm(['title' => 'MAV', 'in_navigation' => true])
->call('create')
->assertHasNoFormErrors()
->assertRedirect(route('pages.editor', Page::query()->sole()));
$page = Page::query()->sole();
$this->assertTrue($page->in_navigation);
Livewire::test(EditContentPage::class, ['record' => $page->getRouteKey()])
->fillForm(['editors' => [$mav->id], 'publishers' => [$mav->id], 'audience_department' => ['Pflege']])
->call('save')
->assertHasNoFormErrors();
$this->assertSame(2, Grant::query()->where('role_id', $mav->id)->where('resource_type', 'page')->where('include_children', true)->count());
$this->assertSame(['Pflege'], Audiences::get('page', $page->id)['department']);
$member = User::factory()->withRoles([$mav])->create();
$child = Page::query()->create(['title' => 'Wahlen', 'parent_id' => $page->id]);
$this->actingAs($member)->get('/admin/seiten')->assertOk();
Livewire::test(ListContentPages::class)->assertCanSeeTableRecords([$page, $child])->assertCountTableRecords(2);
$this->assertTrue($member->can('publish', $child));
}
public function test_pages_cannot_be_moved_below_themselves(): void
{
$this->actingAs(User::factory()->admin()->create());
$parent = Page::query()->create(['title' => 'Handbuch']);
$child = Page::query()->create(['title' => 'Kapitel 1', 'parent_id' => $parent->id]);
Livewire::test(EditContentPage::class, ['record' => $parent->getRouteKey()])
->assertFormFieldExists('parent_id', fn ($field) => ! array_key_exists($child->id, $field->getOptions()) && ! array_key_exists($parent->id, $field->getOptions()));
}
public function test_editors_without_manage_right_cannot_open_foreign_settings(): void
{
$page = Page::query()->create(['title' => 'Geschäftsführung']);
$this->actingAs(User::factory()->create())->get('/admin/seiten/'.$page->id.'/bearbeiten')->assertForbidden();
}
}

View file

@ -0,0 +1,322 @@
<?php
namespace Tests\Feature\Pages;
use App\Models\Grant;
use App\Models\Role;
use App\Models\User;
use App\Notifications\PortalNotification;
use App\Pagebuilder\Content;
use App\Support\Permissions\Audiences;
use App\Support\Permissions\Permissions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\Storage;
use Inertia\Testing\AssertableInertia as Assert;
use Inhaus\Plugins\Pages\Models\Page;
use Inhaus\Plugins\Pages\Models\PageFile;
use Inhaus\Plugins\Pages\PageTree;
use Tests\TestCase;
class PagesTest extends TestCase
{
use RefreshDatabase;
private User $admin;
protected function setUp(): void
{
parent::setUp();
Storage::fake('uploads');
Storage::fake('local');
$this->admin = User::factory()->admin()->create();
}
private function content(string $heading = 'Hallo'): array
{
return ['blocks' => [['id' => 'blk00001', 'type' => 'heading', 'data' => ['text' => $heading]]]];
}
private function publishedPage(string $title, ?Page $parent = null, string $heading = 'Hallo'): Page
{
$page = Page::query()->create(['title' => $title, 'parent_id' => $parent?->id]);
$page->publish($title, app(Content::class)->sanitize($this->content($heading)), $this->admin);
return $page->fresh();
}
private function mavRole(Page $page, bool $publish = true): Role
{
$role = Role::query()->create(['name' => 'MAV']);
$role->grants()->create(['ability' => 'pages.edit', 'resource_type' => 'page', 'resource_id' => $page->id, 'include_children' => true]);
if ($publish) {
$role->grants()->create(['ability' => 'pages.publish', 'resource_type' => 'page', 'resource_id' => $page->id, 'include_children' => true]);
}
return $role;
}
public function test_draft_publish_and_versions(): void
{
$this->actingAs($this->admin)->post('/redaktion/seiten', ['title' => 'Arbeitsschutz'])->assertRedirect();
$page = Page::query()->sole();
$this->assertSame('arbeitsschutz', $page->path);
$this->get('/redaktion/seiten/'.$page->id)->assertOk()->assertInertia(fn (Assert $p) => $p
->component('pages::Editor')
->where('working.title', 'Arbeitsschutz')
->has('blockTypes')
->where('page.can.publish', true));
$this->putJson('/redaktion/seiten/'.$page->id.'/entwurf', ['title' => 'Arbeitsschutz', 'content' => $this->content('Entwurf')])
->assertOk()->assertJsonPath('page.has_draft', true);
$employee = User::factory()->create();
$this->actingAs($employee)->get('/seiten/arbeitsschutz')->assertNotFound();
$this->actingAs($this->admin)->postJson('/redaktion/seiten/'.$page->id.'/veroeffentlichen', ['title' => 'Arbeitsschutz', 'content' => $this->content('Version 1')])
->assertOk()->assertJsonPath('page.is_published', true)->assertJsonPath('page.has_draft', false);
$this->actingAs($employee)->get('/seiten/arbeitsschutz')->assertOk()->assertInertia(fn (Assert $p) => $p
->component('pages::Show')
->where('content.blocks.0.data.text', 'Version 1')
->where('content.blocks.0.component', 'Heading')
->where('editor', null));
// Neuer Entwurf ändert die veröffentlichte Seite nicht.
$this->actingAs($this->admin)->putJson('/redaktion/seiten/'.$page->id.'/entwurf', ['title' => 'Arbeitsschutz', 'content' => $this->content('Version 2')]);
$this->actingAs($employee)->get('/seiten/arbeitsschutz')->assertInertia(fn (Assert $p) => $p->where('content.blocks.0.data.text', 'Version 1'));
// Unveränderter Stand = kein Entwurf.
$this->actingAs($this->admin)->putJson('/redaktion/seiten/'.$page->id.'/entwurf', ['title' => 'Arbeitsschutz', 'content' => $this->content('Version 1')])
->assertJsonPath('page.has_draft', false);
$this->postJson('/redaktion/seiten/'.$page->id.'/veroeffentlichen', ['title' => 'Arbeitsschutz neu', 'content' => $this->content('Version 2')]);
$revisions = $this->getJson('/redaktion/seiten/'.$page->id.'/versionen')->assertOk()->json('revisions');
$this->assertCount(2, $revisions);
$first = end($revisions);
$this->postJson('/redaktion/seiten/'.$page->id.'/versionen/'.$first['id'].'/wiederherstellen')
->assertOk()->assertJsonPath('working.content.blocks.0.data.text', 'Version 1')->assertJsonPath('working.title', 'Arbeitsschutz');
$this->assertSame('Arbeitsschutz neu', $page->fresh()->title, 'Wiederherstellen erzeugt nur einen Entwurf.');
}
public function test_mav_edits_its_page_and_all_subpages_but_nothing_else(): void
{
$mavPage = $this->publishedPage('MAV');
$other = $this->publishedPage('Geschäftsführung');
$mav = User::factory()->withRoles([$this->mavRole($mavPage)])->create();
$this->actingAs($mav)->post('/redaktion/seiten', ['title' => 'Wahlen', 'parent_id' => $mavPage->id])->assertRedirect();
$child = Page::query()->where('title', 'Wahlen')->sole();
$this->assertSame('mav/wahlen', $child->path);
// Neue Unterseite ist sofort mit abgedeckt (Rechte-Cache hängt am Seitenbaum).
$this->get('/redaktion/seiten/'.$child->id)->assertOk();
$this->postJson('/redaktion/seiten/'.$child->id.'/veroeffentlichen', ['title' => 'Wahlen', 'content' => $this->content()])->assertOk();
$this->get('/redaktion/seiten/'.$other->id)->assertForbidden();
$this->putJson('/redaktion/seiten/'.$other->id.'/entwurf', ['title' => 'x', 'content' => $this->content()])->assertForbidden();
$this->post('/redaktion/seiten', ['title' => 'Oberste Ebene'])->assertForbidden();
$this->get('/redaktion')->assertOk()->assertInertia(fn (Assert $p) => $p
->where('sections.0.key', 'pages')
->where('sections.0.props.pages', fn ($pages) => collect($pages)->pluck('title')->sort()->values()->all() === ['MAV', 'Wahlen']));
$this->get('/seiten/mav')->assertInertia(fn (Assert $p) => $p->where('editor.url', route('pages.editor', $mavPage)));
$this->get('/seiten/geschaeftsfuehrung')->assertInertia(fn (Assert $p) => $p->where('editor', null));
}
public function test_without_publish_right_a_review_is_requested(): void
{
Notification::fake();
$page = $this->publishedPage('MAV');
$author = User::factory()->withRoles([$this->mavRole($page, publish: false)])->create();
$publisherRole = Role::query()->create(['name' => 'Redaktion']);
$publisherRole->grants()->create(['ability' => 'pages.publish', 'resource_type' => 'page', 'resource_id' => $page->id]);
$publisher = User::factory()->withRoles([$publisherRole])->create();
$unrelated = User::factory()->create();
$this->actingAs($author)->get('/redaktion/seiten/'.$page->id)->assertInertia(fn (Assert $p) => $p->where('page.can.publish', false));
$this->postJson('/redaktion/seiten/'.$page->id.'/veroeffentlichen', ['title' => 'MAV', 'content' => $this->content()])->assertForbidden();
$this->postJson('/redaktion/seiten/'.$page->id.'/freigabe', ['message' => 'Bitte bis Freitag'])->assertOk()->assertJsonPath('recipients', 2);
Notification::assertSentTo([$publisher, $this->admin], PortalNotification::class, fn ($n) => str_contains($n->body, 'Bitte bis Freitag'));
Notification::assertNotSentTo([$author, $unrelated], PortalNotification::class);
$this->postJson('/redaktion/seiten/'.$page->id.'/freigabe')->assertStatus(429);
}
public function test_visibility_is_inherited_by_subpages(): void
{
$care = $this->publishedPage('Pflege');
$child = $this->publishedPage('Dienstpläne', $care);
Audiences::sync('page', $care->id, ['department' => ['Pflege']]);
PageTree::flush();
$nurse = User::factory()->create(['department' => 'Pflege']);
$clerk = User::factory()->create(['department' => 'Verwaltung']);
$this->actingAs($nurse)->get('/seiten/pflege/dienstplaene')->assertOk();
$this->actingAs($clerk)->get('/seiten/pflege/dienstplaene')->assertNotFound();
$this->actingAs($clerk)->get('/seiten')->assertInertia(fn (Assert $p) => $p->where('tree', []));
$this->actingAs($nurse)->get('/seiten')->assertInertia(fn (Assert $p) => $p->where('tree.0.children.0.id', $child->id));
}
public function test_edit_lock_prevents_concurrent_changes(): void
{
$page = $this->publishedPage('Handbuch');
$colleague = User::factory()->admin()->create(['first_name' => 'Kim', 'last_name' => 'Kollegin']);
$this->actingAs($this->admin)->get('/redaktion/seiten/'.$page->id)->assertInertia(fn (Assert $p) => $p->where('lockedBy', null));
$this->actingAs($colleague)->get('/redaktion/seiten/'.$page->id)->assertInertia(fn (Assert $p) => $p->where('lockedBy.id', $this->admin->id));
$this->putJson('/redaktion/seiten/'.$page->id.'/entwurf', ['title' => 'x', 'content' => $this->content()])->assertStatus(423);
$this->postJson('/redaktion/seiten/'.$page->id.'/sperre')->assertStatus(423);
$this->postJson('/redaktion/seiten/'.$page->id.'/sperre', ['takeover' => true])->assertOk();
$this->putJson('/redaktion/seiten/'.$page->id.'/entwurf', ['title' => 'Handbuch', 'content' => $this->content('Kim')])->assertOk();
$this->actingAs($this->admin)->putJson('/redaktion/seiten/'.$page->id.'/entwurf', ['title' => 'x', 'content' => $this->content()])
->assertStatus(423)->assertJsonPath('lockedBy.name', 'Kim Kollegin');
// Ohne Lebenszeichen läuft die Sperre ab.
$this->travel(Page::LOCK_SECONDS + 1)->seconds();
$this->putJson('/redaktion/seiten/'.$page->id.'/entwurf', ['title' => 'Handbuch', 'content' => $this->content()])->assertOk();
}
public function test_scheduled_publishing(): void
{
$page = $this->publishedPage('Sommerfest', heading: 'Alt');
$employee = User::factory()->create();
$this->actingAs($this->admin)->postJson('/redaktion/seiten/'.$page->id.'/veroeffentlichen', [
'title' => 'Sommerfest', 'content' => $this->content('Neu'), 'scheduled_at' => now()->addDay()->toIso8601String(),
])->assertOk()->assertJsonPath('page.scheduled_at', fn ($v) => $v !== null);
$this->actingAs($employee)->get('/seiten/sommerfest')->assertInertia(fn (Assert $p) => $p->where('content.blocks.0.data.text', 'Alt'));
$this->travel(25)->hours();
$this->artisan('schedule:run');
$this->actingAs($employee)->get('/seiten/sommerfest')->assertInertia(fn (Assert $p) => $p->where('content.blocks.0.data.text', 'Neu'));
$this->assertNull($page->fresh()->scheduled_at);
$this->assertSame('scheduled', $page->revisions()->first()->action);
$this->actingAs($this->admin)->postJson('/redaktion/seiten/'.$page->id.'/veroeffentlichen', [
'title' => 'x', 'content' => $this->content(), 'scheduled_at' => now()->subHour()->toIso8601String(),
])->assertUnprocessable();
}
public function test_downloads_are_only_served_to_people_who_see_the_page(): void
{
$page = $this->publishedPage('Formulare');
Audiences::sync('page', $page->id, ['department' => ['Pflege']]);
PageTree::flush();
$this->actingAs($this->admin)->postJson('/redaktion/seiten/'.$page->id.'/dateien', ['file' => UploadedFile::fake()->create('shell.php', 1)])->assertUnprocessable();
$file = $this->postJson('/redaktion/seiten/'.$page->id.'/dateien', ['file' => UploadedFile::fake()->create('Urlaubsantrag 2027.pdf', 120, 'application/pdf')])
->assertOk()->json('file');
$this->assertSame('Urlaubsantrag 2027.pdf', $file['name']);
$stored = PageFile::query()->sole();
Storage::disk('local')->assertExists($stored->path);
$this->assertStringNotContainsString('Urlaubsantrag', $stored->path);
$this->postJson('/redaktion/seiten/'.$page->id.'/veroeffentlichen', ['title' => 'Formulare', 'content' => ['blocks' => [['type' => 'downloads', 'data' => ['files' => [$stored->id, 999]]]]]]);
$nurse = User::factory()->create(['department' => 'Pflege']);
$this->actingAs($nurse)->get('/seiten/formulare')->assertInertia(fn (Assert $p) => $p->where('content.blocks.0.props.files.0.name', 'Urlaubsantrag 2027.pdf')->has('content.blocks.0.props.files', 1));
$this->get($file['url'])->assertOk()->assertDownload('Urlaubsantrag 2027.pdf');
$this->actingAs(User::factory()->create(['department' => 'Küche']))->get($file['url'])->assertNotFound();
}
public function test_images_are_stored_as_webp(): void
{
$page = $this->publishedPage('Galerie');
$result = $this->actingAs($this->admin)->postJson('/redaktion/seiten/'.$page->id.'/bilder', ['image' => UploadedFile::fake()->image('foto.jpg', 3000, 2000)])
->assertOk()->json();
$this->assertStringStartsWith('pagebuilder/pages/'.$page->id.'/', $result['path']);
$this->assertStringEndsWith('.webp', $result['path']);
Storage::disk('uploads')->assertExists($result['path']);
$props = $this->postJson('/redaktion/seiten/'.$page->id.'/vorschau', ['blocks' => [['id' => 'img00001', 'type' => 'image', 'data' => ['path' => $result['path']]]]])
->assertOk()->json('props.img00001');
$this->assertStringEndsWith($result['path'], $props['url']);
}
public function test_top_level_pages_can_appear_in_the_main_navigation(): void
{
$page = $this->publishedPage('MAV');
$page->update(['in_navigation' => true]);
$restricted = $this->publishedPage('Leitung');
$restricted->update(['in_navigation' => true]);
Audiences::sync('page', $restricted->id, ['department' => ['Leitung']]);
PageTree::flush();
$this->actingAs(User::factory()->create())->get('/seiten/mav')->assertInertia(fn (Assert $p) => $p
->where('navigation', fn ($items) => collect($items)->contains(fn ($i) => $i['label'] === 'MAV' && $i['active'])
&& ! collect($items)->contains('label', 'Leitung')
&& ! collect($items)->contains('key', 'editorial')));
}
public function test_changing_the_address_moves_all_subpages(): void
{
$parent = $this->publishedPage('MAV');
$child = $this->publishedPage('Wahlen', $parent);
$grandchild = $this->publishedPage('Ergebnisse', $child);
$this->actingAs($this->admin)->putJson('/redaktion/seiten/'.$parent->id.'/einstellungen', ['slug' => 'mitarbeitervertretung'])->assertOk();
$this->assertSame('mitarbeitervertretung/wahlen', $child->fresh()->path);
$this->assertSame('mitarbeitervertretung/wahlen/ergebnisse', $grandchild->fresh()->path);
$this->get('/seiten/mitarbeitervertretung/wahlen/ergebnisse')->assertOk();
$this->putJson('/redaktion/seiten/'.$parent->id.'/einstellungen', ['slug' => 'Mit Leerzeichen'])->assertUnprocessable();
$this->deleteJson('/redaktion/seiten/'.$parent->id)->assertUnprocessable();
$this->deleteJson('/redaktion/seiten/'.$grandchild->id)->assertOk()->assertJsonPath('redirect', '/seiten/mitarbeitervertretung/wahlen');
}
public function test_notifications_can_be_read_and_opened(): void
{
$this->admin->notify(new PortalNotification('Freigabe angefordert', 'Bitte prüfen', '/seiten/mav'));
$this->admin->notify(new PortalNotification('Fremder Link', '', 'https://evil.example'));
$this->actingAs($this->admin)->get('/')->assertInertia(fn (Assert $p) => $p->where('notifications.unread', 2));
$items = $this->getJson('/benachrichtigungen')->assertOk()->assertJsonPath('unread', 2)->json('notifications');
$mav = collect($items)->firstWhere('title', 'Freigabe angefordert');
$this->get('/benachrichtigungen/'.$mav['id'])->assertRedirect('/seiten/mav');
$this->get('/benachrichtigungen/'.collect($items)->firstWhere('title', 'Fremder Link')['id'])->assertRedirect('/');
$this->postJson('/benachrichtigungen/gelesen')->assertOk();
$this->assertSame(0, $this->admin->unreadNotifications()->count());
$this->actingAs(User::factory()->create())->get('/benachrichtigungen/'.$mav['id'])->assertNotFound();
}
public function test_role_form_offers_including_subpages(): void
{
$page = $this->publishedPage('MAV');
$child = $this->publishedPage('Wahlen', $page);
$role = Role::query()->create(['name' => 'MAV']);
$role->grants()->create(['ability' => 'pages.edit', 'resource_type' => 'page', 'resource_id' => $page->id, 'include_children' => false]);
$user = User::factory()->withRoles([$role])->create();
$this->assertTrue($user->can('update', $page));
$this->assertFalse($user->can('update', $child), 'Ohne „inkl. Unterseiten“ nur die Seite selbst.');
Grant::query()->update(['include_children' => true]);
Permissions::flush();
$this->assertTrue($user->fresh()->can('update', $child));
}
}

View file

@ -22,7 +22,7 @@ class CorePluginToggleTest extends TestCase
$file = storage_path('app/plugins.json');
$this->previousState = is_file($file) ? file_get_contents($file) : null;
file_put_contents($file, json_encode(['news' => ['enabled' => false], 'events' => ['enabled' => false]]));
file_put_contents($file, json_encode(['news' => ['enabled' => false], 'events' => ['enabled' => false], 'pages' => ['enabled' => false]]));
// Plugins werden beim Start der Anwendung geladen – also neu starten.
$this->refreshApplication();

View file

@ -6,6 +6,7 @@ use App\Support\Update\Filesystem;
use App\Support\Update\InstalledVersion;
use App\Support\Update\MaintenanceFlag;
use App\Support\Update\UpdateProgress;
use App\Version;
use InvalidArgumentException;
use Tests\TestCase;
@ -33,14 +34,14 @@ class UpdateStateTest extends TestCase
$version = new InstalledVersion($this->dir.'/.version');
$this->assertNull($version->current());
$this->assertSame('0.4.0', $version->release());
$this->assertSame('0.4.0', $version->full());
$this->assertSame(Version::VERSION, $version->release());
$this->assertSame(Version::VERSION, $version->full());
$version->save('A1B2C3D4E5F60718293a4b5c6d7e8f9012345678');
$this->assertSame('a1b2c3d4e5f60718293a4b5c6d7e8f9012345678', $version->current());
$this->assertSame('a1b2c3d', $version->short());
$this->assertSame('0.4.0 (a1b2c3d)', $version->full());
$this->assertSame(Version::VERSION.' (a1b2c3d)', $version->full());
}
public function test_invalid_sha_is_rejected(): void