You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.4 KiB

  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 Tests\TestCase;
  7. class PasswordUpdateTest extends TestCase
  8. {
  9. use RefreshDatabase;
  10. public function test_password_can_be_updated(): void
  11. {
  12. $user = User::factory()->create();
  13. $response = $this
  14. ->actingAs($user)
  15. ->from('/profile')
  16. ->put('/password', [
  17. 'current_password' => 'password',
  18. 'password' => 'new-password',
  19. 'password_confirmation' => 'new-password',
  20. ]);
  21. $response
  22. ->assertSessionHasNoErrors()
  23. ->assertRedirect('/profile');
  24. $this->assertTrue(Hash::check('new-password', $user->refresh()->password));
  25. }
  26. public function test_correct_password_must_be_provided_to_update_password(): void
  27. {
  28. $user = User::factory()->create();
  29. $response = $this
  30. ->actingAs($user)
  31. ->from('/profile')
  32. ->put('/password', [
  33. 'current_password' => 'wrong-password',
  34. 'password' => 'new-password',
  35. 'password_confirmation' => 'new-password',
  36. ]);
  37. $response
  38. ->assertSessionHasErrors('current_password')
  39. ->assertRedirect('/profile');
  40. }
  41. }