|
0
|
1 <?php
|
|
|
2
|
|
|
3 use App\Models\User;
|
|
|
4 use Illuminate\Auth\Notifications\ResetPassword;
|
|
|
5 use Illuminate\Support\Facades\Notification;
|
|
|
6
|
|
|
7 test('reset password link screen can be rendered', function () {
|
|
|
8 $response = $this->get('/forgot-password');
|
|
|
9
|
|
|
10 $response->assertStatus(200);
|
|
|
11 });
|
|
|
12
|
|
|
13 test('reset password link can be requested', function () {
|
|
|
14 Notification::fake();
|
|
|
15
|
|
|
16 $user = User::factory()->create();
|
|
|
17
|
|
|
18 $this->post('/forgot-password', ['email' => $user->email]);
|
|
|
19
|
|
|
20 Notification::assertSentTo($user, ResetPassword::class);
|
|
|
21 });
|
|
|
22
|
|
|
23 test('reset password screen can be rendered', function () {
|
|
|
24 Notification::fake();
|
|
|
25
|
|
|
26 $user = User::factory()->create();
|
|
|
27
|
|
|
28 $this->post('/forgot-password', ['email' => $user->email]);
|
|
|
29
|
|
|
30 Notification::assertSentTo($user, ResetPassword::class, function ($notification) {
|
|
|
31 $response = $this->get('/reset-password/'.$notification->token);
|
|
|
32
|
|
|
33 $response->assertStatus(200);
|
|
|
34
|
|
|
35 return true;
|
|
|
36 });
|
|
|
37 });
|
|
|
38
|
|
|
39 test('password can be reset with valid token', function () {
|
|
|
40 Notification::fake();
|
|
|
41
|
|
|
42 $user = User::factory()->create();
|
|
|
43
|
|
|
44 $this->post('/forgot-password', ['email' => $user->email]);
|
|
|
45
|
|
|
46 Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) {
|
|
|
47 $response = $this->post('/reset-password', [
|
|
|
48 'token' => $notification->token,
|
|
|
49 'email' => $user->email,
|
|
|
50 'password' => 'password',
|
|
|
51 'password_confirmation' => 'password',
|
|
|
52 ]);
|
|
|
53
|
|
|
54 $response
|
|
|
55 ->assertSessionHasNoErrors()
|
|
|
56 ->assertRedirect(route('login'));
|
|
|
57
|
|
|
58 return true;
|
|
|
59 });
|
|
|
60 });
|