RoutingExtensionTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bridge\Twig\Tests\Extension;
  11. use Symfony\Bridge\Twig\Extension\RoutingExtension;
  12. use Symfony\Bridge\Twig\Tests\TestCase;
  13. class RoutingExtensionTest extends TestCase
  14. {
  15. protected function setUp()
  16. {
  17. parent::setUp();
  18. if (!class_exists('Symfony\Component\Routing\Route')) {
  19. $this->markTestSkipped('The "Routing" component is not available');
  20. }
  21. }
  22. /**
  23. * @dataProvider getEscapingTemplates
  24. */
  25. public function testEscaping($template, $mustBeEscaped)
  26. {
  27. $twig = new \Twig_Environment(null, array('debug' => true, 'cache' => false, 'autoescape' => true, 'optimizations' => 0));
  28. $twig->addExtension(new RoutingExtension($this->getMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface')));
  29. $nodes = $twig->parse($twig->tokenize($template));
  30. $this->assertSame($mustBeEscaped, $nodes->getNode('body')->getNode(0)->getNode('expr') instanceof \Twig_Node_Expression_Filter);
  31. }
  32. public function getEscapingTemplates()
  33. {
  34. return array(
  35. array('{{ path("foo") }}', false),
  36. array('{{ path("foo", {}) }}', false),
  37. array('{{ path("foo", { foo: "foo" }) }}', false),
  38. array('{{ path("foo", foo) }}', true),
  39. array('{{ path("foo", { foo: foo }) }}', true),
  40. array('{{ path("foo", { foo: ["foo", "bar"] }) }}', true),
  41. array('{{ path("foo", { foo: "foo", bar: "bar" }) }}', true),
  42. array('{{ path(name = "foo", parameters = {}) }}', false),
  43. array('{{ path(name = "foo", parameters = { foo: "foo" }) }}', false),
  44. array('{{ path(name = "foo", parameters = foo) }}', true),
  45. array('{{ path(name = "foo", parameters = { foo: ["foo", "bar"] }) }}', true),
  46. array('{{ path(name = "foo", parameters = { foo: foo }) }}', true),
  47. array('{{ path(name = "foo", parameters = { foo: "foo", bar: "bar" }) }}', true),
  48. );
  49. }
  50. }