diff options
Diffstat (limited to 'tests/units')
-rw-r--r-- | tests/units/Model/CustomFilterTest.php | 46 | ||||
-rw-r--r-- | tests/units/Model/EmailNotificationTest.php | 18 | ||||
-rw-r--r-- | tests/units/Model/TaskFinderTest.php | 22 | ||||
-rw-r--r-- | tests/units/Model/TaskLinkTest.php | 42 | ||||
-rw-r--r-- | tests/units/Model/TaskTest.php | 35 | ||||
-rw-r--r-- | tests/units/Model/WebNotificationTest.php | 3 |
6 files changed, 152 insertions, 14 deletions
diff --git a/tests/units/Model/CustomFilterTest.php b/tests/units/Model/CustomFilterTest.php index 5950ca13..4178aea6 100644 --- a/tests/units/Model/CustomFilterTest.php +++ b/tests/units/Model/CustomFilterTest.php @@ -34,6 +34,52 @@ class CustomFilterTest extends Base $this->assertEquals(1, $filter['is_shared']); } + public function testModification() + { + $p = new Project($this->container); + $cf = new CustomFilter($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); + $this->assertEquals(1, $cf->create(array('name' => 'My filter 1', 'filter' => 'status:open color:blue', 'project_id' => 1, 'user_id' => 1))); + $this->assertTrue($cf->update(array('id' => 1, 'filter' => 'color:red', 'is_shared' => 1))); + + $filter = $cf->getById(1); + $this->assertNotEmpty($filter); + $this->assertEquals('My filter 1', $filter['name']); + $this->assertEquals('color:red', $filter['filter']); + $this->assertEquals(1, $filter['project_id']); + $this->assertEquals(1, $filter['user_id']); + $this->assertEquals(1, $filter['is_shared']); + } + + public function testValidation() + { + $cf = new CustomFilter($this->container); + + // Validate creation + $r = $cf->validateCreation(array('filter' => 'test', 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0)); + $this->assertTrue($r[0]); + + $r = $cf->validateCreation(array('filter' => str_repeat('a', 101), 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0)); + $this->assertFalse($r[0]); + + $r = $cf->validateCreation(array('name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0)); + $this->assertFalse($r[0]); + + // Validate modification + $r = $cf->validateModification(array('id' => 1, 'filter' => 'test', 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0)); + $this->assertTrue($r[0]); + + $r = $cf->validateModification(array('filter' => 'test', 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0)); + $this->assertFalse($r[0]); + + $r = $cf->validateModification(array('id' => 1, 'filter' => str_repeat('a', 101), 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0)); + $this->assertFalse($r[0]); + + $r = $cf->validateModification(array('id' => 1, 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0)); + $this->assertFalse($r[0]); + } + public function testGetAll() { $u = new User($this->container); diff --git a/tests/units/Model/EmailNotificationTest.php b/tests/units/Model/EmailNotificationTest.php index 45613acc..7193f923 100644 --- a/tests/units/Model/EmailNotificationTest.php +++ b/tests/units/Model/EmailNotificationTest.php @@ -50,17 +50,15 @@ class EmailNotificationTest extends Base 'file' => $file, 'changes' => array()) )); - } - } - - public function testGetEmailSubject() - { - $en = new EmailNotification($this->container); - $this->assertEquals( - '[test][Task opened] blah (#2)', - $en->getMailSubject(Task::EVENT_OPEN, array('task' => array('id' => 2, 'title' => 'blah', 'project_name' => 'test'))) - ); + $this->assertNotEmpty($en->getMailSubject($event, array( + 'task' => $task, + 'comment' => $comment, + 'subtask' => $subtask, + 'file' => $file, + 'changes' => array()) + )); + } } public function testSendWithEmailAddress() diff --git a/tests/units/Model/TaskFinderTest.php b/tests/units/Model/TaskFinderTest.php index 3601efdd..1d850ba7 100644 --- a/tests/units/Model/TaskFinderTest.php +++ b/tests/units/Model/TaskFinderTest.php @@ -27,7 +27,7 @@ class TaskFinderTest extends Base $tasks = $tf->getOverdueTasks(); $this->assertNotEmpty($tasks); $this->assertTrue(is_array($tasks)); - $this->assertEquals(1, count($tasks)); + $this->assertCount(1, $tasks); $this->assertEquals('Task #1', $tasks[0]['title']); } @@ -48,7 +48,7 @@ class TaskFinderTest extends Base $tasks = $tf->getOverdueTasksByProject(1); $this->assertNotEmpty($tasks); $this->assertTrue(is_array($tasks)); - $this->assertEquals(1, count($tasks)); + $this->assertcount(1, $tasks); $this->assertEquals('Task #1', $tasks[0]['title']); } @@ -69,7 +69,7 @@ class TaskFinderTest extends Base $tasks = $tf->getOverdueTasksByUser(1); $this->assertNotEmpty($tasks); $this->assertTrue(is_array($tasks)); - $this->assertEquals(2, count($tasks)); + $this->assertCount(2, $tasks); $this->assertEquals(1, $tasks[0]['id']); $this->assertEquals('Task #1', $tasks[0]['title']); @@ -81,4 +81,20 @@ class TaskFinderTest extends Base $this->assertEquals('Task #2', $tasks[1]['title']); } + + public function testCountByProject() + { + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $p = new Project($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); + $this->assertEquals(2, $p->create(array('name' => 'Project #2'))); + $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1))); + $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 2))); + $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 2))); + + $this->assertEquals(1, $tf->countByProjectId(1)); + $this->assertEquals(2, $tf->countByProjectId(2)); + } } diff --git a/tests/units/Model/TaskLinkTest.php b/tests/units/Model/TaskLinkTest.php index fed03334..639f3dc8 100644 --- a/tests/units/Model/TaskLinkTest.php +++ b/tests/units/Model/TaskLinkTest.php @@ -114,6 +114,30 @@ class TaskLinkTest extends Base $this->assertEquals(3, $opposite_task_link['link_id']); } + public function testGroupByLabel() + { + $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->assertEquals(3, $tc->create(array('project_id' => 1, 'title' => 'C'))); + + $this->assertNotFalse($tl->create(1, 2, 2)); + $this->assertNotFalse($tl->create(1, 3, 2)); + + $links = $tl->getAllGroupedByLabel(1); + $this->assertCount(1, $links); + $this->assertArrayHasKey('blocks', $links); + $this->assertCount(2, $links['blocks']); + $this->assertEquals('test', $links['blocks'][0]['project_name']); + $this->assertEquals('Backlog', $links['blocks'][0]['column_title']); + $this->assertEquals('blocks', $links['blocks'][0]['label']); + } + public function testUpdate() { $tl = new TaskLink($this->container); @@ -187,7 +211,7 @@ class TaskLinkTest extends Base $links = $tl->getAll(2); $this->assertEmpty($links); - // Check validation + // Check creation $r = $tl->validateCreation(array('task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 2)); $this->assertTrue($r[0]); @@ -202,5 +226,21 @@ class TaskLinkTest extends Base $r = $tl->validateCreation(array('task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 1)); $this->assertFalse($r[0]); + + // Check modification + $r = $tl->validateModification(array('id' => 1, 'task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 2)); + $this->assertTrue($r[0]); + + $r = $tl->validateModification(array('id' => 1, 'task_id' => 1, 'link_id' => 1)); + $this->assertFalse($r[0]); + + $r = $tl->validateModification(array('id' => 1, 'task_id' => 1, 'opposite_task_id' => 2)); + $this->assertFalse($r[0]); + + $r = $tl->validateModification(array('id' => 1, 'task_id' => 1, 'opposite_task_id' => 2)); + $this->assertFalse($r[0]); + + $r = $tl->validateModification(array('id' => 1, 'task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 1)); + $this->assertFalse($r[0]); } } diff --git a/tests/units/Model/TaskTest.php b/tests/units/Model/TaskTest.php index ebafa612..37c68a78 100644 --- a/tests/units/Model/TaskTest.php +++ b/tests/units/Model/TaskTest.php @@ -26,4 +26,39 @@ class TaskTest extends Base $this->assertTrue($t->remove(1)); $this->assertFalse($t->remove(1234)); } + + public function testGetTaskIdFromText() + { + $t = new Task($this->container); + $this->assertEquals(123, $t->getTaskIdFromText('My task #123')); + $this->assertEquals(0, $t->getTaskIdFromText('My task 123')); + } + + public function testRecurrenceSettings() + { + $t = new Task($this->container); + + $statuses = $t->getRecurrenceStatusList(); + $this->assertCount(2, $statuses); + $this->assertArrayHasKey(Task::RECURRING_STATUS_NONE, $statuses); + $this->assertArrayHasKey(Task::RECURRING_STATUS_PENDING, $statuses); + $this->assertArrayNotHasKey(Task::RECURRING_STATUS_PROCESSED, $statuses); + + $triggers = $t->getRecurrenceTriggerList(); + $this->assertCount(3, $triggers); + $this->assertArrayHasKey(Task::RECURRING_TRIGGER_FIRST_COLUMN, $triggers); + $this->assertArrayHasKey(Task::RECURRING_TRIGGER_LAST_COLUMN, $triggers); + $this->assertArrayHasKey(Task::RECURRING_TRIGGER_CLOSE, $triggers); + + $dates = $t->getRecurrenceBasedateList(); + $this->assertCount(2, $dates); + $this->assertArrayHasKey(Task::RECURRING_BASEDATE_DUEDATE, $dates); + $this->assertArrayHasKey(Task::RECURRING_BASEDATE_TRIGGERDATE, $dates); + + $timeframes = $t->getRecurrenceTimeframeList(); + $this->assertCount(3, $timeframes); + $this->assertArrayHasKey(Task::RECURRING_TIMEFRAME_DAYS, $timeframes); + $this->assertArrayHasKey(Task::RECURRING_TIMEFRAME_MONTHS, $timeframes); + $this->assertArrayHasKey(Task::RECURRING_TIMEFRAME_YEARS, $timeframes); + } } diff --git a/tests/units/Model/WebNotificationTest.php b/tests/units/Model/WebNotificationTest.php index 0b9dcb17..fffeb475 100644 --- a/tests/units/Model/WebNotificationTest.php +++ b/tests/units/Model/WebNotificationTest.php @@ -52,6 +52,9 @@ class WebNotificationTest extends Base $this->assertNotEmpty($title); } + + $this->assertNotEmpty($wn->getTitleFromEvent(Task::EVENT_OVERDUE, array('tasks' => array(array('id' => 1))))); + $this->assertNotEmpty($wn->getTitleFromEvent('unkown', array())); } public function testHasNotification() |