Menü-Editor, farbige Initialen, Seitenköpfe, Favoriten, Vorschaubilder
All checks were successful
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m55s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m44s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 3m25s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 3m39s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 3m47s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 3m51s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 3m16s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 3m25s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m10s

- Admin → Portal → Menü: Bereiche, Seiten (mit Unterseiten), Links und
  Gruppen mit Unterpunkten, sortierbar, je Rolle einschränkbar;
  Kopfzeile misst den Platz und legt Überzähliges unter „Mehr“
- Initialen in fester Farbe je Person, Abteilungsfarben im Organigramm
- PageHeader für alle Übersichtsseiten
- Dokumente: Favoriten (auch als Startseiten-Kachel), „Häufig genutzt“,
  Vorschaubilder (Bilder, erste PDF-Seite per pdf.js im Browser)
- Platzhalter beim Nachladen

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-26 13:56:57 +00:00
parent 114811e6c5
commit dda250aaad
140 changed files with 1993 additions and 427 deletions

View file

@ -144,6 +144,51 @@ class DocumentsTest extends TestCase
$this->get("/dokumente/ordner/{$this->vertraege->id}")->assertInertia(fn (Assert $p) => $p->where('recent', [])->where('documents.0.folder_name', null));
}
public function test_favorites_downloads_and_popular_documents(): void
{
$this->uploadTo($this->personal, [UploadedFile::fake()->create('Urlaubsantrag.pdf', 5, 'application/pdf'), UploadedFile::fake()->create('Reisekosten.xlsx', 5)]);
[$antrag, $reise] = [Document::query()->where('title', 'Urlaubsantrag')->sole(), Document::query()->where('title', 'Reisekosten')->sole()];
$employee = User::factory()->create(['department' => 'Pflege']);
$this->actingAs($employee)->post("/dokumente/{$antrag->id}/favorit")->assertRedirect();
$this->post("/dokumente/{$antrag->id}/favorit"); // doppelt schadet nicht
$this->get($reise->downloadUrl())->assertOk();
$this->get($reise->downloadUrl())->assertOk();
$before = $reise->fresh()->updated_at;
$this->get($antrag->downloadUrl().'?vorschau=1')->assertOk()->assertHeader('Content-Security-Policy');
$this->assertSame(2, $reise->fresh()->downloads);
$this->assertSame(0, $antrag->fresh()->downloads, 'Vorschaubilder zählen nicht');
$this->assertEquals($before, $reise->fresh()->updated_at, 'Downloads sind keine Änderung');
$this->get('/dokumente')->assertInertia(fn (Assert $p) => $p
->where('favorites.0.title', 'Urlaubsantrag')
->where('favorites.0.favorite', true)
->where('favorites.0.preview_kind', 'pdf')
->where('popular.0.title', 'Reisekosten')
->where('popular.0.preview_url', null));
$this->get('/')->assertInertia(fn (Assert $p) => $p->where(
'widgets',
fn ($widgets) => collect($widgets)->firstWhere('key', 'documents.favorites')['props']['favorites'][0]['title'] === 'Urlaubsantrag'
));
$this->delete("/dokumente/{$antrag->id}/favorit");
$this->get('/dokumente')->assertInertia(fn (Assert $p) => $p->where('favorites', []));
// Ohne Sichtrecht kein Favorit.
Audiences::sync('document_folder', $this->personal->id, ['department' => ['Personal']]);
FolderTree::flush();
$this->post("/dokumente/{$antrag->id}/favorit")->assertNotFound();
}
public function test_previews_are_only_served_for_safe_types(): void
{
$this->uploadTo($this->personal, [UploadedFile::fake()->create('notiz.txt', 1, 'text/plain')]);
$this->get(Document::query()->sole()->downloadUrl().'?vorschau=1')->assertNotFound();
}
public function test_folders_can_only_be_deleted_when_empty(): void
{
$this->actingAs($this->hr)->delete("/dokumente/ordner/{$this->vertraege->id}")->assertRedirect(route('documents.folder', $this->personal));

120
tests/Feature/MenuTest.php Normal file
View file

@ -0,0 +1,120 @@
<?php
namespace Tests\Feature;
use App\Filament\Pages\MenuSettings;
use App\Models\Role;
use App\Models\User;
use App\Pagebuilder\Content;
use App\Support\Navigation;
use App\Support\Settings;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Inertia\Testing\AssertableInertia as Assert;
use Inhaus\Plugins\Pages\Models\Page;
use Inhaus\Plugins\Pages\PageTree;
use Livewire\Livewire;
use Tests\TestCase;
class MenuTest extends TestCase
{
use RefreshDatabase;
private function page(string $title, ?Page $parent = null): Page
{
$page = Page::query()->create(['title' => $title, 'parent_id' => $parent?->id]);
$page->publish($title, app(Content::class)->sanitize(['blocks' => []]), User::factory()->admin()->create());
return $page->fresh();
}
private function menuFor(User $user, string $url = '/'): array
{
$menu = null;
$this->actingAs($user)->get($url)->assertInertia(function (Assert $page) use (&$menu) {
$menu = $page->toArray()['props']['navigation'];
});
return $menu;
}
public function test_without_a_saved_menu_the_automatic_menu_applies(): void
{
$keys = array_column($this->menuFor(User::factory()->create()), 'key');
$this->assertSame('home', $keys[0]);
$this->assertContains('news', $keys);
}
public function test_custom_menu_with_pages_subpages_groups_links_and_roles(): void
{
$mav = $this->page('Mitarbeitervertretung');
$this->page('Sprechstunden', $mav);
$this->page('Wahlen', $mav);
$hr = Role::query()->create(['name' => 'Personal']);
app(Settings::class)->set(Navigation::MENU_SETTING, [
['id' => 'a', 'type' => 'module', 'module' => 'home'],
['id' => 'b', 'type' => 'page', 'target' => (string) $mav->id, 'subpages' => true],
['id' => 'c', 'type' => 'group', 'label' => 'Service', 'children' => [
['id' => 'c1', 'type' => 'module', 'module' => 'news', 'label' => 'Aktuelles'],
['id' => 'c2', 'type' => 'link', 'url' => 'https://kantine.example.org', 'label' => 'Speiseplan', 'new_tab' => true],
['id' => 'c3', 'type' => 'link', 'url' => 'javascript:alert(1)', 'label' => 'Böse'],
]],
['id' => 'd', 'type' => 'group', 'label' => 'Nur Personal', 'roles' => [$hr->id], 'children' => [
['id' => 'd1', 'type' => 'link', 'url' => '/personen', 'label' => 'Verzeichnis'],
]],
['id' => 'e', 'type' => 'group', 'label' => 'Leer', 'children' => []],
['id' => 'f', 'type' => 'module', 'module' => 'gibt-es-nicht'],
]);
$menu = $this->menuFor(User::factory()->create(), '/seiten/mitarbeitervertretung/wahlen');
$this->assertSame(['Startseite', 'Mitarbeitervertretung', 'Service'], array_column($menu, 'label'));
$this->assertSame(['Sprechstunden', 'Wahlen'], array_column($menu[1]['children'], 'label'));
$this->assertTrue($menu[1]['active'], 'Unterseite aktiv → Menüpunkt aktiv');
$this->assertTrue($menu[1]['children'][1]['active']);
$this->assertSame(['Aktuelles', 'Speiseplan'], array_column($menu[2]['children'], 'label'), 'Unsichere Links fallen weg');
$this->assertTrue($menu[2]['children'][1]['new_tab']);
$this->assertNull($menu[2]['href']);
$withRole = User::factory()->withRoles([$hr])->create();
$this->assertContains('Nur Personal', array_column($this->menuFor($withRole), 'label'));
}
public function test_deleted_pages_disappear_from_the_menu(): void
{
$page = $this->page('Alt');
app(Settings::class)->set(Navigation::MENU_SETTING, [['id' => 'a', 'type' => 'page', 'target' => (string) $page->id]]);
$page->delete();
app(PageTree::class)->flush();
$this->assertSame([], $this->menuFor(User::factory()->create()));
}
public function test_admin_builds_the_menu_starting_from_the_automatic_one(): void
{
$this->actingAs(User::factory()->admin()->create());
$component = Livewire::test(MenuSettings::class);
$items = $component->get('data.items');
$this->assertSame('home', collect($items)->first()['module']);
$component->set('data.items', [
'x' => ['id' => 'x', 'type' => 'module', 'module' => 'news', 'label' => 'News', 'roles' => [], 'children' => [
'y' => ['id' => 'y', 'type' => 'link', 'url' => '/termine', 'label' => 'Termine', 'roles' => []],
]],
])->call('save')->assertHasNoErrors();
$saved = app(Settings::class)->get(Navigation::MENU_SETTING);
$this->assertSame('News', $saved[0]['label']);
$this->assertSame('/termine', $saved[0]['children'][0]['url']);
$component->set('data.items.x.children.y.url', 'ftp://nope')->call('save')->assertHasErrors(['data.items.x.children.y.url']);
$this->assertSame('/termine', app(Settings::class)->get(Navigation::MENU_SETTING)[0]['children'][0]['url'], 'Ungültiges wird nicht gespeichert');
}
public function test_menu_page_requires_the_right(): void
{
$this->actingAs(User::factory()->create())->get('/admin/menue')->assertForbidden();
}
}