Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.

Commit bd091fd

Browse files
committed
added recursive template function tests
1 parent 1a199f1 commit bd091fd

File tree

29 files changed

+2096
-0
lines changed

29 files changed

+2096
-0
lines changed

UnitTests/TemplateSource/TagTests/TemplateFunction/CompileFunctionTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,27 @@ public function testExternalDefinedFunctionNocachedCall3($merge, $text)
272272
$this->assertContains('bar bar', $this->smarty->fetch($tpl), $text);
273273
}
274274

275+
/**
276+
* test external function definition nocache call 3
277+
*
278+
* @run InSeparateProcess
279+
* @preserveGlobalState disabled
280+
*/
281+
public function testExternalDefinedFunctionRecursion()
282+
{
283+
$this->assertEquals('12345', $this->smarty->fetch('test_template_function_recursion2.tpl'));
284+
}
285+
/**
286+
* test external function definition nocache call 3
287+
*
288+
* @run InSeparateProcess
289+
* @preserveGlobalState disabled
290+
*/
291+
public function testExternalDefinedFunctionRecursion2()
292+
{
293+
$this->assertEquals('12345', $this->smarty->fetch('test_template_function_recursion2.tpl'));
294+
}
295+
275296
/**
276297
* Function data provider inline
277298
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/*%%SmartyHeaderCode:12318554f33a0dd75e8_81553017%%*/
3+
if(!defined('SMARTY_DIR')) exit('no direct access allowed');
4+
$_valid = $_smarty_tpl->decodeProperties(array (
5+
'file_dependency' =>
6+
array (
7+
'422f9371d4d2d9de15c6d6b506a1de7f4d71063d' =>
8+
array (
9+
0 => './templates/test_template_function_003.tpl',
10+
1 => 1430802407,
11+
2 => 'file',
12+
),
13+
),
14+
'nocache_hash' => '12318554f33a0dd75e8_81553017',
15+
'tpl_function' =>
16+
array (
17+
'functest' =>
18+
array (
19+
'called_functions' =>
20+
array (
21+
),
22+
'compiled_filepath' => './templates_c/1^422f9371d4d2d9de15c6d6b506a1de7f4d71063d_0.file.test_template_function_003.tpl.cache.php',
23+
'uid' => '422f9371d4d2d9de15c6d6b506a1de7f4d71063d',
24+
'call_name_caching' => 'smarty_template_function_functest_12318554f33a0dd75e8_81553017_nocache',
25+
'call_name' => 'smarty_template_function_functest_12318554f33a0dd75e8_81553017',
26+
),
27+
),
28+
'variables' =>
29+
array (
30+
'default' => 1,
31+
),
32+
'has_nocache_code' => false,
33+
'version' => '3.1.22-dev/32',
34+
'unifunc' => 'content_554f33a0e467b9_89359945',
35+
'saved_tpl_vars' =>
36+
array (
37+
),
38+
'cache_lifetime' => 3600,
39+
),true);
40+
/*/%%SmartyHeaderCode%%*/
41+
if ($_valid && !is_callable('content_554f33a0e467b9_89359945')) {
42+
function content_554f33a0e467b9_89359945 ($_smarty_tpl) {
43+
?>
44+
<?php if (!is_callable('smarty_function_counter')) require_once 'C:/wamp/www/Smarty3.1-test-release/vendor/smarty/smarty/libs/plugins/function.counter.php';
45+
?><?php $saved_tpl_vars = $_smarty_tpl->tpl_vars;
46+
foreach (array (
47+
'default' => 'default',
48+
) as $key => $value) {
49+
$_smarty_tpl->tpl_vars[$key] = new Smarty_Variable($value);
50+
}
51+
?>
52+
<?php echo $_smarty_tpl->tpl_vars['default']->value;?>
53+
<?php echo smarty_function_counter(array('start'=>1),$_smarty_tpl);?>
54+
<?php foreach (Smarty::$global_tpl_vars as $key => $value){
55+
if ($_smarty_tpl->tpl_vars[$key] === $value) $saved_tpl_vars[$key] = $value;
56+
}
57+
$_smarty_tpl->tpl_vars = $saved_tpl_vars;?>
58+
<?php }
59+
}
60+
?><?php /* smarty_template_function_functest_12318554f33a0dd75e8_81553017 */
61+
if (!function_exists('smarty_template_function_functest_12318554f33a0dd75e8_81553017')) {
62+
function smarty_template_function_functest_12318554f33a0dd75e8_81553017($_smarty_tpl,$params) {
63+
if (!is_callable('smarty_function_counter')) require_once 'C:/wamp/www/Smarty3.1-test-release/vendor/smarty/smarty/libs/plugins/function.counter.php';
64+
$saved_tpl_vars = $_smarty_tpl->tpl_vars;
65+
$params = array_merge(array('default'=>'default'), $params);
66+
foreach ($params as $key => $value) {
67+
$_smarty_tpl->tpl_vars[$key] = new Smarty_Variable($value);
68+
}
69+
echo $_smarty_tpl->tpl_vars['default']->value;?>
70+
<?php echo smarty_function_counter(array('start'=>1),$_smarty_tpl);
71+
foreach (Smarty::$global_tpl_vars as $key => $value){
72+
if ($_smarty_tpl->tpl_vars[$key] === $value) $saved_tpl_vars[$key] = $value;
73+
}
74+
$_smarty_tpl->tpl_vars = $saved_tpl_vars;
75+
}
76+
}
77+
/*/ smarty_template_function_functest_12318554f33a0dd75e8_81553017 */?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
/*%%SmartyHeaderCode:22688554f33a06da492_37365358%%*/
3+
if(!defined('SMARTY_DIR')) exit('no direct access allowed');
4+
$_valid = $_smarty_tpl->decodeProperties(array (
5+
'file_dependency' =>
6+
array (
7+
'6df2384df0a3755f460437207bf362b39a168f74' =>
8+
array (
9+
0 => './templates/test_template_function_002.tpl',
10+
1 => 1430802407,
11+
2 => 'file',
12+
),
13+
),
14+
'nocache_hash' => '22688554f33a06da492_37365358',
15+
'tpl_function' =>
16+
array (
17+
'functest' =>
18+
array (
19+
'called_functions' =>
20+
array (
21+
),
22+
'compiled_filepath' => './templates_c/1^6df2384df0a3755f460437207bf362b39a168f74_0.file.test_template_function_002.tpl.cache.php',
23+
'uid' => '6df2384df0a3755f460437207bf362b39a168f74',
24+
'call_name_caching' => 'smarty_template_function_functest_22688554f33a06da492_37365358_nocache',
25+
'call_name' => 'smarty_template_function_functest_22688554f33a06da492_37365358',
26+
),
27+
),
28+
'variables' =>
29+
array (
30+
'default' => 1,
31+
'param' => 0,
32+
),
33+
'has_nocache_code' => true,
34+
'version' => '3.1.22-dev/32',
35+
'unifunc' => 'content_554f33a0754e03_36911292',
36+
'saved_tpl_vars' =>
37+
array (
38+
),
39+
'cache_lifetime' => 3600,
40+
),true);
41+
/*/%%SmartyHeaderCode%%*/
42+
if ($_valid && !is_callable('content_554f33a0754e03_36911292')) {
43+
function content_554f33a0754e03_36911292 ($_smarty_tpl) {
44+
?>
45+
<?php $saved_tpl_vars = $_smarty_tpl->tpl_vars;
46+
foreach (array (
47+
'default' => 'default',
48+
'param' => 'param',
49+
) as $key => $value) {
50+
$_smarty_tpl->tpl_vars[$key] = new Smarty_Variable($value);
51+
}
52+
?>
53+
<?php echo $_smarty_tpl->tpl_vars['default']->value;?>
54+
<?php echo $_smarty_tpl->tpl_vars['param']->value;?>
55+
<?php foreach (Smarty::$global_tpl_vars as $key => $value){
56+
if ($_smarty_tpl->tpl_vars[$key] === $value) $saved_tpl_vars[$key] = $value;
57+
}
58+
$_smarty_tpl->tpl_vars = $saved_tpl_vars;?>
59+
<?php $saved_tpl_vars = $_smarty_tpl->tpl_vars;
60+
foreach (array (
61+
'default' => 'default',
62+
'param' => 1,
63+
) as $key => $value) {
64+
$_smarty_tpl->tpl_vars[$key] = new Smarty_Variable($value);
65+
}
66+
?>
67+
<?php echo $_smarty_tpl->tpl_vars['default']->value;?>
68+
<?php echo $_smarty_tpl->tpl_vars['param']->value;?>
69+
<?php foreach (Smarty::$global_tpl_vars as $key => $value){
70+
if ($_smarty_tpl->tpl_vars[$key] === $value) $saved_tpl_vars[$key] = $value;
71+
}
72+
$_smarty_tpl->tpl_vars = $saved_tpl_vars;?>
73+
<?php $_smarty_tpl->callTemplateFunction ('functest', $_smarty_tpl, array('param'=>$_smarty_tpl->tpl_vars['param']->value,'default'=>$_smarty_tpl->tpl_vars['default']->value), true);?>
74+
<?php }
75+
}
76+
?><?php /* smarty_template_function_functest_22688554f33a06da492_37365358 */
77+
if (!function_exists('smarty_template_function_functest_22688554f33a06da492_37365358')) {
78+
function smarty_template_function_functest_22688554f33a06da492_37365358($_smarty_tpl,$params) {
79+
$saved_tpl_vars = $_smarty_tpl->tpl_vars;
80+
$params = array_merge(array('default'=>'default'), $params);
81+
foreach ($params as $key => $value) {
82+
$_smarty_tpl->tpl_vars[$key] = new Smarty_Variable($value);
83+
}
84+
echo $_smarty_tpl->tpl_vars['default']->value;?>
85+
<?php echo $_smarty_tpl->tpl_vars['param']->value;
86+
foreach (Smarty::$global_tpl_vars as $key => $value){
87+
if ($_smarty_tpl->tpl_vars[$key] === $value) $saved_tpl_vars[$key] = $value;
88+
}
89+
$_smarty_tpl->tpl_vars = $saved_tpl_vars;
90+
}
91+
}
92+
/*/ smarty_template_function_functest_22688554f33a06da492_37365358 */?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
/*%%SmartyHeaderCode:32163554f33a03b9d17_30936283%%*/
3+
if(!defined('SMARTY_DIR')) exit('no direct access allowed');
4+
$_valid = $_smarty_tpl->decodeProperties(array (
5+
'file_dependency' =>
6+
array (
7+
'6df2384df0a3755f460437207bf362b39a168f74' =>
8+
array (
9+
0 => './templates/test_template_function_002.tpl',
10+
1 => 1430802407,
11+
2 => 'file',
12+
),
13+
),
14+
'nocache_hash' => '32163554f33a03b9d17_30936283',
15+
'tpl_function' =>
16+
array (
17+
'functest' =>
18+
array (
19+
'called_functions' =>
20+
array (
21+
),
22+
'compiled_filepath' => './templates_c/6df2384df0a3755f460437207bf362b39a168f74_0.file.test_template_function_002.tpl.cache.php',
23+
'uid' => '6df2384df0a3755f460437207bf362b39a168f74',
24+
'call_name_caching' => 'smarty_template_function_functest_32163554f33a03b9d17_30936283_nocache',
25+
'call_name' => 'smarty_template_function_functest_32163554f33a03b9d17_30936283',
26+
),
27+
),
28+
'variables' =>
29+
array (
30+
'default' => 0,
31+
'param' => 0,
32+
),
33+
'has_nocache_code' => false,
34+
'version' => '3.1.22-dev/32',
35+
'unifunc' => 'content_554f33a04382f2_73659407',
36+
'saved_tpl_vars' =>
37+
array (
38+
),
39+
'cache_lifetime' => 3600,
40+
),true);
41+
/*/%%SmartyHeaderCode%%*/
42+
if ($_valid && !is_callable('content_554f33a04382f2_73659407')) {
43+
function content_554f33a04382f2_73659407 ($_smarty_tpl) {
44+
?>
45+
<?php $saved_tpl_vars = $_smarty_tpl->tpl_vars;
46+
foreach (array (
47+
'default' => 'default',
48+
'param' => 'param',
49+
) as $key => $value) {
50+
$_smarty_tpl->tpl_vars[$key] = new Smarty_Variable($value);
51+
}
52+
?>
53+
default <?php echo $_smarty_tpl->tpl_vars['param']->value;?>
54+
<?php foreach (Smarty::$global_tpl_vars as $key => $value){
55+
if ($_smarty_tpl->tpl_vars[$key] === $value) $saved_tpl_vars[$key] = $value;
56+
}
57+
$_smarty_tpl->tpl_vars = $saved_tpl_vars;?>
58+
<?php $saved_tpl_vars = $_smarty_tpl->tpl_vars;
59+
foreach (array (
60+
'default' => 'default',
61+
'param' => 1,
62+
) as $key => $value) {
63+
$_smarty_tpl->tpl_vars[$key] = new Smarty_Variable($value);
64+
}
65+
?>
66+
default <?php echo $_smarty_tpl->tpl_vars['param']->value;?>
67+
<?php foreach (Smarty::$global_tpl_vars as $key => $value){
68+
if ($_smarty_tpl->tpl_vars[$key] === $value) $saved_tpl_vars[$key] = $value;
69+
}
70+
$_smarty_tpl->tpl_vars = $saved_tpl_vars;?>
71+
<?php $saved_tpl_vars = $_smarty_tpl->tpl_vars;
72+
foreach (array (
73+
'default' => 2,
74+
'param' => 1,
75+
) as $key => $value) {
76+
$_smarty_tpl->tpl_vars[$key] = new Smarty_Variable($value);
77+
}
78+
?>
79+
2 <?php echo $_smarty_tpl->tpl_vars['param']->value;?>
80+
<?php foreach (Smarty::$global_tpl_vars as $key => $value){
81+
if ($_smarty_tpl->tpl_vars[$key] === $value) $saved_tpl_vars[$key] = $value;
82+
}
83+
$_smarty_tpl->tpl_vars = $saved_tpl_vars;?>
84+
<?php }
85+
}
86+
?><?php /* smarty_template_function_functest_32163554f33a03b9d17_30936283 */
87+
if (!function_exists('smarty_template_function_functest_32163554f33a03b9d17_30936283')) {
88+
function smarty_template_function_functest_32163554f33a03b9d17_30936283($_smarty_tpl,$params) {
89+
$saved_tpl_vars = $_smarty_tpl->tpl_vars;
90+
$params = array_merge(array('default'=>'default'), $params);
91+
foreach ($params as $key => $value) {
92+
$_smarty_tpl->tpl_vars[$key] = new Smarty_Variable($value);
93+
}
94+
echo $_smarty_tpl->tpl_vars['default']->value;?>
95+
<?php echo $_smarty_tpl->tpl_vars['param']->value;
96+
foreach (Smarty::$global_tpl_vars as $key => $value){
97+
if ($_smarty_tpl->tpl_vars[$key] === $value) $saved_tpl_vars[$key] = $value;
98+
}
99+
$_smarty_tpl->tpl_vars = $saved_tpl_vars;
100+
}
101+
}
102+
/*/ smarty_template_function_functest_32163554f33a03b9d17_30936283 */?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/*%%SmartyHeaderCode:9227554f33a309a449_19754931%%*/
3+
if(!defined('SMARTY_DIR')) exit('no direct access allowed');
4+
$_valid = $_smarty_tpl->decodeProperties(array (
5+
'file_dependency' =>
6+
array (
7+
'7fe6a2a43aee3e8dbfe08235cf00ef0c2bdd4a61' =>
8+
array (
9+
0 => './templates/test_template_function_nocache_call.tpl',
10+
1 => 1430802407,
11+
2 => 'file',
12+
),
13+
'dfb143ec1fbcb556e13ac1f174c3b8394191bd18' =>
14+
array (
15+
0 => './templates/template_function_lib.tpl',
16+
1 => 1430802407,
17+
2 => 'file',
18+
),
19+
),
20+
'nocache_hash' => '9227554f33a309a449_19754931',
21+
'tpl_function' =>
22+
array (
23+
'template_func1' =>
24+
array (
25+
'called_functions' =>
26+
array (
27+
),
28+
'compiled_filepath' => './templates_c/dfb143ec1fbcb556e13ac1f174c3b8394191bd18_0.file.template_function_lib.tpl.cache.php',
29+
'uid' => 'dfb143ec1fbcb556e13ac1f174c3b8394191bd18',
30+
'call_name_caching' => 'smarty_template_function_template_func1_30703554f33a2534bd6_18319841_nocache',
31+
'call_name' => 'smarty_template_function_template_func1_30703554f33a2534bd6_18319841',
32+
),
33+
),
34+
'has_nocache_code' => true,
35+
'version' => '3.1.22-dev/32',
36+
'unifunc' => 'content_554f33a30ebdc0_07849220',
37+
'cache_lifetime' => 1000,
38+
),true);
39+
/*/%%SmartyHeaderCode%%*/
40+
if ($_valid && !is_callable('content_554f33a30ebdc0_07849220')) {
41+
function content_554f33a30ebdc0_07849220 ($_smarty_tpl) {
42+
?>
43+
44+
<?php $_smarty_tpl->callTemplateFunction ('template_func1', $_smarty_tpl, array(), true);?>
45+
<?php }
46+
}
47+
?><?php /* smarty_template_function_template_func1_30703554f33a2534bd6_18319841 */
48+
if (!function_exists('smarty_template_function_template_func1_30703554f33a2534bd6_18319841')) {
49+
function smarty_template_function_template_func1_30703554f33a2534bd6_18319841($_smarty_tpl,$params) {
50+
$saved_tpl_vars = $_smarty_tpl->tpl_vars;
51+
$params = array_merge(array('default'=>'d1'), $params);
52+
foreach ($params as $key => $value) {
53+
$_smarty_tpl->tpl_vars[$key] = new Smarty_Variable($value);
54+
}
55+
echo htmlspecialchars($_smarty_tpl->tpl_vars['foo']->value, ENT_QUOTES, 'UTF-8', true);?>
56+
<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['foo']->value, ENT_QUOTES, 'UTF-8', true);
57+
foreach (Smarty::$global_tpl_vars as $key => $value){
58+
if ($_smarty_tpl->tpl_vars[$key] === $value) $saved_tpl_vars[$key] = $value;
59+
}
60+
$_smarty_tpl->tpl_vars = $saved_tpl_vars;
61+
}
62+
}
63+
/*/ smarty_template_function_template_func1_30703554f33a2534bd6_18319841 */?>

0 commit comments

Comments
 (0)