- Per-user admin mode (simple: bookings/contracts, blocked periods, guests, portal tasks, reviews; expert: everything the role allows), user menu switch, FollowsAdminMode on all resources/pages (guarded by a test); roles keep deciding permissions. - Users list shows mode and 2FA; admins can reset another user's 2FA. - New "Sperrzeiten" list for all apartments (manual blocks editable, portal blocks read-only). - styles/final: clean hand-built SVG mark, logo, favicon (dark-mode aware), 4 icons, wave divider, plus PNG/WebP for mail/PDF/touch icon; colours via --brand-* variables. - Decisions recorded in KONZEPT §6a/6b (booking path 1 via offer + guest acceptance, direct booking later; tourist tax by Ferienservice Balu); agent documents added and marked as analysis with assumptions; styles excluded from the deploy package. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
113 lines
4.1 KiB
PHP
113 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Enums\AdminMode;
|
|
use App\Enums\UserRole;
|
|
use App\Filament\Concerns\FollowsAdminMode;
|
|
use App\Filament\Resources\BlockedPeriods\BlockedPeriodResource;
|
|
use App\Filament\Resources\BlockedPeriods\Pages\ManageBlockedPeriods;
|
|
use App\Filament\Resources\Properties\PropertyResource;
|
|
use App\Filament\Resources\Users\Pages\ListUsers;
|
|
use App\Filament\Resources\Users\UserResource;
|
|
use App\Models\BlockedPeriod;
|
|
use App\Models\Property;
|
|
use App\Models\User;
|
|
use Filament\Actions\CreateAction;
|
|
use Filament\Actions\Testing\TestAction;
|
|
use Filament\Facades\Filament;
|
|
use Filament\Livewire\Topbar;
|
|
use Filament\Pages\Dashboard;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Livewire\Livewire;
|
|
use Tests\TestCase;
|
|
|
|
class AdminModeTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_rentals_staff_starts_in_the_simple_mode_with_the_daily_menu_only(): void
|
|
{
|
|
$user = User::factory()->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());
|
|
}
|
|
}
|