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
|
<?php
require_once __DIR__.'/../Base.php';
use Kanboard\Model\User;
use Kanboard\Model\PasswordReset;
class PasswordResetTest extends Base
{
public function testCreate()
{
$userModel = new User($this->container);
$passwordResetModel = new PasswordReset($this->container);
$this->assertEquals(2, $userModel->create(array('username' => 'user1')));
$this->assertEquals(3, $userModel->create(array('username' => 'user2', 'email' => 'user1@localhost')));
$this->assertFalse($passwordResetModel->create('user0'));
$this->assertFalse($passwordResetModel->create('user1'));
$this->assertNotFalse($passwordResetModel->create('user2'));
}
public function testGetUserIdByToken()
{
$userModel = new User($this->container);
$passwordResetModel = new PasswordReset($this->container);
$this->assertEquals(2, $userModel->create(array('username' => 'user2', 'email' => 'user1@localhost')));
$token = $passwordResetModel->create('user2');
$this->assertEquals(2, $passwordResetModel->getUserIdByToken($token));
}
public function testGetUserIdByTokenWhenExpired()
{
$userModel = new User($this->container);
$passwordResetModel = new PasswordReset($this->container);
$this->assertEquals(2, $userModel->create(array('username' => 'user2', 'email' => 'user1@localhost')));
$token = $passwordResetModel->create('user2', strtotime('-1 year'));
$this->assertFalse($passwordResetModel->getUserIdByToken($token));
}
public function testDisableTokens()
{
$userModel = new User($this->container);
$passwordResetModel = new PasswordReset($this->container);
$this->assertEquals(2, $userModel->create(array('username' => 'user2', 'email' => 'user1@localhost')));
$token1 = $passwordResetModel->create('user2');
$token2 = $passwordResetModel->create('user2');
$this->assertEquals(2, $passwordResetModel->getUserIdByToken($token1));
$this->assertEquals(2, $passwordResetModel->getUserIdByToken($token2));
$this->assertTrue($passwordResetModel->disable(2));
$this->assertFalse($passwordResetModel->getUserIdByToken($token1));
$this->assertFalse($passwordResetModel->getUserIdByToken($token2));
}
public function testGetAll()
{
$userModel = new User($this->container);
$passwordResetModel = new PasswordReset($this->container);
$this->assertEquals(2, $userModel->create(array('username' => 'user2', 'email' => 'user1@localhost')));
$this->assertNotFalse($passwordResetModel->create('user2'));
$this->assertNotFalse($passwordResetModel->create('user2'));
$tokens = $passwordResetModel->getAll(1);
$this->assertCount(0, $tokens);
$tokens = $passwordResetModel->getAll(2);
$this->assertCount(2, $tokens);
$this->assertNotEmpty($tokens[0]['token']);
$this->assertNotEmpty($tokens[0]['date_creation']);
$this->assertNotEmpty($tokens[0]['date_expiration']);
$this->assertEquals(2, $tokens[0]['user_id']);
$this->assertArrayHasKey('user_agent', $tokens[0]);
$this->assertArrayHasKey('ip', $tokens[0]);
}
}
|