AuthenticationTest.php 944 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. use App\Models\User;
  3. test('login screen can be rendered', function () {
  4. $response = $this->get('/login');
  5. $response->assertStatus(200);
  6. });
  7. test('users can authenticate using the login screen', function () {
  8. $user = User::factory()->create();
  9. $response = $this->post('/login', [
  10. 'email' => $user->email,
  11. 'password' => 'password',
  12. ]);
  13. $this->assertAuthenticated();
  14. $response->assertRedirect(route('dashboard', absolute: false));
  15. });
  16. test('users can not authenticate with invalid password', function () {
  17. $user = User::factory()->create();
  18. $this->post('/login', [
  19. 'email' => $user->email,
  20. 'password' => 'wrong-password',
  21. ]);
  22. $this->assertGuest();
  23. });
  24. test('users can logout', function () {
  25. $user = User::factory()->create();
  26. $response = $this->actingAs($user)->post('/logout');
  27. $this->assertGuest();
  28. $response->assertRedirect('/');
  29. });