Files
AFC-Demo/tests/Feature/Auth/PasswordResetTest.php
T

66 lines
1.8 KiB
PHP
Raw Normal View History

2025-10-16 14:22:46 +02:00
<?php
use App\Models\User;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Support\Facades\Notification;
use Livewire\Volt\Volt;
2025-10-16 14:22:58 +02:00
test('reset password link screen can be rendered', function () {
$response = $this->get(route('password.request'));
2025-10-16 14:22:46 +02:00
2025-10-16 14:22:58 +02:00
$response->assertStatus(200);
});
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));
2025-10-16 14:22:46 +02:00
$response->assertStatus(200);
2025-10-16 14:22:58 +02:00
return true;
});
});
2025-10-16 14:22:46 +02:00
2025-10-16 14:22:58 +02:00
test('password can be reset with valid token', function () {
Notification::fake();
2025-10-16 14:22:46 +02:00
2025-10-16 14:22:58 +02:00
$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])
2025-10-16 14:22:46 +02:00
->set('email', $user->email)
2025-10-16 14:22:58 +02:00
->set('password', 'password')
->set('password_confirmation', 'password')
->call('resetPassword');
2025-10-16 14:22:46 +02:00
2025-10-16 14:22:58 +02:00
$response
->assertHasNoErrors()
->assertRedirect(route('login', absolute: false));
2025-10-16 14:22:46 +02:00
2025-10-16 14:22:58 +02:00
return true;
});
});