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
15 * @covers Twig_Node_Include::__construct
17 public function testConstructor()
19 $expr = new Twig_Node_Expression_Constant('foo.twig', 1);
20 $node = new Twig_Node_Include($expr, null, false, false, 1);
22 $this->assertEquals(null, $node->getNode('variables'));
23 $this->assertEquals($expr, $node->getNode('expr'));
24 $this->assertFalse($node->getAttribute('only'));
26 $vars = new Twig_Node_Expression_Array(array(new Twig_Node_Expression_Constant('foo', 1), new Twig_Node_Expression_Constant(true, 1)), 1);
27 $node = new Twig_Node_Include($expr, $vars, true, false, 1);
28 $this->assertEquals($vars, $node->getNode('variables'));
29 $this->assertTrue($node->getAttribute('only'));
33 * @covers Twig_Node_Include::compile
34 * @dataProvider getTests
36 public function testCompile($node, $source, $environment = null)
38 parent
::testCompile($node, $source, $environment);
41 public function getTests()
45 $expr = new Twig_Node_Expression_Constant('foo.twig', 1);
46 $node = new Twig_Node_Include($expr, null, false, false, 1);
47 $tests[] = array($node, <<<EOF
49 \$this->env->loadTemplate("foo.twig")->display(\$context);
53 $expr = new Twig_Node_Expression_Conditional(
54 new Twig_Node_Expression_Constant(true, 1),
55 new Twig_Node_Expression_Constant('foo', 1),
56 new Twig_Node_Expression_Constant('foo', 1),
59 $node = new Twig_Node_Include($expr, null, false, false, 1);
60 $tests[] = array($node, <<<EOF
62 \$template = \$this->env->resolveTemplate(((true) ? ("foo") : ("foo")));
63 \$template->display(\$context);
67 $expr = new Twig_Node_Expression_Constant('foo.twig', 1);
68 $vars = new Twig_Node_Expression_Array(array(new Twig_Node_Expression_Constant('foo', 1), new Twig_Node_Expression_Constant(true, 1)), 1);
69 $node = new Twig_Node_Include($expr, $vars, false, false, 1);
70 $tests[] = array($node, <<<EOF
72 \$this->env->loadTemplate("foo.twig")->display(array_merge(\$context, array("foo" => true)));
76 $node = new Twig_Node_Include($expr, $vars, true, false, 1);
77 $tests[] = array($node, <<<EOF
79 \$this->env->loadTemplate("foo.twig")->display(array("foo" => true));
83 $node = new Twig_Node_Include($expr, $vars, true, true, 1);
84 $tests[] = array($node, <<<EOF
87 \$this->env->loadTemplate("foo.twig")->display(array("foo" => true));
88 } catch (Twig_Error_Loader \$e) {
89 // ignore missing template