ProfileUpdateTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. use App\Models\User;
  3. test('profile page is displayed', function () {
  4. $user = User::factory()->create();
  5. $response = $this
  6. ->actingAs($user)
  7. ->get(route('profile.edit'));
  8. $response->assertOk();
  9. });
  10. test('profile information can be updated', function () {
  11. $user = User::factory()->create();
  12. $response = $this
  13. ->actingAs($user)
  14. ->patch(route('profile.update'), [
  15. 'name' => 'Test User',
  16. 'email' => 'test@example.com',
  17. ]);
  18. $response
  19. ->assertSessionHasNoErrors()
  20. ->assertRedirect(route('profile.edit'));
  21. $user->refresh();
  22. expect($user->name)->toBe('Test User');
  23. expect($user->email)->toBe('test@example.com');
  24. expect($user->email_verified_at)->toBeNull();
  25. });
  26. test('email verification status is unchanged when the email address is unchanged', function () {
  27. $user = User::factory()->create();
  28. $response = $this
  29. ->actingAs($user)
  30. ->patch(route('profile.update'), [
  31. 'name' => 'Test User',
  32. 'email' => $user->email,
  33. ]);
  34. $response
  35. ->assertSessionHasNoErrors()
  36. ->assertRedirect(route('profile.edit'));
  37. expect($user->refresh()->email_verified_at)->not->toBeNull();
  38. });
  39. test('user can delete their account', function () {
  40. $user = User::factory()->create();
  41. $response = $this
  42. ->actingAs($user)
  43. ->delete(route('profile.destroy'), [
  44. 'password' => 'password',
  45. ]);
  46. $response
  47. ->assertSessionHasNoErrors()
  48. ->assertRedirect(route('home'));
  49. $this->assertGuest();
  50. expect($user->fresh())->toBeNull();
  51. });
  52. test('correct password must be provided to delete account', function () {
  53. $user = User::factory()->create();
  54. $response = $this
  55. ->actingAs($user)
  56. ->from(route('profile.edit'))
  57. ->delete(route('profile.destroy'), [
  58. 'password' => 'wrong-password',
  59. ]);
  60. $response
  61. ->assertSessionHasErrors('password')
  62. ->assertRedirect(route('profile.edit'));
  63. expect($user->fresh())->not->toBeNull();
  64. });