summaryrefslogtreecommitdiff
path: root/tests/units/TaskModificationTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units/TaskModificationTest.php')
-rw-r--r--tests/units/TaskModificationTest.php225
1 files changed, 225 insertions, 0 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']);
+ }
+}