ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Twig_Tests_Loader_FilesystemTest Class Reference
+ Inheritance diagram for Twig_Tests_Loader_FilesystemTest:
+ Collaboration diagram for Twig_Tests_Loader_FilesystemTest:

Public Member Functions

 testGetSourceContext ()
 
 testSecurity ($template)
 @dataProvider getSecurityTests More...
 
 getSecurityTests ()
 
 testPaths ($basePath, $cacheKey, $rootPath)
 @dataProvider getBasePaths More...
 
 getBasePaths ()
 
 testEmptyConstructor ()
 
 testGetNamespaces ()
 
 testFindTemplateExceptionNamespace ()
 
 testFindTemplateWithCache ()
 
 testLoadTemplateAndRenderBlockWithCache ()
 
 getArrayInheritanceTests ()
 
 testArrayInheritance ($templateName)
 @dataProvider getArrayInheritanceTests More...
 
 testLoadTemplateFromPhar ()
 @requires PHP 5.3 More...
 

Detailed Description

Definition at line 12 of file FilesystemTest.php.

Member Function Documentation

◆ getArrayInheritanceTests()

Twig_Tests_Loader_FilesystemTest::getArrayInheritanceTests ( )

Definition at line 188 of file FilesystemTest.php.

189 {
190 return array(
191 'valid array inheritance' => array('array_inheritance_valid_parent.html.twig'),
192 'array inheritance with null first template' => array('array_inheritance_null_parent.html.twig'),
193 'array inheritance with empty first template' => array('array_inheritance_empty_parent.html.twig'),
194 'array inheritance with non-existent first template' => array('array_inheritance_nonexistent_parent.html.twig'),
195 );
196 }

◆ getBasePaths()

Twig_Tests_Loader_FilesystemTest::getBasePaths ( )

Definition at line 96 of file FilesystemTest.php.

97 {
98 return array(
99 array(
100 dirname(__FILE__).'/Fixtures',
101 'test/Twig/Tests/Loader/Fixtures/named_quater/named_absolute.html',
102 null,
103 ),
104 array(
105 dirname(__FILE__).'/Fixtures/../Fixtures',
106 'test/Twig/Tests/Loader/Fixtures/named_quater/named_absolute.html',
107 null,
108 ),
109 array(
110 'test/Twig/Tests/Loader/Fixtures',
111 'test/Twig/Tests/Loader/Fixtures/named_quater/named_absolute.html',
112 getcwd(),
113 ),
114 array(
115 'Fixtures',
116 'Fixtures/named_quater/named_absolute.html',
117 getcwd().'/test/Twig/Tests/Loader',
118 ),
119 array(
120 'Fixtures',
121 'Fixtures/named_quater/named_absolute.html',
122 getcwd().'/test/../test/Twig/Tests/Loader',
123 ),
124 );
125 }

◆ getSecurityTests()

Twig_Tests_Loader_FilesystemTest::getSecurityTests ( )

Definition at line 37 of file FilesystemTest.php.

38 {
39 return array(
40 array("AutoloaderTest\0.php"),
41 array('..\\AutoloaderTest.php'),
42 array('..\\\\\\AutoloaderTest.php'),
43 array('../AutoloaderTest.php'),
44 array('..////AutoloaderTest.php'),
45 array('./../AutoloaderTest.php'),
46 array('.\\..\\AutoloaderTest.php'),
47 array('././././././../AutoloaderTest.php'),
48 array('.\\./.\\./.\\./../AutoloaderTest.php'),
49 array('foo/../../AutoloaderTest.php'),
50 array('foo\\..\\..\\AutoloaderTest.php'),
51 array('foo/../bar/../../AutoloaderTest.php'),
52 array('foo/bar/../../../AutoloaderTest.php'),
53 array('filters/../../AutoloaderTest.php'),
54 array('filters//..//..//AutoloaderTest.php'),
55 array('filters\\..\\..\\AutoloaderTest.php'),
56 array('filters\\\\..\\\\..\\\\AutoloaderTest.php'),
57 array('filters\\//../\\/\\..\\AutoloaderTest.php'),
58 array('/../AutoloaderTest.php'),
59 );
60 }

