All checks were successful
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m35s
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m37s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m41s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m52s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 3m56s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 4m2s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 4m21s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 4m5s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m10s
- Vollständiger Satz (1.854 Symbole + Aliase älterer Namen) in resources/icons/svg.php (Admin) und resources/js/lib/icon-set.js (Portal, wird nur bei Bedarf geladen) - Kuratierte 66 mit deutscher Bezeichnung bleiben im Hauptpaket und stehen in Auswahlfeldern vorne; die Suche findet alle - AppIcon-Komponente für Menü, Schnellzugriffe und Pagebuilder; Symbolfeld im Pagebuilder mit Suche Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
124 lines
5.6 KiB
PHP
124 lines
5.6 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, 'icon' => 'heart-handshake'],
|
|
['id' => 'c', 'type' => 'group', 'label' => 'Service', 'children' => [
|
|
['id' => 'c1', 'type' => 'module', 'module' => 'news', 'label' => 'Aktuelles', 'icon' => 'gibt-es-nicht'],
|
|
['id' => 'c2', 'type' => 'link', 'url' => 'https://kantine.example.org', 'label' => 'Speiseplan', 'new_tab' => true, 'icon' => 'soup'],
|
|
['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->assertSame('heart-handshake', $menu[1]['icon']);
|
|
$this->assertNull($menu[2]['children'][0]['icon'], 'Unbekannte Symbole fallen weg');
|
|
$this->assertSame('soup', $menu[2]['children'][1]['icon'], 'Auch Symbole außerhalb der kuratierten Auswahl');
|
|
$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', 'icon' => 'newspaper', '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('newspaper', $saved[0]['icon']);
|
|
$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();
|
|
}
|
|
}
|