PasswordResetTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 Livewire\Volt\Volt;
  8. use Tests\TestCase;
  9. class PasswordResetTest extends TestCase
  10. {
  11. use RefreshDatabase;
  12. public function test_reset_password_link_screen_can_be_rendered(): void
  13. {
  14. $response = $this->get('/forgot-password');
  15. $response
  16. ->assertSeeVolt('pages.auth.forgot-password')
  17. ->assertStatus(200);
  18. }
  19. public function test_reset_password_link_can_be_requested(): void
  20. {
  21. Notification::fake();
  22. $user = User::factory()->create();
  23. Volt::test('pages.auth.forgot-password')
  24. ->set('email', $user->email)
  25. ->call('sendPasswordResetLink');
  26. Notification::assertSentTo($user, ResetPassword::class);
  27. }
  28. public function test_reset_password_screen_can_be_rendered(): void
  29. {
  30. Notification::fake();
  31. $user = User::factory()->create();
  32. Volt::test('pages.auth.forgot-password')
  33. ->set('email', $user->email)
  34. ->call('sendPasswordResetLink');
  35. Notification::assertSentTo($user, ResetPassword::class, function ($notification) {
  36. $response = $this->get('/reset-password/'.$notification->token);
  37. $response
  38. ->assertSeeVolt('pages.auth.reset-password')
  39. ->assertStatus(200);
  40. return true;
  41. });
  42. }
  43. public function test_password_can_be_reset_with_valid_token(): void
  44. {
  45. Notification::fake();
  46. $user = User::factory()->create();
  47. Volt::test('pages.auth.forgot-password')
  48. ->set('email', $user->email)
  49. ->call('sendPasswordResetLink');
  50. Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) {
  51. $component = Volt::test('pages.auth.reset-password', ['token' => $notification->token])
  52. ->set('email', $user->email)
  53. ->set('password', 'password')
  54. ->set('password_confirmation', 'password');
  55. $component->call('resetPassword');
  56. $component
  57. ->assertRedirect('/login')
  58. ->assertHasNoErrors();
  59. return true;
  60. });
  61. }
  62. }