This commit is contained in:
2026-07-21 23:39:19 +02:00
commit b33b217bdb
217 changed files with 32076 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
<?php
use App\Models\User;
function userWithRole(string $role): User
{
return User::query()->create([
'name' => ucfirst($role).' User',
'email' => $role.'@example.com',
'roles' => [$role],
]);
}
test('guests are redirected to login for every protected area', function (string $uri) {
$this->get($uri)->assertRedirect('/login');
})->with(['/client', '/operator', '/admin']);
test('each role can only access its own area', function () {
$client = userWithRole('client');
$operator = userWithRole('operator');
$admin = userWithRole('admin');
$this->actingAs($client)->get('/client')->assertOk();
$this->actingAs($client)->get('/operator')->assertForbidden();
$this->actingAs($client)->get('/admin')->assertForbidden();
$this->actingAs($operator)->get('/operator')->assertOk();
$this->actingAs($operator)->get('/client')->assertForbidden();
$this->actingAs($operator)->get('/admin')->assertForbidden();
$this->actingAs($admin)->get('/admin')->assertOk();
$this->actingAs($admin)->get('/client')->assertForbidden();
$this->actingAs($admin)->get('/operator')->assertForbidden();
});
test('a user with multiple roles can access every matching area', function () {
$user = User::query()->create([
'name' => 'Multi Role',
'email' => 'multi@example.com',
'roles' => ['operator', 'admin'],
]);
$this->actingAs($user)->get('/operator')->assertOk();
$this->actingAs($user)->get('/admin')->assertOk();
$this->actingAs($user)->get('/client')->assertForbidden();
});