<?php
declare(strict_types=1);
namespace Tests\Feature\Admin;
use App\Models\User;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class AdminTest extends TestCase
{
#[Test]
public function admin_page_redirects_unauthorised_users_to_login_page(): void
$response = $this->get('/admin');
$response->assertRedirect('/login');
}
public function login_page_loads(): void
$response = $this->get('/login');
$response->assertViewIs('login');
public function login_attempt_with_bad_credentials_fails(): void
$response = $this->post('/login', [
'username' => 'bad',
'password' => 'credentials',
]);
public function login_succeeds(): void
User::factory([
'name' => 'admin',
'password' => bcrypt('password'),
])->create();
'password' => 'password',
$response->assertRedirect('/admin');
public function when_logged_in_redirects_to_admin_page(): void
$user = User::factory()->create();
$response = $this->actingAs($user)->get('/login');
$response->assertRedirect('/');
public function logged_out_users_simply_redirected(): void
$response = $this->get('/logout');
public function logged_in_users_shown_logout_form(): void
$response = $this->actingAs($user)->get('/logout');
$response->assertViewIs('logout');
public function logged_in_users_can_logout(): void
$response = $this->actingAs($user)->post('/logout');