◆ testArrayInheritance()

Twig_Tests_Loader_FilesystemTest::testArrayInheritance (   $templateName)

@dataProvider getArrayInheritanceTests

Parameters
$templateNamestring Template name with array inheritance

Definition at line 203 of file FilesystemTest.php.

204 {
205 $loader = new Twig_Loader_Filesystem(array());
206 $loader->addPath(dirname(__FILE__).'/Fixtures/inheritance');
207
208 $twig = new Twig_Environment($loader);
209
210 $template = $twig->loadTemplate($templateName);
211 $this->assertSame('VALID Child', $template->renderBlock('body', array()));
212 }
Stores the Twig configuration.
Definition: Environment.php:18
Loads template from the filesystem.
Definition: Filesystem.php:18
$template

References $loader, and $template.

◆ testEmptyConstructor()

Twig_Tests_Loader_FilesystemTest::testEmptyConstructor ( )

Definition at line 127 of file FilesystemTest.php.

128 {
130 $this->assertEquals(array(), $loader->getPaths());
131 }

References $loader.

◆ testFindTemplateExceptionNamespace()

Twig_Tests_Loader_FilesystemTest::testFindTemplateExceptionNamespace ( )

Definition at line 142 of file FilesystemTest.php.

143 {
144 $basePath = dirname(__FILE__).'/Fixtures';
145
146 $loader = new Twig_Loader_Filesystem(array($basePath.'/normal'));
147 $loader->addPath($basePath.'/named', 'named');
148
149 try {
150 $loader->getSourceContext('@named/nowhere.html');
151 } catch (Exception $e) {
152 $this->assertInstanceof('Twig_Error_Loader', $e);
153 $this->assertContains('Unable to find template "@named/nowhere.html"', $e->getMessage());
154 }
155 }

References $loader.

◆ testFindTemplateWithCache()

Twig_Tests_Loader_FilesystemTest::testFindTemplateWithCache ( )

Definition at line 157 of file FilesystemTest.php.

158 {
159 $basePath = dirname(__FILE__).'/Fixtures';
160
161 $loader = new Twig_Loader_Filesystem(array($basePath.'/normal'));
162 $loader->addPath($basePath.'/named', 'named');
163
164 // prime the cache for index.html in the named namespace
165 $namedSource = $loader->getSourceContext('@named/index.html')->getCode();
166 $this->assertEquals("named path\n", $namedSource);
167
168 // get index.html from the main namespace
169 $this->assertEquals("path\n", $loader->getSourceContext('index.html')->getCode());
170 }

References $loader.

◆ testGetNamespaces()

Twig_Tests_Loader_FilesystemTest::testGetNamespaces ( )

Definition at line 133 of file FilesystemTest.php.

134 {
135 $loader = new Twig_Loader_Filesystem(sys_get_temp_dir());
136 $this->assertEquals(array(Twig_Loader_Filesystem::MAIN_NAMESPACE), $loader->getNamespaces());
137
138 $loader->addPath(sys_get_temp_dir(), 'named');
139 $this->assertEquals(array(Twig_Loader_Filesystem::MAIN_NAMESPACE, 'named'), $loader->getNamespaces());
140 }
const MAIN_NAMESPACE
Identifier of the main namespace.
Definition: Filesystem.php:20

References $loader, and Twig_Loader_Filesystem\MAIN_NAMESPACE.

◆ testGetSourceContext()

Twig_Tests_Loader_FilesystemTest::testGetSourceContext ( )

Definition at line 14 of file FilesystemTest.php.

15 {
16 $path = dirname(__FILE__).'/../Fixtures';
18 $this->assertEquals('errors/index.html', $loader->getSourceContext('errors/index.html')->getName());
19 $this->assertEquals(realpath($path.'/errors/index.html'), realpath($loader->getSourceContext('errors/index.html')->getPath()));
20 }

References $loader, and $path.

◆ testLoadTemplateAndRenderBlockWithCache()

