12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- use App\Models\User;
- test('login screen can be rendered', function () {
- $response = $this->get(route('login'));
- $response->assertStatus(200);
- });
- test('users can authenticate using the login screen', function () {
- $user = User::factory()->create();
- $response = $this->post(route('login.store'), [
- 'email' => $user->email,
- 'password' => 'password',
- ]);
- $this->assertAuthenticated();
- $response->assertRedirect(route('dashboard', absolute: false));
- });
- test('users can not authenticate with invalid password', function () {
- $user = User::factory()->create();
- $this->post(route('login.store'), [
- 'email' => $user->email,
- 'password' => 'wrong-password',
- ]);
- $this->assertGuest();
- });
- test('users can logout', function () {
- $user = User::factory()->create();
- $response = $this->actingAs($user)->post(route('logout'));
- $this->assertGuest();
- $response->assertRedirect(route('home'));
- });
- test('users are rate limited', function () {
- $user = User::factory()->create();
- for ($i = 0; $i < 5; $i++) {
- $this->post(route('login.store'), [
- 'email' => $user->email,
- 'password' => 'wrong-password',
- ])
- ->assertStatus(302)
- ->assertSessionHasErrors([
- 'email' => 'These credentials do not match our records.',
- ]);
- }
- $response = $this->post(route('login.store'), [
- 'email' => $user->email,
- 'password' => 'wrong-password',
- ]);
- $response->assertSessionHasErrors('email');
- $errors = session('errors');
- $this->assertStringContainsString('Too many login attempts', $errors->first('email'));
- });
|