AuthenticationTest.php 1.0 KB

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