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
12use Twig\Environment;
13use Twig\Node\Expression\NameExpression;
14use Twig\Test\NodeTestCase;
15
16class Twig_Tests_Node_Expression_NameTest extends NodeTestCase
17{
18    public function testConstructor()
19    {
20        $node = new NameExpression('foo', 1);
21
22        $this->assertEquals('foo', $node->getAttribute('name'));
23    }
24
25    public function getTests()
26    {
27        $node = new NameExpression('foo', 1);
28        $context = new NameExpression('_context', 1);
29
30        $env = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['strict_variables' => true]);
31        $env1 = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['strict_variables' => false]);
32
33        if (PHP_VERSION_ID >= 70000) {
34            $output = '($context["foo"] ?? $this->getContext($context, "foo"))';
35        } elseif (PHP_VERSION_ID >= 50400) {
36            $output = '(isset($context["foo"]) ? $context["foo"] : $this->getContext($context, "foo"))';
37        } else {
38            $output = '$this->getContext($context, "foo")';
39        }
40
41        return [
42            [$node, "// line 1\n".$output, $env],
43            [$node, $this->getVariableGetter('foo', 1), $env1],
44            [$context, "// line 1\n\$context"],
45        ];
46    }
47}
48