Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m7s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 7m30s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 8m6s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 8m21s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 17m13s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 17m12s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 9m52s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 9m29s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 47s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m23s
Untertitel, Logo, Kategorie, Rollen und Anheften je Eintrag; Knopf „Anwendungen“ in der Kopfzeile mit allen sichtbaren Einträgen. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
101 lines
4.3 KiB
PHP
101 lines
4.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Admin;
|
|
|
|
use App\Filament\Pages\QuickLinksSettings;
|
|
use App\Models\Role;
|
|
use App\Models\User;
|
|
use App\Support\QuickLinks;
|
|
use App\Support\Settings;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Livewire\Livewire;
|
|
use Tests\TestCase;
|
|
|
|
class QuickLinksSettingsTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_admin_can_save_quick_links(): void
|
|
{
|
|
$this->actingAs(User::factory()->admin()->create());
|
|
|
|
Livewire::test(QuickLinksSettings::class)
|
|
->fillForm(['links' => [
|
|
['label' => 'Urlaubsantrag', 'url' => 'https://urlaub.example.com', 'icon' => 'plane', 'new_tab' => true],
|
|
['label' => 'Personen', 'url' => '/personen', 'icon' => 'users', 'new_tab' => false],
|
|
]])
|
|
->call('save')
|
|
->assertHasNoFormErrors();
|
|
|
|
$links = app(QuickLinks::class)->all();
|
|
$this->assertCount(2, $links);
|
|
$this->assertSame('Urlaubsantrag', $links[0]['label']);
|
|
$this->assertSame('plane', $links[0]['icon']);
|
|
}
|
|
|
|
public function test_unsafe_urls_are_rejected(): void
|
|
{
|
|
$this->actingAs(User::factory()->admin()->create());
|
|
|
|
Livewire::test(QuickLinksSettings::class)
|
|
->fillForm(['links' => [
|
|
['label' => 'Böse', 'url' => 'javascript:alert(1)', 'icon' => 'link'],
|
|
]])
|
|
->call('save')
|
|
->assertHasFormErrors();
|
|
}
|
|
|
|
public function test_page_is_admin_only(): void
|
|
{
|
|
$this->actingAs(User::factory()->create())->get('/admin/startseite-menue/schnellzugriffe')->assertForbidden();
|
|
$this->actingAs(User::factory()->admin()->create())->get('/admin/startseite-menue/schnellzugriffe')->assertOk();
|
|
}
|
|
|
|
public function test_links_can_be_limited_to_roles_and_pinned(): void
|
|
{
|
|
$admin = User::factory()->admin()->create();
|
|
$clients = Role::create(['name' => 'Klienten']);
|
|
$this->actingAs($admin);
|
|
|
|
Livewire::test(QuickLinksSettings::class)
|
|
->fillForm(['links' => [
|
|
['label' => 'Vivendi PEP', 'subtitle' => 'Dienstplan', 'url' => 'https://pep.example.com', 'icon' => 'calendar', 'category' => 'Pflege', 'roles' => [], 'pinned' => true, 'new_tab' => true],
|
|
['label' => 'DocuWare', 'subtitle' => 'Archiv', 'url' => 'https://docuware.example.com', 'icon' => 'archive', 'category' => 'Verwaltung', 'roles' => [], 'pinned' => false, 'new_tab' => true],
|
|
['label' => 'Werkstattrat', 'url' => '/seiten/werkstattrat', 'icon' => 'users', 'roles' => [(string) $clients->id], 'pinned' => false, 'new_tab' => false],
|
|
]])
|
|
->call('save')
|
|
->assertHasNoFormErrors();
|
|
|
|
$stored = app(QuickLinks::class)->all();
|
|
$this->assertSame('Dienstplan', $stored[0]['subtitle']);
|
|
$this->assertSame('Pflege', $stored[0]['category']);
|
|
$this->assertSame([$clients->id], $stored[2]['roles']);
|
|
|
|
// Personen ohne die Rolle sehen den eingeschränkten Eintrag nicht
|
|
$employee = User::factory()->create();
|
|
$this->assertSame(['Vivendi PEP', 'DocuWare'], array_column(app(QuickLinks::class)->forUser($employee), 'label'));
|
|
|
|
$client = User::factory()->create();
|
|
$client->roles()->attach($clients);
|
|
$this->assertContains('Werkstattrat', array_column(app(QuickLinks::class)->forUser($client), 'label'));
|
|
|
|
// Startseite: nur angeheftete, dazu die Gesamtzahl für „Alle Anwendungen“
|
|
$widget = $this->dashboardWidget($this->actingAs($employee)->get('/'), 'core.quick-links');
|
|
$this->assertSame(['Vivendi PEP'], array_column($widget['links'], 'label'));
|
|
$this->assertSame(2, $widget['total']);
|
|
|
|
// Kopfzeile: alle sichtbaren
|
|
$this->actingAs($employee)->get('/')->assertInertia(fn ($page) => $page->has('apps', 2));
|
|
}
|
|
|
|
public function test_quick_link_widget_disappears_without_visible_links(): void
|
|
{
|
|
$role = Role::create(['name' => 'Verwaltung']);
|
|
app(Settings::class)->set('portal.quick_links', [
|
|
['label' => 'Nur Verwaltung', 'url' => 'https://x.example.com', 'icon' => 'link', 'roles' => [$role->id]],
|
|
]);
|
|
|
|
$response = $this->actingAs(User::factory()->create())->get('/');
|
|
$this->assertNull($this->dashboardWidget($response, 'core.quick-links'));
|
|
}
|
|
}
|