summaryrefslogtreecommitdiff
path: root/tests/units/Model/SwimlaneTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units/Model/SwimlaneTest.php')
-rw-r--r--tests/units/Model/SwimlaneTest.php274
1 files changed, 106 insertions, 168 deletions
diff --git a/tests/units/Model/SwimlaneTest.php b/tests/units/Model/SwimlaneTest.php
index 3d048abd..71c13e40 100644
--- a/tests/units/Model/SwimlaneTest.php
+++ b/tests/units/Model/SwimlaneTest.php
@@ -3,7 +3,6 @@
require_once __DIR__.'/../Base.php';
use Kanboard\Model\Project;
-use Kanboard\Model\Task;
use Kanboard\Model\TaskCreation;
use Kanboard\Model\TaskFinder;
use Kanboard\Model\Swimlane;
@@ -86,7 +85,23 @@ class SwimlaneTest extends Base
$this->assertEquals(0, $default['show_default_swimlane']);
}
- public function testDisable()
+ public function testDisableEnableDefaultSwimlane()
+ {
+ $projectModel = new Project($this->container);
+ $swimlaneModel = new Swimlane($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
+
+ $this->assertTrue($swimlaneModel->disableDefault(1));
+ $default = $swimlaneModel->getDefault(1);
+ $this->assertEquals(0, $default['show_default_swimlane']);
+
+ $this->assertTrue($swimlaneModel->enableDefault(1));
+ $default = $swimlaneModel->getDefault(1);
+ $this->assertEquals(1, $default['show_default_swimlane']);
+ }
+
+ public function testDisableEnable()
{
$p = new Project($this->container);
$s = new Swimlane($this->container);
@@ -210,172 +225,6 @@ class SwimlaneTest extends Base
$this->assertEquals(1, $swimlane['position']);
}
- public function testMoveUp()
- {
- $p = new Project($this->container);
- $s = new Swimlane($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
- $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
- $this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'Swimlane #2')));
- $this->assertEquals(3, $s->create(array('project_id' => 1, 'name' => 'Swimlane #3')));
-
- $swimlane = $s->getById(1);
- $this->assertNotEmpty($swimlane);
- $this->assertEquals(1, $swimlane['is_active']);
- $this->assertEquals(1, $swimlane['position']);
-
- $swimlane = $s->getById(2);
- $this->assertNotEmpty($swimlane);
- $this->assertEquals(1, $swimlane['is_active']);
- $this->assertEquals(2, $swimlane['position']);
-
- $swimlane = $s->getById(3);
- $this->assertNotEmpty($swimlane);
- $this->assertEquals(1, $swimlane['is_active']);
- $this->assertEquals(3, $swimlane['position']);
-
- // Move the swimlane 3 up
- $this->assertTrue($s->moveUp(1, 3));
-
- $swimlane = $s->getById(1);
- $this->assertNotEmpty($swimlane);
- $this->assertEquals(1, $swimlane['is_active']);
- $this->assertEquals(1, $swimlane['position']);
-
- $swimlane = $s->getById(2);
- $this->assertNotEmpty($swimlane);
- $this->assertEquals(1, $swimlane['is_active']);
- $this->assertEquals(3, $swimlane['position']);
-
- $swimlane = $s->getById(3);
- $this->assertNotEmpty($swimlane);
- $this->assertEquals(1, $swimlane['is_active']);
- $this->assertEquals(2, $swimlane['position']);
-
- // First swimlane can be moved up
- $this->assertFalse($s->moveUp(1, 1));
-
- // Move with a disabled swimlane
- $this->assertTrue($s->disable(1, 1));
-
- $swimlane = $s->getById(1);
- $this->assertNotEmpty($swimlane);
- $this->assertEquals(0, $swimlane['is_active']);
- $this->assertEquals(0, $swimlane['position']);
-
- $swimlane = $s->getById(2);
- $this->assertNotEmpty($swimlane);
- $this->assertEquals(1, $swimlane['is_active']);
- $this->assertEquals(2, $swimlane['position']);
-
- $swimlane = $s->getById(3);
- $this->assertNotEmpty($swimlane);
- $this->assertEquals(1, $swimlane['is_active']);
- $this->assertEquals(1, $swimlane['position']);
-
- // Move the 2nd swimlane up
- $this->assertTrue($s->moveUp(1, 2));
-
- $swimlane = $s->getById(1);
- $this->assertNotEmpty($swimlane);
- $this->assertEquals(0, $swimlane['is_active']);
- $this->assertEquals(0, $swimlane['position']);
-
- $swimlane = $s->getById(2);
- $this->assertNotEmpty($swimlane);
- $this->assertEquals(1, $swimlane['is_active']);
- $this->assertEquals(1, $swimlane['position']);
-
- $swimlane = $s->getById(3);
- $this->assertNotEmpty($swimlane);
- $this->assertEquals(1, $swimlane['is_active']);
- $this->assertEquals(2, $swimlane['position']);
- }
-
- public function testMoveDown()
- {
- $p = new Project($this->container);
- $s = new Swimlane($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
- $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
- $this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'Swimlane #2')));
- $this->assertEquals(3, $s->create(array('project_id' => 1, 'name' => 'Swimlane #3')));
-
- $swimlane = $s->getById(1);
- $this->assertNotEmpty($swimlane);
- $this->assertEquals(1, $swimlane['is_active']);
- $this->assertEquals(1, $swimlane['position']);
-
- $swimlane = $s->getById(2);
- $this->assertNotEmpty($swimlane);
- $this->assertEquals(1, $swimlane['is_active']);
- $this->assertEquals(2, $swimlane['position']);
-
- $swimlane = $s->getById(3);
- $this->assertNotEmpty($swimlane);
- $this->assertEquals(1, $swimlane['is_active']);
- $this->assertEquals(3, $swimlane['position']);
-
- // Move the swimlane 1 down
- $this->assertTrue($s->moveDown(1, 1));
-
- $swimlane = $s->getById(1);
- $this->assertNotEmpty($swimlane);
- $this->assertEquals(1, $swimlane['is_active']);
- $this->assertEquals(2, $swimlane['position']);
-
- $swimlane = $s->getById(2);
- $this->assertNotEmpty($swimlane);
- $this->assertEquals(1, $swimlane['is_active']);
- $this->assertEquals(1, $swimlane['position']);
-
- $swimlane = $s->getById(3);
- $this->assertNotEmpty($swimlane);
- $this->assertEquals(1, $swimlane['is_active']);
- $this->assertEquals(3, $swimlane['position']);
-
- // Last swimlane can be moved down
- $this->assertFalse($s->moveDown(1, 3));
-
- // Move with a disabled swimlane
- $this->assertTrue($s->disable(1, 3));
-
- $swimlane = $s->getById(1);
- $this->assertNotEmpty($swimlane);
- $this->assertEquals(1, $swimlane['is_active']);
- $this->assertEquals(2, $swimlane['position']);
-
- $swimlane = $s->getById(2);
- $this->assertNotEmpty($swimlane);
- $this->assertEquals(1, $swimlane['is_active']);
- $this->assertEquals(1, $swimlane['position']);
-
- $swimlane = $s->getById(3);
- $this->assertNotEmpty($swimlane);
- $this->assertEquals(0, $swimlane['is_active']);
- $this->assertEquals(0, $swimlane['position']);
-
- // Move the 2st swimlane down
- $this->assertTrue($s->moveDown(1, 2));
-
- $swimlane = $s->getById(1);
- $this->assertNotEmpty($swimlane);
- $this->assertEquals(1, $swimlane['is_active']);
- $this->assertEquals(1, $swimlane['position']);
-
- $swimlane = $s->getById(2);
- $this->assertNotEmpty($swimlane);
- $this->assertEquals(1, $swimlane['is_active']);
- $this->assertEquals(2, $swimlane['position']);
-
- $swimlane = $s->getById(3);
- $this->assertNotEmpty($swimlane);
- $this->assertEquals(0, $swimlane['is_active']);
- $this->assertEquals(0, $swimlane['position']);
- }
-
public function testDuplicateSwimlane()
{
$p = new Project($this->container);
@@ -406,4 +255,93 @@ class SwimlaneTest extends Base
$new_default = $s->getDefault(2);
$this->assertEquals('New Default', $new_default['default_swimlane']);
}
+
+ public function testChangePosition()
+ {
+ $projectModel = new Project($this->container);
+ $swimlaneModel = new Swimlane($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
+ $this->assertEquals(2, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #2')));
+ $this->assertEquals(3, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #3')));
+ $this->assertEquals(4, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #4')));
+
+ $swimlanes = $swimlaneModel->getAllByStatus(1);
+ $this->assertEquals(1, $swimlanes[0]['position']);
+ $this->assertEquals(1, $swimlanes[0]['id']);
+ $this->assertEquals(2, $swimlanes[1]['position']);
+ $this->assertEquals(2, $swimlanes[1]['id']);
+ $this->assertEquals(3, $swimlanes[2]['position']);
+ $this->assertEquals(3, $swimlanes[2]['id']);
+
+ $this->assertTrue($swimlaneModel->changePosition(1, 3, 2));
+
+ $swimlanes = $swimlaneModel->getAllByStatus(1);
+ $this->assertEquals(1, $swimlanes[0]['position']);
+ $this->assertEquals(1, $swimlanes[0]['id']);
+ $this->assertEquals(2, $swimlanes[1]['position']);
+ $this->assertEquals(3, $swimlanes[1]['id']);
+ $this->assertEquals(3, $swimlanes[2]['position']);
+ $this->assertEquals(2, $swimlanes[2]['id']);
+
+ $this->assertTrue($swimlaneModel->changePosition(1, 2, 1));
+
+ $swimlanes = $swimlaneModel->getAllByStatus(1);
+ $this->assertEquals(1, $swimlanes[0]['position']);
+ $this->assertEquals(2, $swimlanes[0]['id']);
+ $this->assertEquals(2, $swimlanes[1]['position']);
+ $this->assertEquals(1, $swimlanes[1]['id']);
+ $this->assertEquals(3, $swimlanes[2]['position']);
+ $this->assertEquals(3, $swimlanes[2]['id']);
+
+ $this->assertTrue($swimlaneModel->changePosition(1, 2, 2));
+
+ $swimlanes = $swimlaneModel->getAllByStatus(1);
+ $this->assertEquals(1, $swimlanes[0]['position']);
+ $this->assertEquals(1, $swimlanes[0]['id']);
+ $this->assertEquals(2, $swimlanes[1]['position']);
+ $this->assertEquals(2, $swimlanes[1]['id']);
+ $this->assertEquals(3, $swimlanes[2]['position']);
+ $this->assertEquals(3, $swimlanes[2]['id']);
+
+ $this->assertTrue($swimlaneModel->changePosition(1, 4, 1));
+
+ $swimlanes = $swimlaneModel->getAllByStatus(1);
+ $this->assertEquals(1, $swimlanes[0]['position']);
+ $this->assertEquals(4, $swimlanes[0]['id']);
+ $this->assertEquals(2, $swimlanes[1]['position']);
+ $this->assertEquals(1, $swimlanes[1]['id']);
+ $this->assertEquals(3, $swimlanes[2]['position']);
+ $this->assertEquals(2, $swimlanes[2]['id']);
+
+ $this->assertFalse($swimlaneModel->changePosition(1, 2, 0));
+ $this->assertFalse($swimlaneModel->changePosition(1, 2, 5));
+ }
+
+ public function testChangePositionWithInactiveSwimlane()
+ {
+ $projectModel = new Project($this->container);
+ $swimlaneModel = new Swimlane($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
+ $this->assertEquals(2, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #2', 'is_active' => 0)));
+ $this->assertEquals(3, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #3', 'is_active' => 0)));
+ $this->assertEquals(4, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #4')));
+
+ $swimlanes = $swimlaneModel->getAllByStatus(1);
+ $this->assertEquals(1, $swimlanes[0]['position']);
+ $this->assertEquals(1, $swimlanes[0]['id']);
+ $this->assertEquals(2, $swimlanes[1]['position']);
+ $this->assertEquals(4, $swimlanes[1]['id']);
+
+ $this->assertTrue($swimlaneModel->changePosition(1, 4, 1));
+
+ $swimlanes = $swimlaneModel->getAllByStatus(1);
+ $this->assertEquals(1, $swimlanes[0]['position']);
+ $this->assertEquals(4, $swimlanes[0]['id']);
+ $this->assertEquals(2, $swimlanes[1]['position']);
+ $this->assertEquals(1, $swimlanes[1]['id']);
+ }
}