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_IncludeTest extends Twig_Test_NodeTestCase
14 public function testConstructor()
16 $expr = new Twig_Node_Expression_Constant('foo.twig', 1);
17 $node = new Twig_Node_Include($expr, null, false, false, 1);
19 $this->assertFalse($node->hasNode('variables'));
20 $this->assertEquals($expr, $node->getNode('expr'));
21 $this->assertFalse($node->getAttribute('only'));
23 $vars = new Twig_Node_Expression_Array(array(new Twig_Node_Expression_Constant('foo', 1), new Twig_Node_Expression_Constant(true, 1)), 1);
24 $node = new Twig_Node_Include($expr, $vars, true, false, 1);
25 $this->assertEquals($vars, $node->getNode('variables'));
26 $this->assertTrue($node->getAttribute('only'));
29 public function getTests()
33 $expr = new Twig_Node_Expression_Constant('foo.twig', 1);
34 $node = new Twig_Node_Include($expr, null, false, false, 1);
35 $tests[] = array($node, <<<EOF
37 \$this->loadTemplate("foo.twig", null, 1)->display(\$context);
41 $expr = new Twig_Node_Expression_Conditional(
42 new Twig_Node_Expression_Constant(true, 1),
43 new Twig_Node_Expression_Constant('foo', 1),
44 new Twig_Node_Expression_Constant('foo', 1),
47 $node = new Twig_Node_Include($expr, null, false, false, 1);
48 $tests[] = array($node, <<<EOF
50 \$this->loadTemplate(((true) ? ("foo") : ("foo")), null, 1)->display(\$context);
54 $expr = new Twig_Node_Expression_Constant('foo.twig', 1);
55 $vars = new Twig_Node_Expression_Array(array(new Twig_Node_Expression_Constant('foo', 1), new Twig_Node_Expression_Constant(true, 1)), 1);
56 $node = new Twig_Node_Include($expr, $vars, false, false, 1);
57 $tests[] = array($node, <<<EOF
59 \$this->loadTemplate("foo.twig", null, 1)->display(array_merge(\$context, array("foo" => true)));
63 $node = new Twig_Node_Include($expr, $vars, true, false, 1);
64 $tests[] = array($node, <<<EOF
66 \$this->loadTemplate("foo.twig", null, 1)->display(array("foo" => true));
70 $node = new Twig_Node_Include($expr, $vars, true, true, 1);
71 $tests[] = array($node, <<<EOF
74 \$this->loadTemplate("foo.twig", null, 1)->display(array("foo" => true));
75 } catch (Twig_Error_Loader \$e) {
76 // ignore missing template