From fea0d02d99e2de239b9c37fef9bfb3ffa35a4623 Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Wed, 27 Mar 2024 22:57:04 +0100 Subject: [PATCH 1/5] version bump --- CHANGELOG.md | 4 ++++ changelog/966.md | 1 - src/Smarty.php | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) delete mode 100644 changelog/966.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 724651bc2..274c3b74a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [5.0.1] - 2024-03-27 +- Fix error in Smarty\Smarty::compileAllTemplates() by including missing FilesystemIterator class [#966](https://github.com/smarty-php/smarty/issues/966) + + ## [5.0.0] - 2024-03-25 - Fixed that scoped variables would overwrite parent scope [#952](https://github.com/smarty-php/smarty/issues/952) - Removed publicly accessible `$tpl->_var_stack` variable diff --git a/changelog/966.md b/changelog/966.md deleted file mode 100644 index 5332ce59c..000000000 --- a/changelog/966.md +++ /dev/null @@ -1 +0,0 @@ -- Fix error in Smarty\Smarty::compileAllTemplates() by including missing FilesystemIterator class [#966](https://github.com/smarty-php/smarty/issues/966) \ No newline at end of file diff --git a/src/Smarty.php b/src/Smarty.php index 0f6ee0ce7..bf1d3fad5 100644 --- a/src/Smarty.php +++ b/src/Smarty.php @@ -55,7 +55,7 @@ class Smarty extends \Smarty\TemplateBase { /** * smarty version */ - const SMARTY_VERSION = '5.0.0'; + const SMARTY_VERSION = '5.0.1'; /** * define caching modes From 4fec27ccc274ff615df13612637160264b343bd9 Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Wed, 27 Mar 2024 23:05:16 +0100 Subject: [PATCH 2/5] fix release tooling to support/5 branch --- make-release.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/make-release.sh b/make-release.sh index 2b6db0d75..a5e9ffdea 100755 --- a/make-release.sh +++ b/make-release.sh @@ -15,7 +15,7 @@ php utilities/update-smarty-version-number.php $1 git add changelog CHANGELOG.md src/Smarty.php git commit -m "version bump" -git checkout master +git checkout support/5 git pull git merge --no-ff "release/$1" git branch -d "release/$1" From 6f054ecc2ffea472b438691f42afcad598b98d61 Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Thu, 28 Mar 2024 11:22:29 +0100 Subject: [PATCH 3/5] Fix Smarty::assign() not returning when called with an array as first parameter. (#973) Fixes #972 --- changelog/972.md | 1 + src/Data.php | 2 +- .../SmartyMethodsTests/Assign/AssignTest.php | 11 +++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 changelog/972.md diff --git a/changelog/972.md b/changelog/972.md new file mode 100644 index 000000000..e1e930a3c --- /dev/null +++ b/changelog/972.md @@ -0,0 +1 @@ +- Fix Smarty::assign() not returning $this when called with an array as first parameter [#972](https://github.com/smarty-php/smarty/pull/972) \ No newline at end of file diff --git a/src/Data.php b/src/Data.php index 3176c7f05..582ee6601 100644 --- a/src/Data.php +++ b/src/Data.php @@ -109,7 +109,7 @@ public function assign($tpl_var, $value = null, $nocache = false, $scope = null) foreach ($tpl_var as $_key => $_val) { $this->assign($_key, $_val, $nocache, $scope); } - return; + return $this; } switch ($scope ?? $this->getDefaultScope()) { case self::SCOPE_GLOBAL: diff --git a/tests/UnitTests/SmartyMethodsTests/Assign/AssignTest.php b/tests/UnitTests/SmartyMethodsTests/Assign/AssignTest.php index ea5f3a4bc..e8ae92b73 100644 --- a/tests/UnitTests/SmartyMethodsTests/Assign/AssignTest.php +++ b/tests/UnitTests/SmartyMethodsTests/Assign/AssignTest.php @@ -42,4 +42,15 @@ public function testArrayAssign() $this->smarty->assign(array('foo' => 'bar', 'foo2' => 'bar2')); $this->assertEquals('bar bar2', $this->smarty->fetch('eval:{$foo} {$foo2}')); } + + /** + * Test that assign returns this. + */ + public function testAssignReturnsThis() + { + $this->assertEquals( + 'data', + $this->smarty->assign(['dummy' => 'data'])->fetch('eval:{$dummy}') + ); + } } From 52dc8adafba3672c7ad1a7f792200450e8c629e7 Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Thu, 28 Mar 2024 11:23:16 +0100 Subject: [PATCH 4/5] version bump --- CHANGELOG.md | 4 ++++ changelog/972.md | 1 - src/Smarty.php | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) delete mode 100644 changelog/972.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 274c3b74a..c5b8c447d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [5.0.2] - 2024-03-28 +- Fix Smarty::assign() not returning $this when called with an array as first parameter [#972](https://github.com/smarty-php/smarty/pull/972) + + ## [5.0.1] - 2024-03-27 - Fix error in Smarty\Smarty::compileAllTemplates() by including missing FilesystemIterator class [#966](https://github.com/smarty-php/smarty/issues/966) diff --git a/changelog/972.md b/changelog/972.md deleted file mode 100644 index e1e930a3c..000000000 --- a/changelog/972.md +++ /dev/null @@ -1 +0,0 @@ -- Fix Smarty::assign() not returning $this when called with an array as first parameter [#972](https://github.com/smarty-php/smarty/pull/972) \ No newline at end of file diff --git a/src/Smarty.php b/src/Smarty.php index bf1d3fad5..ce21710c8 100644 --- a/src/Smarty.php +++ b/src/Smarty.php @@ -55,7 +55,7 @@ class Smarty extends \Smarty\TemplateBase { /** * smarty version */ - const SMARTY_VERSION = '5.0.1'; + const SMARTY_VERSION = '5.0.2'; /** * define caching modes From 3232277bc526602801225ac4fbc7aae3867f582e Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Fri, 29 Mar 2024 23:32:49 +0100 Subject: [PATCH 5/5] Fix warning when calling hasVariable for an undefined variable (#978) Fixes #977 --- changelog/977.md | 1 + src/Data.php | 2 +- .../GetTemplateVars/cache/.gitignore | 2 -- .../GetTemplateVars/templates_c/.gitignore | 2 -- .../GetTemplateVarsTest.php | 0 .../TemplateVars/HasVariableTest.php | 32 +++++++++++++++++++ 6 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 changelog/977.md delete mode 100644 tests/UnitTests/SmartyMethodsTests/GetTemplateVars/cache/.gitignore delete mode 100644 tests/UnitTests/SmartyMethodsTests/GetTemplateVars/templates_c/.gitignore rename tests/UnitTests/SmartyMethodsTests/{GetTemplateVars => TemplateVars}/GetTemplateVarsTest.php (100%) create mode 100644 tests/UnitTests/SmartyMethodsTests/TemplateVars/HasVariableTest.php diff --git a/changelog/977.md b/changelog/977.md new file mode 100644 index 000000000..d41453c1b --- /dev/null +++ b/changelog/977.md @@ -0,0 +1 @@ +- Fix warning when calling hasVariable for an undefined variable [#977](https://github.com/smarty-php/smarty/issues/977) \ No newline at end of file diff --git a/src/Data.php b/src/Data.php index 582ee6601..3bb7814db 100644 --- a/src/Data.php +++ b/src/Data.php @@ -290,7 +290,7 @@ public function setVariable($varName, Variable $variableObject) { * @return bool */ public function hasVariable($varName): bool { - return !($this->getVariable($varName) instanceof UndefinedVariable); + return !($this->getVariable($varName, true, false) instanceof UndefinedVariable); } /** diff --git a/tests/UnitTests/SmartyMethodsTests/GetTemplateVars/cache/.gitignore b/tests/UnitTests/SmartyMethodsTests/GetTemplateVars/cache/.gitignore deleted file mode 100644 index d88cc1446..000000000 --- a/tests/UnitTests/SmartyMethodsTests/GetTemplateVars/cache/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Ignore anything in here, but keep this directory -* diff --git a/tests/UnitTests/SmartyMethodsTests/GetTemplateVars/templates_c/.gitignore b/tests/UnitTests/SmartyMethodsTests/GetTemplateVars/templates_c/.gitignore deleted file mode 100644 index d88cc1446..000000000 --- a/tests/UnitTests/SmartyMethodsTests/GetTemplateVars/templates_c/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Ignore anything in here, but keep this directory -* diff --git a/tests/UnitTests/SmartyMethodsTests/GetTemplateVars/GetTemplateVarsTest.php b/tests/UnitTests/SmartyMethodsTests/TemplateVars/GetTemplateVarsTest.php similarity index 100% rename from tests/UnitTests/SmartyMethodsTests/GetTemplateVars/GetTemplateVarsTest.php rename to tests/UnitTests/SmartyMethodsTests/TemplateVars/GetTemplateVarsTest.php diff --git a/tests/UnitTests/SmartyMethodsTests/TemplateVars/HasVariableTest.php b/tests/UnitTests/SmartyMethodsTests/TemplateVars/HasVariableTest.php new file mode 100644 index 000000000..047af7b90 --- /dev/null +++ b/tests/UnitTests/SmartyMethodsTests/TemplateVars/HasVariableTest.php @@ -0,0 +1,32 @@ +setUpSmarty(__DIR__); + } + + + public function testInit() + { + $this->cleanDirs(); + } + + public function testSimpleTrue() + { + $this->smarty->assign('foo', 'bar'); + $this->assertTrue($this->smarty->hasVariable('foo')); + } + + + public function testSimpleFalse() + { + $this->smarty->assign('foo', 'bar'); + $this->assertFalse($this->smarty->hasVariable('foox')); + } + +}