mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX Passing 0 as first argument breaks template
Replace !empty with explicit string test Added test for falseish first parameter arguments
This commit is contained in:
parent
fd57f06755
commit
face94371e
@ -242,7 +242,7 @@ class SSTemplateParser extends Parser implements TemplateParser
|
||||
*/
|
||||
function CallArguments_Argument(&$res, $sub)
|
||||
{
|
||||
if (!empty($res['php'])) {
|
||||
if ($res['php'] !== '') {
|
||||
$res['php'] .= ', ';
|
||||
}
|
||||
|
||||
|
@ -567,7 +567,7 @@ class SSTemplateParser extends Parser implements TemplateParser
|
||||
*/
|
||||
function CallArguments_Argument(&$res, $sub)
|
||||
{
|
||||
if (!empty($res['php'])) {
|
||||
if ($res['php'] !== '') {
|
||||
$res['php'] .= ', ';
|
||||
}
|
||||
|
||||
|
@ -552,6 +552,40 @@ SS;
|
||||
$this->assertEquals("SubKid1SubKid2Number6", $result, "Loop in current scope works");
|
||||
}
|
||||
|
||||
public function provideArgumentTypes()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'arg1:0,arg2:"string",arg3:true',
|
||||
'$methodWithTypedArguments(0, "string", true).RAW',
|
||||
],
|
||||
[
|
||||
'arg1:false,arg2:"string",arg3:true',
|
||||
'$methodWithTypedArguments(false, "string", true).RAW',
|
||||
],
|
||||
[
|
||||
'arg1:null,arg2:"string",arg3:true',
|
||||
'$methodWithTypedArguments(null, "string", true).RAW',
|
||||
],
|
||||
[
|
||||
'arg1:"",arg2:"string",arg3:true',
|
||||
'$methodWithTypedArguments("", "string", true).RAW',
|
||||
],
|
||||
[
|
||||
'arg1:0,arg2:1,arg3:2',
|
||||
'$methodWithTypedArguments(0, 1, 2).RAW',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideArgumentTypes
|
||||
*/
|
||||
public function testArgumentTypes(string $expected, string $template)
|
||||
{
|
||||
$this->assertEquals($expected, $this->render($template, new TestViewableData()));
|
||||
}
|
||||
|
||||
public function testObjectDotArguments()
|
||||
{
|
||||
$this->assertEquals(
|
||||
|
@ -29,6 +29,11 @@ class TestViewableData extends ViewableData implements TestOnly
|
||||
return "arg1:{$arg1},arg2:{$arg2}";
|
||||
}
|
||||
|
||||
public function methodWithTypedArguments($arg1, $arg2, $arg3)
|
||||
{
|
||||
return 'arg1:' . json_encode($arg1) . ',arg2:' . json_encode($arg2) . ',arg3:' . json_encode($arg3);
|
||||
}
|
||||
|
||||
public function Type($arg)
|
||||
{
|
||||
return gettype($arg) . ':' . $arg;
|
||||
|
Loading…
Reference in New Issue
Block a user