From 2021dccc5a444f60c5ba1673d94b39999912cd26 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 20 Sep 2015 15:53:28 -0400 Subject: Move subtask forecast to a plugin Plugin repo: https://github.com/kanboard/plugin-subtask-forecast --- tests/units/Core/Plugin/HookTest.php | 62 +++++++++++++++++++++++++++++++++++ tests/units/Helper/HookHelperTest.php | 40 ++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 tests/units/Core/Plugin/HookTest.php create mode 100644 tests/units/Helper/HookHelperTest.php (limited to 'tests/units') diff --git a/tests/units/Core/Plugin/HookTest.php b/tests/units/Core/Plugin/HookTest.php new file mode 100644 index 00000000..95434ce4 --- /dev/null +++ b/tests/units/Core/Plugin/HookTest.php @@ -0,0 +1,62 @@ +assertEmpty($h->getListeners('myhook')); + + $h->on('myhook', 'A'); + $h->on('myhook', 'B'); + + $this->assertEquals(array('A', 'B'), $h->getListeners('myhook')); + } + + public function testMergeWithNoBinding() + { + $h = new Hook; + $values = array('A', 'B'); + + $result = $h->merge('myhook', $values, array('p' => 'c')); + $this->assertEquals($values, $result); + } + + public function testMergeWithBindings() + { + $h = new Hook; + $values = array('A', 'B'); + $expected = array('A', 'B', 'c', 'D'); + + $h->on('myhook', function($p) { + return array($p); + }); + + $h->on('myhook', function() { + return array('D'); + }); + + $result = $h->merge('myhook', $values, array('p' => 'c')); + $this->assertEquals($expected, $result); + $this->assertEquals($expected, $values); + } + + public function testMergeWithBindingButReturningBadData() + { + $h = new Hook; + $values = array('A', 'B'); + $expected = array('A', 'B'); + + $h->on('myhook', function() { + return 'string'; + }); + + $result = $h->merge('myhook', $values); + $this->assertEquals($expected, $result); + $this->assertEquals($expected, $values); + } +} diff --git a/tests/units/Helper/HookHelperTest.php b/tests/units/Helper/HookHelperTest.php new file mode 100644 index 00000000..6661c90b --- /dev/null +++ b/tests/units/Helper/HookHelperTest.php @@ -0,0 +1,40 @@ +container['template'] = $this + ->getMockBuilder('\Core\Template') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('render')) + ->getMock(); + + $this->container['template'] + ->expects($this->at(0)) + ->method('render') + ->with( + $this->equalTo('tpl1'), + $this->equalTo(array()) + ) + ->will($this->returnValue('tpl1_content')); + + $this->container['template'] + ->expects($this->at(1)) + ->method('render') + ->with( + $this->equalTo('tpl2'), + $this->equalTo(array()) + ) + ->will($this->returnValue('tpl2_content')); + + $h = new Hook($this->container); + $h->attach('test', 'tpl1'); + $h->attach('test', 'tpl2'); + $this->assertEquals('tpl1_contenttpl2_content', $h->render('test')); + } +} \ No newline at end of file -- cgit v1.2.3