Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

PasswordResetTest.php 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace Tests\Feature;
  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 Laravel\Fortify\Features;
  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. if (! Features::enabled(Features::resetPasswords())) {
  15. $this->markTestSkipped('Password updates are not enabled.');
  16. return;
  17. }
  18. $response = $this->get('/forgot-password');
  19. $response->assertStatus(200);
  20. }
  21. public function test_reset_password_link_can_be_requested(): void
  22. {
  23. if (! Features::enabled(Features::resetPasswords())) {
  24. $this->markTestSkipped('Password updates are not enabled.');
  25. return;
  26. }
  27. Notification::fake();
  28. $user = User::factory()->create();
  29. $response = $this->post('/forgot-password', [
  30. 'email' => $user->email,
  31. ]);
  32. Notification::assertSentTo($user, ResetPassword::class);
  33. }
  34. public function test_reset_password_screen_can_be_rendered(): void
  35. {
  36. if (! Features::enabled(Features::resetPasswords())) {
  37. $this->markTestSkipped('Password updates are not enabled.');
  38. return;
  39. }
  40. Notification::fake();
  41. $user = User::factory()->create();
  42. $response = $this->post('/forgot-password', [
  43. 'email' => $user->email,
  44. ]);
  45. Notification::assertSentTo($user, ResetPassword::class, function (object $notification) {
  46. $response = $this->get('/reset-password/'.$notification->token);
  47. $response->assertStatus(200);
  48. return true;
  49. });
  50. }
  51. public function test_password_can_be_reset_with_valid_token(): void
  52. {
  53. if (! Features::enabled(Features::resetPasswords())) {
  54. $this->markTestSkipped('Password updates are not enabled.');
  55. return;
  56. }
  57. Notification::fake();
  58. $user = User::factory()->create();
  59. $response = $this->post('/forgot-password', [
  60. 'email' => $user->email,
  61. ]);
  62. Notification::assertSentTo($user, ResetPassword::class, function (object $notification) use ($user) {
  63. $response = $this->post('/reset-password', [
  64. 'token' => $notification->token,
  65. 'email' => $user->email,
  66. 'password' => 'password',
  67. 'password_confirmation' => 'password',
  68. ]);
  69. $response->assertSessionHasNoErrors();
  70. return true;
  71. });
  72. }
  73. }