-
Notifications
You must be signed in to change notification settings - Fork 308
/
Copy pathPasswordResetLinkRequestControllerTest.php
98 lines (73 loc) · 3.71 KB
/
PasswordResetLinkRequestControllerTest.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
namespace Laravel\Fortify\Tests;
use Illuminate\Contracts\Auth\PasswordBroker;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Password;
use Laravel\Fortify\Contracts\RequestPasswordResetLinkViewResponse;
use Mockery;
class PasswordResetLinkRequestControllerTest extends OrchestraTestCase
{
public function test_the_reset_link_request_view_is_returned()
{
$this->mock(RequestPasswordResetLinkViewResponse::class)
->shouldReceive('toResponse')
->andReturn(response('hello world'));
$response = $this->get('/forgot-password');
$response->assertStatus(200);
$response->assertSeeText('hello world');
}
public function test_reset_link_can_be_successfully_requested()
{
Password::shouldReceive('broker')->andReturn($broker = Mockery::mock(PasswordBroker::class));
$broker->shouldReceive('sendResetLink')->andReturn(Password::RESET_LINK_SENT);
$response = $this->from(url('/forgot-password'))
->post('/forgot-password', ['email' => '[email protected]']);
$response->assertStatus(302);
$response->assertRedirect('/forgot-password');
$response->assertSessionHasNoErrors();
$response->assertSessionHas('status', trans(Password::RESET_LINK_SENT));
}
public function test_reset_link_request_can_fail()
{
Password::shouldReceive('broker')->andReturn($broker = Mockery::mock(PasswordBroker::class));
$broker->shouldReceive('sendResetLink')->andReturn(Password::INVALID_USER);
$response = $this->from(url('/forgot-password'))
->post('/forgot-password', ['email' => '[email protected]']);
$response->assertStatus(302);
$response->assertRedirect('/forgot-password');
$response->assertSessionHasErrors('email');
}
public function test_reset_link_request_can_fail_with_json()
{
Password::shouldReceive('broker')->andReturn($broker = Mockery::mock(PasswordBroker::class));
$broker->shouldReceive('sendResetLink')->andReturn(Password::INVALID_USER);
$response = $this->from(url('/forgot-password'))
->postJson('/forgot-password', ['email' => '[email protected]']);
$response->assertStatus(422);
$response->assertJsonValidationErrors('email');
}
public function test_reset_link_can_be_successfully_requested_with_customized_email_field()
{
Config::set('fortify.email', 'emailAddress');
Password::shouldReceive('broker')->andReturn($broker = Mockery::mock(PasswordBroker::class));
$broker->shouldReceive('sendResetLink')->andReturn(Password::RESET_LINK_SENT);
$response = $this->from(url('/forgot-password'))
->post('/forgot-password', ['emailAddress' => '[email protected]']);
$response->assertStatus(302);
$response->assertRedirect('/forgot-password');
$response->assertSessionHasNoErrors();
$response->assertSessionHas('status', trans(Password::RESET_LINK_SENT));
}
public function test_case_insensitive_usernames_can_be_used()
{
Config::set('fortify.lowercase_usernames', true);
Password::shouldReceive('broker')->andReturn($broker = Mockery::mock(PasswordBroker::class));
$broker->shouldReceive('sendResetLink')->andReturn(Password::RESET_LINK_SENT);
$response = $this->from(url('/forgot-password'))
->post('/forgot-password', ['email' => '[email protected]']);
$response->assertStatus(302);
$response->assertRedirect('/forgot-password');
$response->assertSessionHasNoErrors();
$response->assertSessionHas('status', trans(Password::RESET_LINK_SENT));
}
}