diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-09-11 16:08:03 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-09-11 16:08:03 -0400 |
commit | d8f6d8568396816a6bfaca1e01211384e803cf91 (patch) | |
tree | 16d735faa3f6f9aafb6c78650470e77347cae1ab /tests | |
parent | a0227cad69aff9486fba1d7b2a19e6da97450100 (diff) |
Add project restrictions for custom roles
Diffstat (limited to 'tests')
-rw-r--r-- | tests/units/Helper/BoardHelperTest.php | 98 | ||||
-rw-r--r-- | tests/units/Helper/ProjectRoleHelperTest.php | 189 | ||||
-rw-r--r-- | tests/units/Helper/UserHelperTest.php | 90 |
3 files changed, 189 insertions, 188 deletions
diff --git a/tests/units/Helper/BoardHelperTest.php b/tests/units/Helper/BoardHelperTest.php deleted file mode 100644 index 0a44f8ab..00000000 --- a/tests/units/Helper/BoardHelperTest.php +++ /dev/null @@ -1,98 +0,0 @@ -<?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))); - $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 3))); - - $task = $taskFinderModel->getById(1); - $this->assertTrue($boardHelper->isDraggable($task)); - - $task = $taskFinderModel->getById(2); - $this->assertFalse($boardHelper->isDraggable($task)); - } -} diff --git a/tests/units/Helper/ProjectRoleHelperTest.php b/tests/units/Helper/ProjectRoleHelperTest.php new file mode 100644 index 00000000..cae22d71 --- /dev/null +++ b/tests/units/Helper/ProjectRoleHelperTest.php @@ -0,0 +1,189 @@ +<?php + +use Kanboard\Core\Security\Role; +use Kanboard\Core\User\UserSession; +use Kanboard\Helper\ProjectRoleHelper; +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 ProjectRoleHelperTest extends Base +{ + public function testIsDraggableWithProjectMember() + { + $projectRoleHelper = new ProjectRoleHelper($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($projectRoleHelper->isDraggable($task)); + } + + public function testIsDraggableWithClosedTask() + { + $projectRoleHelper = new ProjectRoleHelper($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($projectRoleHelper->isDraggable($task)); + } + + public function testIsDraggableWithColumnRestrictions() + { + $projectRoleHelper = new ProjectRoleHelper($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))); + $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 3))); + + $task = $taskFinderModel->getById(1); + $this->assertTrue($projectRoleHelper->isDraggable($task)); + + $task = $taskFinderModel->getById(2); + $this->assertFalse($projectRoleHelper->isDraggable($task)); + } + + public function testCanRemoveTask() + { + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectRoleHelper = new ProjectRoleHelper($this->container); + $projectModel = new ProjectModel($this->container); + $userModel = new UserModel($this->container); + $userSessionModel = new UserSession($this->container); + + $this->assertNotFalse($userModel->create(array('username' => 'toto', 'password' => '123456'))); + $this->assertNotFalse($userModel->create(array('username' => 'toto2', 'password' => '123456'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'TaskViewController #1', 'project_id' => 1, 'creator_id' => 1))); + $this->assertEquals(2, $taskCreationModel->create(array('title' => 'TaskViewController #2', 'project_id' => 1, 'creator_id' => 2))); + $this->assertEquals(3, $taskCreationModel->create(array('title' => 'TaskViewController #3', 'project_id' => 1, 'creator_id' => 3))); + $this->assertEquals(4, $taskCreationModel->create(array('title' => 'TaskViewController #4', 'project_id' => 1))); + + // User #1 can remove everything + $user = $userModel->getById(1); + $this->assertNotEmpty($user); + $userSessionModel->initialize($user); + + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertTrue($projectRoleHelper->canRemoveTask($task)); + + // User #2 can't remove the TaskViewController #1 + $user = $userModel->getById(2); + $this->assertNotEmpty($user); + $userSessionModel->initialize($user); + + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertFalse($projectRoleHelper->canRemoveTask($task)); + + // User #1 can remove everything + $user = $userModel->getById(1); + $this->assertNotEmpty($user); + $userSessionModel->initialize($user); + + $task = $taskFinderModel->getById(2); + $this->assertNotEmpty($task); + $this->assertTrue($projectRoleHelper->canRemoveTask($task)); + + // User #2 can remove his own TaskViewController + $user = $userModel->getById(2); + $this->assertNotEmpty($user); + $userSessionModel->initialize($user); + + $task = $taskFinderModel->getById(2); + $this->assertNotEmpty($task); + $this->assertTrue($projectRoleHelper->canRemoveTask($task)); + + // User #1 can remove everything + $user = $userModel->getById(1); + $this->assertNotEmpty($user); + $userSessionModel->initialize($user); + + $task = $taskFinderModel->getById(3); + $this->assertNotEmpty($task); + $this->assertTrue($projectRoleHelper->canRemoveTask($task)); + + // User #2 can't remove the TaskViewController #3 + $user = $userModel->getById(2); + $this->assertNotEmpty($user); + $userSessionModel->initialize($user); + + $task = $taskFinderModel->getById(3); + $this->assertNotEmpty($task); + $this->assertFalse($projectRoleHelper->canRemoveTask($task)); + + // User #1 can remove everything + $user = $userModel->getById(1); + $this->assertNotEmpty($user); + $userSessionModel->initialize($user); + + $task = $taskFinderModel->getById(4); + $this->assertNotEmpty($task); + $this->assertTrue($projectRoleHelper->canRemoveTask($task)); + + // User #2 can't remove the TaskViewController #4 + $user = $userModel->getById(2); + $this->assertNotEmpty($user); + $userSessionModel->initialize($user); + + $task = $taskFinderModel->getById(4); + $this->assertNotEmpty($task); + $this->assertFalse($projectRoleHelper->canRemoveTask($task)); + } +} diff --git a/tests/units/Helper/UserHelperTest.php b/tests/units/Helper/UserHelperTest.php index ed34c990..b66acdba 100644 --- a/tests/units/Helper/UserHelperTest.php +++ b/tests/units/Helper/UserHelperTest.php @@ -294,94 +294,4 @@ class UserHelperTest extends Base $this->assertFalse($helper->hasProjectAccess('TaskViewController', 'show', 2)); $this->assertFalse($helper->hasProjectAccess('TaskCreationController', 'save', 2)); } - - public function testCanRemoveTask() - { - $taskCreationModel = new TaskCreationModel($this->container); - $taskFinderModel = new TaskFinderModel($this->container); - $helper = new UserHelper($this->container); - $projectModel = new ProjectModel($this->container); - $userModel = new UserModel($this->container); - $userSessionModel = new UserSession($this->container); - - $this->assertNotFalse($userModel->create(array('username' => 'toto', 'password' => '123456'))); - $this->assertNotFalse($userModel->create(array('username' => 'toto2', 'password' => '123456'))); - $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); - $this->assertEquals(1, $taskCreationModel->create(array('title' => 'TaskViewController #1', 'project_id' => 1, 'creator_id' => 1))); - $this->assertEquals(2, $taskCreationModel->create(array('title' => 'TaskViewController #2', 'project_id' => 1, 'creator_id' => 2))); - $this->assertEquals(3, $taskCreationModel->create(array('title' => 'TaskViewController #3', 'project_id' => 1, 'creator_id' => 3))); - $this->assertEquals(4, $taskCreationModel->create(array('title' => 'TaskViewController #4', 'project_id' => 1))); - - // User #1 can remove everything - $user = $userModel->getById(1); - $this->assertNotEmpty($user); - $userSessionModel->initialize($user); - - $task = $taskFinderModel->getById(1); - $this->assertNotEmpty($task); - $this->assertTrue($helper->canRemoveTask($task)); - - // User #2 can't remove the TaskViewController #1 - $user = $userModel->getById(2); - $this->assertNotEmpty($user); - $userSessionModel->initialize($user); - - $task = $taskFinderModel->getById(1); - $this->assertNotEmpty($task); - $this->assertFalse($helper->canRemoveTask($task)); - - // User #1 can remove everything - $user = $userModel->getById(1); - $this->assertNotEmpty($user); - $userSessionModel->initialize($user); - - $task = $taskFinderModel->getById(2); - $this->assertNotEmpty($task); - $this->assertTrue($helper->canRemoveTask($task)); - - // User #2 can remove his own TaskViewController - $user = $userModel->getById(2); - $this->assertNotEmpty($user); - $userSessionModel->initialize($user); - - $task = $taskFinderModel->getById(2); - $this->assertNotEmpty($task); - $this->assertTrue($helper->canRemoveTask($task)); - - // User #1 can remove everything - $user = $userModel->getById(1); - $this->assertNotEmpty($user); - $userSessionModel->initialize($user); - - $task = $taskFinderModel->getById(3); - $this->assertNotEmpty($task); - $this->assertTrue($helper->canRemoveTask($task)); - - // User #2 can't remove the TaskViewController #3 - $user = $userModel->getById(2); - $this->assertNotEmpty($user); - $userSessionModel->initialize($user); - - $task = $taskFinderModel->getById(3); - $this->assertNotEmpty($task); - $this->assertFalse($helper->canRemoveTask($task)); - - // User #1 can remove everything - $user = $userModel->getById(1); - $this->assertNotEmpty($user); - $userSessionModel->initialize($user); - - $task = $taskFinderModel->getById(4); - $this->assertNotEmpty($task); - $this->assertTrue($helper->canRemoveTask($task)); - - // User #2 can't remove the TaskViewController #4 - $user = $userModel->getById(2); - $this->assertNotEmpty($user); - $userSessionModel->initialize($user); - - $task = $taskFinderModel->getById(4); - $this->assertNotEmpty($task); - $this->assertFalse($helper->canRemoveTask($task)); - } } |