summaryrefslogtreecommitdiff
path: root/tests/units/Helper
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-09-18 21:19:48 -0400
committerFrederic Guillot <fred@kanboard.net>2016-09-18 21:19:48 -0400
commit3043163747b13ce1942b2e55977cf7c5417021de (patch)
tree31552d8bfdf3b7a6eedfaded116b863e980f86b4 /tests/units/Helper
parent4bc83646b0b15bff9ae55083121f66b7a89e433d (diff)
Add column restrictions to custom project roles
Diffstat (limited to 'tests/units/Helper')
-rw-r--r--tests/units/Helper/ProjectRoleHelperTest.php178
1 files changed, 178 insertions, 0 deletions
diff --git a/tests/units/Helper/ProjectRoleHelperTest.php b/tests/units/Helper/ProjectRoleHelperTest.php
index cae22d71..4583d58e 100644
--- a/tests/units/Helper/ProjectRoleHelperTest.php
+++ b/tests/units/Helper/ProjectRoleHelperTest.php
@@ -4,8 +4,10 @@ use Kanboard\Core\Security\Role;
use Kanboard\Core\User\UserSession;
use Kanboard\Helper\ProjectRoleHelper;
use Kanboard\Model\ColumnMoveRestrictionModel;
+use Kanboard\Model\ColumnRestrictionModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\ProjectRoleModel;
+use Kanboard\Model\ProjectRoleRestrictionModel;
use Kanboard\Model\ProjectUserRoleModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
@@ -16,6 +18,182 @@ require_once __DIR__.'/../Base.php';
class ProjectRoleHelperTest extends Base
{
+ public function testCanCreateTaskInColumnWithProjectViewer()
+ {
+ $projectRoleHelper = new ProjectRoleHelper($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRole = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($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->assertTrue($projectUserRole->addUser(1, 2, Role::PROJECT_VIEWER));
+
+ $this->assertFalse($projectRoleHelper->canCreateTaskInColumn(1, 1));
+ }
+
+ public function testCanCreateTaskInColumnWithProjectMember()
+ {
+ $projectRoleHelper = new ProjectRoleHelper($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRole = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($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->assertTrue($projectUserRole->addUser(1, 2, Role::PROJECT_MEMBER));
+
+ $this->assertTrue($projectRoleHelper->canCreateTaskInColumn(1, 1));
+ }
+
+ public function testCanCreateTaskInColumnWithCustomProjectRole()
+ {
+ $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);
+
+ $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, $projectRoleModel->create(1, 'Custom Role'));
+ $this->assertTrue($projectUserRole->addUser(1, 2, 'Custom Role'));
+
+ $this->assertTrue($projectRoleHelper->canCreateTaskInColumn(1, 1));
+ }
+
+ public function testCanCreateTaskInColumnWithCustomProjectRoleAndRestrictions()
+ {
+ $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);
+ $projectRoleRestrictionModel = new ProjectRoleRestrictionModel($this->container);
+ $columnRestrictionModel = new ColumnRestrictionModel($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, $projectRoleModel->create(1, 'Custom Role'));
+ $this->assertTrue($projectUserRole->addUser(1, 2, 'Custom Role'));
+
+ $this->assertEquals(1, $projectRoleRestrictionModel->create(1, 1, ProjectRoleRestrictionModel::RULE_TASK_CREATION));
+ $this->assertEquals(1, $columnRestrictionModel->create(1, 1, 1, ColumnRestrictionModel::RULE_ALLOW_TASK_CREATION));
+
+ $this->assertTrue($projectRoleHelper->canCreateTaskInColumn(1, 1));
+ $this->assertFalse($projectRoleHelper->canCreateTaskInColumn(1, 2));
+ }
+
+ public function testCanChangeTaskStatusInColumnWithProjectViewer()
+ {
+ $projectRoleHelper = new ProjectRoleHelper($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRole = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($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->assertTrue($projectUserRole->addUser(1, 2, Role::PROJECT_VIEWER));
+
+ $this->assertFalse($projectRoleHelper->canChangeTaskStatusInColumn(1, 1));
+ }
+
+ public function testCanChangeTaskStatusInColumnWithProjectMember()
+ {
+ $projectRoleHelper = new ProjectRoleHelper($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRole = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($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->assertTrue($projectUserRole->addUser(1, 2, Role::PROJECT_MEMBER));
+
+ $this->assertTrue($projectRoleHelper->canChangeTaskStatusInColumn(1, 1));
+ }
+
+ public function testCanChangeTaskStatusInColumnWithCustomProjectRole()
+ {
+ $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);
+
+ $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, $projectRoleModel->create(1, 'Custom Role'));
+ $this->assertTrue($projectUserRole->addUser(1, 2, 'Custom Role'));
+
+ $this->assertTrue($projectRoleHelper->canChangeTaskStatusInColumn(1, 1));
+ }
+
+ public function testCanChangeTaskStatusInColumnWithCustomProjectRoleAndRestrictions()
+ {
+ $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);
+ $projectRoleRestrictionModel = new ProjectRoleRestrictionModel($this->container);
+ $columnRestrictionModel = new ColumnRestrictionModel($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, $projectRoleModel->create(1, 'Custom Role'));
+ $this->assertTrue($projectUserRole->addUser(1, 2, 'Custom Role'));
+
+ $this->assertEquals(1, $projectRoleRestrictionModel->create(1, 1, ProjectRoleRestrictionModel::RULE_TASK_OPEN_CLOSE));
+ $this->assertEquals(1, $columnRestrictionModel->create(1, 1, 1, ColumnRestrictionModel::RULE_ALLOW_TASK_OPEN_CLOSE));
+
+ $this->assertTrue($projectRoleHelper->canChangeTaskStatusInColumn(1, 1));
+ $this->assertFalse($projectRoleHelper->canChangeTaskStatusInColumn(1, 2));
+ }
+
public function testIsDraggableWithProjectMember()
{
$projectRoleHelper = new ProjectRoleHelper($this->container);