PasswordResetTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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()
  12. {
  13. $response = $this->get('/forgot-password');
  14. $response->assertStatus(200);
  15. }
  16. public function test_reset_password_link_can_be_requested()
  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()
  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()
  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->assertSessionHasNoErrors();
  47. return true;
  48. });
  49. }
  50. }