8000 Fixed templateExists on parse or normalization error of template name · symfony/symfony@0120979 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0120979

Browse files
committed
Fixed templateExists on parse or normalization error of template name
1 parent b1f6021 commit 0120979

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,17 @@ private function templateExists($template)
135135
if ($this->templating instanceof EngineInterface) {
136136
try {
137137
return $this->templating->exists($template);
138-
} catch (\InvalidArgumentException $e) {
138+
} catch (\Exception $e) {
139139
return false;
140140
}
141141
}
142142

143143
$loader = $this->templating->getLoader();
144-
if ($loader instanceof ExistsLoaderInterface || method_exists($loader, 'exists')) {
145-
return $loader->exists($template);
146-
}
147-
148144
try {
145+
if ($loader instanceof ExistsLoaderInterface || method_exists($loader, 'exists')) {
146+
return $loader->exists($template);
147+
}
148+
149149
if (method_exists($loader, 'getSourceContext')) {
150150
$loader->getSourceContext($template);
151151
} else {

src/Symfony/Component/HttpKernel/Tests/Fragment/HIncludeFragmentRendererTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,21 @@ public function testRenderWithDefaultText()
8686
$strategy = new HIncludeFragmentRenderer($engine);
8787
$this->assertEquals('<hx:include src="/foo">default</hx:include>', $strategy->render('/foo', Request::create('/'), array('default' => 'default'))->getContent());
8888
}
89+
90+
public function testRenderWithEngineAndDefaultText()
91+
{
92+
$engine = $this->getMockBuilder('Symfony\\Component\\Templating\\EngineInterface')->getMock();
93+
$engine->expects($this->once())
94+
->method('exists')
95+
->with('loading...')
96+
->will($this->throwException(new \RuntimeException()));
97+
98+
// only default
99+
$strategy = new HIncludeFragmentRenderer($engine);
100+
$this->assertEquals('<hx:include src="/foo">loading...</hx:include>', $strategy->render('/foo', Request::create('/'), array('default' => 'loading...'))->getContent());
101+
102+
// only default
103+
$strategy = new HIncludeFragmentRenderer(new \Twig_Environment(new \Twig_Loader_Filesystem()));
104+
$this->assertEquals('<hx:include src="/foo">@default</hx:include>', $strategy->render('/foo', Request::create('/'), array('default' => '@default'))->getContent());
105+
}
89106
}

0 commit comments

Comments
 (0)
0