Security update for Core, with self-updated composer
[yaffs-website] / vendor / twig / twig / test / Twig / Tests / Loader / ArrayTest.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_Loader_ArrayTest extends \PHPUnit\Framework\TestCase
13 {
14     /**
15      * @group legacy
16      */
17     public function testGetSource()
18     {
19         $loader = new Twig_Loader_Array(array('foo' => 'bar'));
20
21         $this->assertEquals('bar', $loader->getSource('foo'));
22     }
23
24     /**
25      * @group legacy
26      * @expectedException Twig_Error_Loader
27      */
28     public function testGetSourceWhenTemplateDoesNotExist()
29     {
30         $loader = new Twig_Loader_Array(array());
31
32         $loader->getSource('foo');
33     }
34
35     /**
36      * @expectedException Twig_Error_Loader
37      */
38     public function testGetSourceContextWhenTemplateDoesNotExist()
39     {
40         $loader = new Twig_Loader_Array(array());
41
42         $loader->getSourceContext('foo');
43     }
44
45     public function testGetCacheKey()
46     {
47         $loader = new Twig_Loader_Array(array('foo' => 'bar'));
48
49         $this->assertEquals('foo:bar', $loader->getCacheKey('foo'));
50     }
51
52     public function testGetCacheKeyWhenTemplateHasDuplicateContent()
53     {
54         $loader = new Twig_Loader_Array(array(
55             'foo' => 'bar',
56             'baz' => 'bar',
57         ));
58
59         $this->assertEquals('foo:bar', $loader->getCacheKey('foo'));
60         $this->assertEquals('baz:bar', $loader->getCacheKey('baz'));
61     }
62
63     public function testGetCacheKeyIsProtectedFromEdgeCollisions()
64     {
65         $loader = new Twig_Loader_Array(array(
66             'foo__' => 'bar',
67             'foo' => '__bar',
68         ));
69
70         $this->assertEquals('foo__:bar', $loader->getCacheKey('foo__'));
71         $this->assertEquals('foo:__bar', $loader->getCacheKey('foo'));
72     }
73
74     /**
75      * @expectedException Twig_Error_Loader
76      */
77     public function testGetCacheKeyWhenTemplateDoesNotExist()
78     {
79         $loader = new Twig_Loader_Array(array());
80
81         $loader->getCacheKey('foo');
82     }
83
84     public function testSetTemplate()
85     {
86         $loader = new Twig_Loader_Array(array());
87         $loader->setTemplate('foo', 'bar');
88
89         $this->assertEquals('bar', $loader->getSourceContext('foo')->getCode());
90     }
91
92     public function testIsFresh()
93     {
94         $loader = new Twig_Loader_Array(array('foo' => 'bar'));
95         $this->assertTrue($loader->isFresh('foo', time()));
96     }
97
98     /**
99      * @expectedException Twig_Error_Loader
100      */
101     public function testIsFreshWhenTemplateDoesNotExist()
102     {
103         $loader = new Twig_Loader_Array(array());
104
105         $loader->isFresh('foo', time());
106     }
107
108     public function testTemplateReference()
109     {
110         $name = new Twig_Test_Loader_TemplateReference('foo');
111         $loader = new Twig_Loader_Array(array('foo' => 'bar'));
112
113         $loader->getCacheKey($name);
114         $loader->getSourceContext($name);
115         $loader->isFresh($name, time());
116         $loader->setTemplate($name, 'foo:bar');
117
118         // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
119         // can be executed without crashing PHP
120         $this->addToAssertionCount(1);
121     }
122 }
123
124 class Twig_Test_Loader_TemplateReference
125 {
126     private $name;
127
128     public function __construct($name)
129     {
130         $this->name = $name;
131     }
132
133     public function __toString()
134     {
135         return $this->name;
136     }
137 }