-
Notifications
You must be signed in to change notification settings - Fork 12
/
ResetsPasswordTest.php
90 lines (73 loc) · 2.15 KB
/
ResetsPasswordTest.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
<?php
namespace Tests\Feature;
use App\User;
use Tests\TestCase;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Password;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class ResetsPasswordTest extends TestCase
{
use DatabaseTransactions;
/**
* Displays the reset password request form.
*
* @return void
*/
public function testDisplaysPasswordResetRequestForm()
{
$response = $this->get('password/reset');
$response->assertStatus(200);
}
/**
* Sends the password reset email when the user exists.
*
* @return void
*/
public function testSendsPasswordResetEmail()
{
$user = factory(User::class)->create();
$this->expectsNotification($user, ResetPassword::class);
$response = $this->post('password/email', ['email' => $user->email]);
$response->assertStatus(302);
}
/**
* Does not send a password reset email when the user does not exist.
*
* @return void
*/
public function testDoesNotSendPasswordResetEmail()
{
$this->doesntExpectJobs(ResetPassword::class);
$this->post('password/email', ['email' => '[email protected]']);
}
/**
* Displays the form to reset a password.
*
* @return void
*/
public function testDisplaysPasswordResetForm()
{
$response = $this->get('/password/reset/token');
$response->assertStatus(200);
}
/**
* Allows a user to reset their password.
*
* @return void
*/
public function testChangesAUsersPassword()
{
$user = factory(User::class)->create();
$token = Password::createToken($user);
$response = $this->post('/password/reset', [
'token' => $token,
'email' => $user->email,
'password' => 'password',
'password_confirmation' => 'password'
]);
$this->assertTrue(Hash::check('password', $user->fresh()->password));
}
}