diff --git a/Tests/Functional/Twig/UrlAutoConverterTest.php b/Tests/Functional/Twig/UrlAutoConverterTest.php index 5bdbbda..64f7868 100644 --- a/Tests/Functional/Twig/UrlAutoConverterTest.php +++ b/Tests/Functional/Twig/UrlAutoConverterTest.php @@ -8,12 +8,24 @@ class UrlAutoConverterTest extends \PHPUnit_Framework_TestCase { public function testEscapedHtml() { - $loader = new \Twig_Loader_String(); - $twig = new \Twig_Environment($loader); - $twig->addExtension(new UrlAutoConverterTwigExtension()); + if (method_exists('\Twig_Environment', 'createTemplate')) { // twig > 2.0 + $twig = new \Twig_Environment(new \Twig_Loader_Array()); + $twig->addExtension(new UrlAutoConverterTwigExtension()); - $body = 'Hello name!'; - $expected = 'Hello <a href="javascript:alert('ups');">name</a>!'; - $this->assertEquals($expected, $twig->render('{{ body | converturls }}', array('body' => $body))); + $body = 'Hello name!'; + $expected = 'Hello <a href="javascript:alert('ups');">name</a>!'; + + $template = $twig->createTemplate('{{ body | converturls }}'); + + $this->assertEquals($expected, $template->render(array('body' => $body))); + } else { // twig < 2.0 + $loader = new \Twig_Loader_String(); + $twig = new \Twig_Environment($loader); + $twig->addExtension(new UrlAutoConverterTwigExtension()); + + $body = 'Hello name!'; + $expected = 'Hello <a href="javascript:alert('ups');">name</a>!'; + $this->assertEquals($expected, $twig->render('{{ body | converturls }}', array('body' => $body))); + } } } diff --git a/composer.json b/composer.json index 05c8a05..bd24bb2 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "require": { "php": "^5.3.9|^7.0", "symfony/framework-bundle": "~2.3|~3.0", - "twig/twig": "~1.12" + "twig/twig": "~1.12|~2.0" }, "require-dev": { "symfony/symfony": "~2.3|~3.0"