*/ public static function roleProvider(): array { return [ 'Administrator' => [UserRole::Admin, true, true, true], 'Vermietung' => [UserRole::Rentals, true, true, false], 'Inhalte' => [UserRole::Content, false, false, false], ]; } #[DataProvider('roleProvider')] public function test_roles_see_only_their_areas(UserRole $role, bool $bookings, bool $properties, bool $users): void { $this->actingAs(User::factory()->role($role)->create()); $this->get(BookingResource::getUrl('index'))->assertStatus($bookings ? 200 : 403); $this->get(PropertyResource::getUrl('index'))->assertStatus($properties ? 200 : 403); $this->get(UserResource::getUrl('index'))->assertStatus($users ? 200 : 403); } public function test_account_without_role_cannot_enter_the_admin(): void { $this->actingAs(User::factory()->role(null)->create()); $this->get(BookingResource::getUrl('index'))->assertForbidden(); } public function test_administrator_creates_a_user_with_role(): void { $this->actingAs(User::factory()->create()); Livewire::test(CreateUser::class) ->fillForm([ 'name' => 'Brigitte Stommer', 'email' => 'brigitte@example.com', 'role' => UserRole::Rentals->value, 'password' => 'sehr-geheim-123', ]) ->call('create') ->assertHasNoFormErrors(); $user = User::where('email', 'brigitte@example.com')->sole(); $this->assertSame(UserRole::Rentals, $user->role); $this->assertTrue(Hash::check('sehr-geheim-123', $user->password)); } public function test_administrators_cannot_delete_themselves(): void { $admin = User::factory()->create(); $this->assertFalse($admin->can('delete', $admin)); $this->assertTrue($admin->can('delete', User::factory()->create())); } }