byos_laravel/tests/Feature/Auth/TwoFactorChallengeTest.php
2026-01-15 23:34:58 +01:00

34 lines
998 B
PHP

<?php
use App\Models\User;
use Laravel\Fortify\Features;
uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
test('two_factor_challenge_redirects_to_login_when_not_authenticated', function (): void {
if (! Features::canManageTwoFactorAuthentication()) {
$this->markTestSkipped('Two-factor authentication is not enabled.');
}
$response = $this->get(route('two-factor.login'));
$response->assertRedirect(route('login'));
});
test('two_factor_challenge_can_be_rendered', function (): void {
if (! Features::canManageTwoFactorAuthentication()) {
$this->markTestSkipped('Two-factor authentication is not enabled.');
}
Features::twoFactorAuthentication([
'confirm' => true,
'confirmPassword' => true,
]);
$user = User::factory()->withTwoFactor()->create();
$this->post(route('login.store'), [
'email' => $user->email,
'password' => 'password',
])->assertRedirect(route('two-factor.login'));
});