home-erp

git clone git://archive.git.mtrnord.blog/MTRNord/home-erp.git
Log | Files | Refs | README

PasswordResetTest.php (2393B)


      1 <?php
      2 
      3 namespace Tests\Feature\Auth;
      4 
      5 use App\Models\User;
      6 use Illuminate\Auth\Notifications\ResetPassword;
      7 use Illuminate\Foundation\Testing\RefreshDatabase;
      8 use Illuminate\Support\Facades\Notification;
      9 use Livewire\Volt\Volt;
     10 use Tests\TestCase;
     11 
     12 class PasswordResetTest extends TestCase
     13 {
     14     use RefreshDatabase;
     15 
     16     public function test_reset_password_link_screen_can_be_rendered(): void
     17     {
     18         $response = $this->get('/forgot-password');
     19 
     20         $response
     21             ->assertSeeVolt('pages.auth.forgot-password')
     22             ->assertStatus(200);
     23     }
     24 
     25     public function test_reset_password_link_can_be_requested(): void
     26     {
     27         Notification::fake();
     28 
     29         $user = User::factory()->create();
     30 
     31         Volt::test('pages.auth.forgot-password')
     32             ->set('email', $user->email)
     33             ->call('sendPasswordResetLink');
     34 
     35         Notification::assertSentTo($user, ResetPassword::class);
     36     }
     37 
     38     public function test_reset_password_screen_can_be_rendered(): void
     39     {
     40         Notification::fake();
     41 
     42         $user = User::factory()->create();
     43 
     44         Volt::test('pages.auth.forgot-password')
     45             ->set('email', $user->email)
     46             ->call('sendPasswordResetLink');
     47 
     48         Notification::assertSentTo($user, ResetPassword::class, function ($notification) {
     49             $response = $this->get('/reset-password/'.$notification->token);
     50 
     51             $response
     52                 ->assertSeeVolt('pages.auth.reset-password')
     53                 ->assertStatus(200);
     54 
     55             return true;
     56         });
     57     }
     58 
     59     public function test_password_can_be_reset_with_valid_token(): void
     60     {
     61         Notification::fake();
     62 
     63         $user = User::factory()->create();
     64 
     65         Volt::test('pages.auth.forgot-password')
     66             ->set('email', $user->email)
     67             ->call('sendPasswordResetLink');
     68 
     69         Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) {
     70             $component = Volt::test('pages.auth.reset-password', ['token' => $notification->token])
     71                 ->set('email', $user->email)
     72                 ->set('password', 'password')
     73                 ->set('password_confirmation', 'password');
     74 
     75             $component->call('resetPassword');
     76 
     77             $component
     78                 ->assertRedirect('/login')
     79                 ->assertHasNoErrors();
     80 
     81             return true;
     82         });
     83     }
     84 }