summaryrefslogtreecommitdiff
path: root/tests/units
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2017-04-05 19:16:04 -0400
committerFrederic Guillot <fred@kanboard.net>2017-04-05 19:16:04 -0400
commit66c8351ad4ce843d791a802374f1eb2b395a45e1 (patch)
treed66a460871560b295b5b33bcee4359631a0a2b45 /tests/units
parent947f4bbc07547b13eab97bba72a767646f28dcfe (diff)
Add new project role restriction to block task suppression
Diffstat (limited to 'tests/units')
-rw-r--r--tests/units/Helper/ProjectRoleHelperTest.php55
-rw-r--r--tests/units/Model/ProjectRoleRestrictionModelTest.php2
2 files changed, 56 insertions, 1 deletions
diff --git a/tests/units/Helper/ProjectRoleHelperTest.php b/tests/units/Helper/ProjectRoleHelperTest.php
index eb9b320c..6f6c9bde 100644
--- a/tests/units/Helper/ProjectRoleHelperTest.php
+++ b/tests/units/Helper/ProjectRoleHelperTest.php
@@ -106,6 +106,61 @@ class ProjectRoleHelperTest extends Base
$this->assertFalse($projectRoleHelper->canCreateTaskInColumn(1, 2));
}
+ public function testCanRemoveTaskWithCustomProjectRole()
+ {
+ $projectRoleHelper = new ProjectRoleHelper($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRole = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectRoleRestrictionModel = new ProjectRoleRestrictionModel($this->container);
+
+ $this->container['sessionStorage']->user = array(
+ 'id' => 2,
+ 'role' => Role::APP_USER,
+ );
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1 , 'title' => 'test')));
+
+ $this->assertEquals(1, $projectRoleModel->create(1, 'Custom Role'));
+ $this->assertTrue($projectUserRole->addUser(1, 2, 'Custom Role'));
+
+ $this->assertEquals(1, $projectRoleRestrictionModel->create(1, 1, ProjectRoleRestrictionModel::RULE_TASK_SUPPRESSION));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertFalse($projectRoleHelper->canRemoveTask($task));
+ }
+
+ public function testCanRemoveTaskWithCustomProjectRoleWithRestriction()
+ {
+ $projectRoleHelper = new ProjectRoleHelper($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRole = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->container['sessionStorage']->user = array(
+ 'id' => 2,
+ 'role' => Role::APP_USER,
+ );
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1 , 'title' => 'test')));
+
+ $this->assertEquals(1, $projectRoleModel->create(1, 'Custom Role'));
+ $this->assertTrue($projectUserRole->addUser(1, 2, 'Custom Role'));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertTrue($projectRoleHelper->canRemoveTask($task));
+ }
+
public function testCanChangeTaskStatusInColumnWithProjectViewer()
{
$projectRoleHelper = new ProjectRoleHelper($this->container);
diff --git a/tests/units/Model/ProjectRoleRestrictionModelTest.php b/tests/units/Model/ProjectRoleRestrictionModelTest.php
index af0f9bf9..e18d2374 100644
--- a/tests/units/Model/ProjectRoleRestrictionModelTest.php
+++ b/tests/units/Model/ProjectRoleRestrictionModelTest.php
@@ -90,7 +90,7 @@ class ProjectRoleRestrictionModelTest extends Base
$projectRoleRestrictionModel = new ProjectRoleRestrictionModel($this->container);
$rules = $projectRoleRestrictionModel->getRules();
- $this->assertCount(3, $rules);
+ $this->assertCount(4, $rules);
$this->assertArrayHasKey(ProjectRoleRestrictionModel::RULE_TASK_OPEN_CLOSE, $rules);
}
}