RoutingExtension example

use Twig\Node\Expression\FilterExpression;
use Twig\Source;

class RoutingExtensionTest extends TestCase
{
    /** * @dataProvider getEscapingTemplates */
    public function testEscaping($template$mustBeEscaped)
    {
        $twig = new Environment($this->createMock(LoaderInterface::class)['debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0]);
        $twig->addExtension(new RoutingExtension($this->createMock(UrlGeneratorInterface::class)));

        $nodes = $twig->parse($twig->tokenize(new Source($template, '')));

        $this->assertSame($mustBeEscaped$nodes->getNode('body')->getNode(0)->getNode('expr') instanceof FilterExpression);
    }

    public static function getEscapingTemplates()
    {
        return [
            ['{{ path("foo") }}', false],
            ['{{ path("foo", {}) }}', false],
            [
Home | Imprint | This part of the site doesn't use cookies.