ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
12class 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 {
30 $loader = new Twig_Loader_Array(array());
31
32 $loader->getSource('foo');
33 }
34
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
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
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
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
102 {
103 $loader = new Twig_Loader_Array(array());
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}
An exception for terminatinating execution or to throw for unit testing.
Loads a template from an array.
Definition: Array.php:27
testGetSource()
@group legacy
Definition: ArrayTest.php:17
testGetCacheKeyWhenTemplateHasDuplicateContent()
Definition: ArrayTest.php:52
testIsFreshWhenTemplateDoesNotExist()
@expectedException Twig_Error_Loader
Definition: ArrayTest.php:101
testGetCacheKeyWhenTemplateDoesNotExist()
@expectedException Twig_Error_Loader
Definition: ArrayTest.php:77
testGetSourceWhenTemplateDoesNotExist()
@group legacy @expectedException Twig_Error_Loader
Definition: ArrayTest.php:28
testGetSourceContextWhenTemplateDoesNotExist()
@expectedException Twig_Error_Loader
Definition: ArrayTest.php:38