]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/twig/twig/test/Twig/Tests/Loader/ChainTest.php
twig implementation
[github/wallabag/wallabag.git] / vendor / twig / twig / test / Twig / Tests / Loader / ChainTest.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_ChainTest extends PHPUnit_Framework_TestCase
13 {
14 public function testGetSource()
15 {
16 $loader = new Twig_Loader_Chain(array(
17 new Twig_Loader_Array(array('foo' => 'bar')),
18 new Twig_Loader_Array(array('foo' => 'foobar', 'bar' => 'foo')),
19 ));
20
21 $this->assertEquals('bar', $loader->getSource('foo'));
22 $this->assertEquals('foo', $loader->getSource('bar'));
23 }
24
25 /**
26 * @expectedException Twig_Error_Loader
27 */
28 public function testGetSourceWhenTemplateDoesNotExist()
29 {
30 $loader = new Twig_Loader_Chain(array());
31
32 $loader->getSource('foo');
33 }
34
35 public function testGetCacheKey()
36 {
37 $loader = new Twig_Loader_Chain(array(
38 new Twig_Loader_Array(array('foo' => 'bar')),
39 new Twig_Loader_Array(array('foo' => 'foobar', 'bar' => 'foo')),
40 ));
41
42 $this->assertEquals('bar', $loader->getCacheKey('foo'));
43 $this->assertEquals('foo', $loader->getCacheKey('bar'));
44 }
45
46 /**
47 * @expectedException Twig_Error_Loader
48 */
49 public function testGetCacheKeyWhenTemplateDoesNotExist()
50 {
51 $loader = new Twig_Loader_Chain(array());
52
53 $loader->getCacheKey('foo');
54 }
55
56 public function testAddLoader()
57 {
58 $loader = new Twig_Loader_Chain();
59 $loader->addLoader(new Twig_Loader_Array(array('foo' => 'bar')));
60
61 $this->assertEquals('bar', $loader->getSource('foo'));
62 }
63
64 public function testExists()
65 {
66 $loader1 = $this->getMock('Twig_Loader_Array', array('exists', 'getSource'), array(), '', false);
67 $loader1->expects($this->once())->method('exists')->will($this->returnValue(false));
68 $loader1->expects($this->never())->method('getSource');
69
70 $loader2 = $this->getMock('Twig_LoaderInterface');
71 $loader2->expects($this->once())->method('getSource')->will($this->returnValue('content'));
72
73 $loader = new Twig_Loader_Chain();
74 $loader->addLoader($loader1);
75 $loader->addLoader($loader2);
76
77 $this->assertTrue($loader->exists('foo'));
78 }
79 }