diff --git a/TODO.md b/TODO.md index e6b4a0af..5df33d1c 100644 --- a/TODO.md +++ b/TODO.md @@ -1,56 +1,2 @@ -# Todo +# Pre-release Todos -## Add unit test for isset issue in correct branch -tests/UnitTests/TemplateSource/ValueTests/PHPfunctions/PhpFunctionTest.php -```php - /** - * test PHP isset() on (non-)variables - * @dataProvider dataTestIsset3 - * @param string $strTemplate template to test - * @param string $result expected result - */ - public function testIsset3($strTemplate, $result) - { - $this->smarty->disableSecurity(); - - $this->smarty->assign('varobject', new TestIsset()); - $this->smarty->assign('vararray', $vararray = [ - 'keythatexists' => false, - 'keywitharray' => [1 => 1], - 'keywithobject' => new TestIsset()] - ); - - $this->smarty->assign('key', 'A'); - $this->smarty->assign('_varsimpleA', 1); - $this->smarty->assign('varsimpleB', 0); - $this->smarty->assign('varsimpleC', null); - - $this->assertEquals($result, $this->smarty->fetch('string:' . $strTemplate)); - } - - /** - * Data provider for testIsset3 - */ - public function dataTestIsset3() - { - return array( - array('{if isset($varobject->arr)}true{else}false{/if}', 'true'), - array('{if isset($vararray["keywitharray"])}true{else}false{/if}', 'true'), - array('{if isset($vararray["keythatexists"])}true{else}false{/if}', 'true'), - array('{if isset($vararray["nonexistingkey"])}true{else}false{/if}', 'false'), - array('{if isset($_GET["sscr6hr6cz34j6"])}true{else}false{/if}', 'false'), - array('{if isset(count([\'hi\']))}true{else}false{/if}', 'true'), - array('{if isset($vararray[\'keywitharray\'][intval(\'1\')])}true{else}false{/if}', 'true'), - array('{if isset($vararray[\'keywithobject\']->arr[\'isSet\'])}true{else}false{/if}', 'true'), - array('{if isset($vararray[\'keywithobject\']->arr[\'isNull\'])}true{else}false{/if}', 'false'), - array('{if isset($varobject->arr[\'isSet\'])}true{else}false{/if}', 'true'), - array('{if isset($varobject->arr[\'isNull\'])}true{else}false{/if}', 'false'), - array('{if isset($_varsimpleA)}true{else}false{/if}', 'true'), - array('{if isset($varsimpleB)}true{else}false{/if}', 'true'), - array('{if isset($varsimpleC)}true{else}false{/if}', 'false'), - array('{if isset($_varsimpleA && varsimpleB)}true{else}false{/if}', 'true'), - array('{if isset($_varsimpleA && varsimpleC)}true{else}false{/if}', 'true'), - array('{if isset($_varsimple{$key})}true{else}false{/if}', 'true'), - ); - } -``` \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/ValueTests/PHPfunctions/PhpFunctionTest.php b/tests/UnitTests/TemplateSource/ValueTests/PHPfunctions/PhpFunctionTest.php index 8892a542..8f13e315 100644 --- a/tests/UnitTests/TemplateSource/ValueTests/PHPfunctions/PhpFunctionTest.php +++ b/tests/UnitTests/TemplateSource/ValueTests/PHPfunctions/PhpFunctionTest.php @@ -156,6 +156,57 @@ class PhpFunctionTest extends PHPUnit_Smarty ,{if isset($var->pass(1))} true {else} false {/IF} ')); } + + /** + * test PHP isset() on (non-)variables + * @dataProvider dataTestIsset3 + * @param string $strTemplate template to test + * @param string $result expected result + */ + public function testIsset3($strTemplate, $result) + { + $this->smarty->disableSecurity(); + + $this->smarty->assign('varobject', new TestIsset()); + $this->smarty->assign('vararray', $vararray = [ + 'keythatexists' => false, + 'keywitharray' => [1 => 1], + 'keywithobject' => new TestIsset()] + ); + + $this->smarty->assign('key', 'A'); + $this->smarty->assign('_varsimpleA', 1); + $this->smarty->assign('varsimpleB', 0); + $this->smarty->assign('varsimpleC', null); + + $this->assertEquals($result, $this->smarty->fetch('string:' . $strTemplate)); + } + + /** + * Data provider for testIsset3 + */ + public function dataTestIsset3() + { + return array( + array('{if isset($varobject->arr)}true{else}false{/if}', 'true'), + array('{if isset($vararray["keywitharray"])}true{else}false{/if}', 'true'), + array('{if isset($vararray["keythatexists"])}true{else}false{/if}', 'true'), + array('{if isset($vararray["nonexistingkey"])}true{else}false{/if}', 'false'), + array('{if isset($_GET["sscr6hr6cz34j6"])}true{else}false{/if}', 'false'), + array('{if isset(count([\'hi\']))}true{else}false{/if}', 'true'), + array('{if isset($vararray[\'keywitharray\'][intval(\'1\')])}true{else}false{/if}', 'true'), + array('{if isset($vararray[\'keywithobject\']->arr[\'isSet\'])}true{else}false{/if}', 'true'), + array('{if isset($vararray[\'keywithobject\']->arr[\'isNull\'])}true{else}false{/if}', 'false'), + array('{if isset($varobject->arr[\'isSet\'])}true{else}false{/if}', 'true'), + array('{if isset($varobject->arr[\'isNull\'])}true{else}false{/if}', 'false'), + array('{if isset($_varsimpleA)}true{else}false{/if}', 'true'), + array('{if isset($varsimpleB)}true{else}false{/if}', 'true'), + array('{if isset($varsimpleC)}true{else}false{/if}', 'false'), + array('{if isset($_varsimpleA && varsimpleB)}true{else}false{/if}', 'true'), + array('{if isset($_varsimpleA && varsimpleC)}true{else}false{/if}', 'true'), + array('{if isset($_varsimple{$key})}true{else}false{/if}', 'true'), + ); + } } /**