]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php
077927cd6d5fc55c03c4b3c9ce79ce1927a93964
[github/wallabag/wallabag.git] / vendor / symfony / twig-bridge / Symfony / Bridge / Twig / Tests / Extension / HttpKernelExtensionTest.php
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Bridge\Twig\Tests\Extension;
13
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;
18
19 class HttpKernelExtensionTest extends TestCase
20 {
21 protected function setUp()
22 {
23 parent::setUp();
24
25 if (!class_exists('Symfony\Component\HttpKernel\HttpKernel')) {
26 $this->markTestSkipped('The "HttpKernel" component is not available');
27 }
28
29 if (!class_exists('Twig_Environment')) {
30 $this->markTestSkipped('Twig is not available.');
31 }
32 }
33
34 /**
35 * @expectedException \Twig_Error_Runtime
36 */
37 public function testFragmentWithError()
38 {
39 $kernel = $this->getFragmentHandler($this->throwException(new \Exception('foo')));
40
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));
44
45 $this->renderTemplate($kernel);
46 }
47
48 protected function getFragmentHandler($return)
49 {
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);
53
54 $renderer = new FragmentHandler(array($strategy));
55 $renderer->setRequest(Request::create('/'));
56
57 return $renderer;
58 }
59
60 protected function renderTemplate(FragmentHandler $renderer, $template = '{{ render("foo") }}')
61 {
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));
65
66 return $twig->render('index');
67 }
68 }