diff options
| author | Simon Wisselink <wisskid@users.noreply.github.com> | 2026-04-13 21:36:33 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-04-13 21:36:33 +0200 |
| commit | ff2ef3b0cb07fd584946254f145f0509a7685f58 (patch) | |
| tree | 30115da294cadea9dbbfd62416ff8649628826f5 /tests/UnitTests/TemplateSource/X_Scopes | |
| parent | aa2dcd82cf6a5caac9b1ed51e4bd0283f4dcced7 (diff) | |
| download | smarty-ff2ef3b0cb07fd584946254f145f0509a7685f58.tar.gz smarty-ff2ef3b0cb07fd584946254f145f0509a7685f58.tar.bz2 smarty-ff2ef3b0cb07fd584946254f145f0509a7685f58.zip | |
Redirect test temp dirs to system temp directory
* Redirect test temp dirs to system temp directory. Fixes #1178
Move all test-generated output (compiled templates, cache files, and
temporary template sources) from per-test-directory folders inside the
working tree to a parallel structure under sys_get_temp_dir()/smarty-tests/.
This removes 215 boilerplate .gitignore files from the repo and ensures
running the test suite leaves zero uncommitted files in the working tree.
All 2296 tests continue to pass with identical behavior.
* Isolate each test class in a unique temp directory
getTempDir() now appends a per-class uniqid token to the temp path, so
concurrent or sequential test runs never share compiled/cached output.
The token is generated lazily on first use and reset in
tearDownAfterClass(), giving every test class a fresh isolated directory.
As a result, the Bootstrap.php pre-run cleanup of smarty-tests/ is no
longer needed for correctness (stale paths are unreachable) and was
harmful to concurrent runs, so it has been removed.
* Remove individualFolders dead code and spurious assertTrue from cleanDirs()
- Remove the never-active individualFolders code path from setUpSmarty()
(the constant was always true, making the branch unreachable)
- Remove define('individualFolders') from Config.php and the constructor
- Remove $this->assertTrue(true) from cleanDirs(): it existed solely to
make testInit() count as a passing test; now that cleanDirs() is called
from setUpSmarty() and from test methods directly, the assertion was
spuriously inflating assertion counts
- Add tests/**/templates_c/, cache/, templates_tmp/ to .gitignore to
prevent stale test output from appearing as untracked files
* Clean up each test class's unique temp dir in tearDownAfterClass()
Add a private static removeDir() helper and call it from
tearDownAfterClass() to recursively delete the per-class unique temp
directory after each test class finishes. Cleanup failures are silently
ignored (@ suppression) so they never cause test failures.
Set KEEP_SMARTY_TEST_ARTIFACTS=1 in the environment to skip cleanup and
keep the artifacts on disk for debugging.
* cleanup of unused template files, non-shared files stored in __shared folder, no longer required calls to add template folders et cetera
* fixed the unit tests
* Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* remove useless resetting of static properties in tearDownAfterClass
* changed an incorrect doc and formatted some code.
* add changelog
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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 -* |
