refactor: rebase on Livewire 4 starter kit

This commit is contained in:
Benjamin Nussbaum 2026-01-15 21:55:24 +01:00
parent b097b0a7d7
commit e660da46fb
69 changed files with 1967 additions and 942 deletions

View file

@ -13,13 +13,13 @@ test('login screen can be rendered', function (): void {
test('users can authenticate using the login screen', function (): void {
$user = User::factory()->create();
$response = Livewire::test('auth.login')
->set('email', $user->email)
->set('password', 'password')
->call('login');
$response = $this->post(route('login.store'), [
'email' => $user->email,
'password' => 'password',
]);
$response
->assertHasNoErrors()
->assertSessionHasNoErrors()
->assertRedirect(route('dashboard', absolute: false));
$this->assertAuthenticated();

View file

@ -10,9 +10,9 @@ uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
test('email verification screen can be rendered', function (): void {
$user = User::factory()->unverified()->create();
$response = $this->actingAs($user)->get('/verify-email');
$response = $this->actingAs($user)->get(route('verification.notice'));
$response->assertStatus(200);
$response->assertOk();
});
test('email can be verified', function (): void {

View file

@ -7,33 +7,7 @@ uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
test('confirm password screen can be rendered', function (): void {
$user = User::factory()->create();
$response = $this->actingAs($user)->get('/confirm-password');
$response = $this->actingAs($user)->get(route('password.confirm'));
$response->assertStatus(200);
});
test('password can be confirmed', function (): void {
$user = User::factory()->create();
$this->actingAs($user);
$response = Livewire::test('auth.confirm-password')
->set('password', 'password')
->call('confirmPassword');
$response
->assertHasNoErrors()
->assertRedirect(route('dashboard', absolute: false));
});
test('password is not confirmed with invalid password', function (): void {
$user = User::factory()->create();
$this->actingAs($user);
$response = Livewire::test('auth.confirm-password')
->set('password', 'wrong-password')
->call('confirmPassword');
$response->assertHasErrors(['password']);
$response->assertOk();
});

View file

@ -17,9 +17,7 @@ test('reset password link can be requested', function (): void {
$user = User::factory()->create();
Livewire::test('auth.forgot-password')
->set('email', $user->email)
->call('sendPasswordResetLink');
$this->post(route('password.request'), ['email' => $user->email]);
Notification::assertSentTo($user, ResetPassword::class);
});
@ -29,14 +27,12 @@ test('reset password screen can be rendered', function (): void {
$user = User::factory()->create();
Livewire::test('auth.forgot-password')
->set('email', $user->email)
->call('sendPasswordResetLink');
$this->post(route('password.request'), ['email' => $user->email]);
Notification::assertSentTo($user, ResetPassword::class, function ($notification): true {
$response = $this->get('/reset-password/'.$notification->token);
$response = $this->get(route('password.reset', $notification->token));
$response->assertStatus(200);
$response->assertOk();
return true;
});
@ -47,19 +43,18 @@ test('password can be reset with valid token', function (): void {
$user = User::factory()->create();
Livewire::test('auth.forgot-password')
->set('email', $user->email)
->call('sendPasswordResetLink');
$this->post(route('password.request'), ['email' => $user->email]);
Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user): true {
$response = Livewire::test('auth.reset-password', ['token' => $notification->token])
->set('email', $user->email)
->set('password', 'password')
->set('password_confirmation', 'password')
->call('resetPassword');
$response = $this->post(route('password.update'), [
'token' => $notification->token,
'email' => $user->email,
'password' => 'password',
'password_confirmation' => 'password',
]);
$response
->assertHasNoErrors()
->assertSessionHasNoErrors()
->assertRedirect(route('login', absolute: false));
return true;

View file

@ -3,21 +3,20 @@
uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
test('registration screen can be rendered', function (): void {
$response = $this->get('/register');
$response = $this->get(route('register'));
$response->assertStatus(200);
$response->assertOk();
});
test('new users can register', function (): void {
$response = Livewire::test('auth.register')
->set('name', 'Test User')
->set('email', 'test@example.com')
->set('password', 'password')
->set('password_confirmation', 'password')
->call('register');
$response = $this->post(route('register.store'), [
'name' => 'John Doe',
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
]);
$response
->assertHasNoErrors()
$response->assertSessionHasNoErrors()
->assertRedirect(route('dashboard', absolute: false));
$this->assertAuthenticated();

View file

@ -0,0 +1,34 @@
<?php
use App\Models\User;
use Laravel\Fortify\Features;
uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
test('two_factor_challenge_redirects_to_login_when_not_authenticated', function (): void {
if (! Features::canManageTwoFactorAuthentication()) {
$this->markTestSkipped('Two-factor authentication is not enabled.');
}
$response = $this->get(route('two-factor.login'));
$response->assertRedirect(route('login'));
});
test('two_factor_challenge_can_be_rendered', function (): void {
if (! Features::canManageTwoFactorAuthentication()) {
$this->markTestSkipped('Two-factor authentication is not enabled.');
}
Features::twoFactorAuthentication([
'confirm' => true,
'confirmPassword' => true,
]);
$user = User::factory()->withTwoFactor()->create();
$this->post(route('login.store'), [
'email' => $user->email,
'password' => 'password',
])->assertRedirect(route('two-factor.login'));
});