role(UserRole::Rentals)->create(); $this->actingAs($user); $this->assertSame(AdminMode::Simple, $user->adminMode()); $this->get(Dashboard::getUrl()) ->assertOk() ->assertSee('Anfragen & Buchungen', false) ->assertSee('Sperrzeiten') ->assertSee('Portal-Aufgaben') ->assertDontSee('Wohnungen') ->assertDontSee('Portal-E-Mails') ->assertSee('Zur Expertenansicht wechseln'); } public function test_expert_mode_shows_everything_the_role_allows(): void { $this->actingAs(User::factory()->role(UserRole::Rentals)->create(['admin_mode' => AdminMode::Expert])); $this->get(Dashboard::getUrl()) ->assertOk() ->assertSee('Wohnungen') ->assertSee('Portal-E-Mails') ->assertSee('Zur einfachen Ansicht wechseln'); } public function test_every_admin_resource_and_page_follows_the_admin_mode(): void { $panel = Filament::getPanel('admin'); $classes = [...$panel->getResources(), ...array_filter($panel->getPages(), fn (string $page): bool => $page !== Dashboard::class)]; foreach ($classes as $class) { $this->assertContains(FollowsAdminMode::class, class_uses_recursive($class), "{$class} must use FollowsAdminMode"); } } public function test_administrators_default_to_the_expert_mode(): void { $this->assertSame(AdminMode::Expert, User::factory()->create()->adminMode()); } public function test_simple_mode_only_changes_the_menu_not_the_rights(): void { $this->actingAs(User::factory()->role(UserRole::Rentals)->create()); $this->get(PropertyResource::getUrl('index'))->assertOk(); $this->get(UserResource::getUrl('index'))->assertForbidden(); } public function test_user_menu_switches_the_mode(): void { $user = User::factory()->role(UserRole::Rentals)->create(); $this->actingAs($user); Filament::setCurrentPanel('admin'); Livewire::test(Topbar::class)->callAction('switchAdminMode'); $this->assertSame(AdminMode::Expert, $user->fresh()->adminMode()); } public function test_blocked_periods_can_be_managed_in_their_own_list(): void { $property = Property::factory()->create(); $this->actingAs(User::factory()->role(UserRole::Rentals)->create()); $this->get(BlockedPeriodResource::getUrl('index'))->assertOk(); Livewire::test(ManageBlockedPeriods::class) ->callAction(CreateAction::class, ['property_id' => $property->id, 'starts_on' => '2026-12-01', 'ends_on' => '2026-12-05', 'reason' => 'Eigennutzung']) ->assertHasNoFormErrors(); $this->assertSame(['manual', 'Eigennutzung'], [BlockedPeriod::sole()->source, BlockedPeriod::sole()->reason]); } public function test_administrator_can_reset_the_two_factor_login_of_another_user(): void { $mother = User::factory()->role(UserRole::Rentals)->create(); $this->actingAs(User::factory()->create()); Livewire::test(ListUsers::class)->callAction(TestAction::make('resetTwoFactor')->table($mother)); $this->assertNull($mother->fresh()->getAppAuthenticationSecret()); } }