PasswordUpdateTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace Tests\Feature\Auth;
  3. use App\Models\User;
  4. use Illuminate\Foundation\Testing\RefreshDatabase;
  5. use Illuminate\Support\Facades\Hash;
  6. use Livewire\Volt\Volt;
  7. use Tests\TestCase;
  8. class PasswordUpdateTest extends TestCase
  9. {
  10. use RefreshDatabase;
  11. public function test_password_can_be_updated(): void
  12. {
  13. $user = User::factory()->create();
  14. $this->actingAs($user);
  15. $component = Volt::test('profile.update-password-form')
  16. ->set('current_password', 'password')
  17. ->set('password', 'new-password')
  18. ->set('password_confirmation', 'new-password')
  19. ->call('updatePassword');
  20. $component
  21. ->assertHasNoErrors()
  22. ->assertNoRedirect();
  23. $this->assertTrue(Hash::check('new-password', $user->refresh()->password));
  24. }
  25. public function test_correct_password_must_be_provided_to_update_password(): void
  26. {
  27. $user = User::factory()->create();
  28. $this->actingAs($user);
  29. $component = Volt::test('profile.update-password-form')
  30. ->set('current_password', 'wrong-password')
  31. ->set('password', 'new-password')
  32. ->set('password_confirmation', 'new-password')
  33. ->call('updatePassword');
  34. $component
  35. ->assertHasErrors(['current_password'])
  36. ->assertNoRedirect();
  37. }
  38. }