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_IfTest extends Twig_Test_NodeTestCase
14 public function testConstructor()
16 $t = new Twig_Node(array(
17 new Twig_Node_Expression_Constant(true, 1),
18 new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 1), 1),
21 $node = new Twig_Node_If($t, $else, 1);
23 $this->assertEquals($t, $node->getNode('tests'));
24 $this->assertFalse($node->hasNode('else'));
26 $else = new Twig_Node_Print(new Twig_Node_Expression_Name('bar', 1), 1);
27 $node = new Twig_Node_If($t, $else, 1);
28 $this->assertEquals($else, $node->getNode('else'));
31 public function getTests()
35 $t = new Twig_Node(array(
36 new Twig_Node_Expression_Constant(true, 1),
37 new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 1), 1),
40 $node = new Twig_Node_If($t, $else, 1);
42 $tests[] = array($node, <<<EOF
45 echo {$this->getVariableGetter('foo')};
50 $t = new Twig_Node(array(
51 new Twig_Node_Expression_Constant(true, 1),
52 new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 1), 1),
53 new Twig_Node_Expression_Constant(false, 1),
54 new Twig_Node_Print(new Twig_Node_Expression_Name('bar', 1), 1),
57 $node = new Twig_Node_If($t, $else, 1);
59 $tests[] = array($node, <<<EOF
62 echo {$this->getVariableGetter('foo')};
64 echo {$this->getVariableGetter('bar')};
69 $t = new Twig_Node(array(
70 new Twig_Node_Expression_Constant(true, 1),
71 new Twig_Node_Print(new Twig_Node_Expression_Name('foo', 1), 1),
73 $else = new Twig_Node_Print(new Twig_Node_Expression_Name('bar', 1), 1);
74 $node = new Twig_Node_If($t, $else, 1);
76 $tests[] = array($node, <<<EOF
79 echo {$this->getVariableGetter('foo')};
81 echo {$this->getVariableGetter('bar')};