|
0
|
1 <?php
|
|
|
2
|
|
|
3 namespace Tests\Feature\Auth;
|
|
|
4
|
|
|
5 use App\Models\User;
|
|
|
6 use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
7 use Illuminate\Support\Facades\Hash;
|
|
|
8 use Tests\TestCase;
|
|
|
9
|
|
|
10 class PasswordUpdateTest extends TestCase
|
|
|
11 {
|
|
|
12 use RefreshDatabase;
|
|
|
13
|
|
|
14 public function test_password_can_be_updated(): void
|
|
|
15 {
|
|
|
16 $user = User::factory()->create();
|
|
|
17
|
|
|
18 $response = $this
|
|
|
19 ->actingAs($user)
|
|
|
20 ->from('/profile')
|
|
|
21 ->put('/password', [
|
|
|
22 'current_password' => 'password',
|
|
|
23 'password' => 'new-password',
|
|
|
24 'password_confirmation' => 'new-password',
|
|
|
25 ]);
|
|
|
26
|
|
|
27 $response
|
|
|
28 ->assertSessionHasNoErrors()
|
|
|
29 ->assertRedirect('/profile');
|
|
|
30
|
|
|
31 $this->assertTrue(Hash::check('new-password', $user->refresh()->password));
|
|
|
32 }
|
|
|
33
|
|
|
34 public function test_correct_password_must_be_provided_to_update_password(): void
|
|
|
35 {
|
|
|
36 $user = User::factory()->create();
|
|
|
37
|
|
|
38 $response = $this
|
|
|
39 ->actingAs($user)
|
|
|
40 ->from('/profile')
|
|
|
41 ->put('/password', [
|
|
|
42 'current_password' => 'wrong-password',
|
|
|
43 'password' => 'new-password',
|
|
|
44 'password_confirmation' => 'new-password',
|
|
|
45 ]);
|
|
|
46
|
|
|
47 $response
|
|
|
48 ->assertSessionHasErrorsIn('updatePassword', 'current_password')
|
|
|
49 ->assertRedirect('/profile');
|
|
|
50 }
|
|
|
51 }
|