diff options
Diffstat (limited to 'vendor/twig/twig/test/Twig/Tests/Node/Expression/GetAttrTest.php')
-rw-r--r-- | vendor/twig/twig/test/Twig/Tests/Node/Expression/GetAttrTest.php | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/vendor/twig/twig/test/Twig/Tests/Node/Expression/GetAttrTest.php b/vendor/twig/twig/test/Twig/Tests/Node/Expression/GetAttrTest.php new file mode 100644 index 00000000..6a63cce6 --- /dev/null +++ b/vendor/twig/twig/test/Twig/Tests/Node/Expression/GetAttrTest.php | |||
@@ -0,0 +1,62 @@ | |||
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 | } | ||