summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/units/LinkTest.php161
-rw-r--r--tests/units/SubtaskTimeTrackingTest.php82
-rw-r--r--tests/units/TaskCreationTest.php4
-rw-r--r--tests/units/TaskLinkTest.php108
4 files changed, 352 insertions, 3 deletions
diff --git a/tests/units/LinkTest.php b/tests/units/LinkTest.php
new file mode 100644
index 00000000..ebcbcd39
--- /dev/null
+++ b/tests/units/LinkTest.php
@@ -0,0 +1,161 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Model\Link;
+
+class LinkTest extends Base
+{
+ public function testCreateLink()
+ {
+ $l = new Link($this->container);
+
+ $this->assertTrue($l->create('Link A'));
+ $this->assertFalse($l->create('Link A'));
+ $this->assertTrue($l->create('Link B', 'Link C'));
+
+ $links = $l->getAll();
+ $this->assertNotEmpty($links);
+ $this->assertCount(14, $links);
+
+ $link = $l->getByLabel('Link A');
+ $this->assertNotEmpty($link);
+ $this->assertEquals('Link A', $link['label']);
+ $this->assertEquals(0, $link['opposite_id']);
+
+ $link1 = $l->getByLabel('Link B');
+ $this->assertNotEmpty($link1);
+ $this->assertEquals('Link B', $link1['label']);
+ $this->assertNotEmpty($link1['opposite_id']);
+
+ $link2 = $l->getByLabel('Link C');
+ $this->assertNotEmpty($link2);
+ $this->assertEquals('Link C', $link2['label']);
+ $this->assertNotEmpty($link2['opposite_id']);
+
+ $this->assertNotEquals($link1['opposite_id'], $link2['opposite_id']);
+ }
+
+ public function testUpdate()
+ {
+ $l = new Link($this->container);
+
+ $this->assertTrue($l->update(array('id' => 2, 'label' => 'test', 'opposite_id' => 0)));
+
+ $link = $l->getById(2);
+ $this->assertNotEmpty($link);
+ $this->assertEquals('test', $link['label']);
+ $this->assertEquals(0, $link['opposite_id']);
+ }
+
+ public function testRemove()
+ {
+ $l = new Link($this->container);
+
+ $link = $l->getById(3);
+ $this->assertNotEmpty($link);
+ $this->assertEquals('is blocked by', $link['label']);
+ $this->assertEquals(2, $link['opposite_id']);
+
+ $this->assertTrue($l->remove(2));
+
+ $link = $l->getById(2);
+ $this->assertEmpty($link);
+
+ $link = $l->getById(3);
+ $this->assertNotEmpty($link);
+ $this->assertEquals('is blocked by', $link['label']);
+ $this->assertEquals(0, $link['opposite_id']);
+ }
+
+ public function testGetMergedList()
+ {
+ $l = new Link($this->container);
+ $links = $l->getMergedList();
+
+ $this->assertNotEmpty($links);
+ $this->assertCount(11, $links);
+ $this->assertEquals('blocks', $links[1]['label']);
+ $this->assertEquals('is blocked by', $links[1]['opposite_label']);
+ }
+
+ public function testGetList()
+ {
+ $l = new Link($this->container);
+ $links = $l->getList();
+
+ $this->assertNotEmpty($links);
+ $this->assertCount(12, $links);
+ $this->assertEquals('', $links[0]);
+ $this->assertEquals('relates to', $links[1]);
+
+ $links = $l->getList(1);
+
+ $this->assertNotEmpty($links);
+ $this->assertCount(11, $links);
+ $this->assertEquals('', $links[0]);
+ $this->assertArrayNotHasKey(1, $links);
+ $this->assertEquals('blocks', $links[2]);
+
+ $links = $l->getList(1, false);
+
+ $this->assertNotEmpty($links);
+ $this->assertCount(10, $links);
+ $this->assertArrayNotHasKey(0, $links);
+ $this->assertArrayNotHasKey(1, $links);
+ $this->assertEquals('blocks', $links[2]);
+
+ $links = $l->getList(0, false);
+
+ $this->assertNotEmpty($links);
+ $this->assertCount(11, $links);
+ $this->assertArrayNotHasKey(0, $links);
+ $this->assertEquals('relates to', $links[1]);
+ }
+
+ public function testValidateCreation()
+ {
+ $l = new Link($this->container);
+
+ $r = $l->validateCreation(array('label' => 'a'));
+ $this->assertTrue($r[0]);
+
+ $r = $l->validateCreation(array('label' => 'a', 'opposite_label' => 'b'));
+ $this->assertTrue($r[0]);
+
+ $r = $l->validateCreation(array('label' => 'relates to'));
+ $this->assertFalse($r[0]);
+
+ $r = $l->validateCreation(array('label' => 'a', 'opposite_label' => 'a'));
+ $this->assertFalse($r[0]);
+
+ $r = $l->validateCreation(array('label' => ''));
+ $this->assertFalse($r[0]);
+ }
+
+ public function testValidateModification()
+ {
+ $l = new Link($this->container);
+
+ $r = $l->validateModification(array('id' => 20, 'label' => 'a', 'opposite_id' => 0));
+ $this->assertTrue($r[0]);
+
+ $r = $l->validateModification(array('id' => 20, 'label' => 'a', 'opposite_id' => '1'));
+ $this->assertTrue($r[0]);
+
+ $r = $l->validateModification(array('id' => 20, 'label' => 'relates to', 'opposite_id' => '1'));
+ $this->assertFalse($r[0]);
+
+ $r = $l->validateModification(array('id' => 20, 'label' => '', 'opposite_id' => '1'));
+ $this->assertFalse($r[0]);
+
+ $r = $l->validateModification(array('label' => '', 'opposite_id' => '1'));
+ $this->assertFalse($r[0]);
+
+ $r = $l->validateModification(array('id' => 20, 'opposite_id' => '1'));
+ $this->assertFalse($r[0]);
+
+ $r = $l->validateModification(array('label' => 'test'));
+ $this->assertFalse($r[0]);
+ }
+}
diff --git a/tests/units/SubtaskTimeTrackingTest.php b/tests/units/SubtaskTimeTrackingTest.php
index a68d8ee1..90650e42 100644
--- a/tests/units/SubtaskTimeTrackingTest.php
+++ b/tests/units/SubtaskTimeTrackingTest.php
@@ -135,7 +135,7 @@ class SubtaskTimeTrackingTest extends Base
$this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
$this->assertEquals(2, $tc->create(array('title' => 'test 2', 'project_id' => 1, 'time_estimated' => 1.5, 'time_spent' => 0.5)));
- $this->assertEquals(1, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_spent' => 2.2)));
+ $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_spent' => 2.2)));
$this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => 1)));
$st->updateTaskTimeTracking(1);
@@ -151,4 +151,84 @@ class SubtaskTimeTrackingTest extends Base
$this->assertEquals(0.5, $task['time_spent'], 'Total spent', 0.01);
$this->assertEquals(1.5, $task['time_estimated'], 'Total estimated', 0.01);
}
+
+ public function testGetCalendarEvents()
+ {
+ $tf = new TaskFinder($this->container);
+ $tc = new TaskCreation($this->container);
+ $s = new Subtask($this->container);
+ $st = new SubtaskTimeTracking($this->container);
+ $p = new Project($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+ $this->assertEquals(2, $p->create(array('name' => 'test2')));
+
+ $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
+ $this->assertEquals(2, $tc->create(array('title' => 'test 1', 'project_id' => 2)));
+
+ $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1)));
+ $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1)));
+ $this->assertEquals(3, $s->create(array('title' => 'subtask #3', 'task_id' => 1)));
+
+ $this->assertEquals(4, $s->create(array('title' => 'subtask #4', 'task_id' => 2)));
+ $this->assertEquals(5, $s->create(array('title' => 'subtask #5', 'task_id' => 2)));
+ $this->assertEquals(6, $s->create(array('title' => 'subtask #6', 'task_id' => 2)));
+ $this->assertEquals(7, $s->create(array('title' => 'subtask #7', 'task_id' => 2)));
+ $this->assertEquals(8, $s->create(array('title' => 'subtask #8', 'task_id' => 2)));
+
+ // Create a couple of time slots
+ $now = time();
+
+ // Slot start before and finish inside the calendar time range
+ $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 1, 'start' => $now - 86400, 'end' => $now + 3600));
+
+ // Slot start inside time range and finish after the time range
+ $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 2, 'start' => $now + 3600, 'end' => $now + 2*86400));
+
+ // Start before time range and finish inside time range
+ $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 3, 'start' => $now - 86400, 'end' => $now + 1.5*86400));
+
+ // Start and finish inside time range
+ $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 4, 'start' => $now + 3600, 'end' => $now + 2*3600));
+
+ // Start and finish after the time range
+ $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 5, 'start' => $now + 2*86400, 'end' => $now + 3*86400));
+
+ // Start and finish before the time range
+ $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 6, 'start' => $now - 2*86400, 'end' => $now - 86400));
+
+ // Start before time range and not finished
+ $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 7, 'start' => $now - 86400));
+
+ // Start inside time range and not finish
+ $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 8, 'start' => $now + 3200));
+
+ $timesheet = $st->getUserTimesheet(1);
+ $this->assertNotEmpty($timesheet);
+ $this->assertCount(8, $timesheet);
+
+ $events = $st->getUserCalendarEvents(1, date('Y-m-d', $now), date('Y-m-d', $now + 86400));
+ $this->assertNotEmpty($events);
+ $this->assertCount(6, $events);
+ $this->assertEquals(1, $events[0]['subtask_id']);
+ $this->assertEquals(2, $events[1]['subtask_id']);
+ $this->assertEquals(3, $events[2]['subtask_id']);
+ $this->assertEquals(4, $events[3]['subtask_id']);
+ $this->assertEquals(7, $events[4]['subtask_id']);
+ $this->assertEquals(8, $events[5]['subtask_id']);
+
+ $events = $st->getProjectCalendarEvents(1, date('Y-m-d', $now), date('Y-m-d', $now + 86400));
+ $this->assertNotEmpty($events);
+ $this->assertCount(3, $events);
+ $this->assertEquals(1, $events[0]['subtask_id']);
+ $this->assertEquals(2, $events[1]['subtask_id']);
+ $this->assertEquals(3, $events[2]['subtask_id']);
+
+ $events = $st->getProjectCalendarEvents(2, date('Y-m-d', $now), date('Y-m-d', $now + 86400));
+ $this->assertNotEmpty($events);
+ $this->assertCount(3, $events);
+ $this->assertEquals(4, $events[0]['subtask_id']);
+ $this->assertEquals(7, $events[1]['subtask_id']);
+ $this->assertEquals(8, $events[2]['subtask_id']);
+ }
}
diff --git a/tests/units/TaskCreationTest.php b/tests/units/TaskCreationTest.php
index bdb0a79d..986f1eb1 100644
--- a/tests/units/TaskCreationTest.php
+++ b/tests/units/TaskCreationTest.php
@@ -93,8 +93,8 @@ class TaskCreationTest extends Base
$this->assertEquals('', $task['description']);
$this->assertEquals('', $task['reference']);
- $this->assertEquals(time(), $task['date_creation']);
- $this->assertEquals(time(), $task['date_modification']);
+ $this->assertEquals(time(), $task['date_creation'], 'Wrong timestamp', 1);
+ $this->assertEquals(time(), $task['date_modification'], 'Wrog timestamp', 1);
$this->assertEquals(0, $task['date_due']);
$this->assertEquals(0, $task['date_completed']);
$this->assertEquals(0, $task['date_started']);
diff --git a/tests/units/TaskLinkTest.php b/tests/units/TaskLinkTest.php
new file mode 100644
index 00000000..b78ffd28
--- /dev/null
+++ b/tests/units/TaskLinkTest.php
@@ -0,0 +1,108 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Model\Link;
+use Model\TaskLink;
+use Model\TaskCreation;
+use Model\Project;
+
+class TaskLinkTest extends Base
+{
+ public function testCreateTaskLinkWithNoOpposite()
+ {
+ $tl = new TaskLink($this->container);
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertTrue($tl->create(1, 2, 1));
+
+ $links = $tl->getLinks(1);
+ $this->assertNotEmpty($links);
+ $this->assertCount(1, $links);
+ $this->assertEquals('relates to', $links[0]['label']);
+ $this->assertEquals('B', $links[0]['title']);
+ $this->assertEquals(2, $links[0]['task_id']);
+ $this->assertEquals(1, $links[0]['is_active']);
+
+ $links = $tl->getLinks(2);
+ $this->assertNotEmpty($links);
+ $this->assertCount(1, $links);
+ $this->assertEquals('relates to', $links[0]['label']);
+ $this->assertEquals('A', $links[0]['title']);
+ $this->assertEquals(1, $links[0]['task_id']);
+ $this->assertEquals(1, $links[0]['is_active']);
+ }
+
+ public function testCreateTaskLinkWithOpposite()
+ {
+ $tl = new TaskLink($this->container);
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertTrue($tl->create(1, 2, 2));
+
+ $links = $tl->getLinks(1);
+ $this->assertNotEmpty($links);
+ $this->assertCount(1, $links);
+ $this->assertEquals('blocks', $links[0]['label']);
+ $this->assertEquals('B', $links[0]['title']);
+ $this->assertEquals(2, $links[0]['task_id']);
+ $this->assertEquals(1, $links[0]['is_active']);
+
+ $links = $tl->getLinks(2);
+ $this->assertNotEmpty($links);
+ $this->assertCount(1, $links);
+ $this->assertEquals('is blocked by', $links[0]['label']);
+ $this->assertEquals('A', $links[0]['title']);
+ $this->assertEquals(1, $links[0]['task_id']);
+ $this->assertEquals(1, $links[0]['is_active']);
+ }
+
+ public function testRemove()
+ {
+ $tl = new TaskLink($this->container);
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertTrue($tl->create(1, 2, 2));
+
+ $links = $tl->getLinks(1);
+ $this->assertNotEmpty($links);
+ $links = $tl->getLinks(2);
+ $this->assertNotEmpty($links);
+
+ $this->assertTrue($tl->remove($links[0]['id']));
+
+ $links = $tl->getLinks(1);
+ $this->assertEmpty($links);
+ $links = $tl->getLinks(2);
+ $this->assertEmpty($links);
+ }
+
+ public function testValidation()
+ {
+ $tl = new TaskLink($this->container);
+
+ $r = $tl->validateCreation(array('task_id' => 1, 'link_id' => 1, 'title' => 'a'));
+ $this->assertTrue($r[0]);
+
+ $r = $tl->validateCreation(array('task_id' => 1, 'link_id' => 1));
+ $this->assertFalse($r[0]);
+
+ $r = $tl->validateCreation(array('task_id' => 1, 'title' => 'a'));
+ $this->assertFalse($r[0]);
+
+ $r = $tl->validateCreation(array('link_id' => 1, 'title' => 'a'));
+ $this->assertFalse($r[0]);
+ }
+}