4 * This file is part of Twig.
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 class Twig_Tests_Loader_ArrayTest extends PHPUnit_Framework_TestCase
17 public function testGetSource()
19 $loader = new Twig_Loader_Array(array('foo' => 'bar'));
21 $this->assertEquals('bar', $loader->getSource('foo'));
26 * @expectedException Twig_Error_Loader
28 public function testGetSourceWhenTemplateDoesNotExist()
30 $loader = new Twig_Loader_Array(array());
32 $loader->getSource('foo');
36 * @expectedException Twig_Error_Loader
38 public function testGetSourceContextWhenTemplateDoesNotExist()
40 $loader = new Twig_Loader_Array(array());
42 $loader->getSourceContext('foo');
45 public function testGetCacheKey()
47 $loader = new Twig_Loader_Array(array('foo' => 'bar'));
49 $this->assertEquals('foo:bar', $loader->getCacheKey('foo'));
52 public function testGetCacheKeyWhenTemplateHasDuplicateContent()
54 $loader = new Twig_Loader_Array(array(
59 $this->assertEquals('foo:bar', $loader->getCacheKey('foo'));
60 $this->assertEquals('baz:bar', $loader->getCacheKey('baz'));
63 public function testGetCacheKeyIsProtectedFromEdgeCollisions()
65 $loader = new Twig_Loader_Array(array(
70 $this->assertEquals('foo__:bar', $loader->getCacheKey('foo__'));
71 $this->assertEquals('foo:__bar', $loader->getCacheKey('foo'));
75 * @expectedException Twig_Error_Loader
77 public function testGetCacheKeyWhenTemplateDoesNotExist()
79 $loader = new Twig_Loader_Array(array());
81 $loader->getCacheKey('foo');
84 public function testSetTemplate()
86 $loader = new Twig_Loader_Array(array());
87 $loader->setTemplate('foo', 'bar');
89 $this->assertEquals('bar', $loader->getSourceContext('foo')->getCode());
92 public function testIsFresh()
94 $loader = new Twig_Loader_Array(array('foo' => 'bar'));
95 $this->assertTrue($loader->isFresh('foo', time()));
99 * @expectedException Twig_Error_Loader
101 public function testIsFreshWhenTemplateDoesNotExist()
103 $loader = new Twig_Loader_Array(array());
105 $loader->isFresh('foo', time());
108 public function testTemplateReference()
110 $name = new Twig_Test_Loader_TemplateReference('foo');
111 $loader = new Twig_Loader_Array(array('foo' => 'bar'));
113 $loader->getCacheKey($name);
114 $loader->getSourceContext($name);
115 $loader->isFresh($name, time());
116 $loader->setTemplate($name, 'foo:bar');
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);
124 class Twig_Test_Loader_TemplateReference
128 public function __construct($name)
133 public function __toString()