Skip to content
This repository has been archived by the owner on Dec 5, 2017. It is now read-only.

Commit

Permalink
Merge pull request #35 from toooni/twig_2
Browse files Browse the repository at this point in the history
Twig 2
  • Loading branch information
lsmith77 authored Mar 7, 2017
2 parents 8be640f + add409b commit 0d19d76
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
24 changes: 18 additions & 6 deletions Tests/Functional/Twig/UrlAutoConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="javascript:alert(\'ups\');">name</a>!';
$expected = 'Hello &lt;a href=&quot;javascript:alert(&#039;ups&#039;);&quot;&gt;name&lt;/a&gt;!';
$this->assertEquals($expected, $twig->render('{{ body | converturls }}', array('body' => $body)));
$body = 'Hello <a href="javascript:alert(\'ups\');">name</a>!';
$expected = 'Hello &lt;a href=&quot;javascript:alert(&#039;ups&#039;);&quot;&gt;name&lt;/a&gt;!';

$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 <a href="javascript:alert(\'ups\');">name</a>!';
$expected = 'Hello &lt;a href=&quot;javascript:alert(&#039;ups&#039;);&quot;&gt;name&lt;/a&gt;!';
$this->assertEquals($expected, $twig->render('{{ body | converturls }}', array('body' => $body)));
}
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 0d19d76

Please sign in to comment.