4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Bridge\Twig\Tests\Extension
;
14 use Symfony\Bridge\Twig\Extension\HttpKernelExtension
;
15 use Symfony\Bridge\Twig\Tests\TestCase
;
16 use Symfony\Component\HttpFoundation\Request
;
17 use Symfony\Component\HttpKernel\Fragment\FragmentHandler
;
19 class HttpKernelExtensionTest
extends TestCase
21 protected function setUp()
25 if (!class_exists('Symfony\Component\HttpKernel\HttpKernel')) {
26 $this->markTestSkipped('The "HttpKernel" component is not available');
29 if (!class_exists('Twig_Environment')) {
30 $this->markTestSkipped('Twig is not available.');
35 * @expectedException \Twig_Error_Runtime
37 public function testFragmentWithError()
39 $kernel = $this->getFragmentHandler($this->throwException(new \
Exception('foo')));
41 $loader = new \
Twig_Loader_Array(array('index' => '{{ fragment("foo") }}'));
42 $twig = new \
Twig_Environment($loader, array('debug' => true, 'cache' => false));
43 $twig->addExtension(new HttpKernelExtension($kernel));
45 $this->renderTemplate($kernel);
48 protected function getFragmentHandler($return)
50 $strategy = $this->getMock('Symfony\\Component\\HttpKernel\\Fragment\\FragmentRendererInterface');
51 $strategy->expects($this->once())->method('getName')->will($this->returnValue('inline'));
52 $strategy->expects($this->once())->method('render')->will($return);
54 $renderer = new FragmentHandler(array($strategy));
55 $renderer->setRequest(Request
::create('/'));
60 protected function renderTemplate(FragmentHandler
$renderer, $template = '{{ render("foo") }}')
62 $loader = new \
Twig_Loader_Array(array('index' => $template));
63 $twig = new \
Twig_Environment($loader, array('debug' => true, 'cache' => false));
64 $twig->addExtension(new HttpKernelExtension($renderer));
66 return $twig->render('index');