get('/login'); $response->assertStatus(200); } public function testUnauthenticatedUserIsRedirectedToLogin(): void { $response = $this->get('/home'); $response->assertRedirect('/login'); } public function testUserCanLoginWithValidCredentials(): void { $user = User::factory()->create([ 'password' => bcrypt('password'), ]); $response = $this->post('/login', [ 'email' => $user->email, 'password' => 'password', ]); $this->assertAuthenticatedAs($user); $response->assertRedirect(); } public function testLoginFailsWithWrongPassword(): void { $user = User::factory()->create([ 'password' => bcrypt('correct-password'), ]); $response = $this->post('/login', [ 'email' => $user->email, 'password' => 'wrong-password', ]); $this->assertGuest(); $response->assertSessionHasErrors('email'); } public function testLoginFailsWithUnknownEmail(): void { $response = $this->post('/login', [ 'email' => 'nobody@example.com', 'password' => 'password', ]); $this->assertGuest(); $response->assertSessionHasErrors('email'); } public function testInactiveUserCannotLogin(): void { $user = User::factory()->inactive()->create([ 'password' => bcrypt('password'), ]); $response = $this->post('/login', [ 'email' => $user->email, 'password' => 'password', ]); $this->assertGuest(); } public function testAuthenticatedUserIsRedirectedAwayFromLoginPage(): void { $user = User::factory()->create(); $response = $this->actingAs($user)->get('/login'); $response->assertRedirect(); } public function testUserCanLogout(): void { $user = User::factory()->create(); $this->actingAs($user)->post('/logout'); $this->assertGuest(); } }