You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.2 KiB

  1. <?php
  2. namespace Tests\Feature\Auth;
  3. use App\Models\User;
  4. use Illuminate\Foundation\Testing\RefreshDatabase;
  5. use Tests\TestCase;
  6. class AuthenticationTest extends TestCase
  7. {
  8. use RefreshDatabase;
  9. public function test_login_screen_can_be_rendered(): void
  10. {
  11. $response = $this->get('/login');
  12. $response->assertStatus(200);
  13. }
  14. public function test_users_can_authenticate_using_the_login_screen(): void
  15. {
  16. $user = User::factory()->create();
  17. $response = $this->post('/login', [
  18. 'email' => $user->email,
  19. 'password' => 'password',
  20. ]);
  21. $this->assertAuthenticated();
  22. $response->assertRedirect(route('dashboard', absolute: false));
  23. }
  24. public function test_users_can_not_authenticate_with_invalid_password(): void
  25. {
  26. $user = User::factory()->create();
  27. $this->post('/login', [
  28. 'email' => $user->email,
  29. 'password' => 'wrong-password',
  30. ]);
  31. $this->assertGuest();
  32. }
  33. public function test_users_can_logout(): void
  34. {
  35. $user = User::factory()->create();
  36. $response = $this->actingAs($user)->post('/logout');
  37. $this->assertGuest();
  38. $response->assertRedirect('/');
  39. }
  40. }