]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Extension/RoutingExtensionTest.php
twig implementation
[github/wallabag/wallabag.git] / vendor / symfony / twig-bridge / Symfony / Bridge / Twig / Tests / Extension / RoutingExtensionTest.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\RoutingExtension;
15 use Symfony\Bridge\Twig\Tests\TestCase;
16
17 class RoutingExtensionTest extends TestCase
18 {
19 protected function setUp()
20 {
21 parent::setUp();
22
23 if (!class_exists('Symfony\Component\Routing\Route')) {
24 $this->markTestSkipped('The "Routing" component is not available');
25 }
26 }
27
28 /**
29 * @dataProvider getEscapingTemplates
30 */
31 public function testEscaping($template, $mustBeEscaped)
32 {
33 $twig = new \Twig_Environment(null, array('debug' => true, 'cache' => false, 'autoescape' => true, 'optimizations' => 0));
34 $twig->addExtension(new RoutingExtension($this->getMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface')));
35
36 $nodes = $twig->parse($twig->tokenize($template));
37
38 $this->assertSame($mustBeEscaped, $nodes->getNode('body')->getNode(0)->getNode('expr') instanceof \Twig_Node_Expression_Filter);
39 }
40
41 public function getEscapingTemplates()
42 {
43 return array(
44 array('{{ path("foo") }}', false),
45 array('{{ path("foo", {}) }}', false),
46 array('{{ path("foo", { foo: "foo" }) }}', false),
47 array('{{ path("foo", foo) }}', true),
48 array('{{ path("foo", { foo: foo }) }}', true),
49 array('{{ path("foo", { foo: ["foo", "bar"] }) }}', true),
50 array('{{ path("foo", { foo: "foo", bar: "bar" }) }}', true),
51
52 array('{{ path(name = "foo", parameters = {}) }}', false),
53 array('{{ path(name = "foo", parameters = { foo: "foo" }) }}', false),
54 array('{{ path(name = "foo", parameters = foo) }}', true),
55 array('{{ path(name = "foo", parameters = { foo: ["foo", "bar"] }) }}', true),
56 array('{{ path(name = "foo", parameters = { foo: foo }) }}', true),
57 array('{{ path(name = "foo", parameters = { foo: "foo", bar: "bar" }) }}', true),
58 );
59 }
60 }