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.

99 lines
2.4 KiB

  1. <?php
  2. namespace Tests\Feature;
  3. use App\Models\User;
  4. use Illuminate\Foundation\Testing\RefreshDatabase;
  5. use Tests\TestCase;
  6. class ProfileTest extends TestCase
  7. {
  8. use RefreshDatabase;
  9. public function test_profile_page_is_displayed(): void
  10. {
  11. $user = User::factory()->create();
  12. $response = $this
  13. ->actingAs($user)
  14. ->get('/profile');
  15. $response->assertOk();
  16. }
  17. public function test_profile_information_can_be_updated(): void
  18. {
  19. $user = User::factory()->create();
  20. $response = $this
  21. ->actingAs($user)
  22. ->patch('/profile', [
  23. 'name' => 'Test User',
  24. 'email' => 'test@example.com',
  25. ]);
  26. $response
  27. ->assertSessionHasNoErrors()
  28. ->assertRedirect('/profile');
  29. $user->refresh();
  30. $this->assertSame('Test User', $user->name);
  31. $this->assertSame('test@example.com', $user->email);
  32. $this->assertNull($user->email_verified_at);
  33. }
  34. public function test_email_verification_status_is_unchanged_when_the_email_address_is_unchanged(): void
  35. {
  36. $user = User::factory()->create();
  37. $response = $this
  38. ->actingAs($user)
  39. ->patch('/profile', [
  40. 'name' => 'Test User',
  41. 'email' => $user->email,
  42. ]);
  43. $response
  44. ->assertSessionHasNoErrors()
  45. ->assertRedirect('/profile');
  46. $this->assertNotNull($user->refresh()->email_verified_at);
  47. }
  48. public function test_user_can_delete_their_account(): void
  49. {
  50. $user = User::factory()->create();
  51. $response = $this
  52. ->actingAs($user)
  53. ->delete('/profile', [
  54. 'password' => 'password',
  55. ]);
  56. $response
  57. ->assertSessionHasNoErrors()
  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. $response = $this
  66. ->actingAs($user)
  67. ->from('/profile')
  68. ->delete('/profile', [
  69. 'password' => 'wrong-password',
  70. ]);
  71. $response
  72. ->assertSessionHasErrors('password')
  73. ->assertRedirect('/profile');
  74. $this->assertNotNull($user->fresh());
  75. }
  76. }