67 lines
1.7 KiB
PHP
67 lines
1.7 KiB
PHP
<?php
|
|
|
|
use App\Models\User;
|
|
|
|
uses(\Illuminate\Foundation\Testing\RefreshDatabase::class);
|
|
|
|
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'));
|
|
}); |