diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-10-03 17:21:29 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-10-03 17:21:29 -0400 |
commit | 260c8515c507b8c339fdbe1a10b0f13792eac09d (patch) | |
tree | 39483e9918e1589786144af79b367492f04e2281 | |
parent | d7c0fabcb79fd72993cd00fe00d49bc5656bc204 (diff) |
Add more unit tests
-rw-r--r-- | app/Model/TaskStatus.php | 17 | ||||
-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 |
7 files changed, 152 insertions, 31 deletions
diff --git a/app/Model/TaskStatus.php b/app/Model/TaskStatus.php index 3f62667c..23d77fa4 100644 --- a/app/Model/TaskStatus.php +++ b/app/Model/TaskStatus.php @@ -13,23 +13,6 @@ use Event\TaskEvent; class TaskStatus extends Base { /** - * Return the list of statuses - * - * @access public - * @param boolean $prepend Prepend default value - * @return array - */ - public function getList($prepend = false) - { - $listing = $prepend ? array(-1 => t('All status')) : array(); - - return $listing + array( - Task::STATUS_OPEN => t('Open'), - Task::STATUS_CLOSED => t('Closed'), - ); - } - - /** * Return true if the task is closed * * @access public 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() |