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_ChainTest
extends PHPUnit_Framework_TestCase
14 public function testGetSource()
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')),
21 $this->assertEquals('bar', $loader->getSource('foo'));
22 $this->assertEquals('foo', $loader->getSource('bar'));
26 * @expectedException Twig_Error_Loader
28 public function testGetSourceWhenTemplateDoesNotExist()
30 $loader = new Twig_Loader_Chain(array());
32 $loader->getSource('foo');
35 public function testGetCacheKey()
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')),
42 $this->assertEquals('bar', $loader->getCacheKey('foo'));
43 $this->assertEquals('foo', $loader->getCacheKey('bar'));
47 * @expectedException Twig_Error_Loader
49 public function testGetCacheKeyWhenTemplateDoesNotExist()
51 $loader = new Twig_Loader_Chain(array());
53 $loader->getCacheKey('foo');
56 public function testAddLoader()
58 $loader = new Twig_Loader_Chain();
59 $loader->addLoader(new Twig_Loader_Array(array('foo' => 'bar')));
61 $this->assertEquals('bar', $loader->getSource('foo'));
64 public function testExists()
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');
70 $loader2 = $this->getMock('Twig_LoaderInterface');
71 $loader2->expects($this->once())->method('getSource')->will($this->returnValue('content'));
73 $loader = new Twig_Loader_Chain();
74 $loader->addLoader($loader1);
75 $loader->addLoader($loader2);
77 $this->assertTrue($loader->exists('foo'));