Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions tests/Feature/Auth/AuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ public function test_users_can_authenticate_using_the_login_screen()

public function test_users_with_two_factor_enabled_are_redirected_to_two_factor_challenge()
{
if (! Features::canManageTwoFactorAuthentication()) {
$this->markTestSkipped('Two-factor authentication is not enabled.');
}
$this->skipUnlessFortifyFeature(Features::twoFactorAuthentication());

Features::twoFactorAuthentication([
'confirm' => true,
Expand Down
8 changes: 8 additions & 0 deletions tests/Feature/Auth/EmailVerificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\URL;
use Laravel\Fortify\Features;
use Tests\TestCase;

class EmailVerificationTest extends TestCase
{
use RefreshDatabase;

protected function setUp(): void
{
parent::setUp();

$this->skipUnlessFortifyFeature(Features::emailVerification());
}

public function test_email_verification_screen_can_be_rendered()
{
$user = User::factory()->unverified()->create();
Expand Down
8 changes: 8 additions & 0 deletions tests/Feature/Auth/PasswordResetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use Laravel\Fortify\Features;
use Tests\TestCase;

class PasswordResetTest extends TestCase
{
use RefreshDatabase;

protected function setUp(): void
{
parent::setUp();

$this->skipUnlessFortifyFeature(Features::resetPasswords());
}

public function test_reset_password_link_screen_can_be_rendered()
{
$response = $this->get(route('password.request'));
Expand Down
8 changes: 8 additions & 0 deletions tests/Feature/Auth/RegistrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@
namespace Tests\Feature\Auth;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Fortify\Features;
use Tests\TestCase;

class RegistrationTest extends TestCase
{
use RefreshDatabase;

protected function setUp(): void
{
parent::setUp();

$this->skipUnlessFortifyFeature(Features::registration());
}

public function test_registration_screen_can_be_rendered()
{
$response = $this->get(route('register'));
Expand Down
15 changes: 7 additions & 8 deletions tests/Feature/Auth/TwoFactorChallengeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,22 @@ class TwoFactorChallengeTest extends TestCase
{
use RefreshDatabase;

public function test_two_factor_challenge_redirects_to_login_when_not_authenticated(): void
protected function setUp(): void
{
if (! Features::canManageTwoFactorAuthentication()) {
$this->markTestSkipped('Two-factor authentication is not enabled.');
}
parent::setUp();

$this->skipUnlessFortifyFeature(Features::twoFactorAuthentication());
}

public function test_two_factor_challenge_redirects_to_login_when_not_authenticated(): void
{
$response = $this->get(route('two-factor.login'));

$response->assertRedirect(route('login'));
}

public function test_two_factor_challenge_can_be_rendered(): void
{
if (! Features::canManageTwoFactorAuthentication()) {
$this->markTestSkipped('Two-factor authentication is not enabled.');
}

Features::twoFactorAuthentication([
'confirm' => true,
'confirmPassword' => true,
Expand Down
8 changes: 8 additions & 0 deletions tests/Feature/Auth/VerificationNotificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@
use Illuminate\Auth\Notifications\VerifyEmail;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use Laravel\Fortify\Features;
use Tests\TestCase;

class VerificationNotificationTest extends TestCase
{
use RefreshDatabase;

protected function setUp(): void
{
parent::setUp();

$this->skipUnlessFortifyFeature(Features::emailVerification());
}

public function test_sends_verification_notification(): void
{
Notification::fake();
Expand Down
16 changes: 4 additions & 12 deletions tests/Feature/Settings/TwoFactorAuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ class TwoFactorAuthenticationTest extends TestCase

public function test_two_factor_settings_page_can_be_rendered()
{
if (! Features::canManageTwoFactorAuthentication()) {
$this->markTestSkipped('Two-factor authentication is not enabled.');
}
$this->skipUnlessFortifyFeature(Features::twoFactorAuthentication());

Features::twoFactorAuthentication([
'confirm' => true,
Expand All @@ -36,9 +34,7 @@ public function test_two_factor_settings_page_can_be_rendered()

public function test_two_factor_settings_page_requires_password_confirmation_when_enabled()
{
if (! Features::canManageTwoFactorAuthentication()) {
$this->markTestSkipped('Two-factor authentication is not enabled.');
}
$this->skipUnlessFortifyFeature(Features::twoFactorAuthentication());

$user = User::factory()->create();

Expand All @@ -55,9 +51,7 @@ public function test_two_factor_settings_page_requires_password_confirmation_whe

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.');
}
$this->skipUnlessFortifyFeature(Features::twoFactorAuthentication());

$user = User::factory()->create();

Expand All @@ -76,9 +70,7 @@ public function test_two_factor_settings_page_does_not_requires_password_confirm

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.');
}
$this->skipUnlessFortifyFeature(Features::twoFactorAuthentication());

config(['fortify.features' => []]);

Expand Down
8 changes: 7 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
namespace Tests;

use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Laravel\Fortify\Features;

abstract class TestCase extends BaseTestCase
{
//
protected function skipUnlessFortifyFeature(string $feature, ?string $message = null): void
{
if (! Features::enabled($feature)) {
$this->markTestSkipped($message ?? "Fortify feature [{$feature}] is not enabled.");
}
}
}