summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-09-01 19:36:40 -0800
committerFrédéric Guillot <fred@kanboard.net>2014-09-01 19:36:40 -0800
commite6d0658a0eedeb6a641c003d1c492af0f9a7502c (patch)
tree31004fe37246e39e438fb2dc7f1d07996634f1f3 /tests
parente4965546543be040da29dc341900fa9511a158be (diff)
Add the possibility to duplicate a task to another project
Diffstat (limited to 'tests')
-rw-r--r--tests/units/Base.php1
-rw-r--r--tests/units/SubtaskTest.php56
-rw-r--r--tests/units/TaskTest.php9
3 files changed, 62 insertions, 4 deletions
diff --git a/tests/units/Base.php b/tests/units/Base.php
index fad5d074..7d8a075f 100644
--- a/tests/units/Base.php
+++ b/tests/units/Base.php
@@ -39,6 +39,7 @@ require_once __DIR__.'/../../app/Model/User.php';
require_once __DIR__.'/../../app/Model/Board.php';
require_once __DIR__.'/../../app/Model/Action.php';
require_once __DIR__.'/../../app/Model/Category.php';
+require_once __DIR__.'/../../app/Model/SubTask.php';
require_once __DIR__.'/../../app/Action/Base.php';
require_once __DIR__.'/../../app/Action/TaskClose.php';
diff --git a/tests/units/SubtaskTest.php b/tests/units/SubtaskTest.php
new file mode 100644
index 00000000..a74ee60a
--- /dev/null
+++ b/tests/units/SubtaskTest.php
@@ -0,0 +1,56 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Model\Task;
+use Model\SubTask;
+use Model\Project;
+use Model\Category;
+use Model\User;
+
+class SubTaskTest extends Base
+{
+ public function testDuplicate()
+ {
+ $t = new Task($this->registry);
+ $s = new SubTask($this->registry);
+ $p = new Project($this->registry);
+
+ // 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)));
+
+ // 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)));
+ $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => 0, 'time_spent' => 0, 'status' => 2, 'user_id' => 1)));
+
+ // We duplicate our subtasks
+ $this->assertTrue($s->duplicate(1, 2));
+ $subtasks = $s->getAll(2);
+
+ $this->assertNotFalse($subtasks);
+ $this->assertNotEmpty($subtasks);
+ $this->assertEquals(2, count($subtasks));
+
+ $this->assertEquals('subtask #1', $subtasks[0]['title']);
+ $this->assertEquals('subtask #2', $subtasks[1]['title']);
+
+ $this->assertEquals(2, $subtasks[0]['task_id']);
+ $this->assertEquals(2, $subtasks[1]['task_id']);
+
+ $this->assertEquals(5, $subtasks[0]['time_estimated']);
+ $this->assertEquals(0, $subtasks[1]['time_estimated']);
+
+ $this->assertEquals(0, $subtasks[0]['time_spent']);
+ $this->assertEquals(0, $subtasks[1]['time_spent']);
+
+ $this->assertEquals(0, $subtasks[0]['status']);
+ $this->assertEquals(0, $subtasks[1]['status']);
+
+ $this->assertEquals(0, $subtasks[0]['user_id']);
+ $this->assertEquals(0, $subtasks[1]['user_id']);
+ }
+}
diff --git a/tests/units/TaskTest.php b/tests/units/TaskTest.php
index 66f82016..064f30b0 100644
--- a/tests/units/TaskTest.php
+++ b/tests/units/TaskTest.php
@@ -170,15 +170,16 @@ class TaskTest extends Base
// We create a task
$this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1, 'category_id' => 1)));
+ $task = $t->getById(1);
// We duplicate our task to the 2nd project
- $this->assertEquals(2, $t->duplicateToAnotherProject(1, 2));
+ $this->assertEquals(2, $t->duplicateToAnotherProject(2, $task));
$this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_CREATE));
// Check the values of the duplicated task
$task = $t->getById(2);
$this->assertNotEmpty($task);
- $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(1, $task['owner_id']);
$this->assertEquals(0, $task['category_id']);
$this->assertEquals(2, $task['project_id']);
$this->assertEquals('test', $task['title']);
@@ -204,7 +205,7 @@ class TaskTest extends Base
// We duplicate our task to the 2nd project
$task = $t->getById(1);
- $this->assertTrue($t->moveToAnotherProject(2, $task));
+ $this->assertEquals(1, $t->moveToAnotherProject(2, $task));
//$this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_CREATE));
// Check the values of the duplicated task
@@ -222,7 +223,7 @@ class TaskTest extends Base
// The owner should be reseted
$task = $t->getById(2);
- $this->assertTrue($t->moveToAnotherProject(2, $task));
+ $this->assertEquals(2, $t->moveToAnotherProject(2, $task));
$task = $t->getById(2);
$this->assertNotEmpty($task);