diff options
| author | Simon Wisselink <wisskid@users.noreply.github.com> | 2024-03-15 16:10:27 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-15 16:10:27 +0100 |
| commit | 82397ec7f074c56844d2e489ac1c40ca2ca3e756 (patch) | |
| tree | ce5ccb237c720650744997115e46643600f6205d /tests | |
| parent | 17da1f585eb0d02c5b55d42d681ab4df77d7538e (diff) | |
| download | smarty-82397ec7f074c56844d2e489ac1c40ca2ca3e756.tar.gz smarty-82397ec7f074c56844d2e489ac1c40ca2ca3e756.tar.bz2 smarty-82397ec7f074c56844d2e489ac1c40ca2ca3e756.zip | |
Fixed that scoped variables would overwrite parent scope. (#954)
* Fixed that scoped variables would overwrite parent scope.
Fixes #952
* Moved variable stack maintenance to methods and private properties in Data class.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/UnitTests/TemplateSource/X_Scopes/ScopeTest.php | 9 | ||||
| -rw-r--r-- | tests/UnitTests/__shared/PHPunitplugins/function.checkvar.php | 6 |
2 files changed, 9 insertions, 6 deletions
diff --git a/tests/UnitTests/TemplateSource/X_Scopes/ScopeTest.php b/tests/UnitTests/TemplateSource/X_Scopes/ScopeTest.php index 4f805fae..3999538e 100644 --- a/tests/UnitTests/TemplateSource/X_Scopes/ScopeTest.php +++ b/tests/UnitTests/TemplateSource/X_Scopes/ScopeTest.php @@ -325,4 +325,13 @@ class ScopeTest extends PHPUnit_Smarty $this->smarty->assign('scope', 'none'); $r = $this->smarty->fetch('test_function_scope.tpl'); } + + public function testFunctionScopeIsLocalByDefault() + { + $this->assertEquals( + 'a', + $this->smarty->fetch('string:{function name=test}{$var="b"}{/function}{$var="a"}{test}{$var}') + ); + } + } diff --git a/tests/UnitTests/__shared/PHPunitplugins/function.checkvar.php b/tests/UnitTests/__shared/PHPunitplugins/function.checkvar.php index 62a4e674..71740902 100644 --- a/tests/UnitTests/__shared/PHPunitplugins/function.checkvar.php +++ b/tests/UnitTests/__shared/PHPunitplugins/function.checkvar.php @@ -29,12 +29,6 @@ function smarty_function_checkvar($params, \Smarty\Template $template) 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<'; - $i = 0; - while (isset($ptr->_var_stack[ $i ])) { - $output .= "#{$ptr->_var_stack[ $i ]['name']} = "; - $output .= isset($ptr->_var_stack[ $i ][ 'tpl' ][$var]) ? preg_replace('/\s/', '', var_export($ptr->_var_stack[ $i ][ 'tpl' ][$var]->value, true)) : '>unassigned<'; - $i ++; - } $ptr = $ptr->parent; } elseif (in_array('data', $types) && !($ptr instanceof Template || $ptr instanceof \Smarty\Smarty)) { $output .= "#data:\${$var} ="; |
