You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.9 KiB

  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_screen_can_be_rendered(): void
  12. {
  13. $response = $this->get('/forgot-password');
  14. $response->assertStatus(200);
  15. }
  16. public function test_reset_password_link_can_be_requested(): void
  17. {
  18. Notification::fake();
  19. $user = User::factory()->create();
  20. $this->post('/forgot-password', ['email' => $user->email]);
  21. Notification::assertSentTo($user, ResetPassword::class);
  22. }
  23. public function test_reset_password_screen_can_be_rendered(): void
  24. {
  25. Notification::fake();
  26. $user = User::factory()->create();
  27. $this->post('/forgot-password', ['email' => $user->email]);
  28. Notification::assertSentTo($user, ResetPassword::class, function ($notification) {
  29. $response = $this->get('/reset-password/'.$notification->token);
  30. $response->assertStatus(200);
  31. return true;
  32. });
  33. }
  34. public function test_password_can_be_reset_with_valid_token(): void
  35. {
  36. Notification::fake();
  37. $user = User::factory()->create();
  38. $this->post('/forgot-password', ['email' => $user->email]);
  39. Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) {
  40. $response = $this->post('/reset-password', [
  41. 'token' => $notification->token,
  42. 'email' => $user->email,
  43. 'password' => 'password',
  44. 'password_confirmation' => 'password',
  45. ]);
  46. $response
  47. ->assertSessionHasNoErrors()
  48. ->assertRedirect(route('login'));
  49. return true;
  50. });
  51. }
  52. }