summaryrefslogtreecommitdiff
path: root/tests/units/Model
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units/Model')
-rw-r--r--tests/units/Model/ProjectGroupRoleTest.php38
-rw-r--r--tests/units/Model/ProjectPermissionTest.php22
-rw-r--r--tests/units/Model/ProjectUserRoleTest.php61
-rw-r--r--tests/units/Model/UserTest.php27
4 files changed, 145 insertions, 3 deletions
diff --git a/tests/units/Model/ProjectGroupRoleTest.php b/tests/units/Model/ProjectGroupRoleTest.php
index 29a9536b..e38e812a 100644
--- a/tests/units/Model/ProjectGroupRoleTest.php
+++ b/tests/units/Model/ProjectGroupRoleTest.php
@@ -204,6 +204,44 @@ class ProjectGroupRoleTest extends Base
$this->assertEquals('', $users[1]['name']);
}
+ public function testGetAssignableUsersWithDisabledUsers()
+ {
+ $userModel = new User($this->container);
+ $projectModel = new Project($this->container);
+ $groupModel = new Group($this->container);
+ $groupMemberModel = new GroupMember($this->container);
+ $groupRoleModel = new ProjectGroupRole($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2')));
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user 1', 'name' => 'User #1')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'user 2', 'is_active' => 0)));
+ $this->assertEquals(4, $userModel->create(array('username' => 'user 3')));
+
+ $this->assertEquals(1, $groupModel->create('Group A'));
+ $this->assertEquals(2, $groupModel->create('Group B'));
+ $this->assertEquals(3, $groupModel->create('Group C'));
+
+ $this->assertTrue($groupMemberModel->addUser(1, 4));
+ $this->assertTrue($groupMemberModel->addUser(2, 3));
+ $this->assertTrue($groupMemberModel->addUser(3, 2));
+
+ $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_VIEWER));
+ $this->assertTrue($groupRoleModel->addGroup(1, 2, Role::PROJECT_MEMBER));
+ $this->assertTrue($groupRoleModel->addGroup(1, 3, Role::PROJECT_MANAGER));
+
+ $users = $groupRoleModel->getAssignableUsers(2);
+ $this->assertCount(0, $users);
+
+ $users = $groupRoleModel->getAssignableUsers(1);
+ $this->assertCount(1, $users);
+
+ $this->assertEquals(2, $users[0]['id']);
+ $this->assertEquals('user 1', $users[0]['username']);
+ $this->assertEquals('User #1', $users[0]['name']);
+ }
+
public function testGetProjectsByUser()
{
$userModel = new User($this->container);
diff --git a/tests/units/Model/ProjectPermissionTest.php b/tests/units/Model/ProjectPermissionTest.php
index 035a1246..10fcdcc2 100644
--- a/tests/units/Model/ProjectPermissionTest.php
+++ b/tests/units/Model/ProjectPermissionTest.php
@@ -192,6 +192,28 @@ class ProjectPermissionTest extends Base
$this->assertFalse($projectPermission->isAssignable(2, 5));
}
+ public function testIsAssignableWhenUserIsDisabled()
+ {
+ $userModel = new User($this->container);
+ $projectModel = new Project($this->container);
+ $groupModel = new Group($this->container);
+ $groupRoleModel = new ProjectGroupRole($this->container);
+ $groupMemberModel = new GroupMember($this->container);
+ $userRoleModel = new ProjectUserRole($this->container);
+ $projectPermission = new ProjectPermission($this->container);
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user 1')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'user 2', 'is_active' => 0)));
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1')));
+
+ $this->assertTrue($userRoleModel->addUser(1, 2, Role::PROJECT_MEMBER));
+ $this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_MEMBER));
+
+ $this->assertTrue($projectPermission->isAssignable(1, 2));
+ $this->assertFalse($projectPermission->isAssignable(1, 3));
+ }
+
public function testIsMember()
{
$userModel = new User($this->container);
diff --git a/tests/units/Model/ProjectUserRoleTest.php b/tests/units/Model/ProjectUserRoleTest.php
index c6b4eb7c..06cd1b70 100644
--- a/tests/units/Model/ProjectUserRoleTest.php
+++ b/tests/units/Model/ProjectUserRoleTest.php
@@ -8,6 +8,7 @@ use Kanboard\Model\Group;
use Kanboard\Model\GroupMember;
use Kanboard\Model\ProjectGroupRole;
use Kanboard\Model\ProjectUserRole;
+use Kanboard\Model\ProjectPermission;
use Kanboard\Core\Security\Role;
class ProjectUserRoleTest extends Base
@@ -100,6 +101,36 @@ class ProjectUserRoleTest extends Base
$this->assertEquals('', $userRoleModel->getUserRole(1, 2));
}
+ public function testGetAssignableUsersWithDisabledUsers()
+ {
+ $projectModel = new Project($this->container);
+ $userModel = new User($this->container);
+ $userRoleModel = new ProjectUserRole($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User1')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User2')));
+
+ $this->assertTrue($userRoleModel->addUser(1, 1, Role::PROJECT_MEMBER));
+ $this->assertTrue($userRoleModel->addUser(1, 2, Role::PROJECT_MEMBER));
+ $this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_MEMBER));
+
+ $users = $userRoleModel->getAssignableUsers(1);
+ $this->assertCount(3, $users);
+
+ $this->assertEquals('admin', $users[1]);
+ $this->assertEquals('User1', $users[2]);
+ $this->assertEquals('User2', $users[3]);
+
+ $this->assertTrue($userModel->disable(2));
+
+ $users = $userRoleModel->getAssignableUsers(1);
+ $this->assertCount(2, $users);
+
+ $this->assertEquals('admin', $users[1]);
+ $this->assertEquals('User2', $users[3]);
+ }
+
public function testGetAssignableUsersWithoutGroups()
{
$projectModel = new Project($this->container);
@@ -219,6 +250,36 @@ class ProjectUserRoleTest extends Base
$this->assertEquals('User4', $users[5]);
}
+ public function testGetAssignableUsersWithDisabledUsersAndEverybodyAllowed()
+ {
+ $projectModel = new Project($this->container);
+ $projectPermission = new ProjectPermission($this->container);
+ $userModel = new User($this->container);
+ $userRoleModel = new ProjectUserRole($this->container);
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User1')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User2')));
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1', 'is_everybody_allowed' => 1)));
+
+ $this->assertTrue($projectPermission->isEverybodyAllowed(1));
+
+ $users = $userRoleModel->getAssignableUsers(1);
+ $this->assertCount(3, $users);
+
+ $this->assertEquals('admin', $users[1]);
+ $this->assertEquals('User1', $users[2]);
+ $this->assertEquals('User2', $users[3]);
+
+ $this->assertTrue($userModel->disable(2));
+
+ $users = $userRoleModel->getAssignableUsers(1);
+ $this->assertCount(2, $users);
+
+ $this->assertEquals('admin', $users[1]);
+ $this->assertEquals('User2', $users[3]);
+ }
+
public function testGetProjectsByUser()
{
$userModel = new User($this->container);
diff --git a/tests/units/Model/UserTest.php b/tests/units/Model/UserTest.php
index 0987fa56..e411da0c 100644
--- a/tests/units/Model/UserTest.php
+++ b/tests/units/Model/UserTest.php
@@ -96,13 +96,14 @@ class UserTest extends Base
$this->assertEquals('you', $users[2]['username']);
}
- public function testGetList()
+ public function testGetActiveUsersList()
{
$u = new User($this->container);
$this->assertEquals(2, $u->create(array('username' => 'you')));
$this->assertEquals(3, $u->create(array('username' => 'me', 'name' => 'Me too')));
+ $this->assertEquals(4, $u->create(array('username' => 'foobar', 'is_active' => 0)));
- $users = $u->getList();
+ $users = $u->getActiveUsersList();
$expected = array(
1 => 'admin',
@@ -112,7 +113,7 @@ class UserTest extends Base
$this->assertEquals($expected, $users);
- $users = $u->getList(true);
+ $users = $u->getActiveUsersList(true);
$expected = array(
User::EVERYBODY_ID => 'Everybody',
@@ -391,4 +392,24 @@ class UserTest extends Base
$this->assertEquals('toto', $user['username']);
$this->assertEmpty($user['token']);
}
+
+ public function testEnableDisable()
+ {
+ $userModel = new User($this->container);
+ $this->assertEquals(2, $userModel->create(array('username' => 'toto')));
+
+ $this->assertTrue($userModel->isActive(2));
+ $user = $userModel->getById(2);
+ $this->assertEquals(1, $user['is_active']);
+
+ $this->assertTrue($userModel->disable(2));
+ $user = $userModel->getById(2);
+ $this->assertEquals(0, $user['is_active']);
+ $this->assertFalse($userModel->isActive(2));
+
+ $this->assertTrue($userModel->enable(2));
+ $user = $userModel->getById(2);
+ $this->assertEquals(1, $user['is_active']);
+ $this->assertTrue($userModel->isActive(2));
+ }
}