@@ -28,162 +28,29 @@ public function testInit()
28
28
$ this ->cleanDirs ();
29
29
}
30
30
31
- /**
32
- * test <?php...\> tag
33
- * PHP_REMOVE
34
- */
35
- public function testPHP_REMOVE_php ()
36
- {
37
- $ this ->smarty ->setPhpHandling (Smarty::PHP_REMOVE );
38
- $ content = $ this ->smarty ->fetch ("string:a<?php echo 'hello world'; ?>e " );
39
- $ this ->assertEquals ("a echo 'hello world'; e " , $ content , 'remove <?php ?> ' );
40
- }
41
31
42
32
/**
43
- * test <%...%> tag
44
- * PHP_REMOVE
45
- */
46
- public function testPHP_REMOVE_asp ()
47
- {
48
- $ this ->smarty ->setPhpHandling (Smarty::PHP_REMOVE );
49
- $ content = $ this ->smarty ->fetch ("string:a<% echo 'hello world';%>e " );
50
- $ this ->assertEquals ("a echo 'hello world';e " , $ content , 'remove <% %> ' );
51
- }
52
- /**
53
- * test <script language='php'>...</script> tag
54
- * PHP_REMOVE
55
- */
56
- public function testPHP_REMOVE_script ()
57
- {
58
- $ this ->smarty ->setPhpHandling (Smarty::PHP_REMOVE );
59
- $ content = $ this ->smarty ->fetch ("string:a<script language='php'> echo 'hello world';</script>e " );
60
- $ this ->assertEquals ("a echo 'hello world';e " , $ content , "remove <script language='php'> " );
61
- }
62
- /**
63
- * test <?php...\> tag
64
- * PHP_PASSTHRU
65
- */
66
- public function testPHP_PASSTHRU_php ()
67
- {
68
- $ this ->smarty ->setPhpHandling (Smarty::PHP_PASSTHRU );
69
- $ content = $ this ->smarty ->fetch ("string:pa<?php echo 'hello world'; ?>pe " );
70
- $ this ->assertEquals ("pa<?php echo 'hello world'; ?>pe " , $ content , 'passthru <?php ?> ' );
71
- }
72
- /**
73
- * test <%...%> tag
74
- * PHP_PASSTHRU
75
- */
76
- public function testPHP_PASSTHRU_asp ()
77
- {
78
- $ this ->smarty ->setPhpHandling (Smarty::PHP_PASSTHRU );
79
- $ content = $ this ->smarty ->fetch ("string:pa<% echo 'hello world';%>pe " );
80
- $ this ->assertEquals ("pa<% echo 'hello world';%>pe " , $ content , 'passthru <% %> ' );
81
- }
82
- /**
83
- * test <script language='php'>...</script> tag
84
- * PHP_PASSTHRU
85
- */
86
- public function testPHP_PASSTHRU_script ()
87
- {
88
- $ this ->smarty ->setPhpHandling (Smarty::PHP_PASSTHRU );
89
- $ content = $ this ->smarty ->fetch ("string:pa<script language='php'> echo 'hello world';</script>pe " );
90
- $ this ->assertEquals ("pa<script language='php'> echo 'hello world';</script>pe " , $ content , "passthru <script language='php'> " );
91
- }
92
- /**
93
- * test <?php...\> tag
94
- * PHP_QUOTE
95
- */
96
- public function testPHP_QUOTE_php ()
97
- {
98
- $ this ->smarty ->setPhpHandling (Smarty::PHP_QUOTE );
99
- $ content = $ this ->smarty ->fetch ("string:qa<?php echo 'hello world'; \necho ' multiline'; ?>qe " );
100
- $ this ->assertEquals ("qa<?php echo 'hello world'; \necho ' multiline'; ?>qe " , $ content , 'qoute <?php ?> ' );
101
- }
102
- /**
103
- * test <%...%> tag
104
- * PHP_QUOTE
105
- */
106
- public function testPHP_QUOTE_asp ()
107
- {
108
- $ this ->smarty ->setPhpHandling (Smarty::PHP_QUOTE );
109
- $ content = $ this ->smarty ->fetch ("string:qa<% echo 'hello world';%>qe " );
110
- $ this ->assertEquals ("qa<% echo 'hello world';%>qe " , $ content , 'qoute <% %> ' );
111
- }
112
- /**
113
- * test <script language='php'>...</script> tag
114
- * PHP_QUOTE
115
- */
116
- public function testPHP_QUOTE_script ()
117
- {
118
- $ this ->smarty ->setPhpHandling (Smarty::PHP_QUOTE );
119
- $ content = $ this ->smarty ->fetch ("string:qa<script language='php'> echo 'hello world';</script>qe " );
120
- $ this ->assertEquals ("qa<script language='php'> echo 'hello world';</script>qe " , $ content , "quote <script language='php'> " );
121
- }
122
- /**
123
- * test <?php...\> tag
124
- * PHP_ALLOW
125
- */
126
- public function testPHP_ALLOW_php ()
127
- {
128
- $ this ->smartyBC ->setPhpHandling (Smarty::PHP_ALLOW );
129
- $ content = $ this ->smartyBC ->fetch ("string:aa <?php echo 'hello world'; ?> ae " );
130
- }
131
- /**
132
- * test <%...%> tag
133
- * PHP_ALLOW
33
+ * Test
34
+ * @run inSeparateProcess
35
+ * @preserveGlobalState disabled
36
+ * @dataProvider data
37
+ *
134
38
*/
135
- public function testPHP_ALLOW_asp ( )
39
+ public function testPHP ( $ phpHandling , $ templateFile , $ result , $ testName )
136
40
{
137
- $ this -> smartyBC -> setPhpHandling (Smarty:: PHP_ALLOW );
138
- $ content = $ this ->smartyBC ->fetch ( " string:aa <% echo 'hello world'; \n echo ' multiline';%> ae " ) ;
139
- if ( ini_get ( ' asp_tags ' )) {
140
- $ this ->assertEquals ( ' aa hello world multiline ae ' , $ content , ' allow <% %> ' );
141
- } else {
142
- $ this -> assertEquals ( " aa <% echo 'hello world'; \n echo ' multiline';%> ae " , $ content , ' allow asp disabled <% %> ' );
41
+ $ result = str_replace ( "\r" , '' , $ result );
42
+ $ this ->smartyBC ->php_handling = $ phpHandling ;
43
+ $ this -> smartyBC -> compile_id = $ testName ;
44
+ $ tpl = $ this ->smartyBC -> createTemplate ( $ templateFile );
45
+ if ( $ phpHandling == Smarty:: PHP_PASSTHRU || $ phpHandling == Smarty:: PHP_QUOTE ) {
46
+ $ result = str_replace ( "\r" , '' , $ tpl -> source -> content );
143
47
}
48
+ if ($ phpHandling == Smarty::PHP_QUOTE ) {
49
+ $ result = preg_replace_callback ('#(<\?(?:php|=)?)|(<%)|(<script\s+language\s*=\s*[" \']?\s*php\s*[" \']?\s*>)|(\?>)|(%>)|(<\/script>)#i ' , array ($ this , 'quote ' ), $ result );
50
+ }
51
+ $ content = $ tpl ->fetch ();
52
+ $ this ->assertEquals ($ result , $ content , $ testName );
144
53
}
145
- /**
146
- * test <script language='php'>...</script> tag
147
- * PHP_ALLOW
148
- */
149
- public function testPHP_ALLOW_script ()
150
- {
151
- $ this ->smartyBC ->setPhpHandling (Smarty::PHP_ALLOW );
152
- $ content = $ this ->smartyBC ->fetch ("string:aa <script language='php'> echo 'hello world'; \n echo ' multiline';</script> ae " );
153
- $ this ->assertEquals ('aa hello world multiline ae ' , $ content , "allow <script language='php'> " );
154
- }
155
- /**
156
- * test <?php...\> tag
157
- * PHP_ALLOW
158
- */
159
- public function testPHP_ALLOW_php2 ()
160
- {
161
- $ this ->smartyBC ->setPhpHandling (Smarty::PHP_ALLOW );
162
- $ content = $ this ->smartyBC ->fetch ("string:aa <?php echo '<?php'; \necho ' ?>'; ?> ae " );
163
- $ this ->assertEquals ('aa <?php ?> ae ' , $ content );
164
- }
165
- /**
166
- * test <?php...\> tag
167
- * PHP_ALLOW
168
- */
169
- public function testPHP_ALLOW_php3 ()
170
- {
171
- $ this ->smartyBC ->setPhpHandling (Smarty::PHP_ALLOW );
172
- $ content = $ this ->smartyBC ->fetch ("string:aa <?php echo '?>'; ?> ae " );
173
- $ this ->assertEquals ('aa ?> ae ' , $ content );
174
- }
175
- /**
176
- * test <?php...\> tag
177
- * PHP_ALLOW
178
- */
179
- public function testPHP_ALLOW_php4 ()
180
- {
181
- $ this ->smartyBC ->setPhpHandling (Smarty::PHP_ALLOW );
182
- $ content = $ this ->smartyBC ->fetch ("string:aa <?php /* ?> */ echo '?>'; ?> ae " );
183
- $ this ->assertEquals ('aa ?> ae ' , $ content );
184
- }
185
-
186
-
187
54
/**
188
55
* @expectedException SmartyCompilerException
189
56
* @expectedExceptionMessage $smarty->php_handling PHP_ALLOW not allowed. Use SmartyBC to enable it
@@ -196,84 +63,22 @@ public function testPHP_ALLOW_error()
196
63
}
197
64
198
65
/**
199
- * test <?=...\> shorttag
200
- * default is PASSTHRU
66
+ * test {php nocache}{/php} tag
201
67
*/
202
- public function testShortTag ()
68
+ public function testPHP_Tag_Nocache1 ()
203
69
{
204
- $ this ->smartyBC ->assign ('foo ' , 'bar ' );
205
- $ content = $ this ->smartyBC ->fetch ('eval:<?=$foo?> ' );
206
- $ this ->assertEquals ('<?=$foo?> ' , $ content );
70
+ $ this ->smartyBC ->caching = 1 ;
71
+ $ this ->smartyBC ->assign ('foo ' , 'foo ' );
72
+ $ content = $ this ->smartyBC ->fetch ('phptag_nocache.tpl ' );
73
+ $ this ->assertEquals ('-->foo<-- ' , $ content );
207
74
}
208
75
209
- /**
210
- * test unmatched <?php
211
- *
212
- */
213
- public function testUnmatched_php ()
214
- {
215
- $ this ->smartyBC ->setPhpHandling (Smarty::PHP_ALLOW );
216
- $ content = $ this ->smartyBC ->fetch ('string:aa <?php ee ' );
217
- $ this ->assertEquals ('aa <?php ee ' , $ content );
218
- }
219
- /**
220
- * test unmatched ?>
221
- *
222
- */
223
- public function testUnmatched_php_close ()
224
- {
225
- $ this ->smartyBC ->setPhpHandling (Smarty::PHP_ALLOW );
226
- $ content = $ this ->smartyBC ->fetch ('string:aa ?> ee ' );
227
- $ this ->assertEquals ('aa ?> ee ' , $ content );
228
- }
229
- /**
230
- * test unmatched <%
231
- *
232
- */
233
- public function testUnmatched_asp ()
234
- {
235
- $ this ->smartyBC ->setPhpHandling (Smarty::PHP_ALLOW );
236
- $ content = $ this ->smartyBC ->fetch ('string:aa <% ee ' );
237
- $ this ->assertEquals ('aa <% ee ' , $ content );
238
- }
239
- /**
240
- * test unmatched %>
241
- *
242
- */
243
- public function testUnmatched_asp_close ()
244
- {
245
- $ this ->smartyBC ->setPhpHandling (Smarty::PHP_ALLOW );
246
- $ content = $ this ->smartyBC ->fetch ('string:aa %> ee ' );
247
- $ this ->assertEquals ('aa %> ee ' , $ content );
248
- }
249
- /**
250
- * test unmatched <script language='php'>
251
- *
252
- */
253
- public function testUnmatched_script ()
254
- {
255
- $ this ->smartyBC ->setPhpHandling (Smarty::PHP_ALLOW );
256
- $ content = $ this ->smartyBC ->fetch ("string:aa <script language='php'> echo 'hello world'; ae " );
257
- $ this ->assertEquals ("aa <script language='php'> echo 'hello world'; ae " , $ content );
258
- }
259
- /**
260
- * test {php}{/php} tag
261
- * PHP_ALLOW
262
- */
263
- public function testPHP_Tag ()
264
- {
265
- $ content = $ this ->smartyBC ->fetch ("string:aa {php} echo 'hallo'; {/php} ae " );
266
- $ this ->assertEquals ('aa hallo ae ' , $ content );
267
- }
268
- /**
269
- * test {php nocache}{/php} tag
270
- * PHP_ALLOW
271
- */
272
- public function testPHP_Tag_Nocache ()
76
+ public function testPHP_Tag_Nocache2 ()
273
77
{
274
78
$ this ->smartyBC ->caching = 1 ;
275
- $ content = $ this ->smartyBC ->fetch ("string:aa {php nocache} echo 'hallo'; {/php} ae " );
276
- $ this ->assertEquals ('aa hallo ae ' , $ content );
79
+ $ this ->smartyBC ->assign ('foo ' , 'bar ' );
80
+ $ content = $ this ->smartyBC ->fetch ('phptag_nocache.tpl ' );
81
+ $ this ->assertEquals ('-->bar<-- ' , $ content );
277
82
}
278
83
/**
279
84
* test {php no cache}illegal option
@@ -286,33 +91,66 @@ public function testPHP_Tag_IllegalOption()
286
91
$ content = $ this ->smartyBC ->fetch ("string:aa {php no cache} echo 'hallo'; {/php} ae " );
287
92
}
288
93
289
- /**
290
- * test { php}{/php} tag
291
- * PHP_Tag Literal
292
- */
293
- public function testPHP_Tag_Literal ()
294
- {
295
- $ content = $ this ->smartyBC ->fetch ("string:aa { php} echo 'hallo'; { /php} ae " );
296
- $ this ->assertEquals ('aa { php} echo \'hallo \'; { /php} ae ' , $ content );
297
- }
298
- /**
299
- * test unmatched {php} tag
300
- * @expectedException SmartyCompilerException
301
- * @expectedExceptionMessage Missing {/php} closing tag
302
- *
303
- */
304
- public function testPHP_Tag_unmatch ()
94
+
95
+ public function data ()
305
96
{
306
- $ content = $ this ->smartyBC ->fetch ("string:aa {php} echo 'hallo'; ae " );
307
- }
308
- /**
309
- * test unmatched {/php} tag
310
- * @expectedException SmartyCompilerException
311
- * @expectedExceptionMessage Missing {php} open tag
312
- *
313
- */
314
- public function testPHP_TagOpen_unmatch ()
97
+ $ shortTag = ini_get ('short_open_tag ' ) == 1 ;
98
+ $ aspTag = ini_get ('asp_tags ' ) == 1 ;
99
+
100
+ return array (
101
+ /*
102
+ * php_handling
103
+ * template file
104
+ * result
105
+ * text
106
+ */
107
+ array (Smarty::PHP_REMOVE , 'php.tpl ' , '--><-- ' , 'PHP_REMOVE, \'php.tpl \'' ),
108
+ array (Smarty::PHP_PASSTHRU , 'php.tpl ' , '' , 'PHP_PASSTHRU, \'php.tpl \'' ),
109
+ array (Smarty::PHP_QUOTE , 'php.tpl ' , '' , 'PHP_QUOTE, \'php.tpl \'' ),
110
+ array (Smarty::PHP_ALLOW , 'php.tpl ' , '--> hello world <?php ?> <-- ' , 'PHP_ALLOW, \'php.tpl \'' ),
111
+ array (Smarty::PHP_REMOVE , 'php_line_comment.tpl ' , '--><-- ' , 'PHP_REMOVE, \'php_line_comment.tpl \'' ),
112
+ array (Smarty::PHP_PASSTHRU , 'php_line_comment.tpl ' , '' , 'PHP_PASSTHRU, \'php_line_comment.tpl \'' ),
113
+ array (Smarty::PHP_QUOTE , 'php_line_comment.tpl ' , '' , 'PHP_QUOTE, \'php_line_comment.tpl \'' ),
114
+ array (Smarty::PHP_ALLOW , 'php_line_comment.tpl ' , '--> hello world <?php ?> <-- ' , 'PHP_ALLOW, \'php_line_comment.tpl \'' ),
115
+ array (Smarty::PHP_REMOVE , 'php_block_comment.tpl ' , '--><-- ' , 'PHP_REMOVE, \'php_block_comment.tpl \'' ),
116
+ array (Smarty::PHP_PASSTHRU , 'php_block_comment.tpl ' , '' , 'PHP_PASSTHRU, \'php_block_comment.tpl \'' ),
117
+ array (Smarty::PHP_QUOTE , 'php_block_comment.tpl ' , '' , 'PHP_QUOTE, \'php_block_comment.tpl \'' ),
118
+ array (Smarty::PHP_ALLOW , 'php_block_comment.tpl ' , '--> hello world <?php ?> <-- ' , 'PHP_ALLOW, \'php_block_comment.tpl \'' ),
119
+ array (Smarty::PHP_REMOVE , 'php2.tpl ' , '--><-- ' , 'PHP_REMOVE, \'php2.tpl \'' ),
120
+ array (Smarty::PHP_PASSTHRU , 'php2.tpl ' , '' , 'PHP_PASSTHRU, \'php2.tpl \'' ),
121
+ array (Smarty::PHP_QUOTE , 'php2.tpl ' , '' , 'PHP_QUOTE, \'php2.tpl \'' ),
122
+ array (Smarty::PHP_ALLOW , 'php2.tpl ' , $ shortTag ? '--> hello world <? ?> <-- ' : '--><? echo \' hello world \';
123
+ echo \'<? \';
124
+ echo \'?> \';
125
+ ?><-- ' , 'PHP_ALLOW, \'php2.tpl \'' ),
126
+ array (Smarty::PHP_REMOVE , 'asp.tpl ' , '--><-- ' , 'PHP_REMOVE, \'asp.tpl \'' ),
127
+ array (Smarty::PHP_PASSTHRU , 'asp.tpl ' , '' , 'PHP_PASSTHRU, \'asp.tpl \'' ),
128
+ array (Smarty::PHP_QUOTE , 'asp.tpl ' , '' , 'PHP_QUOTE, \'asp.tpl \'' ),
129
+ array (Smarty::PHP_ALLOW , 'asp.tpl ' , $ aspTag ? '-->hello world <% %> <-- ' : '--><% echo \'hello world \';
130
+ echo \'<% \';
131
+ echo \'%> \';
132
+ %><-- ' , 'PHP_ALLOW, \'asp.tpl \'' ),
133
+ array (Smarty::PHP_REMOVE , 'script.tpl ' , '--><-- ' , 'PHP_REMOVE, \'script.tpl \'' ),
134
+ array (Smarty::PHP_PASSTHRU , 'script.tpl ' , '' , 'PHP_PASSTHRU, \'script.tpl \'' ),
135
+ array (Smarty::PHP_QUOTE , 'script.tpl ' , '' , 'PHP_QUOTE, \'script.tpl \'' ),
136
+ array (Smarty::PHP_ALLOW , 'script.tpl ' , '--> hello world <script language= \'php \'> </script> <-- ' , 'PHP_ALLOW, \'script.tpl \'' ),
137
+ array (Smarty::PHP_ALLOW , 'phptag.tpl ' , '--> hello world {php} {/php} <-- ' , 'PHP_ALLOW, \'phptag.tpl \'' ),
138
+ array (Smarty::PHP_ALLOW , 'phptag_line_comment.tpl ' , '--> hello world {php} {/php} <-- ' , 'PHP_ALLOW, \'phptag_line_comment.tpl \'' ),
139
+ array (Smarty::PHP_ALLOW , 'phptag_block_comment.tpl ' , '--> hello world {php} {/php} <-- ' , 'PHP_ALLOW, \'phptag_block_comment.tpl \'' ),
140
+ array (Smarty::PHP_ALLOW , 'phptag_literal.tpl ' , '-->{ php} echo \' hello world \';
141
+ echo \'foo \';
142
+ echo \'bar \';
143
+ $foo = 3;
144
+ { /php}<-- ' , 'PHP_ALLOW, \'phptag_literal.tpl \'' ),
145
+ );
146
+ }
147
+ /*
148
+ * Call back function for $php_handling = PHP_QUOTE
149
+ *
150
+ */
151
+ private function quote ($ match )
315
152
{
316
- $ content = $ this -> smartyBC -> fetch ( " string:aa {/php} ae " );
153
+ return htmlspecialchars ( $ match [ 0 ], ENT_QUOTES );
317
154
}
155
+
318
156
}
0 commit comments