aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/twig/twig/test/Twig/Tests/Node/IncludeTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/twig/twig/test/Twig/Tests/Node/IncludeTest.php')
-rw-r--r--vendor/twig/twig/test/Twig/Tests/Node/IncludeTest.php96
1 files changed, 96 insertions, 0 deletions
diff --git a/vendor/twig/twig/test/Twig/Tests/Node/IncludeTest.php b/vendor/twig/twig/test/Twig/Tests/Node/IncludeTest.php
new file mode 100644
index 00000000..3b7da6e0
--- /dev/null
+++ b/vendor/twig/twig/test/Twig/Tests/Node/IncludeTest.php
@@ -0,0 +1,96 @@
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
12class Twig_Tests_Node_IncludeTest extends Twig_Test_NodeTestCase
13{
14 /**
15 * @covers Twig_Node_Include::__construct
16 */
17 public function testConstructor()
18 {
19 $expr = new Twig_Node_Expression_Constant('foo.twig', 1);
20 $node = new Twig_Node_Include($expr, null, false, false, 1);
21
22 $this->assertEquals(null, $node->getNode('variables'));
23 $this->assertEquals($expr, $node->getNode('expr'));
24 $this->assertFalse($node->getAttribute('only'));
25
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'));
30 }
31
32 /**
33 * @covers Twig_Node_Include::compile
34 * @dataProvider getTests
35 */
36 public function testCompile($node, $source, $environment = null)
37 {
38 parent::testCompile($node, $source, $environment);
39 }
40
41 public function getTests()
42 {
43 $tests = array();
44
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
48// line 1
49\$this->env->loadTemplate("foo.twig")->display(\$context);
50EOF
51 );
52
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),
57 0
58 );
59 $node = new Twig_Node_Include($expr, null, false, false, 1);
60 $tests[] = array($node, <<<EOF
61// line 1
62\$template = \$this->env->resolveTemplate(((true) ? ("foo") : ("foo")));
63\$template->display(\$context);
64EOF
65 );
66
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
71// line 1
72\$this->env->loadTemplate("foo.twig")->display(array_merge(\$context, array("foo" => true)));
73EOF
74 );
75
76 $node = new Twig_Node_Include($expr, $vars, true, false, 1);
77 $tests[] = array($node, <<<EOF
78// line 1
79\$this->env->loadTemplate("foo.twig")->display(array("foo" => true));
80EOF
81 );
82
83 $node = new Twig_Node_Include($expr, $vars, true, true, 1);
84 $tests[] = array($node, <<<EOF
85// line 1
86try {
87 \$this->env->loadTemplate("foo.twig")->display(array("foo" => true));
88} catch (Twig_Error_Loader \$e) {
89 // ignore missing template
90}
91EOF
92 );
93
94 return $tests;
95 }
96}