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_Expression_GetAttrTest extends Twig_Test_NodeTestCase
14 public function testConstructor()
16 $expr = new Twig_Node_Expression_Name('foo', 1);
17 $attr = new Twig_Node_Expression_Constant('bar', 1);
18 $args = new Twig_Node_Expression_Array(array(), 1);
19 $args->addElement(new Twig_Node_Expression_Name('foo', 1));
20 $args->addElement(new Twig_Node_Expression_Constant('bar', 1));
21 $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::ARRAY_CALL, 1);
23 $this->assertEquals($expr, $node->getNode('node'));
24 $this->assertEquals($attr, $node->getNode('attribute'));
25 $this->assertEquals($args, $node->getNode('arguments'));
26 $this->assertEquals(Twig_Template::ARRAY_CALL, $node->getAttribute('type'));
29 public function getTests()
33 $expr = new Twig_Node_Expression_Name('foo', 1);
34 $attr = new Twig_Node_Expression_Constant('bar', 1);
35 $args = new Twig_Node_Expression_Array(array(), 1);
36 $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::ANY_CALL, 1);
37 $tests[] = array($node, sprintf('%s%s, "bar", array())', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1)));
39 $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::ARRAY_CALL, 1);
40 $tests[] = array($node, sprintf('%s%s, "bar", array(), "array")', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1)));
42 $args = new Twig_Node_Expression_Array(array(), 1);
43 $args->addElement(new Twig_Node_Expression_Name('foo', 1));
44 $args->addElement(new Twig_Node_Expression_Constant('bar', 1));
45 $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_Template::METHOD_CALL, 1);
46 $tests[] = array($node, sprintf('%s%s, "bar", array(0 => %s, 1 => "bar"), "method")', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1), $this->getVariableGetter('foo')));