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\RoutingExtension
;
15 use Symfony\Bridge\Twig\Tests\TestCase
;
17 class RoutingExtensionTest
extends TestCase
19 protected function setUp()
23 if (!class_exists('Symfony\Component\Routing\Route')) {
24 $this->markTestSkipped('The "Routing" component is not available');
29 * @dataProvider getEscapingTemplates
31 public function testEscaping($template, $mustBeEscaped)
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')));
36 $nodes = $twig->parse($twig->tokenize($template));
38 $this->assertSame($mustBeEscaped, $nodes->getNode('body')->getNode(0)->getNode('expr') instanceof \Twig_Node_Expression_Filter
);
41 public function getEscapingTemplates()
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),
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),