/
Shamaeva2
/
coursework.local
Обзор
Документация
Войти
/
Shamaeva2
/
coursework.local
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
tests/Feature/Settings/TwoFactorAuthenticationTest.php
92 строки
3 KB
Шамаева Виктория Сергеевна
Инициализация проекта
20 мар 2026, 14:08
20 мар 2026, 14:08
2ebca05
Код
Авторство
О чём код?
<?php namespace Tests\Feature\Settings; use App\Models\User; use Illuminate\Foundation\Testing\RefreshDatabase; use Inertia\Testing\AssertableInertia as Assert; use Laravel\Fortify\Features; use Tests\TestCase; class TwoFactorAuthenticationTest extends TestCase { use RefreshDatabase; public function test_two_factor_settings_page_can_be_rendered() { if (! Features::canManageTwoFactorAuthentication()) { $this->markTestSkipped('Two-factor authentication is not enabled.'); } Features::twoFactorAuthentication([ 'confirm' => true, 'confirmPassword' => true, ]); $user = User::factory()->create(); $this->actingAs($user) ->withSession(['auth.password_confirmed_at' => time()]) ->get(route('two-factor.show')) ->assertInertia(fn (Assert $page) => $page ->component('settings/TwoFactor') ->where('twoFactorEnabled', false) ); } public function test_two_factor_settings_page_requires_password_confirmation_when_enabled() { if (! Features::canManageTwoFactorAuthentication()) { $this->markTestSkipped('Two-factor authentication is not enabled.'); } $user = User::factory()->create(); Features::twoFactorAuthentication([ 'confirm' => true, 'confirmPassword' => true, ]); $response = $this->actingAs($user) ->get(route('two-factor.show')); $response->assertRedirect(route('password.confirm')); } public function test_two_factor_settings_page_does_not_requires_password_confirmation_when_disabled() { if (! Features::canManageTwoFactorAuthentication()) { $this->markTestSkipped('Two-factor authentication is not enabled.'); } $user = User::factory()->create(); Features::twoFactorAuthentication([ 'confirm' => true, 'confirmPassword' => false, ]); $this->actingAs($user) ->get(route('two-factor.show')) ->assertOk() ->assertInertia(fn (Assert $page) => $page ->component('settings/TwoFactor') ); } public function test_two_factor_settings_page_returns_forbidden_response_when_two_factor_is_disabled() { if (! Features::canManageTwoFactorAuthentication()) { $this->markTestSkipped('Two-factor authentication is not enabled.'); } config(['fortify.features' => []]); $user = User::factory()->create(); $this->actingAs($user) ->withSession(['auth.password_confirmed_at' => time()]) ->get(route('two-factor.show')) ->assertForbidden(); } }