No Description
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.

ProfileTest.php 2.0KB

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('/profile');
  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('/profile', [
  15. 'name' => 'Test User',
  16. 'email' => 'test@example.com',
  17. ]);
  18. $response
  19. ->assertSessionHasNoErrors()
  20. ->assertRedirect('/profile');
  21. $user->refresh();
  22. $this->assertSame('Test User', $user->name);
  23. $this->assertSame('test@example.com', $user->email);
  24. $this->assertNull($user->email_verified_at);
  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('/profile', [
  31. 'name' => 'Test User',
  32. 'email' => $user->email,
  33. ]);
  34. $response
  35. ->assertSessionHasNoErrors()
  36. ->assertRedirect('/profile');
  37. $this->assertNotNull($user->refresh()->email_verified_at);
  38. });
  39. test('user can delete their account', function () {
  40. $user = User::factory()->create();
  41. $response = $this
  42. ->actingAs($user)
  43. ->delete('/profile', [
  44. 'password' => 'password',
  45. ]);
  46. $response
  47. ->assertSessionHasNoErrors()
  48. ->assertRedirect('/');
  49. $this->assertGuest();
  50. $this->assertNull($user->fresh());
  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('/profile')
  57. ->delete('/profile', [
  58. 'password' => 'wrong-password',
  59. ]);
  60. $response
  61. ->assertSessionHasErrorsIn('userDeletion', 'password')
  62. ->assertRedirect('/profile');
  63. $this->assertNotNull($user->fresh());
  64. });