summaryrefslogtreecommitdiff
path: root/tests/units/Model
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-02-20 18:11:08 -0500
committerFrederic Guillot <fred@kanboard.net>2016-02-20 18:11:08 -0500
commit5fe68d4d499a8496229763369b50d71c9fa16200 (patch)
tree95bc4160b1da2fa79ca5ec1c0af4baab7cec1300 /tests/units/Model
parentda7259819bb6c3947317b39fc2a10626471bfca3 (diff)
Add drag and drop to change swimlane positions
Diffstat (limited to 'tests/units/Model')
-rw-r--r--tests/units/Model/SwimlaneTest.php273
1 files changed, 106 insertions, 167 deletions
diff --git a/tests/units/Model/SwimlaneTest.php b/tests/units/Model/SwimlaneTest.php
index 3d048abd..f8b496cf 100644
--- a/tests/units/Model/SwimlaneTest.php
+++ b/tests/units/Model/SwimlaneTest.php
@@ -86,7 +86,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 +226,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 +256,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']);
+ }
}