get('/') ->assertOk() ->assertSee('Welcome back.') ->assertSee('Secure administrator access'); } public function test_guests_are_redirected_to_login_from_admin_pages(): void { $this->get('/dashboard')->assertRedirect(route('login')); $this->get('/inventory')->assertRedirect(route('login')); } public function test_admin_can_sign_in_and_reach_dashboard(): void { $admin = User::factory()->create([ 'email' => 'admin@example.com', 'password' => 'secret-password', 'is_admin' => true, ]); $this->post(route('login.store'), ['email' => $admin->email, 'password' => 'secret-password']) ->assertRedirect(route('dashboard')); $this->assertAuthenticatedAs($admin); } public function test_non_admin_account_cannot_sign_in_to_admin_portal(): void { $user = User::factory()->create(['password' => 'secret-password', 'is_admin' => false]); $this->post(route('login.store'), ['email' => $user->email, 'password' => 'secret-password']) ->assertSessionHasErrors('email'); $this->assertGuest(); $this->actingAs($user)->get('/dashboard')->assertForbidden(); } public function test_admin_can_sign_out(): void { $admin = User::factory()->create(['is_admin' => true]); $this->actingAs($admin)->post(route('logout'))->assertRedirect(route('login')); $this->assertGuest(); } }