-
Notifications
You must be signed in to change notification settings - Fork 716
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some unit test to study consistent behavior on passing argument…
… by reference.
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
tests/UnitTests/TemplateSource/_Issues/ArgumentMustBePassedByReference961Test.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
class ArgumentMustBePassedByReference961Test extends PHPUnit_Smarty | ||
{ | ||
|
||
/** | ||
* @group issue961 | ||
*/ | ||
public function testReset() | ||
{ | ||
$smarty = new Smarty(); | ||
$smarty->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) | ||
); | ||
} | ||
} |