-
Notifications
You must be signed in to change notification settings - Fork 715
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
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
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
70 changes: 70 additions & 0 deletions
70
tests/UnitTests/SmartyMethodsTests/AssignByRef/AssignByRefTest.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,70 @@ | ||
<?php | ||
/** | ||
* Smarty PHPunit tests assignByRef method | ||
*/ | ||
|
||
/** | ||
* Class for assignByRef tests | ||
*/ | ||
class AssignByRefTest extends PHPUnit_Smarty | ||
{ | ||
public function setUp(): void | ||
{ | ||
$this->setUpSmarty(__DIR__); | ||
} | ||
|
||
public function testInit() | ||
{ | ||
$this->cleanDirs(); | ||
} | ||
|
||
private $testStr = null; | ||
/** | ||
* Test assignByRef for nullable string property | ||
*/ | ||
public function testAssignByRefForNullableStringProperry() | ||
{ | ||
$this->smarty->assignByRef('myVar', $this->testStr); | ||
$this->assertEquals(null, $this->smarty->fetch('eval:{$myVar}')); | ||
$this->testStr = 'abc'; | ||
$this->assertEquals('abc', $this->smarty->fetch('eval:{$myVar}')); | ||
} | ||
|
||
/** | ||
* Test assignByRef for string | ||
*/ | ||
public function testAssignByRefForString() | ||
{ | ||
$var = 'abc'; | ||
$this->smarty->assignByRef('myVar', $var); | ||
$this->assertEquals('abc', $this->smarty->fetch('eval:{$myVar}')); | ||
$var = 'def'; | ||
$this->assertEquals('def', $this->smarty->fetch('eval:{$myVar}')); | ||
} | ||
|
||
/** | ||
* Test assignByRef for array | ||
*/ | ||
public function testAssignByRefForArray() | ||
{ | ||
$var = array( | ||
'a' => 'A', | ||
); | ||
$this->smarty->assignByRef('myVar', $var); | ||
$this->assertEquals('{"a":"A"}', $this->smarty->fetch('eval:{$myVar|json_encode}')); | ||
$var['b'] = 'B'; | ||
$this->assertEquals('{"a":"A","b":"B"}', $this->smarty->fetch('eval:{$myVar|json_encode}')); | ||
} | ||
|
||
/** | ||
* Test that assignByRef returns this. | ||
*/ | ||
public function testAssignByRefReturnsThis() | ||
{ | ||
$var = 'data'; | ||
$this->assertEquals( | ||
'data', | ||
$this->smarty->assignByRef('dummy', $var)->fetch('eval:{$dummy}') | ||
); | ||
} | ||
} |