Security update to Drupal 8.4.6
[yaffs-website] / vendor / twig / twig / lib / Twig / Test / NodeTestCase.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 use PHPUnit\Framework\TestCase;
13
14 abstract class Twig_Test_NodeTestCase extends TestCase
15 {
16     abstract public function getTests();
17
18     /**
19      * @dataProvider getTests
20      */
21     public function testCompile($node, $source, $environment = null, $isPattern = false)
22     {
23         $this->assertNodeCompilation($source, $node, $environment, $isPattern);
24     }
25
26     public function assertNodeCompilation($source, Twig_Node $node, Twig_Environment $environment = null, $isPattern = false)
27     {
28         $compiler = $this->getCompiler($environment);
29         $compiler->compile($node);
30
31         if ($isPattern) {
32             $this->assertStringMatchesFormat($source, trim($compiler->getSource()));
33         } else {
34             $this->assertEquals($source, trim($compiler->getSource()));
35         }
36     }
37
38     protected function getCompiler(Twig_Environment $environment = null)
39     {
40         return new Twig_Compiler(null === $environment ? $this->getEnvironment() : $environment);
41     }
42
43     protected function getEnvironment()
44     {
45         return new Twig_Environment(new Twig_Loader_Array(array()));
46     }
47
48     protected function getVariableGetter($name, $line = false)
49     {
50         $line = $line > 0 ? "// line {$line}\n" : '';
51
52         if (PHP_VERSION_ID >= 70000) {
53             return sprintf('%s($context["%s"] ?? null)', $line, $name, $name);
54         }
55
56         if (PHP_VERSION_ID >= 50400) {
57             return sprintf('%s(isset($context["%s"]) ? $context["%s"] : null)', $line, $name, $name);
58         }
59
60         return sprintf('%s$this->getContext($context, "%s")', $line, $name);
61     }
62
63     protected function getAttributeGetter()
64     {
65         if (function_exists('twig_template_get_attributes')) {
66             return 'twig_template_get_attributes($this, ';
67         }
68
69         return '$this->getAttribute(';
70     }
71 }
72
73 class_alias('Twig_Test_NodeTestCase', 'Twig\Test\NodeTestCase', false);
74 class_exists('Twig_Environment');
75 class_exists('Twig_Node');