byos_laravel/tests/Feature/Auth/PasswordResetTest.php
2026-01-15 23:34:58 +01:00

67 lines
1.9 KiB
PHP

<?php
use App\Models\User;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Support\Facades\Notification;
uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
test('reset password link screen can be rendered', function (): void {
$response = $this->get('/forgot-password');
$response->assertStatus(200);
});
test('reset password link can be requested', function (): void {
Notification::fake();
$user = User::factory()->create();
Livewire::test('auth.forgot-password')
->set('email', $user->email)
->call('sendPasswordResetLink');
Notification::assertSentTo($user, ResetPassword::class);
});
test('reset password screen can be rendered', function (): void {
Notification::fake();
$user = User::factory()->create();
Livewire::test('auth.forgot-password')
->set('email', $user->email)
->call('sendPasswordResetLink');
Notification::assertSentTo($user, ResetPassword::class, function ($notification): true {
$response = $this->get('/reset-password/'.$notification->token);
$response->assertStatus(200);
return true;
});
});
test('password can be reset with valid token', function (): void {
Notification::fake();
$user = User::factory()->create();
Livewire::test('auth.forgot-password')
->set('email', $user->email)
->call('sendPasswordResetLink');
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
->assertHasNoErrors()
->assertRedirect(route('login', absolute: false));
return true;
});
});