summaryrefslogtreecommitdiff
path: root/tests/units/SubtaskTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units/SubtaskTest.php')
-rw-r--r--tests/units/SubtaskTest.php127
1 files changed, 121 insertions, 6 deletions
diff --git a/tests/units/SubtaskTest.php b/tests/units/SubtaskTest.php
index f272db1f..791f8089 100644
--- a/tests/units/SubtaskTest.php
+++ b/tests/units/SubtaskTest.php
@@ -3,25 +3,137 @@
require_once __DIR__.'/Base.php';
use Model\Task;
-use Model\SubTask;
+use Model\TaskCreation;
+use Model\Subtask;
use Model\Project;
use Model\Category;
use Model\User;
class SubTaskTest extends Base
{
+ public function testMoveUp()
+ {
+ $tc = new TaskCreation($this->container);
+ $s = new Subtask($this->container);
+ $p = new Project($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
+
+ $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1)));
+ $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1)));
+ $this->assertEquals(3, $s->create(array('title' => 'subtask #3', 'task_id' => 1)));
+
+ // Check positions
+ $subtask = $s->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(1, $subtask['position']);
+
+ $subtask = $s->getById(2);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(2, $subtask['position']);
+
+ $subtask = $s->getById(3);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(3, $subtask['position']);
+
+ // Move up
+ $this->assertTrue($s->moveUp(1, 2));
+
+ // Check positions
+ $subtask = $s->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(2, $subtask['position']);
+
+ $subtask = $s->getById(2);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(1, $subtask['position']);
+
+ $subtask = $s->getById(3);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(3, $subtask['position']);
+
+ // We can't move up #2
+ $this->assertFalse($s->moveUp(1, 2));
+
+ // Test remove
+ $this->assertTrue($s->remove(1));
+ $this->assertTrue($s->moveUp(1, 3));
+
+ // Check positions
+ $subtask = $s->getById(1);
+ $this->assertEmpty($subtask);
+
+ $subtask = $s->getById(2);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(2, $subtask['position']);
+
+ $subtask = $s->getById(3);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(1, $subtask['position']);
+ }
+
+ public function testMoveDown()
+ {
+ $tc = new TaskCreation($this->container);
+ $s = new Subtask($this->container);
+ $p = new Project($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
+
+ $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1)));
+ $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1)));
+ $this->assertEquals(3, $s->create(array('title' => 'subtask #3', 'task_id' => 1)));
+
+ // Move down #1
+ $this->assertTrue($s->moveDown(1, 1));
+
+ // Check positions
+ $subtask = $s->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(2, $subtask['position']);
+
+ $subtask = $s->getById(2);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(1, $subtask['position']);
+
+ $subtask = $s->getById(3);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(3, $subtask['position']);
+
+ // We can't move down #3
+ $this->assertFalse($s->moveDown(1, 3));
+
+ // Test remove
+ $this->assertTrue($s->remove(1));
+ $this->assertTrue($s->moveDown(1, 2));
+
+ // Check positions
+ $subtask = $s->getById(1);
+ $this->assertEmpty($subtask);
+
+ $subtask = $s->getById(2);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(2, $subtask['position']);
+
+ $subtask = $s->getById(3);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(1, $subtask['position']);
+ }
+
public function testDuplicate()
{
- $t = new Task($this->registry);
- $s = new SubTask($this->registry);
- $p = new Project($this->registry);
+ $tc = new TaskCreation($this->container);
+ $s = new Subtask($this->container);
+ $p = new Project($this->container);
// We create a project
$this->assertEquals(1, $p->create(array('name' => 'test1')));
// We create 2 tasks
- $this->assertEquals(1, $t->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
- $this->assertEquals(2, $t->create(array('title' => 'test 2', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 0)));
+ $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(2, $tc->create(array('title' => 'test 2', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 0)));
// We create many subtasks for the first task
$this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_estimated' => 5, 'time_spent' => 3, 'status' => 1, 'another_subtask' => 'on')));
@@ -52,5 +164,8 @@ class SubTaskTest extends Base
$this->assertEquals(0, $subtasks[0]['user_id']);
$this->assertEquals(0, $subtasks[1]['user_id']);
+
+ $this->assertEquals(1, $subtasks[0]['position']);
+ $this->assertEquals(2, $subtasks[1]['position']);
}
}