summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-09-10 22:37:57 -0400
committerFrederic Guillot <fred@kanboard.net>2016-09-10 22:37:57 -0400
commit44f680cf2f1463721eb5bdb7eda4d3b339e63ba9 (patch)
treeed4aeef8b32dbd76277dacf864b028677bc10809 /tests
parent75470c72428c8d8f278d160369558ab31b137fb1 (diff)
Add ui to create new custom project roles and column restrictions
Diffstat (limited to 'tests')
-rw-r--r--tests/units/Model/ColumnMoveRestrictionModelTest.php50
-rw-r--r--tests/units/Model/ProjectRoleModelTest.php72
2 files changed, 121 insertions, 1 deletions
diff --git a/tests/units/Model/ColumnMoveRestrictionModelTest.php b/tests/units/Model/ColumnMoveRestrictionModelTest.php
index 9227012b..3bef6f99 100644
--- a/tests/units/Model/ColumnMoveRestrictionModelTest.php
+++ b/tests/units/Model/ColumnMoveRestrictionModelTest.php
@@ -32,6 +32,54 @@ class ColumnMoveRestrictionModelTest extends Base
$this->assertTrue($columnMoveRestrictionModel->remove(1));
}
+ public function testGetById()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+ $columnMoveRestrictionModel = new ColumnMoveRestrictionModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $projectRoleModel->create(1, 'Role A'));
+ $this->assertEquals(1, $columnMoveRestrictionModel->create(1, 1, 2, 3));
+
+ $restriction = $columnMoveRestrictionModel->getById(1, 1);
+ $this->assertEquals(1, $restriction['restriction_id']);
+ $this->assertEquals('Role A', $restriction['role']);
+ $this->assertEquals(1, $restriction['role_id']);
+ $this->assertEquals(1, $restriction['project_id']);
+ $this->assertEquals('Ready', $restriction['src_column_title']);
+ $this->assertEquals('Work in progress', $restriction['dst_column_title']);
+ $this->assertEquals(2, $restriction['src_column_id']);
+ $this->assertEquals(3, $restriction['dst_column_id']);
+ }
+
+ public function testGetSrcColumns()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+ $columnMoveRestrictionModel = new ColumnMoveRestrictionModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'Test')));
+
+ $this->assertEquals(1, $projectRoleModel->create(1, 'Role A'));
+ $this->assertEquals(2, $projectRoleModel->create(1, 'Role B'));
+ $this->assertEquals(3, $projectRoleModel->create(2, 'Role C'));
+
+ $this->assertEquals(1, $columnMoveRestrictionModel->create(1, 1, 2, 3));
+ $this->assertEquals(2, $columnMoveRestrictionModel->create(1, 2, 3, 4));
+
+ $columnIds = $columnMoveRestrictionModel->getAllSrcColumns(1, 'Role A');
+ $this->assertEquals(2, $columnIds[2]);
+
+ $this->assertEmpty($columnMoveRestrictionModel->getAllSrcColumns(2, 'Role A'));
+ $this->assertEmpty($columnMoveRestrictionModel->getAllSrcColumns(2, 'Role C'));
+
+ $columnIds = $columnMoveRestrictionModel->getAllSrcColumns(1, 'Role B');
+ $this->assertEquals(3, $columnIds[3]);
+ }
+
public function testGetAll()
{
$projectModel = new ProjectModel($this->container);
@@ -53,6 +101,8 @@ class ColumnMoveRestrictionModelTest extends Base
$this->assertEquals(1, $restrictions[0]['restriction_id']);
$this->assertEquals('Role A', $restrictions[0]['role']);
+ $this->assertEquals(1, $restrictions[0]['role_id']);
+ $this->assertEquals(1, $restrictions[0]['project_id']);
$this->assertEquals('Ready', $restrictions[0]['src_column_title']);
$this->assertEquals('Work in progress', $restrictions[0]['dst_column_title']);
$this->assertEquals(2, $restrictions[0]['src_column_id']);
diff --git a/tests/units/Model/ProjectRoleModelTest.php b/tests/units/Model/ProjectRoleModelTest.php
index ce1392c2..5dd78e20 100644
--- a/tests/units/Model/ProjectRoleModelTest.php
+++ b/tests/units/Model/ProjectRoleModelTest.php
@@ -1,7 +1,12 @@
<?php
+use Kanboard\Core\Security\Role;
+use Kanboard\Model\GroupMemberModel;
+use Kanboard\Model\GroupModel;
+use Kanboard\Model\ProjectGroupRoleModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\ProjectRoleModel;
+use Kanboard\Model\ProjectUserRoleModel;
require_once __DIR__.'/../Base.php';
@@ -46,14 +51,79 @@ class ProjectRoleModelTest extends Base
$this->assertTrue($projectRoleModel->update(1, 1, 'Role B'));
}
- public function testRemove()
+ public function testRemoveWithUserRole()
{
$projectModel = new ProjectModel($this->container);
$projectRoleModel = new ProjectRoleModel($this->container);
+ $projectUserRoleModel = new ProjectUserRoleModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
$this->assertEquals(1, $projectRoleModel->create(1, 'Role A'));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 1, 'Role A'));
+ $this->assertEquals('Role A', $projectUserRoleModel->getUserRole(1, 1));
+
+ $this->assertTrue($projectRoleModel->remove(1, 1));
+ $this->assertEmpty($projectRoleModel->getAll(1));
+ $this->assertEquals(Role::PROJECT_MEMBER, $projectUserRoleModel->getUserRole(1, 1));
+ }
+
+ public function testRemoveWithGroupRole()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+ $projectGroupRoleModel = new ProjectGroupRoleModel($this->container);
+ $groupModel = new GroupModel($this->container);
+ $groupMemberModel = new GroupMemberModel($this->container);
+
+ $this->assertEquals(1, $groupModel->create('Group A'));
+ $this->assertTrue($groupMemberModel->addUser(1, 1));
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $projectRoleModel->create(1, 'Role A'));
+ $this->assertTrue($projectGroupRoleModel->addGroup(1, 1, 'Role A'));
+ $this->assertEquals('Role A', $projectGroupRoleModel->getUserRole(1, 1));
+
$this->assertTrue($projectRoleModel->remove(1, 1));
$this->assertEmpty($projectRoleModel->getAll(1));
+ $this->assertEquals(Role::PROJECT_MEMBER, $projectGroupRoleModel->getUserRole(1, 1));
+ }
+
+ public function testGetRoleListWithoutCustomRoles()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+
+ $roles = $projectRoleModel->getList(1);
+ $this->assertCount(3, $roles);
+ $this->assertEquals('Project Manager', $roles[Role::PROJECT_MANAGER]);
+ }
+
+ public function testGetRoleListWithCustomRoles()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $projectRoleModel->create(1, 'Role A'));
+
+ $roles = $projectRoleModel->getList(1);
+ $this->assertCount(4, $roles);
+ $this->assertEquals('Role A', $roles['Role A']);
+ }
+
+ public function testGetById()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $projectRoleModel->create(1, 'Role A'));
+
+ $role = $projectRoleModel->getById(1, 1);
+ $this->assertEquals(1, $role['role_id']);
+ $this->assertEquals(1, $role['project_id']);
+ $this->assertEquals('Role A', $role['role']);
}
}