Fix handling of named arguments in partials

Also fix tests that weren't even executed
This commit is contained in:
Pascal Thormeier 2015-06-29 17:16:59 +02:00
parent 6ef6b7bc08
commit 2e1b67208d
2 changed files with 15 additions and 4 deletions

View File

@ -538,7 +538,16 @@ class Template
} }
} }
return array_merge($positionalArgs, $arguments->getNamedArguments()); $namedArguments = array();
foreach ($arguments->getNamedArguments() as $key => $value) {
if (false === $value instanceof String) {
$value = $context->get($value);
}
$namedArguments[$key] = $value;
}
return array_merge($positionalArgs, $namedArguments);
} }

View File

@ -729,6 +729,11 @@ EOM;
) )
); );
$this->assertEquals('foobar', $engine->render("{{>presetVariables myVar='foobar'}}", array()));
$this->assertEquals('foobar=barbaz', $engine->render("{{>presetVariables myVar='foobar=barbaz'}}", array()));
$this->assertEquals('qux', $engine->render("{{>presetVariables myVar=foo}}", array('foo' => 'qux')));
$this->assertEquals('qux', $engine->render("{{>presetVariables myVar=foo.bar}}", array('foo' => array('bar' => 'qux'))));
$this->assertEquals('HELLO', $engine->render('{{>test parameter}}', array('parameter' => array('key' => 'HELLO')))); $this->assertEquals('HELLO', $engine->render('{{>test parameter}}', array('parameter' => array('key' => 'HELLO'))));
$this->assertEquals('its foo', $engine->render('{{>foo}}', array())); $this->assertEquals('its foo', $engine->render('{{>foo}}', array()));
$engine->registerPartial('foo-again', 'bar'); $engine->registerPartial('foo-again', 'bar');
@ -737,9 +742,6 @@ EOM;
$this->setExpectedException('RuntimeException'); $this->setExpectedException('RuntimeException');
$engine->render('{{>foo-again}}', array()); $engine->render('{{>foo-again}}', array());
$this->assertEquals('foobar', $engine->render("{{>presetVariables myVar='foobar'}}", array()));
$this->assertEquals('foobar=barbaz', $engine->render("{{>presetVariables myVar='foobar=barbaz'}}", array()));
} }
/** /**