summaryrefslogtreecommitdiff
path: root/tests/units
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-09-08 22:33:16 -0400
committerFrederic Guillot <fred@kanboard.net>2016-09-08 22:33:16 -0400
commit75470c72428c8d8f278d160369558ab31b137fb1 (patch)
tree7fcad6cbc661e2762f1dfa5f643a5beac5217a17 /tests/units
parentfedf4ea2de21fcf95fc5aa942cedc7924865f160 (diff)
Apply column restrictions to the board
Diffstat (limited to 'tests/units')
-rw-r--r--tests/units/Formatter/BoardFormatterTest.php1
-rw-r--r--tests/units/Helper/BoardHelperTest.php94
2 files changed, 95 insertions, 0 deletions
diff --git a/tests/units/Formatter/BoardFormatterTest.php b/tests/units/Formatter/BoardFormatterTest.php
index 0be1be94..4d469eac 100644
--- a/tests/units/Formatter/BoardFormatterTest.php
+++ b/tests/units/Formatter/BoardFormatterTest.php
@@ -123,6 +123,7 @@ class BoardFormatterTest extends Base
$this->assertSame(0, $board[2]['columns'][3]['nb_tasks']);
$this->assertEquals('Task 8', $board[2]['columns'][2]['tasks'][0]['title']);
+ $this->assertArrayHasKey('is_draggable', $board[2]['columns'][2]['tasks'][0]);
}
public function testFormatWithoutDefaultSwimlane()
diff --git a/tests/units/Helper/BoardHelperTest.php b/tests/units/Helper/BoardHelperTest.php
new file mode 100644
index 00000000..641ca9cb
--- /dev/null
+++ b/tests/units/Helper/BoardHelperTest.php
@@ -0,0 +1,94 @@
+<?php
+
+use Kanboard\Core\Security\Role;
+use Kanboard\Helper\BoardHelper;
+use Kanboard\Model\ColumnMoveRestrictionModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\ProjectRoleModel;
+use Kanboard\Model\ProjectUserRoleModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskStatusModel;
+use Kanboard\Model\UserModel;
+
+require_once __DIR__.'/../Base.php';
+
+class BoardHelperTest extends Base
+{
+ public function testIsDraggableWithProjectMember()
+ {
+ $boardHelper = new BoardHelper($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($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->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertTrue($boardHelper->isDraggable($task));
+ }
+
+ public function testIsDraggableWithClosedTask()
+ {
+ $boardHelper = new BoardHelper($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $taskStatusModel = new TaskStatusModel($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->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertTrue($taskStatusModel->close(1));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertFalse($boardHelper->isDraggable($task));
+ }
+
+ public function testIsDraggableWithColumnRestrictions()
+ {
+ $boardHelper = new BoardHelper($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectUserRole = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+ $columnMoveRestrictionModel = new ColumnMoveRestrictionModel($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->assertEquals(1, $columnMoveRestrictionModel->create(1, 1, 2, 3));
+
+ $this->assertTrue($projectUserRole->addUser(1, 2, 'Custom Role'));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertFalse($boardHelper->isDraggable($task));
+ }
+}