Skip to content

Commit b8eae92

Browse files
authored
Skip two factor authentication tests when the feature is disabled (#1095)
1 parent 805afa2 commit b8eae92

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed

stubs/pest-tests/inertia/TwoFactorAuthenticationSettingsTest.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use App\Models\User;
4+
use Laravel\Fortify\Features;
45

56
test('two factor authentication can be enabled', function () {
67
$this->actingAs($user = User::factory()->create());
@@ -11,7 +12,9 @@
1112

1213
expect($user->fresh()->two_factor_secret)->not->toBeNull();
1314
expect($user->fresh()->recoveryCodes())->toHaveCount(8);
14-
});
15+
})->skip(function () {
16+
return ! Features::canManageTwoFactorAuthentication();
17+
}, 'Two factor authentication is not enabled.');
1518

1619
test('recovery codes can be regenerated', function () {
1720
$this->actingAs($user = User::factory()->create());
@@ -27,7 +30,9 @@
2730

2831
expect($user->recoveryCodes())->toHaveCount(8);
2932
expect(array_diff($user->recoveryCodes(), $user->fresh()->recoveryCodes()))->toHaveCount(8);
30-
});
33+
})->skip(function () {
34+
return ! Features::canManageTwoFactorAuthentication();
35+
}, 'Two factor authentication is not enabled.');
3136

3237
test('two factor authentication can be disabled', function () {
3338
$this->actingAs($user = User::factory()->create());
@@ -41,4 +46,6 @@
4146
$this->delete('/user/two-factor-authentication');
4247

4348
expect($user->fresh()->two_factor_secret)->toBeNull();
44-
});
49+
})->skip(function () {
50+
return ! Features::canManageTwoFactorAuthentication();
51+
}, 'Two factor authentication is not enabled.');

stubs/pest-tests/livewire/TwoFactorAuthenticationSettingsTest.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use App\Models\User;
4+
use Laravel\Fortify\Features;
45
use Laravel\Jetstream\Http\Livewire\TwoFactorAuthenticationForm;
56
use Livewire\Livewire;
67

@@ -16,7 +17,9 @@
1617

1718
expect($user->two_factor_secret)->not->toBeNull();
1819
expect($user->recoveryCodes())->toHaveCount(8);
19-
});
20+
})->skip(function () {
21+
return ! Features::canManageTwoFactorAuthentication();
22+
}, 'Two factor authentication is not enabled.');
2023

2124
test('recovery codes can be regenerated', function () {
2225
$this->actingAs($user = User::factory()->create());
@@ -33,7 +36,9 @@
3336

3437
expect($user->recoveryCodes())->toHaveCount(8);
3538
expect(array_diff($user->recoveryCodes(), $user->fresh()->recoveryCodes()))->toHaveCount(8);
36-
});
39+
})->skip(function () {
40+
return ! Features::canManageTwoFactorAuthentication();
41+
}, 'Two factor authentication is not enabled.');
3742

3843
test('two factor authentication can be disabled', function () {
3944
$this->actingAs($user = User::factory()->create());
@@ -48,4 +53,6 @@
4853
$component->call('disableTwoFactorAuthentication');
4954

5055
expect($user->fresh()->two_factor_secret)->toBeNull();
51-
});
56+
})->skip(function () {
57+
return ! Features::canManageTwoFactorAuthentication();
58+
}, 'Two factor authentication is not enabled.');

stubs/tests/inertia/TwoFactorAuthenticationSettingsTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Models\User;
66
use Illuminate\Foundation\Testing\RefreshDatabase;
7+
use Laravel\Fortify\Features;
78
use Tests\TestCase;
89

910
class TwoFactorAuthenticationSettingsTest extends TestCase
@@ -12,6 +13,10 @@ class TwoFactorAuthenticationSettingsTest extends TestCase
1213

1314
public function test_two_factor_authentication_can_be_enabled()
1415
{
16+
if (! Features::canManageTwoFactorAuthentication()) {
17+
return $this->markTestSkipped('Two factor authentication is not enabled.');
18+
}
19+
1520
$this->actingAs($user = User::factory()->create());
1621

1722
$this->withSession(['auth.password_confirmed_at' => time()]);
@@ -24,6 +29,10 @@ public function test_two_factor_authentication_can_be_enabled()
2429

2530
public function test_recovery_codes_can_be_regenerated()
2631
{
32+
if (! Features::canManageTwoFactorAuthentication()) {
33+
return $this->markTestSkipped('Two factor authentication is not enabled.');
34+
}
35+
2736
$this->actingAs($user = User::factory()->create());
2837

2938
$this->withSession(['auth.password_confirmed_at' => time()]);
@@ -41,6 +50,10 @@ public function test_recovery_codes_can_be_regenerated()
4150

4251
public function test_two_factor_authentication_can_be_disabled()
4352
{
53+
if (! Features::canManageTwoFactorAuthentication()) {
54+
return $this->markTestSkipped('Two factor authentication is not enabled.');
55+
}
56+
4457
$this->actingAs($user = User::factory()->create());
4558

4659
$this->withSession(['auth.password_confirmed_at' => time()]);

stubs/tests/livewire/TwoFactorAuthenticationSettingsTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Models\User;
66
use Illuminate\Foundation\Testing\RefreshDatabase;
7+
use Laravel\Fortify\Features;
78
use Laravel\Jetstream\Http\Livewire\TwoFactorAuthenticationForm;
89
use Livewire\Livewire;
910
use Tests\TestCase;
@@ -14,6 +15,10 @@ class TwoFactorAuthenticationSettingsTest extends TestCase
1415

1516
public function test_two_factor_authentication_can_be_enabled()
1617
{
18+
if (! Features::canManageTwoFactorAuthentication()) {
19+
return $this->markTestSkipped('Two factor authentication is not enabled.');
20+
}
21+
1722
$this->actingAs($user = User::factory()->create());
1823

1924
$this->withSession(['auth.password_confirmed_at' => time()]);
@@ -29,6 +34,10 @@ public function test_two_factor_authentication_can_be_enabled()
2934

3035
public function test_recovery_codes_can_be_regenerated()
3136
{
37+
if (! Features::canManageTwoFactorAuthentication()) {
38+
return $this->markTestSkipped('Two factor authentication is not enabled.');
39+
}
40+
3241
$this->actingAs($user = User::factory()->create());
3342

3443
$this->withSession(['auth.password_confirmed_at' => time()]);
@@ -47,6 +56,10 @@ public function test_recovery_codes_can_be_regenerated()
4756

4857
public function test_two_factor_authentication_can_be_disabled()
4958
{
59+
if (! Features::canManageTwoFactorAuthentication()) {
60+
return $this->markTestSkipped('Two factor authentication is not enabled.');
61+
}
62+
5063
$this->actingAs($user = User::factory()->create());
5164

5265
$this->withSession(['auth.password_confirmed_at' => time()]);

0 commit comments

Comments
 (0)