mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-03 18:04:26 +02:00
Moved the isset tests into the test suite
This commit is contained in:
56
TODO.md
56
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'),
|
||||
);
|
||||
}
|
||||
```
|
@@ -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'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user