summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/units/TaskModificationTest.php225
-rw-r--r--tests/units/TaskTest.php23
-rw-r--r--tests/units/TimeTrackingTest.php6
3 files changed, 228 insertions, 26 deletions
diff --git a/tests/units/TaskModificationTest.php b/tests/units/TaskModificationTest.php
new file mode 100644
index 00000000..9217c582
--- /dev/null
+++ b/tests/units/TaskModificationTest.php
@@ -0,0 +1,225 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Model\Task;
+use Model\TaskCreation;
+use Model\TaskModification;
+use Model\TaskFinder;
+use Model\TaskStatus;
+use Model\Project;
+use Model\ProjectPermission;
+
+class TaskModificationTest extends Base
+{
+ public function testChangeTitle()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tm = new TaskModification($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertTrue($tm->update(array('id' => 1, 'title' => 'Task #1')));
+
+ $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE_UPDATE));
+ $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_UPDATE));
+
+ $event_data = $this->container['event']->getEventData(Task::EVENT_UPDATE);
+ $this->assertNotEmpty($event_data);
+ $this->assertEquals(1, $event_data['task_id']);
+ $this->assertEquals('Task #1', $event_data['title']);
+
+ $task = $tf->getById(1);
+ $this->assertEquals('Task #1', $task['title']);
+ }
+
+ public function testChangeAssignee()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tm = new TaskModification($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(0, $task['owner_id']);
+
+ $this->assertTrue($tm->update(array('id' => 1, 'owner_id' => 1)));
+
+ $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_ASSIGNEE_CHANGE));
+
+ $event_data = $this->container['event']->getEventData(Task::EVENT_ASSIGNEE_CHANGE);
+ $this->assertNotEmpty($event_data);
+ $this->assertEquals(1, $event_data['task_id']);
+ $this->assertEquals(1, $event_data['owner_id']);
+
+ $task = $tf->getById(1);
+ $this->assertEquals(1, $task['owner_id']);
+ }
+
+ public function testChangeDescription()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tm = new TaskModification($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $tf->getById(1);
+ $this->assertEquals('', $task['description']);
+
+ $this->assertTrue($tm->update(array('id' => 1, 'description' => 'test')));
+
+ $task = $tf->getById(1);
+ $this->assertEquals('test', $task['description']);
+ }
+
+ public function testChangeCategory()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tm = new TaskModification($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(0, $task['category_id']);
+
+ $this->assertTrue($tm->update(array('id' => 1, 'category_id' => 1)));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(1, $task['category_id']);
+ }
+
+ public function testChangeColor()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tm = new TaskModification($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $tf->getById(1);
+ $this->assertEquals('yellow', $task['color_id']);
+
+ $this->assertTrue($tm->update(array('id' => 1, 'color_id' => 'blue')));
+
+ $task = $tf->getById(1);
+ $this->assertEquals('blue', $task['color_id']);
+ }
+
+ public function testChangeScore()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tm = new TaskModification($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(0, $task['score']);
+
+ $this->assertTrue($tm->update(array('id' => 1, 'score' => 13)));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(13, $task['score']);
+ }
+
+ public function testChangeDueDate()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tm = new TaskModification($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(0, $task['date_due']);
+
+ $this->assertTrue($tm->update(array('id' => 1, 'date_due' => '2014-11-24')));
+
+ $task = $tf->getById(1);
+ $this->assertEquals('2014-11-24', date('Y-m-d', $task['date_due']));
+
+ $this->assertTrue($tm->update(array('id' => 1, 'date_due' => time())));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(date('Y-m-d'), date('Y-m-d', $task['date_due']));
+ }
+
+ public function testChangeStartedDate()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tm = new TaskModification($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(0, $task['date_started']);
+
+ $this->assertTrue($tm->update(array('id' => 1, 'date_started' => '2014-11-24')));
+
+ $task = $tf->getById(1);
+ $this->assertEquals('2014-11-24', date('Y-m-d', $task['date_started']));
+
+ $this->assertTrue($tm->update(array('id' => 1, 'date_started' => time())));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(date('Y-m-d'), date('Y-m-d', $task['date_started']));
+ }
+
+ public function testChangeTimeEstimated()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tm = new TaskModification($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(0, $task['time_estimated']);
+
+ $this->assertTrue($tm->update(array('id' => 1, 'time_estimated' => 13.3)));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(13.3, $task['time_estimated']);
+ }
+
+ public function testChangeTimeSpent()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tm = new TaskModification($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(0, $task['time_spent']);
+
+ $this->assertTrue($tm->update(array('id' => 1, 'time_spent' => 13.3)));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(13.3, $task['time_spent']);
+ }
+}
diff --git a/tests/units/TaskTest.php b/tests/units/TaskTest.php
index 19c37591..e303856a 100644
--- a/tests/units/TaskTest.php
+++ b/tests/units/TaskTest.php
@@ -146,27 +146,4 @@ class TaskTest extends Base
$this->assertNotEmpty($task);
$this->assertEquals(0, $task['owner_id']);
}
-
- public function testEvents()
- {
- $t = new Task($this->container);
- $tc = new TaskCreation($this->container);
- $ts = new TaskStatus($this->container);
- $p = new Project($this->container);
-
- // We create a project
- $this->assertEquals(1, $p->create(array('name' => 'test')));
-
- // We create task
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
-
- // We update a task
- $this->assertTrue($t->update(array('title' => 'test2', 'id' => 1)));
- $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_UPDATE));
- $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CREATE_UPDATE));
-
- // We change the assignee
- $this->assertTrue($t->update(array('owner_id' => 1, 'id' => 1)));
- $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_ASSIGNEE_CHANGE));
- }
}
diff --git a/tests/units/TimeTrackingTest.php b/tests/units/TimeTrackingTest.php
index b7790b51..6cf28eee 100644
--- a/tests/units/TimeTrackingTest.php
+++ b/tests/units/TimeTrackingTest.php
@@ -3,7 +3,7 @@
require_once __DIR__.'/Base.php';
use Model\SubTask;
-use Model\Task;
+use Model\TaskModification;
use Model\TaskCreation;
use Model\TaskFinder;
use Model\Project;
@@ -13,7 +13,7 @@ class TimeTrackingTest extends Base
{
public function testCalculateTime()
{
- $t = new Task($this->container);
+ $tm = new TaskModification($this->container);
$tc = new TaskCreation($this->container);
$tf = new TaskFinder($this->container);
$p = new Project($this->container);
@@ -22,7 +22,7 @@ class TimeTrackingTest extends Base
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'time_estimated' => 4.5)));
- $this->assertTrue($t->update(array('id' => 1, 'time_spent' => 3.5)));
+ $this->assertTrue($tm->update(array('id' => 1, 'time_spent' => 3.5)));
$task = $tf->getById(1);
$this->assertNotEmpty($task);