Add more unit tests

This commit is contained in:
Frederic Guillot 2015-10-03 17:21:29 -04:00
parent d7c0fabcb7
commit 260c8515c5
7 changed files with 152 additions and 31 deletions

View File

@ -12,23 +12,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
*

View File

@ -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);

View File

@ -50,19 +50,17 @@ class EmailNotificationTest extends Base
'file' => $file,
'changes' => array())
));
$this->assertNotEmpty($en->getMailSubject($event, array(
'task' => $task,
'comment' => $comment,
'subtask' => $subtask,
'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')))
);
}
public function testSendWithEmailAddress()
{
$en = new EmailNotification($this->container);

View File

@ -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));
}
}

View File

@ -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]);
}
}

View File

@ -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);
}
}

View File

@ -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()