Twig_Tests_Loader_FilesystemTest::testLoadTemplateAndRenderBlockWithCache ( )

Definition at line 172 of file FilesystemTest.php.

173 {
174 $loader = new Twig_Loader_Filesystem(array());
175 $loader->addPath(dirname(__FILE__).'/Fixtures/themes/theme2');
176 $loader->addPath(dirname(__FILE__).'/Fixtures/themes/theme1');
177 $loader->addPath(dirname(__FILE__).'/Fixtures/themes/theme1', 'default_theme');
178
179 $twig = new Twig_Environment($loader);
180
181 $template = $twig->loadTemplate('blocks.html.twig');
182 $this->assertSame('block from theme 1', $template->renderBlock('b1', array()));
183
184 $template = $twig->loadTemplate('blocks.html.twig');
185 $this->assertSame('block from theme 2', $template->renderBlock('b2', array()));
186 }

References $loader, and $template.

◆ testLoadTemplateFromPhar()

Twig_Tests_Loader_FilesystemTest::testLoadTemplateFromPhar ( )

@requires PHP 5.3

Definition at line 217 of file FilesystemTest.php.

218 {
219 $loader = new Twig_Loader_Filesystem(array());
220 // phar-sample.phar was created with the following script:
221 // $f = new Phar('phar-test.phar');
222 // $f->addFromString('hello.twig', 'hello from phar');
223 $loader->addPath('phar://'.dirname(__FILE__).'/Fixtures/phar/phar-sample.phar');
224 $this->assertSame('hello from phar', $loader->getSourceContext('hello.twig')->getCode());
225 }

References $loader.

◆ testPaths()

Twig_Tests_Loader_FilesystemTest::testPaths (   $basePath,
  $cacheKey,
  $rootPath 
)

@dataProvider getBasePaths

Definition at line 65 of file FilesystemTest.php.

66 {
67 $loader = new Twig_Loader_Filesystem(array($basePath.'/normal', $basePath.'/normal_bis'), $rootPath);
68 $loader->setPaths(array($basePath.'/named', $basePath.'/named_bis'), 'named');
69 $loader->addPath($basePath.'/named_ter', 'named');
70 $loader->addPath($basePath.'/normal_ter');
71 $loader->prependPath($basePath.'/normal_final');
72 $loader->prependPath($basePath.'/named/../named_quater', 'named');
73 $loader->prependPath($basePath.'/named_final', 'named');
74
75 $this->assertEquals(array(
76 $basePath.'/normal_final',
77 $basePath.'/normal',
78 $basePath.'/normal_bis',
79 $basePath.'/normal_ter',
80 ), $loader->getPaths());
81 $this->assertEquals(array(
82 $basePath.'/named_final',
83 $basePath.'/named/../named_quater',
84 $basePath.'/named',
85 $basePath.'/named_bis',
86 $basePath.'/named_ter',
87 ), $loader->getPaths('named'));
88
89 // do not use realpath here as it would make the test unuseful
90 $this->assertEquals($cacheKey, str_replace('\\', '/', $loader->getCacheKey('@named/named_absolute.html')));
91 $this->assertEquals("path (final)\n", $loader->getSourceContext('index.html')->getCode());
92 $this->assertEquals("path (final)\n", $loader->getSourceContext('@__main__/index.html')->getCode());
93 $this->assertEquals("named path (final)\n", $loader->getSourceContext('@named/index.html')->getCode());
94 }

References $loader.

◆ testSecurity()

Twig_Tests_Loader_FilesystemTest::testSecurity (   $template)

@dataProvider getSecurityTests

Definition at line 25 of file FilesystemTest.php.

26 {
27 $loader = new Twig_Loader_Filesystem(array(dirname(__FILE__).'/../Fixtures'));
28
29 try {
30 $loader->getCacheKey($template);
31 $this->fail();
32 } catch (Twig_Error_Loader $e) {
33 $this->assertNotContains('Unable to find template', $e->getMessage());
34 }
35 }
Exception thrown when an error occurs during template loading.
Definition: Loader.php:26

References $loader, and $template.


The documentation for this class was generated from the following file: