AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. namespace Tests\Feature\Settings;
  3. use App\Models\User;
  4. use Illuminate\Foundation\Testing\RefreshDatabase;
  5. use Tests\TestCase;
  6. class ProfileUpdateTest extends TestCase
  7. {
  8. use RefreshDatabase;
  9. public function test_profile_page_is_displayed()
  10. {
  11. $user = User::factory()->create();
  12. $response = $this
  13. ->actingAs($user)
  14. ->get(route('profile.edit'));
  15. $response->assertOk();
  16. }
  17. public function test_profile_information_can_be_updated()
  18. {
  19. $user = User::factory()->create();
  20. $response = $this
  21. ->actingAs($user)
  22. ->patch(route('profile.update'), [
  23. 'name' => 'Test User',
  24. 'email' => 'test@example.com',
  25. ]);
  26. $response
  27. ->assertSessionHasNoErrors()
  28. ->assertRedirect(route('profile.edit'));
  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_is_stored_in_lowercase_so_the_user_can_still_log_in()
  35. {
  36. $user = User::factory()->create();
  37. $this
  38. ->actingAs($user)
  39. ->patch(route('profile.update'), [
  40. 'name' => 'Test User',
  41. 'email' => 'Test@Example.com',
  42. ])
  43. ->assertSessionHasNoErrors();
  44. $this->assertSame('test@example.com', $user->refresh()->email);
  45. $this->post(route('logout'));
  46. $this->post(route('login.store'), [
  47. 'email' => 'Test@Example.com',
  48. 'password' => 'password',
  49. ]);
  50. $this->assertAuthenticatedAs($user);
  51. }
  52. public function test_email_must_be_unique_regardless_of_case()
  53. {
  54. User::factory()->create(['email' => 'taken@example.com']);
  55. $user = User::factory()->create();
  56. $response = $this
  57. ->actingAs($user)
  58. ->from(route('profile.edit'))
  59. ->patch(route('profile.update'), [
  60. 'name' => 'Test User',
  61. 'email' => 'Taken@Example.com',
  62. ]);
  63. $response
  64. ->assertSessionHasErrors('email')
  65. ->assertRedirect(route('profile.edit'));
  66. }
  67. public function test_email_verification_status_is_unchanged_when_the_email_address_is_unchanged()
  68. {
  69. $user = User::factory()->create();
  70. $response = $this
  71. ->actingAs($user)
  72. ->patch(route('profile.update'), [
  73. 'name' => 'Test User',
  74. 'email' => $user->email,
  75. ]);
  76. $response
  77. ->assertSessionHasNoErrors()
  78. ->assertRedirect(route('profile.edit'));
  79. $this->assertNotNull($user->refresh()->email_verified_at);
  80. }
  81. public function test_user_can_delete_their_account()
  82. {
  83. $user = User::factory()->create();
  84. $response = $this
  85. ->actingAs($user)
  86. ->delete(route('profile.destroy'), [
  87. 'password' => 'password',
  88. ]);
  89. $response
  90. ->assertSessionHasNoErrors()
  91. ->assertRedirect(route('home'));
  92. $this->assertGuest();
  93. $this->assertNull($user->fresh());
  94. }
  95. public function test_correct_password_must_be_provided_to_delete_account()
  96. {
  97. $user = User::factory()->create();
  98. $response = $this
  99. ->actingAs($user)
  100. ->from(route('profile.edit'))
  101. ->delete(route('profile.destroy'), [
  102. 'password' => 'wrong-password',
  103. ]);
  104. $response
  105. ->assertSessionHasErrors('password')
  106. ->assertRedirect(route('profile.edit'));
  107. $this->assertNotNull($user->fresh());
  108. }
  109. }