Mercurial > packages > auth
comparison stubs/default/tests/Feature/Auth/PasswordResetTest.php @ 0:90e38de8f2ba
Initial Commit
| author | luka |
|---|---|
| date | Wed, 13 Aug 2025 22:17:20 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:90e38de8f2ba |
|---|---|
| 1 <?php | |
| 2 | |
| 3 namespace Tests\Feature\Auth; | |
| 4 | |
| 5 use App\Models\User; | |
| 6 use Illuminate\Auth\Notifications\ResetPassword; | |
| 7 use Illuminate\Foundation\Testing\RefreshDatabase; | |
| 8 use Illuminate\Support\Facades\Notification; | |
| 9 use Tests\TestCase; | |
| 10 | |
| 11 class PasswordResetTest extends TestCase | |
| 12 { | |
| 13 use RefreshDatabase; | |
| 14 | |
| 15 public function test_reset_password_link_screen_can_be_rendered(): void | |
| 16 { | |
| 17 $response = $this->get('/forgot-password'); | |
| 18 | |
| 19 $response->assertStatus(200); | |
| 20 } | |
| 21 | |
| 22 public function test_reset_password_link_can_be_requested(): void | |
| 23 { | |
| 24 Notification::fake(); | |
| 25 | |
| 26 $user = User::factory()->create(); | |
| 27 | |
| 28 $this->post('/forgot-password', ['email' => $user->email]); | |
| 29 | |
| 30 Notification::assertSentTo($user, ResetPassword::class); | |
| 31 } | |
| 32 | |
| 33 public function test_reset_password_screen_can_be_rendered(): void | |
| 34 { | |
| 35 Notification::fake(); | |
| 36 | |
| 37 $user = User::factory()->create(); | |
| 38 | |
| 39 $this->post('/forgot-password', ['email' => $user->email]); | |
| 40 | |
| 41 Notification::assertSentTo($user, ResetPassword::class, function ($notification) { | |
| 42 $response = $this->get('/reset-password/'.$notification->token); | |
| 43 | |
| 44 $response->assertStatus(200); | |
| 45 | |
| 46 return true; | |
| 47 }); | |
| 48 } | |
| 49 | |
| 50 public function test_password_can_be_reset_with_valid_token(): void | |
| 51 { | |
| 52 Notification::fake(); | |
| 53 | |
| 54 $user = User::factory()->create(); | |
| 55 | |
| 56 $this->post('/forgot-password', ['email' => $user->email]); | |
| 57 | |
| 58 Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) { | |
| 59 $response = $this->post('/reset-password', [ | |
| 60 'token' => $notification->token, | |
| 61 'email' => $user->email, | |
| 62 'password' => 'password', | |
| 63 'password_confirmation' => 'password', | |
| 64 ]); | |
| 65 | |
| 66 $response | |
| 67 ->assertSessionHasNoErrors() | |
| 68 ->assertRedirect(route('login')); | |
| 69 | |
| 70 return true; | |
| 71 }); | |
| 72 } | |
| 73 } |
