Files

92 lines
2.4 KiB
PHP
Raw Permalink Normal View History

2025-02-08 15:06:14 +01:00
<?php
use App\Models\User;
use Laravel\Fortify\Features;
2025-02-25 12:15:35 +01:00
2025-06-17 21:30:59 +02:00
uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
2025-02-08 15:06:14 +01:00
2025-09-24 20:31:32 +02:00
test('login screen can be rendered', function (): void {
2025-02-08 15:06:14 +01:00
$response = $this->get('/login');
$response->assertOk();
2026-05-23 09:18:34 +02:00
$response->assertDontSee('Sign in with a passkey');
});
test('login screen shows passkey sign-in when passkeys are enabled', function (): void {
config(['app.passkeys.enabled' => true]);
Features::passkeys([
'confirmPassword' => true,
]);
$features = array_values(array_filter(config('fortify.features', [])));
$passkeysFeature = Features::passkeys();
if (! in_array($passkeysFeature, $features, true)) {
$features[] = $passkeysFeature;
}
config(['fortify.features' => $features]);
$this->skipUnlessFortifyHas(Features::passkeys());
$response = $this->get('/login');
$response->assertOk();
$response->assertSee('Sign in with a passkey');
2025-02-08 15:06:14 +01:00
});
2025-09-24 20:31:32 +02:00
test('users can authenticate using the login screen', function (): void {
2025-02-08 15:06:14 +01:00
$user = User::factory()->create();
2026-01-15 21:55:24 +01:00
$response = $this->post(route('login.store'), [
'email' => $user->email,
'password' => 'password',
]);
2025-02-08 15:06:14 +01:00
2025-02-25 12:15:35 +01:00
$response
2026-01-15 21:55:24 +01:00
->assertSessionHasNoErrors()
2025-02-08 15:06:14 +01:00
->assertRedirect(route('dashboard', absolute: false));
$this->assertAuthenticated();
});
2025-09-24 20:31:32 +02:00
test('users can not authenticate with invalid password', function (): void {
2025-02-08 15:06:14 +01:00
$user = User::factory()->create();
$response = $this->post(route('login.store'), [
2025-02-25 12:15:35 +01:00
'email' => $user->email,
'password' => 'wrong-password',
]);
2025-02-08 15:06:14 +01:00
$response->assertSessionHasErrorsIn('email');
$this->assertGuest();
});
test('users with two factor enabled are redirected to two factor challenge', function (): void {
$this->skipUnlessFortifyHas(Features::twoFactorAuthentication());
Features::twoFactorAuthentication([
'confirm' => true,
'confirmPassword' => true,
]);
$user = User::factory()->withTwoFactor()->create();
$response = $this->post(route('login.store'), [
'email' => $user->email,
'password' => 'password',
]);
$response->assertRedirect(route('two-factor.login'));
2025-02-08 15:06:14 +01:00
$this->assertGuest();
});
2025-09-24 20:31:32 +02:00
test('users can logout', function (): void {
2025-02-08 15:06:14 +01:00
$user = User::factory()->create();
2025-02-25 12:15:35 +01:00
$response = $this->actingAs($user)->post('/logout');
2025-02-08 15:06:14 +01:00
$this->assertGuest();
$response->assertRedirect(route('home'));
2025-02-26 09:33:54 +01:00
});