summaryrefslogtreecommitdiff
path: root/tests/units
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-11-23 18:23:20 -0500
committerFrédéric Guillot <fred@kanboard.net>2014-11-23 18:23:20 -0500
commit81df22de238bc36d810b95ad67a4426db095fbab (patch)
tree53231a3d46b6b7c54eaec515016247984cf7a4e4 /tests/units
parentf684602ebedc0adc4a329693ba524ad46d5cd8b0 (diff)
Create TaskDuplication model
Diffstat (limited to 'tests/units')
-rw-r--r--tests/units/ActionTaskDuplicateAnotherProjectTest.php1
-rw-r--r--tests/units/CategoryTest.php6
-rw-r--r--tests/units/TaskDuplicationTest.php327
-rw-r--r--tests/units/TaskTest.php120
4 files changed, 334 insertions, 120 deletions
diff --git a/tests/units/ActionTaskDuplicateAnotherProjectTest.php b/tests/units/ActionTaskDuplicateAnotherProjectTest.php
index bbfa928f..d7f9d2c3 100644
--- a/tests/units/ActionTaskDuplicateAnotherProjectTest.php
+++ b/tests/units/ActionTaskDuplicateAnotherProjectTest.php
@@ -77,6 +77,7 @@ class ActionTaskDuplicateAnotherProject extends Base
// Our event should be executed because we define a different project
$action->setParam('column_id', 2);
$action->setParam('project_id', 2);
+ $this->assertTrue($action->hasRequiredCondition($event));
$this->assertTrue($action->execute($event));
// Our task should be assigned to the project 1
diff --git a/tests/units/CategoryTest.php b/tests/units/CategoryTest.php
index f169e961..638f3fe4 100644
--- a/tests/units/CategoryTest.php
+++ b/tests/units/CategoryTest.php
@@ -32,6 +32,12 @@ class CategoryTest extends Base
$this->assertEquals(2, $category['id']);
$this->assertEquals('Category #2', $category['name']);
$this->assertEquals(1, $category['project_id']);
+
+ $this->assertEquals(2, $c->getIdByName(1, 'Category #2'));
+ $this->assertEquals(0, $c->getIdByName(2, 'Category #2'));
+
+ $this->assertEquals('Category #2', $c->getNameById(2));
+ $this->assertEquals('', $c->getNameById(23));
}
public function testRemove()
diff --git a/tests/units/TaskDuplicationTest.php b/tests/units/TaskDuplicationTest.php
new file mode 100644
index 00000000..80f037de
--- /dev/null
+++ b/tests/units/TaskDuplicationTest.php
@@ -0,0 +1,327 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Model\Task;
+use Model\TaskCreation;
+use Model\TaskDuplication;
+use Model\TaskFinder;
+use Model\TaskStatus;
+use Model\Project;
+use Model\ProjectPermission;
+use Model\Category;
+use Model\User;
+
+class TaskDuplicationTest extends Base
+{
+ public function testDuplicateSameProject()
+ {
+ $td = new TaskDuplication($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $c = new Category($this->container);
+
+ // We create a task and a project
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+
+ // Some categories
+ $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
+ $this->assertNotFalse($c->create(array('name' => 'Category #2', 'project_id' => 1)));
+ $this->assertTrue($c->exists(1, 1));
+ $this->assertTrue($c->exists(2, 1));
+
+ $this->assertEquals(
+ 1,
+ $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1, 'category_id' => 2, 'time_spent' => 4.4)
+ ));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(1, $task['project_id']);
+ $this->assertEquals(3, $task['column_id']);
+ $this->assertEquals(2, $task['category_id']);
+ $this->assertEquals(4.4, $task['time_spent']);
+
+ // We duplicate our task
+ $this->assertEquals(2, $td->duplicate(1));
+ $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE));
+ $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE_UPDATE));
+
+ // Check the values of the duplicated task
+ $task = $tf->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(Task::STATUS_OPEN, $task['is_active']);
+ $this->assertEquals(1, $task['project_id']);
+ $this->assertEquals(1, $task['owner_id']);
+ $this->assertEquals(2, $task['category_id']);
+ $this->assertEquals(3, $task['column_id']);
+ $this->assertEquals(2, $task['position']);
+ $this->assertEquals('test', $task['title']);
+ $this->assertEquals(0, $task['time_spent']);
+ }
+
+ public function testDuplicateAnotherProject()
+ {
+ $td = new TaskDuplication($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $c = new Category($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+ $this->assertEquals(2, $p->create(array('name' => 'test2')));
+
+ $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
+ $this->assertTrue($c->exists(1, 1));
+
+ // We create a task
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1, 'category_id' => 1)));
+
+ // We duplicate our task to the 2nd project
+ $this->assertEquals(2, $td->duplicateToProject(1, 2));
+ $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE));
+ $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE_UPDATE));
+
+ // Check the values of the duplicated task
+ $task = $tf->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['owner_id']);
+ $this->assertEquals(0, $task['category_id']);
+ $this->assertEquals(5, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('test', $task['title']);
+ }
+
+ public function testDuplicateAnotherProjectWithCategory()
+ {
+ $td = new TaskDuplication($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $c = new Category($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+ $this->assertEquals(2, $p->create(array('name' => 'test2')));
+
+ $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
+ $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 2)));
+ $this->assertTrue($c->exists(1, 1));
+ $this->assertTrue($c->exists(2, 2));
+
+ // We create a task
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1)));
+
+ // We duplicate our task to the 2nd project
+ $this->assertEquals(2, $td->duplicateToProject(1, 2));
+ $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE));
+ $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE_UPDATE));
+
+ // Check the values of the duplicated task
+ $task = $tf->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(2, $task['category_id']);
+ $this->assertEquals(5, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('test', $task['title']);
+ }
+
+ public function testDuplicateAnotherProjectWithUser()
+ {
+ $td = new TaskDuplication($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $pp = new ProjectPermission($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+ $this->assertEquals(2, $p->create(array('name' => 'test2')));
+
+ // We create a task
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2)));
+
+ // We duplicate our task to the 2nd project
+ $this->assertEquals(2, $td->duplicateToProject(1, 2));
+ $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE));
+ $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE_UPDATE));
+
+ // Check the values of the duplicated task
+ $task = $tf->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(5, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('test', $task['title']);
+
+ // We create a new user for our project
+ $user = new User($this->container);
+ $this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest')));
+ $this->assertTrue($pp->allowUser(1, 2));
+ $this->assertTrue($pp->allowUser(2, 2));
+ $this->assertTrue($pp->isUserAllowed(1, 2));
+ $this->assertTrue($pp->isUserAllowed(2, 2));
+
+ // We duplicate our task to the 2nd project
+ $this->assertEquals(3, $td->duplicateToProject(1, 2));
+
+ // Check the values of the duplicated task
+ $task = $tf->getById(3);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(2, $task['position']);
+ $this->assertEquals(2, $task['owner_id']);
+ $this->assertEquals(2, $task['project_id']);
+
+ // We duplicate a task with a not allowed user
+ $this->assertEquals(4, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 3)));
+ $this->assertEquals(5, $td->duplicateToProject(4, 2));
+
+ $task = $tf->getById(5);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(3, $task['position']);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals(5, $task['column_id']);
+ }
+
+ public function testMoveAnotherProject()
+ {
+ $td = new TaskDuplication($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $pp = new ProjectPermission($this->container);
+ $user = new User($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+ $this->assertEquals(2, $p->create(array('name' => 'test2')));
+
+ // We create a task
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'owner_id' => 1, 'category_id' => 10, 'position' => 333)));
+
+ // We duplicate our task to the 2nd project
+ $this->assertTrue($td->moveToProject(1, 2));
+
+ // Check the values of the moved task
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['owner_id']);
+ $this->assertEquals(0, $task['category_id']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals(5, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals('test', $task['title']);
+ }
+
+ public function testMoveAnotherProjectWithCategory()
+ {
+ $td = new TaskDuplication($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $c = new Category($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+ $this->assertEquals(2, $p->create(array('name' => 'test2')));
+
+ $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
+ $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 2)));
+ $this->assertTrue($c->exists(1, 1));
+ $this->assertTrue($c->exists(2, 2));
+
+ // We create a task
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1)));
+
+ // We move our task to the 2nd project
+ $this->assertTrue($td->moveToProject(1, 2));
+
+ // Check the values of the duplicated task
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(2, $task['category_id']);
+ $this->assertEquals(5, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('test', $task['title']);
+ }
+
+ public function testMoveAnotherProjectWithUser()
+ {
+ $td = new TaskDuplication($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $pp = new ProjectPermission($this->container);
+ $user = new User($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+ $this->assertEquals(2, $p->create(array('name' => 'test2')));
+
+ // We create a new user for our project
+ $this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest')));
+ $this->assertTrue($pp->allowUser(1, 2));
+ $this->assertTrue($pp->allowUser(2, 2));
+ $this->assertTrue($pp->isUserAllowed(1, 2));
+ $this->assertTrue($pp->isUserAllowed(2, 2));
+
+ // We create a task
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2)));
+
+ // We move our task to the 2nd project
+ $this->assertTrue($td->moveToProject(1, 2));
+
+ // Check the values of the moved task
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['owner_id']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals(5, $task['column_id']);
+ }
+
+ public function testMoveAnotherProjectWithForbiddenUser()
+ {
+ $td = new TaskDuplication($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $pp = new ProjectPermission($this->container);
+ $user = new User($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+ $this->assertEquals(2, $p->create(array('name' => 'test2')));
+
+ // We create a new user for our project
+ $this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest')));
+ $this->assertTrue($pp->allowUser(1, 2));
+ $this->assertTrue($pp->allowUser(2, 2));
+ $this->assertTrue($pp->isUserAllowed(1, 2));
+ $this->assertTrue($pp->isUserAllowed(2, 2));
+
+ // We create a task
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 3)));
+
+ // We move our task to the 2nd project
+ $this->assertTrue($td->moveToProject(1, 2));
+
+ // Check the values of the moved task
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals(5, $task['column_id']);
+ }
+}
diff --git a/tests/units/TaskTest.php b/tests/units/TaskTest.php
index e303856a..d9c0fa4f 100644
--- a/tests/units/TaskTest.php
+++ b/tests/units/TaskTest.php
@@ -26,124 +26,4 @@ class TaskTest extends Base
$this->assertTrue($t->remove(1));
$this->assertFalse($t->remove(1234));
}
-
- public function testDuplicateToTheSameProject()
- {
- $t = new Task($this->container);
- $tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
- $p = new Project($this->container);
- $c = new Category($this->container);
-
- // We create a task and a project
- $this->assertEquals(1, $p->create(array('name' => 'test1')));
-
- // Some categories
- $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
- $this->assertNotFalse($c->create(array('name' => 'Category #2', 'project_id' => 1)));
- $this->assertTrue($c->exists(1, 1));
- $this->assertTrue($c->exists(2, 1));
-
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1, 'category_id' => 2)));
-
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(1, $task['position']);
-
- // We duplicate our task
- $this->assertEquals(2, $t->duplicateToSameProject($task));
- $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE));
-
- // Check the values of the duplicated task
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(Task::STATUS_OPEN, $task['is_active']);
- $this->assertEquals(1, $task['project_id']);
- $this->assertEquals(1, $task['owner_id']);
- $this->assertEquals(2, $task['category_id']);
- $this->assertEquals(3, $task['column_id']);
- $this->assertEquals(2, $task['position']);
- }
-
- public function testDuplicateToAnotherProject()
- {
- $t = new Task($this->container);
- $tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
- $p = new Project($this->container);
- $c = new Category($this->container);
-
- // We create 2 projects
- $this->assertEquals(1, $p->create(array('name' => 'test1')));
- $this->assertEquals(2, $p->create(array('name' => 'test2')));
-
- $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
- $this->assertTrue($c->exists(1, 1));
-
- // We create a task
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1, 'category_id' => 1)));
- $task = $tf->getById(1);
-
- // We duplicate our task to the 2nd project
- $this->assertEquals(2, $t->duplicateToAnotherProject(2, $task));
- $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE));
-
- // Check the values of the duplicated task
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(1, $task['owner_id']);
- $this->assertEquals(0, $task['category_id']);
- $this->assertEquals(5, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(2, $task['project_id']);
- $this->assertEquals('test', $task['title']);
- }
-
- public function testMoveToAnotherProject()
- {
- $t = new Task($this->container);
- $tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
- $p = new Project($this->container);
- $pp = new ProjectPermission($this->container);
- $user = new User($this->container);
-
- // We create a regular user
- $user->create(array('username' => 'unittest1', 'password' => 'unittest'));
- $user->create(array('username' => 'unittest2', 'password' => 'unittest'));
-
- // We create 2 projects
- $this->assertEquals(1, $p->create(array('name' => 'test1')));
- $this->assertEquals(2, $p->create(array('name' => 'test2')));
-
- // We create a task
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1, 'category_id' => 10, 'position' => 333)));
- $this->assertEquals(2, $tc->create(array('title' => 'test2', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 3, 'category_id' => 10, 'position' => 333)));
-
- // We duplicate our task to the 2nd project
- $task = $tf->getById(1);
- $this->assertEquals(1, $t->moveToAnotherProject(2, $task));
- //$this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE));
-
- // Check the values of the duplicated task
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(1, $task['owner_id']);
- $this->assertEquals(0, $task['category_id']);
- $this->assertEquals(2, $task['project_id']);
- $this->assertEquals(5, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals('test', $task['title']);
-
- // We allow only one user on the second project
- $this->assertTrue($pp->allowUser(2, 2));
-
- // The owner should be reseted
- $task = $tf->getById(2);
- $this->assertEquals(2, $t->moveToAnotherProject(2, $task));
-
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(0, $task['owner_id']);
- }
}