4 * This file is part of Twig.
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 class Twig_Tests_Node_SandboxedModuleTest
extends Twig_Test_NodeTestCase
15 * @covers Twig_Node_SandboxedModule::__construct
17 public function testConstructor()
19 $body = new Twig_Node_Text('foo', 1);
20 $parent = new Twig_Node_Expression_Constant('layout.twig', 1);
21 $blocks = new Twig_Node();
22 $macros = new Twig_Node();
23 $traits = new Twig_Node();
24 $filename = 'foo.twig';
25 $node = new Twig_Node_Module($body, $parent, $blocks, $macros, $traits, new Twig_Node(array()), $filename);
26 $node = new Twig_Node_SandboxedModule($node, array('for'), array('upper'), array('cycle'));
28 $this->assertEquals($body, $node->getNode('body'));
29 $this->assertEquals($blocks, $node->getNode('blocks'));
30 $this->assertEquals($macros, $node->getNode('macros'));
31 $this->assertEquals($parent, $node->getNode('parent'));
32 $this->assertEquals($filename, $node->getAttribute('filename'));
36 * @covers Twig_Node_SandboxedModule::compile
37 * @covers Twig_Node_SandboxedModule::compileDisplayBody
38 * @covers Twig_Node_SandboxedModule::compileDisplayFooter
39 * @dataProvider getTests
41 public function testCompile($node, $source, $environment = null)
43 parent
::testCompile($node, $source, $environment);
46 public function getTests()
48 $twig = new Twig_Environment(new Twig_Loader_String());
52 $body = new Twig_Node_Text('foo', 1);
54 $blocks = new Twig_Node();
55 $macros = new Twig_Node();
56 $traits = new Twig_Node();
57 $filename = 'foo.twig';
59 $node = new Twig_Node_Module($body, $extends, $blocks, $macros, $traits, new Twig_Node(array()), $filename);
60 $node = new Twig_Node_SandboxedModule($node, array('for'), array('upper'), array('cycle'));
62 $tests[] = array($node, <<<EOF
66 class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template
68 public function __construct(Twig_Environment \$env)
70 parent::__construct(\$env);
72 \$this->parent = false;
74 \$this->blocks = array(
78 protected function doDisplay(array \$context, array \$blocks = array())
80 \$this->checkSecurity();
85 protected function checkSecurity()
87 \$this->env->getExtension('sandbox')->checkSecurity(
94 public function getTemplateName()
99 public function getDebugInfo()
101 return array ( 20 => 1,);
107 $body = new Twig_Node();
108 $extends = new Twig_Node_Expression_Constant('layout.twig', 1);
109 $blocks = new Twig_Node();
110 $macros = new Twig_Node();
111 $traits = new Twig_Node();
112 $filename = 'foo.twig';
114 $node = new Twig_Node_Module($body, $extends, $blocks, $macros, $traits, new Twig_Node(array()), $filename);
115 $node = new Twig_Node_SandboxedModule($node, array('for'), array('upper'), array('cycle'));
117 $tests[] = array($node, <<<EOF
121 class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template
123 public function __construct(Twig_Environment \$env)
125 parent::__construct(\$env);
127 \$this->parent = \$this->env->loadTemplate("layout.twig");
129 \$this->blocks = array(
133 protected function doGetParent(array \$context)
135 return "layout.twig";
138 protected function doDisplay(array \$context, array \$blocks = array())
140 \$this->checkSecurity();
141 \$this->parent->display(\$context, array_merge(\$this->blocks, \$blocks));
144 protected function checkSecurity()
146 \$this->env->getExtension('sandbox')->checkSecurity(
153 public function getTemplateName()
158 public function isTraitable()
163 public function getDebugInfo()