diff options
Diffstat (limited to 'tests/UnitTests/TemplateSource/X_Scopes')
9 files changed, 118 insertions, 13 deletions
diff --git a/tests/UnitTests/TemplateSource/X_Scopes/ScopeTest.php b/tests/UnitTests/TemplateSource/X_Scopes/ScopeTest.php index 3999538e..152d8da3 100644 --- a/tests/UnitTests/TemplateSource/X_Scopes/ScopeTest.php +++ b/tests/UnitTests/TemplateSource/X_Scopes/ScopeTest.php @@ -18,15 +18,9 @@ class ScopeTest extends PHPUnit_Smarty public function setUp(): void { $this->setUpSmarty(__DIR__); - $this->smarty->addPluginsDir("../../__shared/PHPunitplugins/"); - $this->smarty->addTemplateDir("../../__shared/templates/"); - $this->smarty->addTemplateDir("./templates_tmp"); + $this->smarty->addPluginsDir("./plugins/"); } - public function testInit() - { - $this->cleanDirs(); - } /** * Test scope diff --git a/tests/UnitTests/TemplateSource/X_Scopes/cache/.gitignore b/tests/UnitTests/TemplateSource/X_Scopes/cache/.gitignore deleted file mode 100644 index d88cc144..00000000 --- a/tests/UnitTests/TemplateSource/X_Scopes/cache/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Ignore anything in here, but keep this directory -* diff --git a/tests/UnitTests/TemplateSource/X_Scopes/plugins/function.checkconfigvar.php b/tests/UnitTests/TemplateSource/X_Scopes/plugins/function.checkconfigvar.php new file mode 100644 index 00000000..94fcc2c9 --- /dev/null +++ b/tests/UnitTests/TemplateSource/X_Scopes/plugins/function.checkconfigvar.php @@ -0,0 +1,47 @@ +<?php +/** + * Smarty plugin for testing scopes in config vars + * + + + */ + +use Smarty\Template; + +/** + * Smarty {checkconfigvar} + * + * @param array $params parameter array + * @param object $template template object + * + * @return string + */ +function smarty_function_checkconfigvar($params, $template) +{ + $output = ''; + $types = array('template', 'data', 'global'); + if (isset($params['types'])) { + $types = (array)$params['types']; + } + $var = $params['var']; + $ptr = $template; + while ($ptr) { + if (in_array('template', $types) && $ptr instanceof Template) { + $output .= "#{$ptr->getSource()->name}:\${$var} ="; + $output .= $ptr->hasConfigVariable($var) ? preg_replace('/\s/', '', var_export($ptr->getConfigVariable($var), true)) : 'null'; + $ptr = $ptr->parent; + } elseif (in_array('data', $types) && !($ptr instanceof Template || $ptr instanceof \Smarty\Smarty)) { + $output .= "#data:\${$var} ="; + $output .= $ptr->hasConfigVariable($var) ? preg_replace('/\s/', '', var_export($ptr->getConfigVariable($var), true)) : 'null'; + $ptr = $ptr->parent; + } else { + $ptr = null; + } + } + if (in_array('global', $types)) { + $output .= "#global:\${$var} ="; + $output .= $template->getSmarty()->hasConfigVariable($var) ? + preg_replace('/\s/', '', var_export($template->getSmarty()->getConfigVariable($var), true)) : 'null'; + } + return $output; +} diff --git a/tests/UnitTests/TemplateSource/X_Scopes/plugins/function.checkvar.php b/tests/UnitTests/TemplateSource/X_Scopes/plugins/function.checkvar.php new file mode 100644 index 00000000..71740902 --- /dev/null +++ b/tests/UnitTests/TemplateSource/X_Scopes/plugins/function.checkvar.php @@ -0,0 +1,47 @@ +<?php +/** + * Smarty plugin for testing scopes + * + + + */ + +use Smarty\Template; + +/** + * Smarty {checkvar} + * + * @param array $params parameter array + * @param Template $template template object + * + * @return string + */ +function smarty_function_checkvar($params, \Smarty\Template $template) +{ + $output = ''; + $types = ['template', 'data', 'global']; + if (isset($params['types'])) { + $types = (array)$params['types']; + } + $var = $params['var']; + $ptr = $template; + while ($ptr) { + if (in_array('template', $types) && $ptr instanceof Template) { + $output .= "#{$ptr->getSource()->name}:\${$var} ="; + $output .= $ptr->hasVariable($var) ? preg_replace('/\s/', '', var_export($ptr->getValue($var), true)) : '>unassigned<'; + $ptr = $ptr->parent; + } elseif (in_array('data', $types) && !($ptr instanceof Template || $ptr instanceof \Smarty\Smarty)) { + $output .= "#data:\${$var} ="; + $output .= $ptr->hasVariable($var) ? preg_replace('/\s/', '', var_export($ptr->getValue($var), true)) : '>unassigned<'; + $ptr = $ptr->parent; + } else { + $ptr = null; + } + } + if (in_array('global', $types)) { + $output .= "#global:\${$var} ="; + $output .= $template->getSmarty()->hasVariable($var) ? + preg_replace('/\s/', '', var_export($template->getSmarty()->getValue($var), true)) : '>unassigned<'; + } + return $output; +} diff --git a/tests/UnitTests/TemplateSource/X_Scopes/plugins/function.pluginassign.php b/tests/UnitTests/TemplateSource/X_Scopes/plugins/function.pluginassign.php new file mode 100644 index 00000000..7786b742 --- /dev/null +++ b/tests/UnitTests/TemplateSource/X_Scopes/plugins/function.pluginassign.php @@ -0,0 +1,21 @@ +<?php +/** + * Smarty plugin for assign + * + + + */ + +/** + * Smarty {pluginassign} + * + * @param array $params parameter array + * @param object $template template object + * + * @return string + */ +function smarty_function_pluginassign($params, $template) +{ + $template->assign($params[ 'var' ], $params[ 'value' ]); + return ''; +} diff --git a/tests/UnitTests/TemplateSource/X_Scopes/templates/scope_include.tpl b/tests/UnitTests/TemplateSource/X_Scopes/templates/scope_include.tpl new file mode 100644 index 00000000..bfb1e6cb --- /dev/null +++ b/tests/UnitTests/TemplateSource/X_Scopes/templates/scope_include.tpl @@ -0,0 +1 @@ +{include $file} diff --git a/tests/UnitTests/TemplateSource/X_Scopes/templates/scope_tag.tpl b/tests/UnitTests/TemplateSource/X_Scopes/templates/scope_tag.tpl new file mode 100644 index 00000000..734ebb7b --- /dev/null +++ b/tests/UnitTests/TemplateSource/X_Scopes/templates/scope_tag.tpl @@ -0,0 +1 @@ +{include 'scope_include.tpl'}
\ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/X_Scopes/templates_c/.gitignore b/tests/UnitTests/TemplateSource/X_Scopes/templates_c/.gitignore deleted file mode 100644 index d88cc144..00000000 --- a/tests/UnitTests/TemplateSource/X_Scopes/templates_c/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Ignore anything in here, but keep this directory -* diff --git a/tests/UnitTests/TemplateSource/X_Scopes/templates_tmp/.gitignore b/tests/UnitTests/TemplateSource/X_Scopes/templates_tmp/.gitignore deleted file mode 100644 index d88cc144..00000000 --- a/tests/UnitTests/TemplateSource/X_Scopes/templates_tmp/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Ignore anything in here, but keep this directory -* |
