fix handling of a default 'template' as a string

This commit is contained in:
Lukas Kahwe Smith 2013-07-08 14:02:04 +02:00
parent 6dbd1e102b
commit 9d1004b59e
2 changed files with 20 additions and 3 deletions

View File

@ -99,7 +99,11 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer
private function templateExists($template)
{
if ($this->templating instanceof EngineInterface) {
return $this->templating->exists($template);
try {
return $this->templating->exists($template);
} catch (\InvalidArgumentException $e) {
return false;
}
}
$loader = $this->templating->getLoader();

View File

@ -50,7 +50,7 @@ class HIncludeFragmentRendererTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('<hx:include src="/foo"></hx:include>', $strategy->render('/foo', Request::create('/'))->getContent());
}
public function testRenderWhithDefault()
public function testRenderWithDefault()
{
// only default
$strategy = new HIncludeFragmentRenderer();
@ -64,4 +64,17 @@ class HIncludeFragmentRendererTest extends \PHPUnit_Framework_TestCase
$strategy = new HIncludeFragmentRenderer(null, null, 'global_default');
$this->assertEquals('<hx:include src="/foo">default</hx:include>', $strategy->render('/foo', Request::create('/'), array('default' => 'default'))->getContent());
}
}
public function testRenderWithDefaultText()
{
$engine = $this->getMock('Symfony\\Component\\Templating\\EngineInterface');
$engine->expects($this->once())
->method('exists')
->with('default')
->will($this->throwException(new \InvalidArgumentException()));
// only default
$strategy = new HIncludeFragmentRenderer($engine);
$this->assertEquals('<hx:include src="/foo">default</hx:include>', $strategy->render('/foo', Request::create('/'), array('default' => 'default'))->getContent());
}
}