diff options
Diffstat (limited to 'tests/units/Helper')
-rw-r--r-- | tests/units/Helper/HookHelperTest.php | 91 | ||||
-rw-r--r-- | tests/units/Helper/TaskHelperTest.php | 1 |
2 files changed, 83 insertions, 9 deletions
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())); } |