Yaffs site version 1.1
[yaffs-website] / vendor / twig / twig / test / Twig / Tests / Node / Expression / GetAttrTest.php
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
12 class Twig_Tests_Node_Expression_GetAttrTest extends Twig_Test_NodeTestCase
13 {
14     public function testConstructor()
15     {
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);
22
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'));
27     }
28
29     public function getTests()
30     {
31         $tests = array();
32
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)));
38
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)));
41
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')));
47
48         return $tests;
49     }
50 }