ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ChainTest.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_ChainTest extends \PHPUnit\Framework\TestCase
13 {
17  public function testGetSource()
18  {
20  new Twig_Loader_Array(array('foo' => 'bar')),
21  new Twig_Loader_Array(array('foo' => 'foobar', 'bar' => 'foo')),
22  ));
23 
24  $this->assertEquals('bar', $loader->getSource('foo'));
25  $this->assertEquals('foo', $loader->getSource('bar'));
26  }
27 
28  public function testGetSourceContext()
29  {
30  $path = dirname(__FILE__).'/../Fixtures';
32  new Twig_Loader_Array(array('foo' => 'bar')),
33  new Twig_Loader_Array(array('errors/index.html' => 'baz')),
35  ));
36 
37  $this->assertEquals('foo', $loader->getSourceContext('foo')->getName());
38  $this->assertSame('', $loader->getSourceContext('foo')->getPath());
39 
40  $this->assertEquals('errors/index.html', $loader->getSourceContext('errors/index.html')->getName());
41  $this->assertSame('', $loader->getSourceContext('errors/index.html')->getPath());
42  $this->assertEquals('baz', $loader->getSourceContext('errors/index.html')->getCode());
43 
44  $this->assertEquals('errors/base.html', $loader->getSourceContext('errors/base.html')->getName());
45  $this->assertEquals(realpath($path.'/errors/base.html'), realpath($loader->getSourceContext('errors/base.html')->getPath()));
46  $this->assertNotEquals('baz', $loader->getSourceContext('errors/base.html')->getCode());
47  }
48 
53  {
55 
56  $loader->getSourceContext('foo');
57  }
58 
64  {
66 
67  $loader->getSource('foo');
68  }
69 
70  public function testGetCacheKey()
71  {
73  new Twig_Loader_Array(array('foo' => 'bar')),
74  new Twig_Loader_Array(array('foo' => 'foobar', 'bar' => 'foo')),
75  ));
76 
77  $this->assertEquals('foo:bar', $loader->getCacheKey('foo'));
78  $this->assertEquals('bar:foo', $loader->getCacheKey('bar'));
79  }
80 
85  {
87 
88  $loader->getCacheKey('foo');
89  }
90 
91  public function testAddLoader()
92  {
93  $loader = new Twig_Loader_Chain();
94  $loader->addLoader(new Twig_Loader_Array(array('foo' => 'bar')));
95 
96  $this->assertEquals('bar', $loader->getSourceContext('foo')->getCode());
97  }
98 
99  public function testExists()
100  {
101  $loader1 = $this->getMockBuilder('Twig_ChainTestLoaderWithExistsInterface')->getMock();
102  $loader1->expects($this->once())->method('exists')->will($this->returnValue(false));
103  $loader1->expects($this->never())->method('getSourceContext');
104 
105  // can be removed in 2.0
106  $loader2 = $this->getMockBuilder('Twig_ChainTestLoaderInterface')->getMock();
107  //$loader2 = $this->getMockBuilder(array('Twig_LoaderInterface', 'Twig_SourceContextLoaderInterface'))->getMock();
108  $loader2->expects($this->once())->method('getSourceContext')->will($this->returnValue(new Twig_Source('content', 'index')));
109 
110  $loader = new Twig_Loader_Chain();
111  $loader->addLoader($loader1);
112  $loader->addLoader($loader2);
113 
114  $this->assertTrue($loader->exists('foo'));
115  }
116 }
117 
119 {
120 }
121 
123 {
124 }
testGetSourceWhenTemplateDoesNotExist()
legacy Twig_Error_Loader
Definition: ChainTest.php:63
Loads template from the filesystem.
Definition: Filesystem.php:17
testGetSourceContextWhenTemplateDoesNotExist()
Twig_Error_Loader
Definition: ChainTest.php:52
Adds an exists() method for loaders.
Adds a getSourceContext() method for loaders.
Loads templates from other loaders.
Definition: Chain.php:19
Create styles array
The data for the language used.
testGetCacheKeyWhenTemplateDoesNotExist()
Twig_Error_Loader
Definition: ChainTest.php:84
Holds information about a non-compiled Twig template.
Definition: Source.php:19
Interface all loaders must implement.
Loads a template from an array.
Definition: Array.php:26