PasswordResetTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace Tests\Feature\Auth;
  3. use App\Models\User;
  4. use Illuminate\Auth\Notifications\ResetPassword;
  5. use Illuminate\Foundation\Testing\RefreshDatabase;
  6. use Illuminate\Support\Facades\Notification;
  7. use Tests\TestCase;
  8. class PasswordResetTest extends TestCase
  9. {
  10. use RefreshDatabase;
  11. public function test_reset_password_link_can_be_requested(): void
  12. {
  13. Notification::fake();
  14. $user = User::factory()->create();
  15. $this->post('/forgot-password', ['email' => $user->email]);
  16. Notification::assertSentTo($user, ResetPassword::class);
  17. }
  18. public function test_password_can_be_reset_with_valid_token(): void
  19. {
  20. Notification::fake();
  21. $user = User::factory()->create();
  22. $this->post('/forgot-password', ['email' => $user->email]);
  23. Notification::assertSentTo($user, ResetPassword::class, function (object $notification) use ($user) {
  24. $response = $this->post('/reset-password', [
  25. 'token' => $notification->token,
  26. 'email' => $user->email,
  27. 'password' => 'password',
  28. 'password_confirmation' => 'password',
  29. ]);
  30. $response
  31. ->assertSessionHasNoErrors()
  32. ->assertStatus(200);
  33. return true;
  34. });
  35. }
  36. }