summaryrefslogtreecommitdiff
path: root/tests/units/Model/UserTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units/Model/UserTest.php')
-rw-r--r--tests/units/Model/UserTest.php108
1 files changed, 54 insertions, 54 deletions
diff --git a/tests/units/Model/UserTest.php b/tests/units/Model/UserTest.php
index 90a80954..1d381006 100644
--- a/tests/units/Model/UserTest.php
+++ b/tests/units/Model/UserTest.php
@@ -9,34 +9,10 @@ use Kanboard\Model\Task;
use Kanboard\Model\TaskCreation;
use Kanboard\Model\TaskFinder;
use Kanboard\Model\Project;
+use Kanboard\Core\Security\Role;
class UserTest extends Base
{
- public function testFailedLogin()
- {
- $u = new User($this->container);
-
- $this->assertEquals(0, $u->getFailedLogin('admin'));
- $this->assertEquals(0, $u->getFailedLogin('not_found'));
-
- $this->assertTrue($u->incrementFailedLogin('admin'));
- $this->assertTrue($u->incrementFailedLogin('admin'));
-
- $this->assertEquals(2, $u->getFailedLogin('admin'));
- $this->assertTrue($u->resetFailedLogin('admin'));
- $this->assertEquals(0, $u->getFailedLogin('admin'));
- }
-
- public function testLocking()
- {
- $u = new User($this->container);
-
- $this->assertFalse($u->isLocked('admin'));
- $this->assertFalse($u->isLocked('not_found'));
- $this->assertTrue($u->lock('admin', 1));
- $this->assertTrue($u->isLocked('admin'));
- }
-
public function testGetByEmail()
{
$u = new User($this->container);
@@ -47,33 +23,27 @@ class UserTest extends Base
$this->assertEmpty($u->getByEmail(''));
}
- public function testGetByGitlabId()
+ public function testGetByExternalId()
{
$u = new User($this->container);
$this->assertNotFalse($u->create(array('username' => 'user1', 'password' => '123456', 'gitlab_id' => '1234')));
- $this->assertNotEmpty($u->getByGitlabId('1234'));
- $this->assertEmpty($u->getByGitlabId(''));
- }
+ $this->assertNotEmpty($u->getByExternalId('gitlab_id', '1234'));
+ $this->assertEmpty($u->getByExternalId('gitlab_id', ''));
- public function testGetByGithubId()
- {
$u = new User($this->container);
- $this->assertNotFalse($u->create(array('username' => 'user1', 'password' => '123456', 'github_id' => 'plop')));
- $this->assertNotFalse($u->create(array('username' => 'user2', 'password' => '123456', 'github_id' => '')));
+ $this->assertNotFalse($u->create(array('username' => 'user2', 'password' => '123456', 'github_id' => 'plop')));
+ $this->assertNotFalse($u->create(array('username' => 'user3', 'password' => '123456', 'github_id' => '')));
- $this->assertNotEmpty($u->getByGithubId('plop'));
- $this->assertEmpty($u->getByGithubId(''));
- }
+ $this->assertNotEmpty($u->getByExternalId('github_id', 'plop'));
+ $this->assertEmpty($u->getByExternalId('github_id', ''));
- public function testGetByGoogleId()
- {
$u = new User($this->container);
- $this->assertNotFalse($u->create(array('username' => 'user1', 'password' => '123456', 'google_id' => '1234')));
- $this->assertNotFalse($u->create(array('username' => 'user2', 'password' => '123456', 'google_id' => '')));
+ $this->assertNotFalse($u->create(array('username' => 'user4', 'password' => '123456', 'google_id' => '1234')));
+ $this->assertNotFalse($u->create(array('username' => 'user5', 'password' => '123456', 'google_id' => '')));
- $this->assertNotEmpty($u->getByGoogleId('1234'));
- $this->assertEmpty($u->getByGoogleId(''));
+ $this->assertNotEmpty($u->getByExternalId('google_id', '1234'));
+ $this->assertEmpty($u->getByExternalId('google_id', ''));
}
public function testGetByToken()
@@ -197,7 +167,7 @@ class UserTest extends Base
'password' => '1234',
'confirmation' => '1234',
'name' => 'me',
- 'is_admin' => '',
+ 'role' => Role::APP_ADMIN,
);
$u->prepare($input);
@@ -207,9 +177,6 @@ class UserTest extends Base
$this->assertNotEquals('1234', $input['password']);
$this->assertNotEmpty($input['password']);
- $this->assertArrayHasKey('is_admin', $input);
- $this->assertInternalType('integer', $input['is_admin']);
-
$input = array(
'username' => 'user1',
'password' => '1234',
@@ -273,8 +240,8 @@ class UserTest extends Base
$u = new User($this->container);
$this->assertEquals(2, $u->create(array('username' => 'user #1', 'password' => '123456', 'name' => 'User')));
$this->assertEquals(3, $u->create(array('username' => 'user #2', 'is_ldap_user' => 1)));
- $this->assertEquals(4, $u->create(array('username' => 'user #3', 'is_project_admin' => 1)));
- $this->assertEquals(5, $u->create(array('username' => 'user #4', 'gitlab_id' => '')));
+ $this->assertEquals(4, $u->create(array('username' => 'user #3', 'role' => Role::APP_MANAGER)));
+ $this->assertEquals(5, $u->create(array('username' => 'user #4', 'gitlab_id' => '', 'role' => Role::APP_ADMIN)));
$this->assertEquals(6, $u->create(array('username' => 'user #5', 'gitlab_id' => '1234')));
$this->assertFalse($u->create(array('username' => 'user #1')));
@@ -283,7 +250,7 @@ class UserTest extends Base
$this->assertTrue(is_array($user));
$this->assertEquals('admin', $user['username']);
$this->assertEquals('', $user['name']);
- $this->assertEquals(1, $user['is_admin']);
+ $this->assertEquals(Role::APP_ADMIN, $user['role']);
$this->assertEquals(0, $user['is_ldap_user']);
$user = $u->getById(2);
@@ -291,7 +258,7 @@ class UserTest extends Base
$this->assertTrue(is_array($user));
$this->assertEquals('user #1', $user['username']);
$this->assertEquals('User', $user['name']);
- $this->assertEquals(0, $user['is_admin']);
+ $this->assertEquals(Role::APP_USER, $user['role']);
$this->assertEquals(0, $user['is_ldap_user']);
$user = $u->getById(3);
@@ -299,27 +266,28 @@ class UserTest extends Base
$this->assertTrue(is_array($user));
$this->assertEquals('user #2', $user['username']);
$this->assertEquals('', $user['name']);
- $this->assertEquals(0, $user['is_admin']);
+ $this->assertEquals(Role::APP_USER, $user['role']);
$this->assertEquals(1, $user['is_ldap_user']);
$user = $u->getById(4);
$this->assertNotFalse($user);
$this->assertTrue(is_array($user));
$this->assertEquals('user #3', $user['username']);
- $this->assertEquals(0, $user['is_admin']);
- $this->assertEquals(1, $user['is_project_admin']);
+ $this->assertEquals(Role::APP_MANAGER, $user['role']);
$user = $u->getById(5);
$this->assertNotFalse($user);
$this->assertTrue(is_array($user));
$this->assertEquals('user #4', $user['username']);
$this->assertEquals('', $user['gitlab_id']);
+ $this->assertEquals(Role::APP_ADMIN, $user['role']);
$user = $u->getById(6);
$this->assertNotFalse($user);
$this->assertTrue(is_array($user));
$this->assertEquals('user #5', $user['username']);
$this->assertEquals('1234', $user['gitlab_id']);
+ $this->assertEquals(Role::APP_USER, $user['role']);
}
public function testUpdate()
@@ -336,7 +304,7 @@ class UserTest extends Base
$this->assertTrue(is_array($user));
$this->assertEquals('biloute', $user['username']);
$this->assertEquals('Toto', $user['name']);
- $this->assertEquals(0, $user['is_admin']);
+ $this->assertEquals(Role::APP_USER, $user['role']);
$this->assertEquals(0, $user['is_ldap_user']);
$user = $u->getById(3);
@@ -423,4 +391,36 @@ class UserTest extends Base
$this->assertEquals('toto', $user['username']);
$this->assertEmpty($user['token']);
}
+
+ public function testValidatePasswordModification()
+ {
+ $u = new User($this->container);
+
+ $this->container['sessionStorage']->user = array(
+ 'id' => 1,
+ 'role' => Role::APP_ADMIN,
+ 'username' => 'admin',
+ );
+
+ $result = $u->validatePasswordModification(array());
+ $this->assertFalse($result[0]);
+
+ $result = $u->validatePasswordModification(array('id' => 1));
+ $this->assertFalse($result[0]);
+
+ $result = $u->validatePasswordModification(array('id' => 1, 'password' => '123456'));
+ $this->assertFalse($result[0]);
+
+ $result = $u->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => 'wrong'));
+ $this->assertFalse($result[0]);
+
+ $result = $u->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => '123456'));
+ $this->assertFalse($result[0]);
+
+ $result = $u->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => '123456', 'current_password' => 'wrong'));
+ $this->assertFalse($result[0]);
+
+ $result = $u->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => '123456', 'current_password' => 'admin'));
+ $this->assertTrue($result[0]);
+ }
}