summaryrefslogtreecommitdiff
path: root/tests/units/Model/ProjectPermissionTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units/Model/ProjectPermissionTest.php')
-rw-r--r--tests/units/Model/ProjectPermissionTest.php66
1 files changed, 65 insertions, 1 deletions
diff --git a/tests/units/Model/ProjectPermissionTest.php b/tests/units/Model/ProjectPermissionTest.php
index 77419bec..035a1246 100644
--- a/tests/units/Model/ProjectPermissionTest.php
+++ b/tests/units/Model/ProjectPermissionTest.php
@@ -13,6 +13,33 @@ use Kanboard\Core\Security\Role;
class ProjectPermissionTest extends Base
{
+ public function testFindByUsernames()
+ {
+ $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);
+ $userRoleModel = new ProjectUserRole($this->container);
+ $projectPermissionModel = new ProjectPermission($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1')));
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'user2')));
+ $this->assertEquals(4, $userModel->create(array('username' => 'user3')));
+
+ $this->assertEquals(1, $groupModel->create('Group A'));
+ $this->assertTrue($groupMemberModel->addUser(1, 2));
+
+ $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_MEMBER));
+ $this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_MANAGER));
+
+ $this->assertEquals(array('user1', 'user2'), $projectPermissionModel->findUsernames(1, 'us'));
+ $this->assertEmpty($projectPermissionModel->findUsernames(1, 'a'));
+ $this->assertEmpty($projectPermissionModel->findUsernames(2, 'user'));
+ }
+
public function testGetQueryByRole()
{
$userModel = new User($this->container);
@@ -128,6 +155,43 @@ class ProjectPermissionTest extends Base
$this->assertFalse($projectPermission->isUserAllowed(2, 5));
}
+ public function testIsAssignable()
+ {
+ $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')));
+ $this->assertEquals(4, $userModel->create(array('username' => 'user 3')));
+ $this->assertEquals(5, $userModel->create(array('username' => 'user 4')));
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2')));
+
+ $this->assertEquals(1, $groupModel->create('Group A'));
+
+ $this->assertTrue($groupMemberModel->addUser(1, 2));
+ $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_VIEWER));
+
+ $this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_MEMBER));
+ $this->assertTrue($userRoleModel->addUser(1, 4, Role::PROJECT_MANAGER));
+
+ $this->assertFalse($projectPermission->isAssignable(1, 2));
+ $this->assertTrue($projectPermission->isAssignable(1, 3));
+ $this->assertTrue($projectPermission->isAssignable(1, 4));
+ $this->assertFalse($projectPermission->isAssignable(1, 5));
+
+ $this->assertFalse($projectPermission->isAssignable(2, 2));
+ $this->assertFalse($projectPermission->isAssignable(2, 3));
+ $this->assertFalse($projectPermission->isAssignable(2, 4));
+ $this->assertFalse($projectPermission->isAssignable(2, 5));
+ }
+
public function testIsMember()
{
$userModel = new User($this->container);
@@ -154,7 +218,7 @@ class ProjectPermissionTest extends Base
$this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_MEMBER));
$this->assertTrue($userRoleModel->addUser(1, 4, Role::PROJECT_MANAGER));
- $this->assertFalse($projectPermission->isMember(1, 2));
+ $this->assertTrue($projectPermission->isMember(1, 2));
$this->assertTrue($projectPermission->isMember(1, 3));
$this->assertTrue($projectPermission->isMember(1, 4));
$this->assertFalse($projectPermission->isMember(1, 5));