1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
<?php
require_once __DIR__.'/../Base.php';
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
->getMockBuilder('\Kanboard\Core\Template')
->setConstructorArgs(array($this->container['helper']))
->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'));
$hookHelper = new HookHelper($this->container);
$hookHelper->attach('test', 'tpl1');
$hookHelper->attach('test', 'tpl2');
$this->assertEquals('tpl1_contenttpl2_content', $hookHelper->render('test'));
}
public function testAssetHooks()
{
$this->container['helper']->asset = $this
->getMockBuilder('\Kanboard\Helper\AssetHelper')
->setConstructorArgs(array($this->container))
->setMethods(array('css', 'js'))
->getMock();
$this->container['helper']
->asset
->expects($this->at(0))
->method('css')
->with(
$this->equalTo('skin.css')
)
->will($this->returnValue('<link rel="stylesheet" href="skin.css"></link>'));
$this->container['helper']
->asset
->expects($this->at(1))
->method('js')
->with(
$this->equalTo('skin.js')
)
->will($this->returnValue('<script src="skin.js"></script>'));
$hookHelper = new HookHelper($this->container);
$hookHelper->attach('test1', 'skin.css');
$hookHelper->attach('test2', 'skin.js');
$this->assertContains('<link rel="stylesheet" href="skin.css"></link>', $hookHelper->asset('css', 'test1'));
$this->assertContains('<script src="skin.js"></script>', $hookHelper->asset('js', 'test2'));
}
}
|