comparison stubs/default/tests/Feature/ProfileTest.php @ 0:90e38de8f2ba

Initial Commit
author luka
date Wed, 13 Aug 2025 22:17:20 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:90e38de8f2ba
1 <?php
2
3 namespace Tests\Feature;
4
5 use App\Models\User;
6 use Illuminate\Foundation\Testing\RefreshDatabase;
7 use Tests\TestCase;
8
9 class ProfileTest extends TestCase
10 {
11 use RefreshDatabase;
12
13 public function test_profile_page_is_displayed(): void
14 {
15 $user = User::factory()->create();
16
17 $response = $this
18 ->actingAs($user)
19 ->get('/profile');
20
21 $response->assertOk();
22 }
23
24 public function test_profile_information_can_be_updated(): void
25 {
26 $user = User::factory()->create();
27
28 $response = $this
29 ->actingAs($user)
30 ->patch('/profile', [
31 'name' => 'Test User',
32 'email' => 'test@example.com',
33 ]);
34
35 $response
36 ->assertSessionHasNoErrors()
37 ->assertRedirect('/profile');
38
39 $user->refresh();
40
41 $this->assertSame('Test User', $user->name);
42 $this->assertSame('test@example.com', $user->email);
43 $this->assertNull($user->email_verified_at);
44 }
45
46 public function test_email_verification_status_is_unchanged_when_the_email_address_is_unchanged(): void
47 {
48 $user = User::factory()->create();
49
50 $response = $this
51 ->actingAs($user)
52 ->patch('/profile', [
53 'name' => 'Test User',
54 'email' => $user->email,
55 ]);
56
57 $response
58 ->assertSessionHasNoErrors()
59 ->assertRedirect('/profile');
60
61 $this->assertNotNull($user->refresh()->email_verified_at);
62 }
63
64 public function test_user_can_delete_their_account(): void
65 {
66 $user = User::factory()->create();
67
68 $response = $this
69 ->actingAs($user)
70 ->delete('/profile', [
71 'password' => 'password',
72 ]);
73
74 $response
75 ->assertSessionHasNoErrors()
76 ->assertRedirect('/');
77
78 $this->assertGuest();
79 $this->assertNull($user->fresh());
80 }
81
82 public function test_correct_password_must_be_provided_to_delete_account(): void
83 {
84 $user = User::factory()->create();
85
86 $response = $this
87 ->actingAs($user)
88 ->from('/profile')
89 ->delete('/profile', [
90 'password' => 'wrong-password',
91 ]);
92
93 $response
94 ->assertSessionHasErrorsIn('userDeletion', 'password')
95 ->assertRedirect('/profile');
96
97 $this->assertNotNull($user->fresh());
98 }
99 }