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>
120 lines
5.2 KiB
PHP
120 lines
5.2 KiB
PHP
<?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();
|
|
}
|
|
}
|