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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
<?php
/**
* Smarty PHPunit tests for Extendsresource
*
* @author Uwe Tews
*/
use Smarty\Template;
/**
* class for extends resource tests
*/
class ExtendsResourceTest extends PHPUnit_Smarty
{
public function setUp(): void
{
$this->setUpSmarty(__DIR__);
$this->smarty->enableSecurity();
}
public function compiledPrefilter($text, Template $tpl)
{
return str_replace('#', $tpl->getTemplateVars('test'), $text);
}
/**
* test child/parent template chain with prepend
* @dataProvider data
*/
public function testCompileBlockChildPrepend_003($caching, $merge, $testNumber, $compileTestNumber, $renderTestNumber, $testName)
{
$this->smarty->registerFilter('pre', array($this, 'compiledPrefilter'));
$this->smarty->assign('test', $testNumber);
$this->smarty->caching = $caching;
$this->smarty->merge_compiled_includes = $merge;
if ($merge) {
$this->smarty->setCompileId(1);
}
$result = $this->smarty->fetch('extends:003_parent.tpl|003_child_prepend.tpl');
$this->assertStringContainsString(
"prepend - Default Title", $result, $testName . ' - content');
$this->assertStringContainsString(
"test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}",
$result,
$testName . ' - fetch() failure'
);
}
/**
* test child/parent template chain with apppend
* @dataProvider data
*/
public function testCompileBlockChildAppend_004($caching, $merge, $testNumber, $compileTestNumber, $renderTestNumber, $testName)
{
$this->smarty->registerFilter('pre', array($this, 'compiledPrefilter'));
$this->smarty->assign('test', $testNumber);
$this->smarty->caching = $caching;
$this->smarty->merge_compiled_includes = $merge;
if ($merge) {
$this->smarty->setCompileId(1);
}
$result = $this->smarty->fetch('extends:004_parent.tpl|004_child_append.tpl');
$this->assertStringContainsString("Default Title - append", $result, $testName . ' - content');
$this->assertStringContainsString("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, $testName . ' - fetch() failure');
}
/**
* test child/parent template chain with apppend
* @dataProvider data
*/
public function testCompileBlockAssignInChild_040($caching, $merge, $testNumber, $compileTestNumber, $renderTestNumber, $testName)
{
$this->smarty->registerFilter('pre', array($this, 'compiledPrefilter'));
$this->smarty->assign('test', $testNumber);
$this->smarty->caching = $caching;
$this->smarty->merge_compiled_includes = $merge;
if ($merge) {
$this->smarty->setCompileId(1);
}
$result = $this->smarty->fetch('extends:040_parent.tpl|040_child.tpl');
$this->assertStringContainsString("var-bar-var", $result, $testName . ' - content');
$this->assertStringContainsString("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, $testName . ' - fetch() failure');
}
/**
* @dataProvider data
*/
public function testCompileBlockIncreaseInChild_050($caching, $merge, $testNumber, $compileTestNumber, $renderTestNumber, $testName)
{
$this->smarty->registerFilter('pre', array($this, 'compiledPrefilter'));
$this->smarty->assign('test', $testNumber);
$this->smarty->caching = $caching;
$this->smarty->merge_compiled_includes = $merge;
if ($merge) {
$this->smarty->setCompileId(1);
}
$result = $this->smarty->fetch('extends:050_parent.tpl|050_child.tpl|050_grandchild.tpl');
$this->assertStringContainsString("var-bar-var", $result, $testName . ' - content');
$this->assertStringContainsString("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, $testName . ' - fetch() failure');
}
/**
* test grandchild/child/parent dependency test1
*/
public function testCompileBlockGrandChildMustCompile_021_1()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('extends:021_parent.tpl|021_child.tpl|021_grandchild.tpl');
$this->assertFalse($tpl->isCached());
$result = $this->smarty->fetch($tpl);
$this->assertStringContainsString('Grandchild Page Title', $result);
}
/**
* test grandchild/child/parent dependency test1
*/
public function testCompileBlockGrandChildMustCompile_021_12()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl2 = $this->smarty->createTemplate('extends:021_parent.tpl|021_child.tpl|021_grandchild.tpl');
$this->assertTrue($tpl2->isCached());
$result = $this->smarty->fetch($tpl2);
$this->assertStringContainsString('Grandchild Page Title', $result);
}
/**
* test grandchild/child/parent dependency test2
* @group slow
*/
public function testCompileBlockGrandChildMustCompile_021_2()
{
sleep(2);
touch($this->smarty->getTemplateDir(0) . '021_grandchild.tpl');
clearstatcache();
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('extends:021_parent.tpl|021_child.tpl|021_grandchild.tpl');
$this->assertFalse($tpl->isCached());
$result = $this->smarty->fetch($tpl);
$this->assertStringContainsString('Grandchild Page Title', $result);
}
/**
* test grandchild/child/parent dependency test2
*/
public function testCompileBlockGrandChildMustCompile_021_22()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl2 = $this->smarty->createTemplate('extends:021_parent.tpl|021_child.tpl|021_grandchild.tpl');
$this->assertTrue($tpl2->isCached());
$result = $this->smarty->fetch($tpl2);
$this->assertStringContainsString('Grandchild Page Title', $result);
}
/**
* test grandchild/child/parent dependency test3
* @group slow
*/
public function testCompileBlockGrandChildMustCompile_021_3()
{
sleep(2);
touch($this->smarty->getTemplateDir(0) . '021_child.tpl');
clearstatcache();
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('extends:021_parent.tpl|021_child.tpl|021_grandchild.tpl');
$this->assertFalse($tpl->isCached());
$result = $this->smarty->fetch($tpl);
$this->assertStringContainsString('Grandchild Page Title', $result);
}
/**
* test grandchild/child/parent dependency test3
*/
public function testCompileBlockGrandChildMustCompile_021_32()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl2 = $this->smarty->createTemplate('extends:021_parent.tpl|021_child.tpl|021_grandchild.tpl');
$this->assertTrue($tpl2->isCached());
$result = $this->smarty->fetch($tpl2);
$this->assertStringContainsString('Grandchild Page Title', $result);
}
/**
* test grandchild/child/parent dependency test4
* @group slow
*/
public function testCompileBlockGrandChildMustCompile_021_4()
{
sleep(2);
touch($this->smarty->getTemplateDir(0) . '021_parent.tpl');
clearstatcache();
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('extends:021_parent.tpl|021_child.tpl|021_grandchild.tpl');
$this->assertFalse($tpl->isCached());
$result = $this->smarty->fetch($tpl);
$this->assertStringContainsString('Grandchild Page Title', $result);
}
/**
* test grandchild/child/parent dependency test4
*/
public function testCompileBlockGrandChildMustCompile_021_42()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000;
$tpl = $this->smarty->createTemplate('extends:021_parent.tpl|021_child.tpl|021_grandchild.tpl');
$this->assertTrue($tpl->isCached());
$result = $this->smarty->fetch($tpl);
$this->assertStringContainsString('Grandchild Page Title', $result);
}
/**
* test relative includes in {block}
* @dataProvider data
*/
public function testCompileBlockRelativeIncludes_033($caching, $merge, $testNumber, $compileTestNumber,
$renderTestNumber, $testName)
{
$this->smarty->registerFilter('pre', array($this, 'compiledPrefilter'));
$this->smarty->assign('test', $testNumber);
$this->smarty->setCaching($caching);
$this->smarty->setMergeCompiledIncludes($merge);
if ($merge) {
$this->smarty->setCompileId(1);
}
$result = $this->smarty->fetch('extends:./child/parent/033_parent.tpl|./child/033_child.tpl|033_grandchild.tpl');
$this->assertStringContainsString('include grand:content include grand', $result, $testName . ' - grand');
$this->assertStringContainsString('include child:content include child', $result, $testName . ' - grand');
$this->assertStringContainsString('include parent:content include parent', $result, $testName . ' - grand');
$this->assertStringContainsString("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result,
$testName . ' - fetch() failure');
}
public function data(){
return array(
/*
* caching
* merging
* test nr
* result compile nr
* result render nr
* text
*/
array(false, false, 1, 1, 1, 'no caching, no merge - new'),
array(false, false, 2, 1, 2, 'no caching, no merge - exits'),
array(true, false, 3, 3, 3, 'caching, no merge - new'),
array(true, false, 4, 3, 3, 'caching, no merge - exits'),
array(false, true, 5, 5, 5, 'no caching, merge - new'),
array(false, true, 6, 5, 6, 'no caching, merge - exits'),
array(true, true, 7, 7, 7, 'caching, merge - new'),
array(true, true, 8, 7, 7, 'caching, merge - exits'),
);
}
}
|