summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/units/Model/ColumnMoveRestrictionModelTest.php89
-rw-r--r--tests/units/Model/ProjectRoleModelTest.php59
2 files changed, 148 insertions, 0 deletions
diff --git a/tests/units/Model/ColumnMoveRestrictionModelTest.php b/tests/units/Model/ColumnMoveRestrictionModelTest.php
new file mode 100644
index 00000000..9227012b
--- /dev/null
+++ b/tests/units/Model/ColumnMoveRestrictionModelTest.php
@@ -0,0 +1,89 @@
+<?php
+
+use Kanboard\Model\ColumnMoveRestrictionModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\ProjectRoleModel;
+
+require_once __DIR__.'/../Base.php';
+
+class ColumnMoveRestrictionModelTest extends Base
+{
+ public function testCreation()
+ {
+ $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(1, $projectRoleModel->create(1, 'Custom Role'));
+ $this->assertEquals(1, $columnMoveRestrictionModel->create(1, 1, 2, 3));
+ $this->assertFalse($columnMoveRestrictionModel->create(1, 1, 2, 3));
+ }
+
+ public function testRemove()
+ {
+ $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(1, $projectRoleModel->create(1, 'Custom Role'));
+ $this->assertEquals(1, $columnMoveRestrictionModel->create(1, 1, 2, 3));
+ $this->assertTrue($columnMoveRestrictionModel->remove(1));
+ }
+
+ public function testGetAll()
+ {
+ $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));
+
+ $restrictions = $columnMoveRestrictionModel->getAll(1);
+ $this->assertCount(2, $restrictions);
+
+ $this->assertEquals(1, $restrictions[0]['restriction_id']);
+ $this->assertEquals('Role A', $restrictions[0]['role']);
+ $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']);
+ $this->assertEquals(3, $restrictions[0]['dst_column_id']);
+
+ $this->assertEquals(2, $restrictions[1]['restriction_id']);
+ $this->assertEquals('Role B', $restrictions[1]['role']);
+ $this->assertEquals('Work in progress', $restrictions[1]['src_column_title']);
+ $this->assertEquals('Done', $restrictions[1]['dst_column_title']);
+ $this->assertEquals(3, $restrictions[1]['src_column_id']);
+ $this->assertEquals(4, $restrictions[1]['dst_column_id']);
+ }
+
+ public function testIsAllowed()
+ {
+ $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));
+
+ $this->assertTrue($columnMoveRestrictionModel->isAllowed(1, 'Role D', 1, 2));
+ $this->assertTrue($columnMoveRestrictionModel->isAllowed(1, 'Role A', 1, 2));
+ $this->assertFalse($columnMoveRestrictionModel->isAllowed(1, 'Role A', 2, 3));
+ }
+}
diff --git a/tests/units/Model/ProjectRoleModelTest.php b/tests/units/Model/ProjectRoleModelTest.php
new file mode 100644
index 00000000..ce1392c2
--- /dev/null
+++ b/tests/units/Model/ProjectRoleModelTest.php
@@ -0,0 +1,59 @@
+<?php
+
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\ProjectRoleModel;
+
+require_once __DIR__.'/../Base.php';
+
+class ProjectRoleModelTest extends Base
+{
+ public function testCreation()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectRoleModel = new ProjectRoleModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $projectRoleModel->create(1, 'my-custom-role'));
+ $this->assertFalse($projectRoleModel->create(1, 'my-custom-role'));
+ }
+
+ public function testGetAll()
+ {
+ $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'));
+ $this->assertEquals(2, $projectRoleModel->create(1, 'Role B'));
+
+ $roles = $projectRoleModel->getAll(1);
+ $this->assertCount(2, $roles);
+
+ $this->assertEquals(1, $roles[0]['role_id']);
+ $this->assertEquals('Role A', $roles[0]['role']);
+
+ $this->assertEquals(2, $roles[1]['role_id']);
+ $this->assertEquals('Role B', $roles[1]['role']);
+ }
+
+ public function testModification()
+ {
+ $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'));
+ $this->assertTrue($projectRoleModel->update(1, 1, 'Role B'));
+ }
+
+ public function testRemove()
+ {
+ $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'));
+ $this->assertTrue($projectRoleModel->remove(1, 1));
+ $this->assertEmpty($projectRoleModel->getAll(1));
+ }
+}