first
This commit is contained in:
38
tests/Feature/DashboardAccessTest.php
Normal file
38
tests/Feature/DashboardAccessTest.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Database\Seeders\RolePermissionSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DashboardAccessTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_dashboard_redirects_admin_to_admin_dashboard(): void
|
||||
{
|
||||
$this->seed(RolePermissionSeeder::class);
|
||||
|
||||
$admin = User::factory()->create();
|
||||
$admin->assignRole('Admin');
|
||||
|
||||
$response = $this->actingAs($admin)->get('/dashboard');
|
||||
|
||||
$response->assertRedirect(route('admin.dashboard', absolute: false));
|
||||
}
|
||||
|
||||
public function test_role_dashboard_is_protected_by_role_middleware(): void
|
||||
{
|
||||
$this->seed(RolePermissionSeeder::class);
|
||||
|
||||
$admin = User::factory()->create();
|
||||
$admin->assignRole('Admin');
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->actingAs($admin)->get('/admin/dashboard')->assertOk();
|
||||
$this->actingAs($user)->get('/admin/dashboard')->assertForbidden();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user