aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/twig/twig/test/Twig/Tests/Node/IfTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/twig/twig/test/Twig/Tests/Node/IfTest.php')
-rw-r--r--vendor/twig/twig/test/Twig/Tests/Node/IfTest.php100
1 files changed, 100 insertions, 0 deletions
diff --git a/vendor/twig/twig/test/Twig/Tests/Node/IfTest.php b/vendor/twig/twig/test/Twig/Tests/Node/IfTest.php
new file mode 100644
index 00000000..92fc29dc
--- /dev/null
+++ b/vendor/twig/twig/test/Twig/Tests/Node/IfTest.php
@@ -0,0 +1,100 @@
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_IfTest extends Twig_Test_NodeTestCase
13{
14 /**
15 * @covers Twig_Node_If::__construct
16 */
17 public function testConstructor()
18 {
19 $t = new Twig_Node(array(
20 new Twig_Node_Expression_Constant(true, 1),
21 new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 1), 1),
22 ), array(), 1);
23 $else = null;
24 $node = new Twig_Node_If($t, $else, 1);
25
26 $this->assertEquals($t, $node->getNode('tests'));
27 $this->assertEquals(null, $node->getNode('else'));
28
29 $else = new Twig_Node_Print(new Twig_Node_Expression_Name('bar', 1), 1);
30 $node = new Twig_Node_If($t, $else, 1);
31 $this->assertEquals($else, $node->getNode('else'));
32 }
33
34 /**
35 * @covers Twig_Node_If::compile
36 * @dataProvider getTests
37 */
38 public function testCompile($node, $source, $environment = null)
39 {
40 parent::testCompile($node, $source, $environment);
41 }
42
43 public function getTests()
44 {
45 $tests = array();
46
47 $t = new Twig_Node(array(
48 new Twig_Node_Expression_Constant(true, 1),
49 new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 1), 1),
50 ), array(), 1);
51 $else = null;
52 $node = new Twig_Node_If($t, $else, 1);
53
54 $tests[] = array($node, <<<EOF
55// line 1
56if (true) {
57 echo {$this->getVariableGetter('foo')};
58}
59EOF
60 );
61
62 $t = new Twig_Node(array(
63 new Twig_Node_Expression_Constant(true, 1),
64 new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 1), 1),
65 new Twig_Node_Expression_Constant(false, 1),
66 new Twig_Node_Print(new Twig_Node_Expression_Name('bar', 1), 1),
67 ), array(), 1);
68 $else = null;
69 $node = new Twig_Node_If($t, $else, 1);
70
71 $tests[] = array($node, <<<EOF
72// line 1
73if (true) {
74 echo {$this->getVariableGetter('foo')};
75} elseif (false) {
76 echo {$this->getVariableGetter('bar')};
77}
78EOF
79 );
80
81 $t = new Twig_Node(array(
82 new Twig_Node_Expression_Constant(true, 1),
83 new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 1), 1),
84 ), array(), 1);
85 $else = new Twig_Node_Print(new Twig_Node_Expression_Name('bar', 1), 1);
86 $node = new Twig_Node_If($t, $else, 1);
87
88 $tests[] = array($node, <<<EOF
89// line 1
90if (true) {
91 echo {$this->getVariableGetter('foo')};
92} else {
93 echo {$this->getVariableGetter('bar')};
94}
95EOF
96 );
97
98 return $tests;
99 }
100}