use Tests\TestCase;
use App\Models\User;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
class PageTest extends TestCase
{
use RefreshDatabase, WithFaker;
public $user;
protected function setUp(): void
{
parent::setUp();
$this->seed();
$this->user = User::factory()->create();
}
public function testAllowHomepage()
{
$this->withoutExceptionHandling();
$response = $this->actingAs($this->user)->get('/');
$response->assertOk();
$response->assertViewIs('homepage');
}
public function testDenyHomepageWhenNotLoggedIn()
{
$response = $this->get('/');
$response->assertRedirect(route('login'));
}
public function testAllowAdminDashboard()
{
$this->withoutExceptionHandling();
$this->user->givePermissionTo('admin_access');
$response = $this->actingAs($this->user)->get(route('admin.dashboard'));
$response->assertOk();
$response->assertViewIs('admin.dashboard');
}
public function testDenyAdminDashboardWhenNotLoggedIn()
{
$response = $this->get(route('admin.dashboard'));
$response->assertRedirect(route('login'));
}
public function testDeniedAdminDashboardWithoutPermission()
{
$response = $this->actingAs($this->user)->get(route('admin.dashboard'));
$response->assertForbidden();
}