Files

40 lines
896 B
PHP
Raw Permalink Normal View History

<?php
namespace Tests\Feature\Admin;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminAccessTest extends TestCase
{
use RefreshDatabase;
public function test_guest_is_redirected_to_login(): void
{
$response = $this->get(route('admin.dashboard'));
$response->assertRedirect(route('login'));
}
public function test_regular_user_is_forbidden(): void
{
$user = User::factory()->create();
$response = $this->actingAs($user)->get(route('admin.dashboard'));
$response->assertForbidden();
}
public function test_admin_can_view_dashboard(): void
{
$admin = User::factory()->create();
$admin->is_admin = true;
$admin->save();
$response = $this->actingAs($admin)->get(route('admin.dashboard'));
$response->assertOk();
}
}