]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/twig/twig/test/Twig/Tests/Node/Expression/GetAttrTest.php
gitignore vendor
[github/wallabag/wallabag.git] / 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 /**
15 * @covers Twig_Node_Expression_GetAttr::__construct
16 */
17 public function testConstructor()
18 {
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);
25
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'));
30 }
31
32 /**
33 * @covers Twig_Node_Expression_GetAttr::compile
34 * @dataProvider getTests
35 */
36 public function testCompile($node, $source, $environment = null)
37 {
38 parent::testCompile($node, $source, $environment);
39 }
40
41 public function getTests()
42 {
43 $tests = array();
44
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')));
50
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')));
53
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')));
59
60 return $tests;
61 }
62 }