ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ArrayTest.php
Go to the documentation of this file.
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 {
17  public function testGetSource()
18  {
19  $loader = new Twig_Loader_Array(array('foo' => 'bar'));
20 
21  $this->assertEquals('bar', $loader->getSource('foo'));
22  }
23 
29  {
31 
32  $loader->getSource('foo');
33  }
34 
39  {
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 
53  {
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 
64  {
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 
78  {
80 
81  $loader->getCacheKey('foo');
82  }
83 
84  public function testSetTemplate()
85  {
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 
102  {
104 
105  $loader->isFresh('foo', time());
106  }
107 
108  public function testTemplateReference()
109  {
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 
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 }
testIsFreshWhenTemplateDoesNotExist()
Twig_Error_Loader
Definition: ArrayTest.php:101
testGetCacheKeyWhenTemplateDoesNotExist()
Twig_Error_Loader
Definition: ArrayTest.php:77
if($format !==null) $name
Definition: metadata.php:146
testGetCacheKeyWhenTemplateHasDuplicateContent()
Definition: ArrayTest.php:52
Create styles array
The data for the language used.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
testGetSourceContextWhenTemplateDoesNotExist()
Twig_Error_Loader
Definition: ArrayTest.php:38
Loads a template from an array.
Definition: Array.php:26
testGetSourceWhenTemplateDoesNotExist()
legacy Twig_Error_Loader
Definition: ArrayTest.php:28