blob: faea5d2ddf6a6f0ddd9fcb9e6dc4576b76d5429e (
plain)
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
|
<?php
/**
* Smarty PHPunit tests for eval resources
*
* @author Uwe Tews
*/
/**
* class for eval resource tests
*
*
*
*
*/
class EvalResourceTest extends PHPUnit_Smarty
{
public function setUp(): void
{
$this->setUpSmarty(__DIR__);
}
/**
* test template eval exits
*/
public function testTemplateEvalExists1()
{
$tpl = $this->smarty->createTemplate('eval:{$foo}');
$this->assertTrue($tpl->getSource()->exists);
}
public function testTemplateEvalExists2()
{
$this->assertTrue($this->smarty->templateExists('eval:{$foo}'));
}
public function testGetTemplateResourceName()
{
$tpl = $this->smarty->createTemplate('eval:hello world');
$this->assertEquals('hello world', $tpl->getSource()->getResourceName());
}
public function testGetTemplateTimestamp()
{
$tpl = $this->smarty->createTemplate('eval:hello world');
$this->assertTrue($tpl->getSource()->getTimeStamp());
}
/**
* test getTemplateSource
*/
public function testGetTemplateSource()
{
$tpl = $this->smarty->createTemplate('eval:hello world{$foo}');
$this->assertEquals('hello world{$foo}', $tpl->getSource()->getContent());
}
/**
* test empty templates
*/
public function testEmptyTemplate()
{
$tpl = $this->smarty->createTemplate('eval:');
$this->assertEquals('', $this->smarty->fetch($tpl));
}
/**
* test usesCompiler
*/
public function testUsesCompiler()
{
$tpl = $this->smarty->createTemplate('eval:hello world');
$this->markTestIncomplete();
}
/**
* test isEvaluated
*/
public function testIsEvaluated()
{
$tpl = $this->smarty->createTemplate('eval:hello world');
$this->assertTrue($tpl->getSource()->handler->recompiled);
}
/**
* test mustCompile
*/
public function testMustCompile()
{
$tpl = $this->smarty->createTemplate('eval:hello world');
$this->assertTrue($tpl->mustCompile());
}
/**
* test getCompiledFilepath
*/
public function testGetCompiledFilepath()
{
$tpl = $this->smarty->createTemplate('eval:hello world');
$this->assertNull($tpl->getCompiled()->filepath);
}
/**
* test getCompiledTimestamp
*/
public function testGetCompiledTimestamp()
{
$tpl = $this->smarty->createTemplate('eval:hello world');
$this->assertFalse($tpl->getCompiled()->getTimeStamp());
}
/**
* test isCached
*/
public function testIsCached()
{
$tpl = $this->smarty->createTemplate('eval:hello world');
$this->assertFalse($tpl->isCached());
}
/**
* test getRenderedTemplate
*/
public function testGetRenderedTemplate()
{
$tpl = $this->smarty->createTemplate('eval:hello world');
$this->assertEquals('hello world', $tpl->fetch());
}
/**
* test that no complied template and cache file was produced
*/
public function testNoFiles()
{
$this->cleanDir($this->smarty->getCacheDir());
$this->cleanDir($this->smarty->getCompileDir());
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 20;
$tpl = $this->smarty->createTemplate('eval:hello world');
$this->assertEquals('hello world', $this->smarty->fetch($tpl));
$this->assertEquals(0, $this->smarty->clearAllCache());
$this->assertEquals(0, $this->smarty->clearCompiledTemplate());
}
/**
* test $smarty->is_cached
*/
public function testSmartyIsCached()
{
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 20;
$tpl = $this->smarty->createTemplate('eval:hello world');
$this->assertEquals('hello world', $this->smarty->fetch($tpl));
$this->assertFalse($this->smarty->isCached($tpl));
}
public function testUrlencodeTemplate()
{
$tpl = $this->smarty->createTemplate('eval:urlencode:%7B%22foobar%22%7Cescape%7D');
$this->assertEquals('foobar', $tpl->fetch());
}
public function testBase64Template()
{
$tpl = $this->smarty->createTemplate('eval:base64:eyJmb29iYXIifGVzY2FwZX0=');
$this->assertEquals('foobar', $tpl->fetch());
}
/**
* test clearCompiledTemplate()
*/
public function testClearCompiled()
{
$this->assertEquals(0, $this->smarty->clearCompiledTemplate('eval:hello world'));
}
}
|