diff options
Diffstat (limited to 'tests/units')
-rw-r--r-- | tests/units/Core/Security/AccessMapTest.php | 14 | ||||
-rw-r--r-- | tests/units/Model/ProjectGroupRoleTest.php | 23 |
2 files changed, 37 insertions, 0 deletions
diff --git a/tests/units/Core/Security/AccessMapTest.php b/tests/units/Core/Security/AccessMapTest.php index 61693ce8..ae8044c9 100644 --- a/tests/units/Core/Security/AccessMapTest.php +++ b/tests/units/Core/Security/AccessMapTest.php @@ -17,6 +17,20 @@ class AccessMapTest extends Base $this->assertEquals(array('user', 'admin', 'manager'), $acl->getRoleHierarchy('user')); } + public function testGetHighestRole() + { + $acl = new AccessMap; + $acl->setRoleHierarchy('manager', array('member', 'viewer')); + $acl->setRoleHierarchy('member', array('viewer')); + + $this->assertEquals('manager', $acl->getHighestRole(array('viewer', 'manager', 'member'))); + $this->assertEquals('manager', $acl->getHighestRole(array('viewer', 'manager'))); + $this->assertEquals('manager', $acl->getHighestRole(array('manager', 'member'))); + $this->assertEquals('member', $acl->getHighestRole(array('viewer', 'member'))); + $this->assertEquals('member', $acl->getHighestRole(array('member'))); + $this->assertEquals('viewer', $acl->getHighestRole(array('viewer'))); + } + public function testAddRulesAndGetRoles() { $acl = new AccessMap; diff --git a/tests/units/Model/ProjectGroupRoleTest.php b/tests/units/Model/ProjectGroupRoleTest.php index 52b83082..29a9536b 100644 --- a/tests/units/Model/ProjectGroupRoleTest.php +++ b/tests/units/Model/ProjectGroupRoleTest.php @@ -337,4 +337,27 @@ class ProjectGroupRoleTest extends Base $projects = $groupRoleModel->getProjectsByUser(5, array(Project::INACTIVE)); $this->assertCount(0, $projects); } + + public function testUserInMultipleGroupsShouldReturnHighestRole() + { + $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); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(2, $userModel->create(array('username' => 'My user'))); + + $this->assertEquals(1, $groupModel->create('Group A')); + $this->assertEquals(2, $groupModel->create('Group B')); + + $this->assertTrue($groupMemberModel->addUser(1, 1)); + $this->assertTrue($groupMemberModel->addUser(2, 1)); + + $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_MEMBER)); + $this->assertTrue($groupRoleModel->addGroup(1, 2, Role::PROJECT_MANAGER)); + + $this->assertEquals(Role::PROJECT_MANAGER, $groupRoleModel->getUserRole(1, 1)); + } } |