EnvironmentTest.php 1021B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /*
  3. * This file is part of Twig.
  4. *
  5. * (c) Fabien Potencier
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
  11. {
  12. public function testAutoescapeOption()
  13. {
  14. $loader = new Twig_Loader_Array(array(
  15. 'html' => '{{ foo }} {{ foo }}',
  16. 'js' => '{{ bar }} {{ bar }}',
  17. ));
  18. $twig = new Twig_Environment($loader, array(
  19. 'debug' => true,
  20. 'cache' => false,
  21. 'autoescape' => array($this, 'escapingStrategyCallback'),
  22. ));
  23. $this->assertEquals('foo&lt;br/ &gt; foo&lt;br/ &gt;', $twig->render('html', array('foo' => 'foo<br/ >')));
  24. $this->assertEquals('foo\x3Cbr\x2F\x20\x3E foo\x3Cbr\x2F\x20\x3E', $twig->render('js', array('bar' => 'foo<br/ >')));
  25. }
  26. public function escapingStrategyCallback($filename)
  27. {
  28. return $filename;
  29. }
  30. }