Install Pest
This commit is contained in:
1 parent
81a98dd9f4
commit
e8db0d9a5a
16 files changed
+1618
-805
No files matched your search
@@ -51,4 +51,4 @@ jobs:
|
|||||||
run: npm run build
|
run: npm run build
|
||||||
|
|
||||||
- name: Run Tests
|
- name: Run Tests
|
||||||
run: ./vendor/bin/phpunit
|
run: ./vendor/bin/pest
|
||||||
+2
-1
@@ -23,7 +23,8 @@
|
|||||||
"laravel/sail": "^1.41",
|
"laravel/sail": "^1.41",
|
||||||
"mockery/mockery": "^1.6",
|
"mockery/mockery": "^1.6",
|
||||||
"nunomaduro/collision": "^8.6",
|
"nunomaduro/collision": "^8.6",
|
||||||
"phpunit/phpunit": "^11.5.3"
|
"pestphp/pest": "^4.1",
|
||||||
|
"pestphp/pest-plugin-laravel": "^4.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|||||||
Generated
+1227
-316
File diff suppressed because it is too large.
Load diff
@@ -1,91 +1,77 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature\Auth;
|
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
||||||
use Laravel\Fortify\Features;
|
use Laravel\Fortify\Features;
|
||||||
use Livewire\Volt\Volt as LivewireVolt;
|
use Livewire\Volt\Volt as LivewireVolt;
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class AuthenticationTest extends TestCase
|
test('login screen can be rendered', function () {
|
||||||
{
|
$response = $this->get(route('login'));
|
||||||
use RefreshDatabase;
|
|
||||||
|
|
||||||
public function test_login_screen_can_be_rendered(): void
|
$response->assertStatus(200);
|
||||||
{
|
});
|
||||||
$response = $this->get(route('login'));
|
|
||||||
|
|
||||||
$response->assertStatus(200);
|
test('users can authenticate using the login screen', function () {
|
||||||
|
$user = User::factory()->withoutTwoFactor()->create();
|
||||||
|
|
||||||
|
$response = LivewireVolt::test('auth.login')
|
||||||
|
->set('email', $user->email)
|
||||||
|
->set('password', 'password')
|
||||||
|
->call('login');
|
||||||
|
|
||||||
|
$response
|
||||||
|
->assertHasNoErrors()
|
||||||
|
->assertRedirect(route('dashboard', absolute: false));
|
||||||
|
|
||||||
|
$this->assertAuthenticated();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('users can not authenticate with invalid password', function () {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
$response = LivewireVolt::test('auth.login')
|
||||||
|
->set('email', $user->email)
|
||||||
|
->set('password', 'wrong-password')
|
||||||
|
->call('login');
|
||||||
|
|
||||||
|
$response->assertHasErrors('email');
|
||||||
|
|
||||||
|
$this->assertGuest();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('users with two factor enabled are redirected to two factor challenge', function () {
|
||||||
|
if (! Features::canManageTwoFactorAuthentication()) {
|
||||||
|
$this->markTestSkipped('Two-factor authentication is not enabled.');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_users_can_authenticate_using_the_login_screen(): void
|
Features::twoFactorAuthentication([
|
||||||
{
|
'confirm' => true,
|
||||||
$user = User::factory()->withoutTwoFactor()->create();
|
'confirmPassword' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
$response = LivewireVolt::test('auth.login')
|
$user = User::factory()->create();
|
||||||
->set('email', $user->email)
|
|
||||||
->set('password', 'password')
|
|
||||||
->call('login');
|
|
||||||
|
|
||||||
$response
|
$user->forceFill([
|
||||||
->assertHasNoErrors()
|
'two_factor_secret' => encrypt('test-secret'),
|
||||||
->assertRedirect(route('dashboard', absolute: false));
|
'two_factor_recovery_codes' => encrypt(json_encode(['code1', 'code2'])),
|
||||||
|
'two_factor_confirmed_at' => now(),
|
||||||
|
])->save();
|
||||||
|
|
||||||
$this->assertAuthenticated();
|
$response = LivewireVolt::test('auth.login')
|
||||||
}
|
->set('email', $user->email)
|
||||||
|
->set('password', 'password')
|
||||||
|
->call('login');
|
||||||
|
|
||||||
public function test_users_can_not_authenticate_with_invalid_password(): void
|
$response->assertRedirect(route('two-factor.login'));
|
||||||
{
|
$response->assertSessionHas('login.id', $user->id);
|
||||||
$user = User::factory()->create();
|
$this->assertGuest();
|
||||||
|
});
|
||||||
|
|
||||||
$response = LivewireVolt::test('auth.login')
|
test('users can logout', function () {
|
||||||
->set('email', $user->email)
|
$user = User::factory()->create();
|
||||||
->set('password', 'wrong-password')
|
|
||||||
->call('login');
|
|
||||||
|
|
||||||
$response->assertHasErrors('email');
|
$response = $this->actingAs($user)->post(route('logout'));
|
||||||
|
|
||||||
$this->assertGuest();
|
$response->assertRedirect(route('home'));
|
||||||
}
|
|
||||||
|
|
||||||
public function test_users_with_two_factor_enabled_are_redirected_to_two_factor_challenge(): void
|
$this->assertGuest();
|
||||||
{
|
});
|
||||||
if (! Features::canManageTwoFactorAuthentication()) {
|
|
||||||
$this->markTestSkipped('Two-factor authentication is not enabled.');
|
|
||||||
}
|
|
||||||
|
|
||||||
Features::twoFactorAuthentication([
|
|
||||||
'confirm' => true,
|
|
||||||
'confirmPassword' => true,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$user = User::factory()->create();
|
|
||||||
|
|
||||||
$user->forceFill([
|
|
||||||
'two_factor_secret' => encrypt('test-secret'),
|
|
||||||
'two_factor_recovery_codes' => encrypt(json_encode(['code1', 'code2'])),
|
|
||||||
'two_factor_confirmed_at' => now(),
|
|
||||||
])->save();
|
|
||||||
|
|
||||||
$response = LivewireVolt::test('auth.login')
|
|
||||||
->set('email', $user->email)
|
|
||||||
->set('password', 'password')
|
|
||||||
->call('login');
|
|
||||||
|
|
||||||
$response->assertRedirect(route('two-factor.login'));
|
|
||||||
$response->assertSessionHas('login.id', $user->id);
|
|
||||||
$this->assertGuest();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_users_can_logout(): void
|
|
||||||
{
|
|
||||||
$user = User::factory()->create();
|
|
||||||
|
|
||||||
$response = $this->actingAs($user)->post(route('logout'));
|
|
||||||
|
|
||||||
$response->assertRedirect(route('home'));
|
|
||||||
|
|
||||||
$this->assertGuest();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,80 +1,67 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature\Auth;
|
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Auth\Events\Verified;
|
use Illuminate\Auth\Events\Verified;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
use Illuminate\Support\Facades\URL;
|
use Illuminate\Support\Facades\URL;
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class EmailVerificationTest extends TestCase
|
test('email verification screen can be rendered', function () {
|
||||||
{
|
$user = User::factory()->unverified()->create();
|
||||||
use RefreshDatabase;
|
|
||||||
|
|
||||||
public function test_email_verification_screen_can_be_rendered(): void
|
$response = $this->actingAs($user)->get(route('verification.notice'));
|
||||||
{
|
|
||||||
$user = User::factory()->unverified()->create();
|
|
||||||
|
|
||||||
$response = $this->actingAs($user)->get(route('verification.notice'));
|
$response->assertStatus(200);
|
||||||
|
});
|
||||||
|
|
||||||
$response->assertStatus(200);
|
test('email can be verified', function () {
|
||||||
}
|
$user = User::factory()->unverified()->create();
|
||||||
|
|
||||||
public function test_email_can_be_verified(): void
|
Event::fake();
|
||||||
{
|
|
||||||
$user = User::factory()->unverified()->create();
|
|
||||||
|
|
||||||
Event::fake();
|
$verificationUrl = URL::temporarySignedRoute(
|
||||||
|
'verification.verify',
|
||||||
|
now()->addMinutes(60),
|
||||||
|
['id' => $user->id, 'hash' => sha1($user->email)]
|
||||||
|
);
|
||||||
|
|
||||||
$verificationUrl = URL::temporarySignedRoute(
|
$response = $this->actingAs($user)->get($verificationUrl);
|
||||||
'verification.verify',
|
|
||||||
now()->addMinutes(60),
|
|
||||||
['id' => $user->id, 'hash' => sha1($user->email)]
|
|
||||||
);
|
|
||||||
|
|
||||||
$response = $this->actingAs($user)->get($verificationUrl);
|
Event::assertDispatched(Verified::class);
|
||||||
|
|
||||||
Event::assertDispatched(Verified::class);
|
expect($user->fresh()->hasVerifiedEmail())->toBeTrue();
|
||||||
|
$response->assertRedirect(route('dashboard', absolute: false).'?verified=1');
|
||||||
|
});
|
||||||
|
|
||||||
$this->assertTrue($user->fresh()->hasVerifiedEmail());
|
test('email is not verified with invalid hash', function () {
|
||||||
$response->assertRedirect(route('dashboard', absolute: false).'?verified=1');
|
$user = User::factory()->unverified()->create();
|
||||||
}
|
|
||||||
|
|
||||||
public function test_email_is_not_verified_with_invalid_hash(): void
|
$verificationUrl = URL::temporarySignedRoute(
|
||||||
{
|
'verification.verify',
|
||||||
$user = User::factory()->unverified()->create();
|
now()->addMinutes(60),
|
||||||
|
['id' => $user->id, 'hash' => sha1('wrong-email')]
|
||||||
|
);
|
||||||
|
|
||||||
$verificationUrl = URL::temporarySignedRoute(
|
$this->actingAs($user)->get($verificationUrl);
|
||||||
'verification.verify',
|
|
||||||
now()->addMinutes(60),
|
|
||||||
['id' => $user->id, 'hash' => sha1('wrong-email')]
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->actingAs($user)->get($verificationUrl);
|
expect($user->fresh()->hasVerifiedEmail())->toBeFalse();
|
||||||
|
});
|
||||||
|
|
||||||
$this->assertFalse($user->fresh()->hasVerifiedEmail());
|
test('already verified user visiting verification link is redirected without firing event again', function () {
|
||||||
}
|
$user = User::factory()->create([
|
||||||
|
'email_verified_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
public function test_already_verified_user_visiting_verification_link_is_redirected_without_firing_event_again(): void
|
Event::fake();
|
||||||
{
|
|
||||||
$user = User::factory()->create([
|
|
||||||
'email_verified_at' => now(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
Event::fake();
|
$verificationUrl = URL::temporarySignedRoute(
|
||||||
|
'verification.verify',
|
||||||
|
now()->addMinutes(60),
|
||||||
|
['id' => $user->id, 'hash' => sha1($user->email)]
|
||||||
|
);
|
||||||
|
|
||||||
$verificationUrl = URL::temporarySignedRoute(
|
$this->actingAs($user)->get($verificationUrl)
|
||||||
'verification.verify',
|
->assertRedirect(route('dashboard', absolute: false).'?verified=1');
|
||||||
now()->addMinutes(60),
|
|
||||||
['id' => $user->id, 'hash' => sha1($user->email)]
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->actingAs($user)->get($verificationUrl)
|
expect($user->fresh()->hasVerifiedEmail())->toBeTrue();
|
||||||
->assertRedirect(route('dashboard', absolute: false).'?verified=1');
|
Event::assertNotDispatched(Verified::class);
|
||||||
|
});
|
||||||
$this->assertTrue($user->fresh()->hasVerifiedEmail());
|
|
||||||
Event::assertNotDispatched(Verified::class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature\Auth;
|
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class PasswordConfirmationTest extends TestCase
|
test('confirm password screen can be rendered', function () {
|
||||||
{
|
$user = User::factory()->create();
|
||||||
use RefreshDatabase;
|
|
||||||
|
|
||||||
public function test_confirm_password_screen_can_be_rendered(): void
|
$response = $this->actingAs($user)->get(route('password.confirm'));
|
||||||
{
|
|
||||||
$user = User::factory()->create();
|
|
||||||
|
|
||||||
$response = $this->actingAs($user)->get(route('password.confirm'));
|
$response->assertStatus(200);
|
||||||
|
});
|
||||||
$response->assertStatus(200);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,79 +1,66 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature\Auth;
|
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Auth\Notifications\ResetPassword;
|
use Illuminate\Auth\Notifications\ResetPassword;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
||||||
use Illuminate\Support\Facades\Notification;
|
use Illuminate\Support\Facades\Notification;
|
||||||
use Livewire\Volt\Volt;
|
use Livewire\Volt\Volt;
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class PasswordResetTest extends TestCase
|
test('reset password link screen can be rendered', function () {
|
||||||
{
|
$response = $this->get(route('password.request'));
|
||||||
use RefreshDatabase;
|
|
||||||
|
|
||||||
public function test_reset_password_link_screen_can_be_rendered(): void
|
$response->assertStatus(200);
|
||||||
{
|
});
|
||||||
$response = $this->get(route('password.request'));
|
|
||||||
|
test('reset password link can be requested', function () {
|
||||||
|
Notification::fake();
|
||||||
|
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
Volt::test('auth.forgot-password')
|
||||||
|
->set('email', $user->email)
|
||||||
|
->call('sendPasswordResetLink');
|
||||||
|
|
||||||
|
Notification::assertSentTo($user, ResetPassword::class);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('reset password screen can be rendered', function () {
|
||||||
|
Notification::fake();
|
||||||
|
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
Volt::test('auth.forgot-password')
|
||||||
|
->set('email', $user->email)
|
||||||
|
->call('sendPasswordResetLink');
|
||||||
|
|
||||||
|
Notification::assertSentTo($user, ResetPassword::class, function ($notification) {
|
||||||
|
$response = $this->get(route('password.reset', $notification->token));
|
||||||
|
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
}
|
|
||||||
|
|
||||||
public function test_reset_password_link_can_be_requested(): void
|
return true;
|
||||||
{
|
});
|
||||||
Notification::fake();
|
});
|
||||||
|
|
||||||
$user = User::factory()->create();
|
test('password can be reset with valid token', function () {
|
||||||
|
Notification::fake();
|
||||||
|
|
||||||
Volt::test('auth.forgot-password')
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
Volt::test('auth.forgot-password')
|
||||||
|
->set('email', $user->email)
|
||||||
|
->call('sendPasswordResetLink');
|
||||||
|
|
||||||
|
Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) {
|
||||||
|
$response = Volt::test('auth.reset-password', ['token' => $notification->token])
|
||||||
->set('email', $user->email)
|
->set('email', $user->email)
|
||||||
->call('sendPasswordResetLink');
|
->set('password', 'password')
|
||||||
|
->set('password_confirmation', 'password')
|
||||||
|
->call('resetPassword');
|
||||||
|
|
||||||
Notification::assertSentTo($user, ResetPassword::class);
|
$response
|
||||||
}
|
->assertHasNoErrors()
|
||||||
|
->assertRedirect(route('login', absolute: false));
|
||||||
|
|
||||||
public function test_reset_password_screen_can_be_rendered(): void
|
return true;
|
||||||
{
|
});
|
||||||
Notification::fake();
|
});
|
||||||
|
|
||||||
$user = User::factory()->create();
|
|
||||||
|
|
||||||
Volt::test('auth.forgot-password')
|
|
||||||
->set('email', $user->email)
|
|
||||||
->call('sendPasswordResetLink');
|
|
||||||
|
|
||||||
Notification::assertSentTo($user, ResetPassword::class, function ($notification) {
|
|
||||||
$response = $this->get(route('password.reset', $notification->token));
|
|
||||||
|
|
||||||
$response->assertStatus(200);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_password_can_be_reset_with_valid_token(): void
|
|
||||||
{
|
|
||||||
Notification::fake();
|
|
||||||
|
|
||||||
$user = User::factory()->create();
|
|
||||||
|
|
||||||
Volt::test('auth.forgot-password')
|
|
||||||
->set('email', $user->email)
|
|
||||||
->call('sendPasswordResetLink');
|
|
||||||
|
|
||||||
Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) {
|
|
||||||
$response = Volt::test('auth.reset-password', ['token' => $notification->token])
|
|
||||||
->set('email', $user->email)
|
|
||||||
->set('password', 'password')
|
|
||||||
->set('password_confirmation', 'password')
|
|
||||||
->call('resetPassword');
|
|
||||||
|
|
||||||
$response
|
|
||||||
->assertHasNoErrors()
|
|
||||||
->assertRedirect(route('login', absolute: false));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +1,24 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature\Auth;
|
|
||||||
|
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
||||||
use Livewire\Volt\Volt;
|
use Livewire\Volt\Volt;
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class RegistrationTest extends TestCase
|
test('registration screen can be rendered', function () {
|
||||||
{
|
$response = $this->get(route('register'));
|
||||||
use RefreshDatabase;
|
|
||||||
|
|
||||||
public function test_registration_screen_can_be_rendered(): void
|
$response->assertStatus(200);
|
||||||
{
|
});
|
||||||
$response = $this->get(route('register'));
|
|
||||||
|
|
||||||
$response->assertStatus(200);
|
test('new users can register', function () {
|
||||||
}
|
$response = Volt::test('auth.register')
|
||||||
|
->set('name', 'Test User')
|
||||||
|
->set('email', 'test@example.com')
|
||||||
|
->set('password', 'password')
|
||||||
|
->set('password_confirmation', 'password')
|
||||||
|
->call('register');
|
||||||
|
|
||||||
public function test_new_users_can_register(): void
|
$response
|
||||||
{
|
->assertHasNoErrors()
|
||||||
$response = Volt::test('auth.register')
|
->assertRedirect(route('dashboard', absolute: false));
|
||||||
->set('name', 'Test User')
|
|
||||||
->set('email', 'test@example.com')
|
|
||||||
->set('password', 'password')
|
|
||||||
->set('password_confirmation', 'password')
|
|
||||||
->call('register');
|
|
||||||
|
|
||||||
$response
|
$this->assertAuthenticated();
|
||||||
->assertHasNoErrors()
|
});
|
||||||
->assertRedirect(route('dashboard', absolute: false));
|
|
||||||
|
|
||||||
$this->assertAuthenticated();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,52 +1,41 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature\Auth;
|
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
||||||
use Laravel\Fortify\Features;
|
use Laravel\Fortify\Features;
|
||||||
use Livewire\Volt\Volt;
|
use Livewire\Volt\Volt;
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class TwoFactorChallengeTest extends TestCase
|
test('two factor challenge redirects to login when not authenticated', function () {
|
||||||
{
|
if (! Features::canManageTwoFactorAuthentication()) {
|
||||||
use RefreshDatabase;
|
$this->markTestSkipped('Two-factor authentication is not enabled.');
|
||||||
|
|
||||||
public function test_two_factor_challenge_redirects_to_login_when_not_authenticated(): void
|
|
||||||
{
|
|
||||||
if (! Features::canManageTwoFactorAuthentication()) {
|
|
||||||
$this->markTestSkipped('Two-factor authentication is not enabled.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$response = $this->get(route('two-factor.login'));
|
|
||||||
|
|
||||||
$response->assertRedirect(route('login'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_two_factor_challenge_can_be_rendered(): void
|
$response = $this->get(route('two-factor.login'));
|
||||||
{
|
|
||||||
if (! Features::canManageTwoFactorAuthentication()) {
|
|
||||||
$this->markTestSkipped('Two-factor authentication is not enabled.');
|
|
||||||
}
|
|
||||||
|
|
||||||
Features::twoFactorAuthentication([
|
$response->assertRedirect(route('login'));
|
||||||
'confirm' => true,
|
});
|
||||||
'confirmPassword' => true,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$user = User::factory()->create();
|
test('two factor challenge can be rendered', function () {
|
||||||
|
if (! Features::canManageTwoFactorAuthentication()) {
|
||||||
$user->forceFill([
|
$this->markTestSkipped('Two-factor authentication is not enabled.');
|
||||||
'two_factor_secret' => encrypt('test-secret'),
|
|
||||||
'two_factor_recovery_codes' => encrypt(json_encode(['code1', 'code2'])),
|
|
||||||
'two_factor_confirmed_at' => now(),
|
|
||||||
])->save();
|
|
||||||
|
|
||||||
Volt::test('auth.login')
|
|
||||||
->set('email', $user->email)
|
|
||||||
->set('password', 'password')
|
|
||||||
->call('login')
|
|
||||||
->assertRedirect(route('two-factor.login'))
|
|
||||||
->assertOk();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
Features::twoFactorAuthentication([
|
||||||
|
'confirm' => true,
|
||||||
|
'confirmPassword' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
$user->forceFill([
|
||||||
|
'two_factor_secret' => encrypt('test-secret'),
|
||||||
|
'two_factor_recovery_codes' => encrypt(json_encode(['code1', 'code2'])),
|
||||||
|
'two_factor_confirmed_at' => now(),
|
||||||
|
])->save();
|
||||||
|
|
||||||
|
Volt::test('auth.login')
|
||||||
|
->set('email', $user->email)
|
||||||
|
->set('password', 'password')
|
||||||
|
->call('login')
|
||||||
|
->assertRedirect(route('two-factor.login'))
|
||||||
|
->assertOk();
|
||||||
|
});
|
||||||
@@ -1,27 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature;
|
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class DashboardTest extends TestCase
|
test('guests are redirected to the login page', function () {
|
||||||
{
|
$response = $this->get(route('dashboard'));
|
||||||
use RefreshDatabase;
|
$response->assertRedirect(route('login'));
|
||||||
|
});
|
||||||
|
|
||||||
public function test_guests_are_redirected_to_the_login_page(): void
|
test('authenticated users can visit the dashboard', function () {
|
||||||
{
|
$user = User::factory()->create();
|
||||||
$response = $this->get(route('dashboard'));
|
$this->actingAs($user);
|
||||||
$response->assertRedirect(route('login'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_authenticated_users_can_visit_the_dashboard(): void
|
$response = $this->get(route('dashboard'));
|
||||||
{
|
$response->assertStatus(200);
|
||||||
$user = User::factory()->create();
|
});
|
||||||
$this->actingAs($user);
|
|
||||||
|
|
||||||
$response = $this->get(route('dashboard'));
|
|
||||||
$response->assertStatus(200);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature;
|
test('returns a successful response', function () {
|
||||||
|
$response = $this->get(route('home'));
|
||||||
|
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
$response->assertStatus(200);
|
||||||
use Tests\TestCase;
|
});
|
||||||
|
|
||||||
class ExampleTest extends TestCase
|
|
||||||
{
|
|
||||||
use RefreshDatabase;
|
|
||||||
|
|
||||||
public function test_returns_a_successful_response(): void
|
|
||||||
{
|
|
||||||
$response = $this->get(route('home'));
|
|
||||||
|
|
||||||
$response->assertStatus(200);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,50 +1,39 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature\Settings;
|
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
use Livewire\Volt\Volt;
|
use Livewire\Volt\Volt;
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class PasswordUpdateTest extends TestCase
|
test('password can be updated', function () {
|
||||||
{
|
$user = User::factory()->create([
|
||||||
use RefreshDatabase;
|
'password' => Hash::make('password'),
|
||||||
|
]);
|
||||||
|
|
||||||
public function test_password_can_be_updated(): void
|
$this->actingAs($user);
|
||||||
{
|
|
||||||
$user = User::factory()->create([
|
|
||||||
'password' => Hash::make('password'),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->actingAs($user);
|
$response = Volt::test('settings.password')
|
||||||
|
->set('current_password', 'password')
|
||||||
|
->set('password', 'new-password')
|
||||||
|
->set('password_confirmation', 'new-password')
|
||||||
|
->call('updatePassword');
|
||||||
|
|
||||||
$response = Volt::test('settings.password')
|
$response->assertHasNoErrors();
|
||||||
->set('current_password', 'password')
|
|
||||||
->set('password', 'new-password')
|
|
||||||
->set('password_confirmation', 'new-password')
|
|
||||||
->call('updatePassword');
|
|
||||||
|
|
||||||
$response->assertHasNoErrors();
|
expect(Hash::check('new-password', $user->refresh()->password))->toBeTrue();
|
||||||
|
});
|
||||||
|
|
||||||
$this->assertTrue(Hash::check('new-password', $user->refresh()->password));
|
test('correct password must be provided to update password', function () {
|
||||||
}
|
$user = User::factory()->create([
|
||||||
|
'password' => Hash::make('password'),
|
||||||
|
]);
|
||||||
|
|
||||||
public function test_correct_password_must_be_provided_to_update_password(): void
|
$this->actingAs($user);
|
||||||
{
|
|
||||||
$user = User::factory()->create([
|
|
||||||
'password' => Hash::make('password'),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->actingAs($user);
|
$response = Volt::test('settings.password')
|
||||||
|
->set('current_password', 'wrong-password')
|
||||||
|
->set('password', 'new-password')
|
||||||
|
->set('password_confirmation', 'new-password')
|
||||||
|
->call('updatePassword');
|
||||||
|
|
||||||
$response = Volt::test('settings.password')
|
$response->assertHasErrors(['current_password']);
|
||||||
->set('current_password', 'wrong-password')
|
});
|
||||||
->set('password', 'new-password')
|
|
||||||
->set('password_confirmation', 'new-password')
|
|
||||||
->call('updatePassword');
|
|
||||||
|
|
||||||
$response->assertHasErrors(['current_password']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,89 +1,75 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature\Settings;
|
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
||||||
use Livewire\Volt\Volt;
|
use Livewire\Volt\Volt;
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class ProfileUpdateTest extends TestCase
|
test('profile page is displayed', function () {
|
||||||
{
|
$this->actingAs($user = User::factory()->create());
|
||||||
use RefreshDatabase;
|
|
||||||
|
|
||||||
public function test_profile_page_is_displayed(): void
|
$this->get(route('profile.edit'))->assertOk();
|
||||||
{
|
});
|
||||||
$this->actingAs($user = User::factory()->create());
|
|
||||||
|
|
||||||
$this->get(route('profile.edit'))->assertOk();
|
test('profile information can be updated', function () {
|
||||||
}
|
$user = User::factory()->create();
|
||||||
|
|
||||||
public function test_profile_information_can_be_updated(): void
|
$this->actingAs($user);
|
||||||
{
|
|
||||||
$user = User::factory()->create();
|
|
||||||
|
|
||||||
$this->actingAs($user);
|
$response = Volt::test('settings.profile')
|
||||||
|
->set('name', 'Test User')
|
||||||
|
->set('email', 'test@example.com')
|
||||||
|
->call('updateProfileInformation');
|
||||||
|
|
||||||
$response = Volt::test('settings.profile')
|
$response->assertHasNoErrors();
|
||||||
->set('name', 'Test User')
|
|
||||||
->set('email', 'test@example.com')
|
|
||||||
->call('updateProfileInformation');
|
|
||||||
|
|
||||||
$response->assertHasNoErrors();
|
$user->refresh();
|
||||||
|
|
||||||
$user->refresh();
|
expect($user->name)->toEqual('Test User');
|
||||||
|
expect($user->email)->toEqual('test@example.com');
|
||||||
|
expect($user->email_verified_at)->toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
$this->assertEquals('Test User', $user->name);
|
test('email verification status is unchanged when email address is unchanged', function () {
|
||||||
$this->assertEquals('test@example.com', $user->email);
|
$user = User::factory()->create();
|
||||||
$this->assertNull($user->email_verified_at);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_email_verification_status_is_unchanged_when_email_address_is_unchanged(): void
|
$this->actingAs($user);
|
||||||
{
|
|
||||||
$user = User::factory()->create();
|
|
||||||
|
|
||||||
$this->actingAs($user);
|
$response = Volt::test('settings.profile')
|
||||||
|
->set('name', 'Test User')
|
||||||
|
->set('email', $user->email)
|
||||||
|
->call('updateProfileInformation');
|
||||||
|
|
||||||
$response = Volt::test('settings.profile')
|
$response->assertHasNoErrors();
|
||||||
->set('name', 'Test User')
|
|
||||||
->set('email', $user->email)
|
|
||||||
->call('updateProfileInformation');
|
|
||||||
|
|
||||||
$response->assertHasNoErrors();
|
expect($user->refresh()->email_verified_at)->not->toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
$this->assertNotNull($user->refresh()->email_verified_at);
|
test('user can delete their account', function () {
|
||||||
}
|
$user = User::factory()->create();
|
||||||
|
|
||||||
public function test_user_can_delete_their_account(): void
|
$this->actingAs($user);
|
||||||
{
|
|
||||||
$user = User::factory()->create();
|
|
||||||
|
|
||||||
$this->actingAs($user);
|
$response = Volt::test('settings.delete-user-form')
|
||||||
|
->set('password', 'password')
|
||||||
|
->call('deleteUser');
|
||||||
|
|
||||||
$response = Volt::test('settings.delete-user-form')
|
$response
|
||||||
->set('password', 'password')
|
->assertHasNoErrors()
|
||||||
->call('deleteUser');
|
->assertRedirect('/');
|
||||||
|
|
||||||
$response
|
expect($user->fresh())->toBeNull();
|
||||||
->assertHasNoErrors()
|
expect(auth()->check())->toBeFalse();
|
||||||
->assertRedirect('/');
|
});
|
||||||
|
|
||||||
$this->assertNull($user->fresh());
|
test('correct password must be provided to delete account', function () {
|
||||||
$this->assertFalse(auth()->check());
|
$user = User::factory()->create();
|
||||||
}
|
|
||||||
|
|
||||||
public function test_correct_password_must_be_provided_to_delete_account(): void
|
$this->actingAs($user);
|
||||||
{
|
|
||||||
$user = User::factory()->create();
|
|
||||||
|
|
||||||
$this->actingAs($user);
|
$response = Volt::test('settings.delete-user-form')
|
||||||
|
->set('password', 'wrong-password')
|
||||||
|
->call('deleteUser');
|
||||||
|
|
||||||
$response = Volt::test('settings.delete-user-form')
|
$response->assertHasErrors(['password']);
|
||||||
->set('password', 'wrong-password')
|
|
||||||
->call('deleteUser');
|
|
||||||
|
|
||||||
$response->assertHasErrors(['password']);
|
expect($user->fresh())->not->toBeNull();
|
||||||
|
});
|
||||||
$this->assertNotNull($user->fresh());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,86 +1,70 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Feature\Settings;
|
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
||||||
use Laravel\Fortify\Features;
|
use Laravel\Fortify\Features;
|
||||||
use Livewire\Volt\Volt;
|
use Livewire\Volt\Volt;
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class TwoFactorAuthenticationTest extends TestCase
|
beforeEach(function () {
|
||||||
{
|
if (! Features::canManageTwoFactorAuthentication()) {
|
||||||
use RefreshDatabase;
|
$this->markTestSkipped('Two-factor authentication is not enabled.');
|
||||||
|
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
|
|
||||||
if (! Features::canManageTwoFactorAuthentication()) {
|
|
||||||
$this->markTestSkipped('Two-factor authentication is not enabled.');
|
|
||||||
}
|
|
||||||
|
|
||||||
Features::twoFactorAuthentication([
|
|
||||||
'confirm' => true,
|
|
||||||
'confirmPassword' => true,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_two_factor_settings_page_can_be_rendered(): void
|
Features::twoFactorAuthentication([
|
||||||
{
|
'confirm' => true,
|
||||||
$user = User::factory()->withoutTwoFactor()->create();
|
'confirmPassword' => true,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
$this->actingAs($user)
|
test('two factor settings page can be rendered', function () {
|
||||||
->withSession(['auth.password_confirmed_at' => time()])
|
$user = User::factory()->withoutTwoFactor()->create();
|
||||||
->get(route('two-factor.show'))
|
|
||||||
->assertOk()
|
|
||||||
->assertSee('Two Factor Authentication')
|
|
||||||
->assertSee('Disabled');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_two_factor_settings_page_requires_password_confirmation_when_enabled(): void
|
$this->actingAs($user)
|
||||||
{
|
->withSession(['auth.password_confirmed_at' => time()])
|
||||||
$user = User::factory()->create();
|
->get(route('two-factor.show'))
|
||||||
|
->assertOk()
|
||||||
|
->assertSee('Two Factor Authentication')
|
||||||
|
->assertSee('Disabled');
|
||||||
|
});
|
||||||
|
|
||||||
$response = $this->actingAs($user)
|
test('two factor settings page requires password confirmation when enabled', function () {
|
||||||
->get(route('two-factor.show'));
|
$user = User::factory()->create();
|
||||||
|
|
||||||
$response->assertRedirect(route('password.confirm'));
|
$response = $this->actingAs($user)
|
||||||
}
|
->get(route('two-factor.show'));
|
||||||
|
|
||||||
public function test_two_factor_settings_page_returns_forbidden_response_when_two_factor_is_disabled(): void
|
$response->assertRedirect(route('password.confirm'));
|
||||||
{
|
});
|
||||||
config(['fortify.features' => []]);
|
|
||||||
|
|
||||||
$user = User::factory()->create();
|
test('two factor settings page returns forbidden response when two factor is disabled', function () {
|
||||||
|
config(['fortify.features' => []]);
|
||||||
|
|
||||||
$response = $this->actingAs($user)
|
$user = User::factory()->create();
|
||||||
->withSession(['auth.password_confirmed_at' => time()])
|
|
||||||
->get(route('two-factor.show'));
|
|
||||||
|
|
||||||
$response->assertForbidden();
|
$response = $this->actingAs($user)
|
||||||
}
|
->withSession(['auth.password_confirmed_at' => time()])
|
||||||
|
->get(route('two-factor.show'));
|
||||||
|
|
||||||
public function test_two_factor_authentication_disabled_when_confirmation_abandoned_between_requests(): void
|
$response->assertForbidden();
|
||||||
{
|
});
|
||||||
$user = User::factory()->create();
|
|
||||||
|
|
||||||
$user->forceFill([
|
test('two factor authentication disabled when confirmation abandoned between requests', function () {
|
||||||
'two_factor_secret' => encrypt('test-secret'),
|
$user = User::factory()->create();
|
||||||
'two_factor_recovery_codes' => encrypt(json_encode(['code1', 'code2'])),
|
|
||||||
'two_factor_confirmed_at' => null,
|
|
||||||
])->save();
|
|
||||||
|
|
||||||
$this->actingAs($user);
|
$user->forceFill([
|
||||||
|
'two_factor_secret' => encrypt('test-secret'),
|
||||||
|
'two_factor_recovery_codes' => encrypt(json_encode(['code1', 'code2'])),
|
||||||
|
'two_factor_confirmed_at' => null,
|
||||||
|
])->save();
|
||||||
|
|
||||||
$component = Volt::test('settings.two-factor');
|
$this->actingAs($user);
|
||||||
|
|
||||||
$component->assertSet('twoFactorEnabled', false);
|
$component = Volt::test('settings.two-factor');
|
||||||
|
|
||||||
$this->assertDatabaseHas('users', [
|
$component->assertSet('twoFactorEnabled', false);
|
||||||
'id' => $user->id,
|
|
||||||
'two_factor_secret' => null,
|
$this->assertDatabaseHas('users', [
|
||||||
'two_factor_recovery_codes' => null,
|
'id' => $user->id,
|
||||||
]);
|
'two_factor_secret' => null,
|
||||||
}
|
'two_factor_recovery_codes' => null,
|
||||||
}
|
]);
|
||||||
|
});
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Test Case
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The closure you provide to your test functions is always bound to a specific PHPUnit test
|
||||||
|
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
|
||||||
|
| need to change it using the "pest()" function to bind a different classes or traits.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
pest()->extend(Tests\TestCase::class)
|
||||||
|
->use(Illuminate\Foundation\Testing\RefreshDatabase::class)
|
||||||
|
->in('Feature');
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Expectations
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| When you're writing tests, you often need to check that values meet certain conditions. The
|
||||||
|
| "expect()" function gives you access to a set of "expectations" methods that you can use
|
||||||
|
| to assert different things. Of course, you may extend the Expectation API at any time.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
expect()->extend('toBeOne', function () {
|
||||||
|
return $this->toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Functions
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
|
||||||
|
| project that you don't want to repeat in every file. Here you can also expose helpers as
|
||||||
|
| global functions to help you to reduce the number of lines of code in your test files.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
function something()
|
||||||
|
{
|
||||||
|
// ..
|
||||||
|
}
|
||||||
@@ -1,16 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Unit;
|
test('that true is true', function () {
|
||||||
|
expect(true)->toBeTrue();
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
});
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class ExampleTest extends TestCase
|
|
||||||
{
|
|
||||||
use RefreshDatabase;
|
|
||||||
|
|
||||||
public function test_that_true_is_true(): void
|
|
||||||
{
|
|
||||||
$this->assertTrue(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user