78 lines
2.2 KiB
PHP
78 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Auth;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class UserRoleAccessTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_user_role_cannot_access_dashboard(): void
|
|
{
|
|
$user = User::factory()->create(['role' => 'user']);
|
|
|
|
$response = $this->actingAs($user)->get('/dashboard');
|
|
|
|
$response->assertRedirect('/packages');
|
|
}
|
|
|
|
public function test_user_role_cannot_access_event_admin_dashboard(): void
|
|
{
|
|
$user = User::factory()->create(['role' => 'user']);
|
|
|
|
$response = $this->actingAs($user)->get('/event-admin/dashboard');
|
|
|
|
$response->assertRedirect('/packages');
|
|
}
|
|
|
|
public function test_user_role_cannot_access_event_admin_logout(): void
|
|
{
|
|
$user = User::factory()->create(['role' => 'user']);
|
|
|
|
$response = $this->actingAs($user)->get('/event-admin/logout');
|
|
|
|
$response->assertRedirect('/packages');
|
|
}
|
|
|
|
public function test_user_role_login_redirects_to_packages(): void
|
|
{
|
|
$user = User::factory()->create(['email' => 'test@example.com', 'role' => 'user']);
|
|
|
|
$response = $this->post('/login', [
|
|
'login' => 'test@example.com',
|
|
'password' => 'password',
|
|
]);
|
|
|
|
$response->assertRedirect('/packages');
|
|
}
|
|
|
|
public function test_tenant_admin_can_access_both_dashboards(): void
|
|
{
|
|
$user = User::factory()->create(['role' => 'tenant_admin']);
|
|
|
|
// Can access regular dashboard
|
|
$response1 = $this->actingAs($user)->get('/dashboard');
|
|
$response1->assertStatus(200);
|
|
|
|
// Can access event admin dashboard
|
|
$response2 = $this->actingAs($user)->get('/event-admin/dashboard');
|
|
$response2->assertStatus(200);
|
|
}
|
|
|
|
public function test_super_admin_can_access_both_dashboards(): void
|
|
{
|
|
$user = User::factory()->create(['role' => 'super_admin']);
|
|
|
|
// Can access regular dashboard
|
|
$response1 = $this->actingAs($user)->get('/dashboard');
|
|
$response1->assertStatus(200);
|
|
|
|
// Can access event admin dashboard
|
|
$response2 = $this->actingAs($user)->get('/event-admin/dashboard');
|
|
$response2->assertStatus(200);
|
|
}
|
|
}
|