Add the possibility to attach template hooks with a callback

This commit is contained in:
Frederic Guillot
2016-08-13 18:41:01 -04:00
parent 2ebe8b3272
commit 010199e8f8
4 changed files with 87 additions and 1 deletions

View File

@@ -6,6 +6,57 @@ 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