-
Notifications
You must be signed in to change notification settings - Fork 308
/
Copy pathPasswordControllerTest.php
66 lines (55 loc) · 2.03 KB
/
PasswordControllerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
namespace Laravel\Fortify\Tests;
use App\Actions\Fortify\UpdateUserPassword;
use Database\Factories\UserFactory;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Validation\ValidationException;
use Laravel\Fortify\Contracts\UpdatesUserPasswords;
class PasswordControllerTest extends OrchestraTestCase
{
use RefreshDatabase;
public function test_passwords_can_be_updated()
{
$user = UserFactory::new()->create();
$this->mock(UpdatesUserPasswords::class)
->shouldReceive('update')
->once();
$response = $this->withoutExceptionHandling()->actingAs($user)->putJson('/user/password', [
'current_password' => 'password',
'password' => 'new-password',
'password_confirmation' => 'new-password',
]);
$response->assertStatus(200);
}
public function test_passwords_cannot_be_updated_without_current_password()
{
$user = UserFactory::new()->create();
try {
(new UpdateUserPassword())->update($user, [
'password' => 'new-password',
'password_confirmation' => 'new-password',
]);
} catch (ValidationException $e) {
$this->assertTrue(in_array(
'The current password field is required.',
$e->errors()['current_password']
));
}
}
public function test_passwords_cannot_be_updated_without_current_password_confirmation()
{
$user = UserFactory::new()->create();
try {
(new UpdateUserPassword())->update($user, [
'current_password' => 'invalid-password',
'password' => 'new-password',
'password_confirmation' => 'new-password',
]);
} catch (ValidationException $e) {
$this->assertTrue(in_array(
'The provided password does not match your current password.',
$e->errors()['current_password']
));
}
}
}