d801f3387eb7bf714e97c92e5ab34c030603146b
[yaffs-website] / vendor / twig / twig / test / Twig / Tests / Node / IncludeTest.php
1 <?php
2
3 /*
4  * This file is part of Twig.
5  *
6  * (c) Fabien Potencier
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 class Twig_Tests_Node_IncludeTest extends Twig_Test_NodeTestCase
13 {
14     public function testConstructor()
15     {
16         $expr = new Twig_Node_Expression_Constant('foo.twig', 1);
17         $node = new Twig_Node_Include($expr, null, false, false, 1);
18
19         $this->assertFalse($node->hasNode('variables'));
20         $this->assertEquals($expr, $node->getNode('expr'));
21         $this->assertFalse($node->getAttribute('only'));
22
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'));
27     }
28
29     public function getTests()
30     {
31         $tests = array();
32
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
36 // line 1
37 \$this->loadTemplate("foo.twig", null, 1)->display(\$context);
38 EOF
39         );
40
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),
45                         0
46                     );
47         $node = new Twig_Node_Include($expr, null, false, false, 1);
48         $tests[] = array($node, <<<EOF
49 // line 1
50 \$this->loadTemplate(((true) ? ("foo") : ("foo")), null, 1)->display(\$context);
51 EOF
52         );
53
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
58 // line 1
59 \$this->loadTemplate("foo.twig", null, 1)->display(array_merge(\$context, array("foo" => true)));
60 EOF
61         );
62
63         $node = new Twig_Node_Include($expr, $vars, true, false, 1);
64         $tests[] = array($node, <<<EOF
65 // line 1
66 \$this->loadTemplate("foo.twig", null, 1)->display(array("foo" => true));
67 EOF
68         );
69
70         $node = new Twig_Node_Include($expr, $vars, true, true, 1);
71         $tests[] = array($node, <<<EOF
72 // line 1
73 try {
74     \$this->loadTemplate("foo.twig", null, 1)->display(array("foo" => true));
75 } catch (Twig_Error_Loader \$e) {
76     // ignore missing template
77 }
78 EOF
79         );
80
81         return $tests;
82     }
83 }