From 010199e8f846f6c0b4f23336338bfda17ec04901 Mon Sep 17 00:00:00 2001
From: Frederic Guillot <fred@kanboard.net>
Date: Sat, 13 Aug 2016 18:41:01 -0400
Subject: Add the possibility to attach template hooks with a callback

---
 tests/units/Helper/HookHelperTest.php | 51 +++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

(limited to 'tests')

diff --git a/tests/units/Helper/HookHelperTest.php b/tests/units/Helper/HookHelperTest.php
index 66d13381..a67eaed9 100644
--- a/tests/units/Helper/HookHelperTest.php
+++ b/tests/units/Helper/HookHelperTest.php
@@ -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
-- 
cgit v1.2.3