summaryrefslogtreecommitdiff
path: root/tests/units/TaskTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units/TaskTest.php')
-rw-r--r--tests/units/TaskTest.php161
1 files changed, 78 insertions, 83 deletions
diff --git a/tests/units/TaskTest.php b/tests/units/TaskTest.php
index 4d121fcd..e82faf19 100644
--- a/tests/units/TaskTest.php
+++ b/tests/units/TaskTest.php
@@ -3,6 +3,7 @@
require_once __DIR__.'/Base.php';
use Model\Task;
+use Model\TaskFinder;
use Model\Project;
use Model\ProjectPermission;
use Model\Category;
@@ -13,6 +14,7 @@ class TaskTest extends Base
public function testPrepareCreation()
{
$t = new Task($this->registry);
+ $tf = new TaskFinder($this->registry);
$p = new Project($this->registry);
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
@@ -91,6 +93,7 @@ class TaskTest extends Base
public function testPrepareModification()
{
$t = new Task($this->registry);
+ $tf = new TaskFinder($this->registry);
$p = new Project($this->registry);
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
@@ -110,12 +113,13 @@ class TaskTest extends Base
public function testCreation()
{
$t = new Task($this->registry);
+ $tf = new TaskFinder($this->registry);
$p = new Project($this->registry);
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
$this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
- $task = $t->getById(1);
+ $task = $tf->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
@@ -126,7 +130,7 @@ class TaskTest extends Base
$this->assertEquals(2, $t->create(array('title' => 'Task #2', 'project_id' => 1)));
- $task = $t->getById(2);
+ $task = $tf->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
@@ -134,19 +138,20 @@ class TaskTest extends Base
$this->assertEquals(time(), $task['date_modification']);
$this->assertEquals(0, $task['date_due']);
- $tasks = $t->getAll(1, 1);
+ $tasks = $tf->getAll(1, 1);
$this->assertNotEmpty($tasks);
$this->assertTrue(is_array($tasks));
$this->assertEquals(1, $tasks[0]['id']);
$this->assertEquals(2, $tasks[1]['id']);
- $tasks = $t->getAll(1, 0);
+ $tasks = $tf->getAll(1, 0);
$this->assertEmpty($tasks);
}
public function testRemove()
{
$t = new Task($this->registry);
+ $tf = new TaskFinder($this->registry);
$p = new Project($this->registry);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
@@ -156,27 +161,10 @@ class TaskTest extends Base
$this->assertFalse($t->remove(1234));
}
- public function testGetOverdueTasks()
- {
- $t = new Task($this->registry);
- $p = new Project($this->registry);
-
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'date_due' => strtotime('-1 day'))));
- $this->assertEquals(2, $t->create(array('title' => 'Task #2', 'project_id' => 1, 'date_due' => strtotime('+1 day'))));
- $this->assertEquals(3, $t->create(array('title' => 'Task #3', 'project_id' => 1, 'date_due' => 0)));
- $this->assertEquals(4, $t->create(array('title' => 'Task #3', 'project_id' => 1)));
-
- $tasks = $t->getOverdueTasks();
- $this->assertNotEmpty($tasks);
- $this->assertTrue(is_array($tasks));
- $this->assertEquals(1, count($tasks));
- $this->assertEquals('Task #1', $tasks[0]['title']);
- }
-
public function testMoveTaskWithColumnThatNotChange()
{
$t = new Task($this->registry);
+ $tf = new TaskFinder($this->registry);
$p = new Project($this->registry);
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
@@ -194,42 +182,42 @@ class TaskTest extends Base
$this->assertTrue($t->movePosition(1, 3, 3, 2));
// Check tasks position
- $task = $t->getById(1);
+ $task = $tf->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $t->getById(2);
+ $task = $tf->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $task = $t->getById(3);
+ $task = $tf->getById(3);
$this->assertEquals(3, $task['id']);
$this->assertEquals(3, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $task = $t->getById(4);
+ $task = $tf->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $t->getById(5);
+ $task = $tf->getById(5);
$this->assertEquals(5, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $task = $t->getById(6);
+ $task = $tf->getById(6);
$this->assertEquals(6, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(3, $task['position']);
- $task = $t->getById(7);
+ $task = $tf->getById(7);
$this->assertEquals(7, $task['id']);
$this->assertEquals(3, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $t->getById(8);
+ $task = $tf->getById(8);
$this->assertEquals(8, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(3, $task['position']);
@@ -238,6 +226,7 @@ class TaskTest extends Base
public function testMoveTaskWithBadPreviousPosition()
{
$t = new Task($this->registry);
+ $tf = new TaskFinder($this->registry);
$p = new Project($this->registry);
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
@@ -251,17 +240,17 @@ class TaskTest extends Base
$this->assertTrue($t->movePosition(1, 1, 2, 3));
// Check tasks position
- $task = $t->getById(2);
+ $task = $tf->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $t->getById(3);
+ $task = $tf->getById(3);
$this->assertEquals(3, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $task = $t->getById(1);
+ $task = $tf->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(3, $task['position']);
@@ -270,6 +259,7 @@ class TaskTest extends Base
public function testMoveTaskTop()
{
$t = new Task($this->registry);
+ $tf = new TaskFinder($this->registry);
$p = new Project($this->registry);
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
@@ -282,22 +272,22 @@ class TaskTest extends Base
$this->assertTrue($t->movePosition(1, 4, 1, 1));
// Check tasks position
- $task = $t->getById(1);
+ $task = $tf->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $task = $t->getById(2);
+ $task = $tf->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(3, $task['position']);
- $task = $t->getById(3);
+ $task = $tf->getById(3);
$this->assertEquals(3, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(4, $task['position']);
- $task = $t->getById(4);
+ $task = $tf->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
@@ -306,6 +296,7 @@ class TaskTest extends Base
public function testMoveTaskBottom()
{
$t = new Task($this->registry);
+ $tf = new TaskFinder($this->registry);
$p = new Project($this->registry);
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
@@ -318,22 +309,22 @@ class TaskTest extends Base
$this->assertTrue($t->movePosition(1, 1, 1, 4));
// Check tasks position
- $task = $t->getById(1);
+ $task = $tf->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(4, $task['position']);
- $task = $t->getById(2);
+ $task = $tf->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $t->getById(3);
+ $task = $tf->getById(3);
$this->assertEquals(3, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $task = $t->getById(4);
+ $task = $tf->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(3, $task['position']);
@@ -342,6 +333,7 @@ class TaskTest extends Base
public function testMovePosition()
{
$t = new Task($this->registry);
+ $tf = new TaskFinder($this->registry);
$p = new Project($this->registry);
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
@@ -361,7 +353,7 @@ class TaskTest extends Base
$this->assertEquals($counter, $t->create($task));
- $task = $t->getById($counter);
+ $task = $tf->getById($counter);
$this->assertNotFalse($task);
$this->assertNotEmpty($task);
$this->assertEquals($i, $task['position']);
@@ -372,68 +364,68 @@ class TaskTest extends Base
$this->assertTrue($t->movePosition(1, 4, 2, 3));
// We check the new position of the task
- $task = $t->getById(4);
+ $task = $tf->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(3, $task['position']);
// The tasks before have the correct position
- $task = $t->getById(3);
+ $task = $tf->getById(3);
$this->assertEquals(3, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(3, $task['position']);
- $task = $t->getById(7);
+ $task = $tf->getById(7);
$this->assertEquals(7, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(2, $task['position']);
// The tasks after have the correct position
- $task = $t->getById(5);
+ $task = $tf->getById(5);
$this->assertEquals(5, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(4, $task['position']);
- $task = $t->getById(8);
+ $task = $tf->getById(8);
$this->assertEquals(8, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(4, $task['position']);
// The number of tasks per column
- $this->assertEquals($task_per_column - 1, $t->countByColumnId(1, 1));
- $this->assertEquals($task_per_column + 1, $t->countByColumnId(1, 2));
- $this->assertEquals($task_per_column, $t->countByColumnId(1, 3));
- $this->assertEquals($task_per_column, $t->countByColumnId(1, 4));
+ $this->assertEquals($task_per_column - 1, $tf->countByColumnId(1, 1));
+ $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
+ $this->assertEquals($task_per_column, $tf->countByColumnId(1, 3));
+ $this->assertEquals($task_per_column, $tf->countByColumnId(1, 4));
// We move task id #1, column 1, position 1 to the column 4, position 6 (last position)
$this->assertTrue($t->movePosition(1, 1, 4, $task_per_column + 1));
// We check the new position of the task
- $task = $t->getById(1);
+ $task = $tf->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(4, $task['column_id']);
$this->assertEquals($task_per_column + 1, $task['position']);
// The tasks before have the correct position
- $task = $t->getById(20);
+ $task = $tf->getById(20);
$this->assertEquals(20, $task['id']);
$this->assertEquals(4, $task['column_id']);
$this->assertEquals($task_per_column, $task['position']);
// The tasks after have the correct position
- $task = $t->getById(2);
+ $task = $tf->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
// The number of tasks per column
- $this->assertEquals($task_per_column - 2, $t->countByColumnId(1, 1));
- $this->assertEquals($task_per_column + 1, $t->countByColumnId(1, 2));
- $this->assertEquals($task_per_column, $t->countByColumnId(1, 3));
- $this->assertEquals($task_per_column + 1, $t->countByColumnId(1, 4));
+ $this->assertEquals($task_per_column - 2, $tf->countByColumnId(1, 1));
+ $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
+ $this->assertEquals($task_per_column, $tf->countByColumnId(1, 3));
+ $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 4));
// Our previous moved task should stay at the same place
- $task = $t->getById(4);
+ $task = $tf->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(3, $task['position']);
@@ -448,28 +440,28 @@ class TaskTest extends Base
// Test position greater than the last position
$this->assertTrue($t->movePosition(1, 11, 1, 22));
- $task = $t->getById(11);
+ $task = $tf->getById(11);
$this->assertEquals(11, $task['id']);
$this->assertEquals(1, $task['column_id']);
- $this->assertEquals($t->countByColumnId(1, 1), $task['position']);
+ $this->assertEquals($tf->countByColumnId(1, 1), $task['position']);
- $task = $t->getById(5);
+ $task = $tf->getById(5);
$this->assertEquals(5, $task['id']);
$this->assertEquals(1, $task['column_id']);
- $this->assertEquals($t->countByColumnId(1, 1) - 1, $task['position']);
+ $this->assertEquals($tf->countByColumnId(1, 1) - 1, $task['position']);
- $task = $t->getById(4);
+ $task = $tf->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(3, $task['position']);
- $this->assertEquals($task_per_column - 1, $t->countByColumnId(1, 1));
- $this->assertEquals($task_per_column + 1, $t->countByColumnId(1, 2));
- $this->assertEquals($task_per_column - 1, $t->countByColumnId(1, 3));
- $this->assertEquals($task_per_column + 1, $t->countByColumnId(1, 4));
+ $this->assertEquals($task_per_column - 1, $tf->countByColumnId(1, 1));
+ $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
+ $this->assertEquals($task_per_column - 1, $tf->countByColumnId(1, 3));
+ $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 4));
// Our previous moved task should stay at the same place
- $task = $t->getById(4);
+ $task = $tf->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(3, $task['position']);
@@ -477,25 +469,26 @@ class TaskTest extends Base
// Test moving task to position 1
$this->assertTrue($t->movePosition(1, 14, 1, 1));
- $task = $t->getById(14);
+ $task = $tf->getById(14);
$this->assertEquals(14, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $t->getById(2);
+ $task = $tf->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $this->assertEquals($task_per_column, $t->countByColumnId(1, 1));
- $this->assertEquals($task_per_column + 1, $t->countByColumnId(1, 2));
- $this->assertEquals($task_per_column - 2, $t->countByColumnId(1, 3));
- $this->assertEquals($task_per_column + 1, $t->countByColumnId(1, 4));
+ $this->assertEquals($task_per_column, $tf->countByColumnId(1, 1));
+ $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
+ $this->assertEquals($task_per_column - 2, $tf->countByColumnId(1, 3));
+ $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 4));
}
public function testDuplicateToTheSameProject()
{
$t = new Task($this->registry);
+ $tf = new TaskFinder($this->registry);
$p = new Project($this->registry);
$c = new Category($this->registry);
@@ -510,7 +503,7 @@ class TaskTest extends Base
$this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1, 'category_id' => 2)));
- $task = $t->getById(1);
+ $task = $tf->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals(1, $task['position']);
@@ -519,7 +512,7 @@ class TaskTest extends Base
$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CREATE));
// Check the values of the duplicated task
- $task = $t->getById(2);
+ $task = $tf->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(Task::STATUS_OPEN, $task['is_active']);
$this->assertEquals(1, $task['project_id']);
@@ -532,6 +525,7 @@ class TaskTest extends Base
public function testDuplicateToAnotherProject()
{
$t = new Task($this->registry);
+ $tf = new TaskFinder($this->registry);
$p = new Project($this->registry);
$c = new Category($this->registry);
@@ -544,14 +538,14 @@ class TaskTest extends Base
// We create a task
$this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1, 'category_id' => 1)));
- $task = $t->getById(1);
+ $task = $tf->getById(1);
// We duplicate our task to the 2nd project
$this->assertEquals(2, $t->duplicateToAnotherProject(2, $task));
$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CREATE));
// Check the values of the duplicated task
- $task = $t->getById(2);
+ $task = $tf->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(1, $task['owner_id']);
$this->assertEquals(0, $task['category_id']);
@@ -564,6 +558,7 @@ class TaskTest extends Base
public function testMoveToAnotherProject()
{
$t = new Task($this->registry);
+ $tf = new TaskFinder($this->registry);
$p = new Project($this->registry);
$pp = new ProjectPermission($this->registry);
$user = new User($this->registry);
@@ -581,12 +576,12 @@ class TaskTest extends Base
$this->assertEquals(2, $t->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 = $t->getById(1);
+ $task = $tf->getById(1);
$this->assertEquals(1, $t->moveToAnotherProject(2, $task));
//$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CREATE));
// Check the values of the duplicated task
- $task = $t->getById(1);
+ $task = $tf->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals(1, $task['owner_id']);
$this->assertEquals(0, $task['category_id']);
@@ -599,10 +594,10 @@ class TaskTest extends Base
$this->assertTrue($pp->allowUser(2, 2));
// The owner should be reseted
- $task = $t->getById(2);
+ $task = $tf->getById(2);
$this->assertEquals(2, $t->moveToAnotherProject(2, $task));
- $task = $t->getById(2);
+ $task = $tf->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(0, $task['owner_id']);
}