summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/units/Model/ProjectPermissionTest.php111
1 files changed, 111 insertions, 0 deletions
diff --git a/tests/units/Model/ProjectPermissionTest.php b/tests/units/Model/ProjectPermissionTest.php
index 0f5996b5..77419bec 100644
--- a/tests/units/Model/ProjectPermissionTest.php
+++ b/tests/units/Model/ProjectPermissionTest.php
@@ -79,6 +79,117 @@ class ProjectPermissionTest extends Base
$this->assertEquals('Project 3', $users[0]['project_name']);
}
+ public function testEverybodyAllowed()
+ {
+ $projectModel = new Project($this->container);
+ $projectPermission = new ProjectPermission($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2', 'is_everybody_allowed' => 1)));
+
+ $this->assertFalse($projectPermission->isEverybodyAllowed(1));
+ $this->assertTrue($projectPermission->isEverybodyAllowed(2));
+ }
+
+ public function testIsUserAllowed()
+ {
+ $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->assertTrue($projectPermission->isUserAllowed(1, 2));
+ $this->assertTrue($projectPermission->isUserAllowed(1, 3));
+ $this->assertTrue($projectPermission->isUserAllowed(1, 4));
+ $this->assertFalse($projectPermission->isUserAllowed(1, 5));
+
+ $this->assertFalse($projectPermission->isUserAllowed(2, 2));
+ $this->assertFalse($projectPermission->isUserAllowed(2, 3));
+ $this->assertFalse($projectPermission->isUserAllowed(2, 4));
+ $this->assertFalse($projectPermission->isUserAllowed(2, 5));
+ }
+
+ public function testIsMember()
+ {
+ $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->isMember(1, 2));
+ $this->assertTrue($projectPermission->isMember(1, 3));
+ $this->assertTrue($projectPermission->isMember(1, 4));
+ $this->assertFalse($projectPermission->isMember(1, 5));
+
+ $this->assertFalse($projectPermission->isMember(2, 2));
+ $this->assertFalse($projectPermission->isMember(2, 3));
+ $this->assertFalse($projectPermission->isMember(2, 4));
+ $this->assertFalse($projectPermission->isMember(2, 5));
+ }
+
+ public function testGetActiveProjectIds()
+ {
+ $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(1, $projectModel->create(array('name' => 'Project 1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2', 'is_active' => 0)));
+
+ $this->assertTrue($userRoleModel->addUser(1, 2, Role::PROJECT_MEMBER));
+ $this->assertTrue($userRoleModel->addUser(2, 2, Role::PROJECT_VIEWER));
+ $this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_VIEWER));
+
+ $this->assertEmpty($projectPermission->getActiveProjectIds(1));
+ $this->assertEquals(array(1), $projectPermission->getActiveProjectIds(2));
+ $this->assertEquals(array(1), $projectPermission->getActiveProjectIds(3));
+ }
+
public function testDuplicate()
{
$userModel = new User($this->container);