ProfileTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace Tests\Feature;
  3. use App\Models\User;
  4. use Illuminate\Foundation\Testing\RefreshDatabase;
  5. use Livewire\Volt\Volt;
  6. use Tests\TestCase;
  7. class ProfileTest extends TestCase
  8. {
  9. use RefreshDatabase;
  10. public function test_profile_page_is_displayed(): void
  11. {
  12. $user = User::factory()->create();
  13. $response = $this->actingAs($user)->get('/profile');
  14. $response
  15. ->assertOk()
  16. ->assertSeeVolt('profile.update-profile-information-form')
  17. ->assertSeeVolt('profile.update-password-form')
  18. ->assertSeeVolt('profile.delete-user-form');
  19. }
  20. public function test_profile_information_can_be_updated(): void
  21. {
  22. $user = User::factory()->create();
  23. $this->actingAs($user);
  24. $component = Volt::test('profile.update-profile-information-form')
  25. ->set('name', 'Test User')
  26. ->set('email', 'test@example.com')
  27. ->call('updateProfileInformation');
  28. $component
  29. ->assertHasNoErrors()
  30. ->assertNoRedirect();
  31. $user->refresh();
  32. $this->assertSame('Test User', $user->name);
  33. $this->assertSame('test@example.com', $user->email);
  34. $this->assertNull($user->email_verified_at);
  35. }
  36. public function test_email_verification_status_is_unchanged_when_the_email_address_is_unchanged(): void
  37. {
  38. $user = User::factory()->create();
  39. $this->actingAs($user);
  40. $component = Volt::test('profile.update-profile-information-form')
  41. ->set('name', 'Test User')
  42. ->set('email', $user->email)
  43. ->call('updateProfileInformation');
  44. $component
  45. ->assertHasNoErrors()
  46. ->assertNoRedirect();
  47. $this->assertNotNull($user->refresh()->email_verified_at);
  48. }
  49. public function test_user_can_delete_their_account(): void
  50. {
  51. $user = User::factory()->create();
  52. $this->actingAs($user);
  53. $component = Volt::test('profile.delete-user-form')
  54. ->set('password', 'password')
  55. ->call('deleteUser');
  56. $component
  57. ->assertHasNoErrors()
  58. ->assertRedirect('/');
  59. $this->assertGuest();
  60. $this->assertNull($user->fresh());
  61. }
  62. public function test_correct_password_must_be_provided_to_delete_account(): void
  63. {
  64. $user = User::factory()->create();
  65. $this->actingAs($user);
  66. $component = Volt::test('profile.delete-user-form')
  67. ->set('password', 'wrong-password')
  68. ->call('deleteUser');
  69. $component
  70. ->assertHasErrors('password')
  71. ->assertNoRedirect();
  72. $this->assertNotNull($user->fresh());
  73. }
  74. }