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
15 * @covers Twig_Node_Expression_GetAttr::__construct
17 public function testConstructor()
19 $expr = new Twig_Node_Expression_Name('foo', 1);
20 $attr = new Twig_Node_Expression_Constant('bar', 1);
21 $args = new Twig_Node_Expression_Array(array(), 1);
22 $args->addElement(new Twig_Node_Expression_Name('foo', 1));
23 $args->addElement(new Twig_Node_Expression_Constant('bar', 1));
24 $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_TemplateInterface
::ARRAY_CALL
, 1);
26 $this->assertEquals($expr, $node->getNode('node'));
27 $this->assertEquals($attr, $node->getNode('attribute'));
28 $this->assertEquals($args, $node->getNode('arguments'));
29 $this->assertEquals(Twig_TemplateInterface
::ARRAY_CALL
, $node->getAttribute('type'));
33 * @covers Twig_Node_Expression_GetAttr::compile
34 * @dataProvider getTests
36 public function testCompile($node, $source, $environment = null)
38 parent
::testCompile($node, $source, $environment);
41 public function getTests()
45 $expr = new Twig_Node_Expression_Name('foo', 1);
46 $attr = new Twig_Node_Expression_Constant('bar', 1);
47 $args = new Twig_Node_Expression_Array(array(), 1);
48 $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_TemplateInterface
::ANY_CALL
, 1);
49 $tests[] = array($node, sprintf('%s%s, "bar")', $this->getAttributeGetter(), $this->getVariableGetter('foo')));
51 $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_TemplateInterface
::ARRAY_CALL
, 1);
52 $tests[] = array($node, sprintf('%s%s, "bar", array(), "array")', $this->getAttributeGetter(), $this->getVariableGetter('foo')));
54 $args = new Twig_Node_Expression_Array(array(), 1);
55 $args->addElement(new Twig_Node_Expression_Name('foo', 1));
56 $args->addElement(new Twig_Node_Expression_Constant('bar', 1));
57 $node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_TemplateInterface
::METHOD_CALL
, 1);
58 $tests[] = array($node, sprintf('%s%s, "bar", array(0 => %s, 1 => "bar"), "method")', $this->getAttributeGetter(), $this->getVariableGetter('foo'), $this->getVariableGetter('foo')));