diff --git a/tests/UnitTests/TemplateSource/_Issues/ArgumentMustBePassedByReference961Test.php b/tests/UnitTests/TemplateSource/_Issues/ArgumentMustBePassedByReference961Test.php new file mode 100644 index 000000000..ea80b4f84 --- /dev/null +++ b/tests/UnitTests/TemplateSource/_Issues/ArgumentMustBePassedByReference961Test.php @@ -0,0 +1,65 @@ +registerPlugin('modifier', 'reset', 'reset'); + $templateStr = "string:{reset(\$ar)}"; + $smarty->assign('ar', [1,2,3]); + $this->assertEquals( + '1', + $smarty->fetch($templateStr) + ); + } + + /** + * @group issue961 + */ + public function testResetAsModifier() + { + $smarty = new Smarty(); + $templateStr = "string:{\$ar|reset}"; + $smarty->assign('ar', [1,2,3]); + $this->assertEquals( + '1', + $smarty->fetch($templateStr) + ); + } + + /** + * @group issue961 + */ + public function testResetInExpression() + { + $smarty = new Smarty(); + $smarty->registerPlugin('modifier', 'reset', 'reset'); + $templateStr = "string:{if reset(\$ar)}ok{/if}"; + $smarty->assign('ar', [1,2,3]); + $this->assertEquals( + 'ok', + $smarty->fetch($templateStr) + ); + } + + /** + * @group issue961 + * @deprecated + */ + public function testMatch() + { + $smarty = new Smarty(); + $smarty->setErrorReporting(E_ALL & ~ E_USER_DEPRECATED); + $smarty->registerPlugin('modifier', 'preg_match', 'preg_match'); + $templateStr = 'string:{assign var="match" value=null}{if preg_match(\'/([a-z]{4})/\', "a test", $match)}{$match.1}{/if}'; + $this->assertEquals( + 'test', + $smarty->fetch($templateStr) + ); + } +} \ No newline at end of file