SandboxTest.php 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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_Node_SandboxTest extends Twig_Test_NodeTestCase
  11. {
  12. /**
  13. * @covers Twig_Node_Sandbox::__construct
  14. */
  15. public function testConstructor()
  16. {
  17. $body = new Twig_Node_Text('foo', 1);
  18. $node = new Twig_Node_Sandbox($body, 1);
  19. $this->assertEquals($body, $node->getNode('body'));
  20. }
  21. /**
  22. * @covers Twig_Node_Sandbox::compile
  23. * @dataProvider getTests
  24. */
  25. public function testCompile($node, $source, $environment = null)
  26. {
  27. parent::testCompile($node, $source, $environment);
  28. }
  29. public function getTests()
  30. {
  31. $tests = array();
  32. $body = new Twig_Node_Text('foo', 1);
  33. $node = new Twig_Node_Sandbox($body, 1);
  34. $tests[] = array($node, <<<EOF
  35. // line 1
  36. \$sandbox = \$this->env->getExtension('sandbox');
  37. if (!\$alreadySandboxed = \$sandbox->isSandboxed()) {
  38. \$sandbox->enableSandbox();
  39. }
  40. echo "foo";
  41. if (!\$alreadySandboxed) {
  42. \$sandbox->disableSandbox();
  43. }
  44. EOF
  45. );
  46. return $tests;
  47. }
  48. }