Files
Benjamin NussbaumandCursor f2ff4ad111 starter-kit-upgrade: Browser tests & Fortify skip guards
Upstream: laravel/livewire-starter-kit@0ca77fa
Adds skipUnlessFortifyHas on TestCase and Fortify-aware skips/assertions in auth tests.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-26 18:07:58 +02:00

68 lines
1.9 KiB
PHP

<?php
use App\Models\User;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Support\Facades\Notification;
use Laravel\Fortify\Features;
uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
beforeEach(function (): void {
$this->skipUnlessFortifyHas(Features::resetPasswords());
});
test('reset password link screen can be rendered', function (): void {
$response = $this->get(route('password.request'));
$response->assertOk();
});
test('reset password link can be requested', function (): void {
Notification::fake();
$user = User::factory()->create();
$this->post(route('password.request'), ['email' => $user->email]);
Notification::assertSentTo($user, ResetPassword::class);
});
test('reset password screen can be rendered', function (): void {
Notification::fake();
$user = User::factory()->create();
$this->post(route('password.request'), ['email' => $user->email]);
Notification::assertSentTo($user, ResetPassword::class, function ($notification): true {
$response = $this->get(route('password.reset', $notification->token));
$response->assertOk();
return true;
});
});
test('password can be reset with valid token', function (): void {
Notification::fake();
$user = User::factory()->create();
$this->post(route('password.request'), ['email' => $user->email]);
Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user): true {
$response = $this->post(route('password.update'), [
'token' => $notification->token,
'email' => $user->email,
'password' => 'password',
'password_confirmation' => 'password',
]);
$response
->assertSessionHasNoErrors()
->assertRedirect(route('login', absolute: false));
return true;
});
});