Loheide-eu-mitarbeiterplatt.../tests/Feature/HeaderItemsTest.php
Friederich Loheide 8a9399b6a5
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 8m25s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 8m46s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 11m36s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 11m31s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 11m34s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 12m12s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 12m14s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 46s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 11m18s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m15s
Symbole für alle Hauptpunkte im automatischen Menü (0.40.0)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 18:02:11 +00:00

37 lines
1.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Tests\Feature;
use App\Layout\HeaderItems;
use App\Models\Role;
use App\Models\User;
use App\Plugins\PluginAccess;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Inertia\Testing\AssertableInertia as Assert;
use Tests\TestCase;
class HeaderItemsTest extends TestCase
{
use RefreshDatabase;
public function test_plugins_add_header_icons_per_person(): void
{
$items = app(HeaderItems::class);
$items->add('news', 'news::Unread', fn (User $user) => ['unread' => 3]);
$items->add('events', 'events::Hidden', fn () => null);
$items->add('forms', 'forms::Broken', fn () => throw new \RuntimeException('kaputt'));
$user = User::factory()->create();
// Nur die hier angemeldeten Symbole betrachten – lokal installierte Plugins bringen ggf. eigene mit
$mine = fn (array $items) => collect($items)->whereIn('key', ['news', 'events', 'forms'])->values()->all();
$this->actingAs($user)->get('/')->assertInertia(fn (Assert $p) => $p->where('headerItems', fn ($items) => $mine($items->all()) === [
['key' => 'news', 'component' => 'news::Unread', 'props' => ['unread' => 3]],
]));
// Vom Modul ausgeschlossene Rollen sehen das Symbol nicht
$role = Role::query()->create(['name' => 'Extern']);
app(PluginAccess::class)->exclude('news', [$role->id]);
$external = User::factory()->withRoles([$role])->create();
$this->actingAs($external)->get('/')->assertInertia(fn (Assert $p) => $p->where('headerItems', fn ($items) => $mine($items->all()) === []));
}
}