diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration/TaskMetadataProcedureTest.php | 45 | ||||
-rw-r--r-- | tests/units/Core/Plugin/HookTest.php | 62 | ||||
-rw-r--r-- | tests/units/Helper/HookHelperTest.php | 91 | ||||
-rw-r--r-- | tests/units/Helper/TaskHelperTest.php | 1 | ||||
-rw-r--r-- | tests/units/Model/TaskFinderModelTest.php | 61 | ||||
-rw-r--r-- | tests/units/Notification/MailNotificationTest.php | 5 |
6 files changed, 232 insertions, 33 deletions
diff --git a/tests/integration/TaskMetadataProcedureTest.php b/tests/integration/TaskMetadataProcedureTest.php new file mode 100644 index 00000000..9b9b2f39 --- /dev/null +++ b/tests/integration/TaskMetadataProcedureTest.php @@ -0,0 +1,45 @@ +<?php + +require_once __DIR__.'/BaseProcedureTest.php'; + +class TaskMetadataProcedureTest extends BaseProcedureTest +{ + protected $projectName = 'My project to test tasks metadata'; + protected $metaKey = 'MyTestMetaKey'; + + public function testAll() + { + $this->assertCreateTeamProject(); + $this->assertCreateTask(); + $this->assertSaveTaskMetadata(); + $this->assertGetTaskMetadata(); + $this->assertGetTaskMetadataByName(); + $this->assertRemoveTaskMetadata(); + } + + public function assertSaveTaskMetadata() + { + $this->assertTrue($this->app->saveTaskMetadata($this->taskId, array($this->metaKey => 'metaValue1'))); + } + + public function assertGetTaskMetadata() + { + $metaData = $this->app->getTaskMetadata(($this->taskId)); + $this->assertArrayHasKey($this->metaKey, $metaData); + $this->assertEquals('metaValue1', $metaData[$this->metaKey]); + } + + public function assertGetTaskMetadataByName() + { + $metaValue = $this->app->getTaskMetadataByName($this->taskId, $this->metaKey); + $this->assertEquals('metaValue1', $metaValue, 'Did not return correct metadata value'); + } + + public function assertRemoveTaskMetadata() + { + $result = $this->app->removeTaskMetadata($this->taskId, $this->metaKey); + $this->assertTrue($result, 'Did not remove metakey with success'); + $metaValue = $this->app->getTaskMetadataByName($this->taskId, $this->metaKey); + $this->assertEquals('', $metaValue, 'Did not return an empty string due to metadata being deleted'); + } +} diff --git a/tests/units/Core/Plugin/HookTest.php b/tests/units/Core/Plugin/HookTest.php index d1c139b3..acadede0 100644 --- a/tests/units/Core/Plugin/HookTest.php +++ b/tests/units/Core/Plugin/HookTest.php @@ -8,89 +8,103 @@ class HookTest extends Base { public function testGetListeners() { - $h = new Hook; - $this->assertEmpty($h->getListeners('myhook')); + $hook = new Hook; + $this->assertEmpty($hook->getListeners('myhook')); - $h->on('myhook', 'A'); - $h->on('myhook', 'B'); + $hook->on('myhook', 'A'); + $hook->on('myhook', 'B'); - $this->assertEquals(array('A', 'B'), $h->getListeners('myhook')); + $this->assertEquals(array('A', 'B'), $hook->getListeners('myhook')); } public function testExists() { - $h = new Hook; - $this->assertFalse($h->exists('myhook')); + $hook = new Hook; + $this->assertFalse($hook->exists('myhook')); - $h->on('myhook', 'A'); + $hook->on('myhook', 'A'); - $this->assertTrue($h->exists('myhook')); + $this->assertTrue($hook->exists('myhook')); } public function testMergeWithNoBinding() { - $h = new Hook; + $hook = new Hook; $values = array('A', 'B'); - $result = $h->merge('myhook', $values, array('p' => 'c')); + $result = $hook->merge('myhook', $values, array('p' => 'c')); $this->assertEquals($values, $result); } public function testMergeWithBindings() { - $h = new Hook; + $hook = new Hook; $values = array('A', 'B'); $expected = array('A', 'B', 'c', 'D'); - $h->on('myhook', function ($p) { + $hook->on('myhook', function ($p) { return array($p); }); - $h->on('myhook', function () { + $hook->on('myhook', function () { return array('D'); }); - $result = $h->merge('myhook', $values, array('p' => 'c')); + $result = $hook->merge('myhook', $values, array('p' => 'c')); $this->assertEquals($expected, $result); $this->assertEquals($expected, $values); } public function testMergeWithBindingButReturningBadData() { - $h = new Hook; + $hook = new Hook; $values = array('A', 'B'); $expected = array('A', 'B'); - $h->on('myhook', function () { + $hook->on('myhook', function () { return 'string'; }); - $result = $h->merge('myhook', $values); + $result = $hook->merge('myhook', $values); $this->assertEquals($expected, $result); $this->assertEquals($expected, $values); } public function testFirstWithNoBinding() { - $h = new Hook; + $hook = new Hook; - $result = $h->first('myhook', array('p' => 2)); + $result = $hook->first('myhook', array('p' => 2)); $this->assertEquals(null, $result); } public function testFirstWithMultipleBindings() { - $h = new Hook; + $hook = new Hook; - $h->on('myhook', function ($p) { + $hook->on('myhook', function ($p) { return $p + 1; }); - $h->on('myhook', function ($p) { + $hook->on('myhook', function ($p) { return $p; }); - $result = $h->first('myhook', array('p' => 3)); + $result = $hook->first('myhook', array('p' => 3)); $this->assertEquals(4, $result); } + + public function testHookWithReference() + { + $hook = new Hook(); + + $hook->on('myhook', function (&$p) { + $p = 2; + }); + + $param = 123; + $result = $hook->reference('myhook', $param); + $this->assertSame(2, $result); + $this->assertSame(2, $param); + } } diff --git a/tests/units/Helper/HookHelperTest.php b/tests/units/Helper/HookHelperTest.php index 6e03acd1..a67eaed9 100644 --- a/tests/units/Helper/HookHelperTest.php +++ b/tests/units/Helper/HookHelperTest.php @@ -6,6 +6,79 @@ use Kanboard\Helper\HookHelper; class HookHelperTest extends Base { + public function testAttachCallable() + { + $this->container['template'] = $this + ->getMockBuilder('\Kanboard\Core\Template') + ->setConstructorArgs(array($this->container['helper'])) + ->setMethods(array('render')) + ->getMock(); + + $this->container['template'] + ->expects($this->once()) + ->method('render') + ->with( + $this->equalTo('tpl1'), + $this->equalTo(array('k0' => 'v0', 'k1' => 'v1')) + ) + ->will($this->returnValue('tpl1_content')); + + $hookHelper = new HookHelper($this->container); + $hookHelper->attachCallable('test', 'tpl1', function() { + return array( + 'k1' => 'v1', + ); + }); + + $this->assertEquals('tpl1_content', $hookHelper->render('test', array('k0' => 'v0'))); + } + + public function testAttachCallableWithNoResult() + { + $this->container['template'] = $this + ->getMockBuilder('\Kanboard\Core\Template') + ->setConstructorArgs(array($this->container['helper'])) + ->setMethods(array('render')) + ->getMock(); + + $this->container['template'] + ->expects($this->once()) + ->method('render') + ->with( + $this->equalTo('tpl1'), + $this->equalTo(array('k0' => 'v0')) + ) + ->will($this->returnValue('tpl1_content')); + + $hookHelper = new HookHelper($this->container); + $hookHelper->attachCallable('test', 'tpl1', function() { + }); + + $this->assertEquals('tpl1_content', $hookHelper->render('test', array('k0' => 'v0'))); + } + + public function testAttachLocalVariables() + { + $this->container['template'] = $this + ->getMockBuilder('\Kanboard\Core\Template') + ->setConstructorArgs(array($this->container['helper'])) + ->setMethods(array('render')) + ->getMock(); + + $this->container['template'] + ->expects($this->once()) + ->method('render') + ->with( + $this->equalTo('tpl1'), + $this->equalTo(array('k0' => 'v0', 'k1' => 'v1')) + ) + ->will($this->returnValue('tpl1_content')); + + $hookHelper = new HookHelper($this->container); + $hookHelper->attach('test', 'tpl1', array('k1' => 'v1')); + $this->assertEquals('tpl1_content', $hookHelper->render('test', array('k0' => 'v0'))); + } + public function testMultipleHooks() { $this->container['template'] = $this @@ -32,10 +105,10 @@ class HookHelperTest extends Base ) ->will($this->returnValue('tpl2_content')); - $h = new HookHelper($this->container); - $h->attach('test', 'tpl1'); - $h->attach('test', 'tpl2'); - $this->assertEquals('tpl1_contenttpl2_content', $h->render('test')); + $hookHelper = new HookHelper($this->container); + $hookHelper->attach('test', 'tpl1'); + $hookHelper->attach('test', 'tpl2'); + $this->assertEquals('tpl1_contenttpl2_content', $hookHelper->render('test')); } public function testAssetHooks() @@ -64,11 +137,11 @@ class HookHelperTest extends Base ) ->will($this->returnValue('<script src="skin.js"></script>')); - $h = new HookHelper($this->container); - $h->attach('test1', 'skin.css'); - $h->attach('test2', 'skin.js'); + $hookHelper = new HookHelper($this->container); + $hookHelper->attach('test1', 'skin.css'); + $hookHelper->attach('test2', 'skin.js'); - $this->assertContains('<link rel="stylesheet" href="skin.css"></link>', $h->asset('css', 'test1')); - $this->assertContains('<script src="skin.js"></script>', $h->asset('js', 'test2')); + $this->assertContains('<link rel="stylesheet" href="skin.css"></link>', $hookHelper->asset('css', 'test1')); + $this->assertContains('<script src="skin.js"></script>', $hookHelper->asset('js', 'test2')); } } diff --git a/tests/units/Helper/TaskHelperTest.php b/tests/units/Helper/TaskHelperTest.php index 454da553..2e2da6ee 100644 --- a/tests/units/Helper/TaskHelperTest.php +++ b/tests/units/Helper/TaskHelperTest.php @@ -9,6 +9,7 @@ class TaskHelperTest extends Base public function testSelectPriority() { $helper = new TaskHelper($this->container); + $this->assertNotEmpty($helper->selectPriority(array('priority_end' => '1', 'priority_start' => '5', 'priority_default' => '2'), array())); $this->assertNotEmpty($helper->selectPriority(array('priority_end' => '3', 'priority_start' => '1', 'priority_default' => '2'), array())); $this->assertEmpty($helper->selectPriority(array('priority_end' => '3', 'priority_start' => '3', 'priority_default' => '2'), array())); } diff --git a/tests/units/Model/TaskFinderModelTest.php b/tests/units/Model/TaskFinderModelTest.php index b2e2bd84..a9f018ff 100644 --- a/tests/units/Model/TaskFinderModelTest.php +++ b/tests/units/Model/TaskFinderModelTest.php @@ -6,9 +6,70 @@ use Kanboard\Model\ColumnModel; use Kanboard\Model\TaskCreationModel; use Kanboard\Model\TaskFinderModel; use Kanboard\Model\ProjectModel; +use Kanboard\Model\TaskModel; class TaskFinderModelTest extends Base { + public function testGetDetails() + { + $taskCreationModel = new TaskCreationModel($this->container); + $taskFinderModel = new TaskFinderModel($this->container); + $projectModel = new ProjectModel($this->container); + $categoryModel = new \Kanboard\Model\CategoryModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $categoryModel->create(array('project_id' => 1, 'name' => 'C1'))); + $this->assertEquals(1, $taskCreationModel->create(array( + 'project_id' => 1, + 'title' => 'Task #1', + 'reference' => 'test', + 'description' => 'desc', + 'owner_id' => 1, + 'category_id' => 1, + ))); + + $task = $taskFinderModel->getDetails(1); + $this->assertEquals(1, $task['id']); + $this->assertEquals('test', $task['reference']); + $this->assertEquals('Task #1', $task['title']); + $this->assertEquals('desc', $task['description']); + $this->assertEquals(time(), $task['date_creation'], 'Delta', 1); + $this->assertEquals(time(), $task['date_modification'], 'Delta', 1); + $this->assertEquals(time(), $task['date_moved'], 'Delta', 1); + $this->assertEquals(0, $task['date_completed']); + $this->assertEquals(0, $task['date_due']); + $this->assertEquals(0, $task['date_started']); + $this->assertEquals(0, $task['time_estimated']); + $this->assertEquals(0, $task['time_spent']); + $this->assertEquals('yellow', $task['color_id']); + $this->assertEquals(1, $task['project_id']); + $this->assertEquals(1, $task['column_id']); + $this->assertEquals(1, $task['owner_id']); + $this->assertEquals(0, $task['creator_id']); + $this->assertEquals(1, $task['position']); + $this->assertEquals(TaskModel::STATUS_OPEN, $task['is_active']); + $this->assertEquals(0, $task['score']); + $this->assertEquals(1, $task['category_id']); + $this->assertEquals(0, $task['priority']); + $this->assertEquals(0, $task['swimlane_id']); + $this->assertEquals(TaskModel::RECURRING_STATUS_NONE, $task['recurrence_status']); + $this->assertEquals(TaskModel::RECURRING_TRIGGER_FIRST_COLUMN, $task['recurrence_trigger']); + $this->assertEquals(0, $task['recurrence_factor']); + $this->assertEquals(TaskModel::RECURRING_TIMEFRAME_DAYS, $task['recurrence_timeframe']); + $this->assertEquals(TaskModel::RECURRING_BASEDATE_DUEDATE, $task['recurrence_basedate']); + $this->assertEquals(0, $task['recurrence_parent']); + $this->assertEquals(0, $task['recurrence_child']); + $this->assertEquals('C1', $task['category_name']); + $this->assertNull($task['swimlane_name']); + $this->assertEquals('Default swimlane', $task['default_swimlane']); + $this->assertEquals('Project #1', $task['project_name']); + $this->assertEquals('Backlog', $task['column_title']); + $this->assertEquals('admin', $task['assignee_username']); + $this->assertEquals('', $task['assignee_name']); + $this->assertEquals('', $task['creator_username']); + $this->assertEquals('', $task['creator_name']); + } + public function testGetTasksForDashboardWithHiddenColumn() { $taskCreationModel = new TaskCreationModel($this->container); diff --git a/tests/units/Notification/MailNotificationTest.php b/tests/units/Notification/MailNotificationTest.php index 05f1f882..93eeef0c 100644 --- a/tests/units/Notification/MailNotificationTest.php +++ b/tests/units/Notification/MailNotificationTest.php @@ -58,6 +58,11 @@ class MailNotificationTest extends Base $this->assertNotEmpty($mailNotification->getMailContent($eventName, $eventData)); $this->assertStringStartsWith('[test] ', $mailNotification->getMailSubject($eventName, $eventData)); } + + $this->assertStringStartsWith('[Test1, Test2] ', $mailNotification->getMailSubject(TaskModel::EVENT_OVERDUE, array( + 'tasks' => array(array('id' => 123), array('id' => 456)), + 'project_name' => 'Test1, Test2', + ))); } public function testSendWithEmailAddress() |