forked from mongodb/laravel-mongodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuthTest.php
65 lines (51 loc) · 1.97 KB
/
AuthTest.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
<?php
use Illuminate\Auth\Passwords\PasswordBroker;
class AuthTest extends TestCase {
public function tearDown()
{
User::truncate();
DB::collection('password_reminders')->truncate();
}
public function testAuthAttempt()
{
$user = User::create(array(
'name' => 'John Doe',
'email' => '[email protected]',
'password' => Hash::make('foobar')
));
$this->assertTrue(Auth::attempt(array('email' => '[email protected]', 'password' => 'foobar'), true));
$this->assertTrue(Auth::check());
}
public function testRemind()
{
$mailer = Mockery::mock('Illuminate\Mail\Mailer');
$tokens = $this->app->make('auth.password.tokens');
$users = $this->app['auth']->driver()->getProvider();
$broker = new PasswordBroker($tokens, $users, $mailer, '');
$user = User::create(array(
'name' => 'John Doe',
'email' => '[email protected]',
'password' => Hash::make('foobar')
));
$mailer->shouldReceive('send')->once();
$broker->sendResetLink(array('email' => '[email protected]'));
$this->assertEquals(1, DB::collection('password_resets')->count());
$reminder = DB::collection('password_resets')->first();
$this->assertEquals('[email protected]', $reminder['email']);
$this->assertNotNull($reminder['token']);
$this->assertInstanceOf('MongoDate', $reminder['created_at']);
$credentials = array(
'email' => '[email protected]',
'password' => 'foobar',
'password_confirmation' => 'foobar',
'token' => $reminder['token']
);
$response = $broker->reset($credentials, function($user, $password)
{
$user->password = bcrypt($password);
$user->save();
});
$this->assertEquals('passwords.reset', $response);
$this->assertEquals(0, DB::collection('password_resets')->count());
}
}