init
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (8.3) (push) Has been cancelled
tests / ci (8.4) (push) Has been cancelled
tests / ci (8.5) (push) Has been cancelled

This commit is contained in:
Ovidiu U
2026-04-03 16:47:05 +01:00
parent 8cf504ec3c
commit c94c4f7beb
117 changed files with 16703 additions and 0 deletions

View File

@@ -0,0 +1,75 @@
<?php
use App\Models\User;
use Livewire\Livewire;
test('profile page is displayed', function () {
$this->actingAs($user = User::factory()->create());
$this->get(route('profile.edit'))->assertOk();
});
test('profile information can be updated', function () {
$user = User::factory()->create();
$this->actingAs($user);
$response = Livewire::test('pages::settings.profile')
->set('name', 'Test User')
->set('email', 'test@example.com')
->call('updateProfileInformation');
$response->assertHasNoErrors();
$user->refresh();
expect($user->name)->toEqual('Test User');
expect($user->email)->toEqual('test@example.com');
expect($user->email_verified_at)->toBeNull();
});
test('email verification status is unchanged when email address is unchanged', function () {
$user = User::factory()->create();
$this->actingAs($user);
$response = Livewire::test('pages::settings.profile')
->set('name', 'Test User')
->set('email', $user->email)
->call('updateProfileInformation');
$response->assertHasNoErrors();
expect($user->refresh()->email_verified_at)->not->toBeNull();
});
test('user can delete their account', function () {
$user = User::factory()->create();
$this->actingAs($user);
$response = Livewire::test('pages::settings.delete-user-modal')
->set('password', 'password')
->call('deleteUser');
$response
->assertHasNoErrors()
->assertRedirect('/');
expect($user->fresh())->toBeNull();
expect(auth()->check())->toBeFalse();
});
test('correct password must be provided to delete account', function () {
$user = User::factory()->create();
$this->actingAs($user);
$response = Livewire::test('pages::settings.delete-user-modal')
->set('password', 'wrong-password')
->call('deleteUser');
$response->assertHasErrors(['password']);
expect($user->fresh())->not->toBeNull();
});

View File

@@ -0,0 +1,104 @@
<?php
use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Laravel\Fortify\Features;
use Livewire\Livewire;
beforeEach(function () {
$this->skipUnlessFortifyHas(Features::twoFactorAuthentication());
Features::twoFactorAuthentication([
'confirm' => true,
'confirmPassword' => true,
]);
});
test('security settings page can be rendered', function () {
$user = User::factory()->create();
$this->actingAs($user)
->withSession(['auth.password_confirmed_at' => time()])
->get(route('security.edit'))
->assertOk()
->assertSee('Two-factor authentication')
->assertSee('Enable 2FA');
});
test('security settings page requires password confirmation when enabled', function () {
$user = User::factory()->create();
$response = $this->actingAs($user)
->get(route('security.edit'));
$response->assertRedirect(route('password.confirm'));
});
test('security settings page renders without two factor when feature is disabled', function () {
config(['fortify.features' => []]);
$user = User::factory()->create();
$this->actingAs($user)
->withSession(['auth.password_confirmed_at' => time()])
->get(route('security.edit'))
->assertOk()
->assertSee('Update password')
->assertDontSee('Two-factor authentication');
});
test('two factor authentication disabled when confirmation abandoned between requests', function () {
$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' => null,
])->save();
$this->actingAs($user);
$component = Livewire::test('pages::settings.security');
$component->assertSet('twoFactorEnabled', false);
$this->assertDatabaseHas('users', [
'id' => $user->id,
'two_factor_secret' => null,
'two_factor_recovery_codes' => null,
]);
});
test('password can be updated', function () {
$user = User::factory()->create([
'password' => Hash::make('password'),
]);
$this->actingAs($user);
$response = Livewire::test('pages::settings.security')
->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();
});
test('correct password must be provided to update password', function () {
$user = User::factory()->create([
'password' => Hash::make('password'),
]);
$this->actingAs($user);
$response = Livewire::test('pages::settings.security')
->set('current_password', 'wrong-password')
->set('password', 'new-password')
->set('password_confirmation', 'new-password')
->call('updatePassword');
$response->assertHasErrors(['current_password']);
});