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_FilesystemTest
extends PHPUnit_Framework_TestCase
15 * @dataProvider getSecurityTests
17 public function testSecurity($template)
19 $loader = new Twig_Loader_Filesystem(array(dirname(__FILE__
).'/../Fixtures'));
22 $loader->getCacheKey($template);
24 } catch (Twig_Error_Loader
$e) {
25 $this->assertNotContains('Unable to find template', $e->getMessage());
29 public function getSecurityTests()
32 array("AutoloaderTest\0.php"),
33 array('..\\AutoloaderTest.php'),
34 array('..\\\\\\AutoloaderTest.php'),
35 array('../AutoloaderTest.php'),
36 array('..////AutoloaderTest.php'),
37 array('./../AutoloaderTest.php'),
38 array('.\\..\\AutoloaderTest.php'),
39 array('././././././../AutoloaderTest.php'),
40 array('.\\./.\\./.\\./../AutoloaderTest.php'),
41 array('foo/../../AutoloaderTest.php'),
42 array('foo\\..\\..\\AutoloaderTest.php'),
43 array('foo/../bar/../../AutoloaderTest.php'),
44 array('foo/bar/../../../AutoloaderTest.php'),
45 array('filters/../../AutoloaderTest.php'),
46 array('filters//..//..//AutoloaderTest.php'),
47 array('filters\\..\\..\\AutoloaderTest.php'),
48 array('filters\\\\..\\\\..\\\\AutoloaderTest.php'),
49 array('filters\\//../\\/\\..\\AutoloaderTest.php'),
50 array('/../AutoloaderTest.php'),
54 public function testPaths()
56 $basePath = dirname(__FILE__
).'/Fixtures';
58 $loader = new Twig_Loader_Filesystem(array($basePath.'/normal', $basePath.'/normal_bis'));
59 $loader->setPaths(array($basePath.'/named', $basePath.'/named_bis'), 'named');
60 $loader->addPath($basePath.'/named_ter', 'named');
61 $loader->addPath($basePath.'/normal_ter');
62 $loader->prependPath($basePath.'/normal_final');
63 $loader->prependPath($basePath.'/named_final', 'named');
65 $this->assertEquals(array(
66 $basePath.'/normal_final',
68 $basePath.'/normal_bis',
69 $basePath.'/normal_ter',
70 ), $loader->getPaths());
71 $this->assertEquals(array(
72 $basePath.'/named_final',
74 $basePath.'/named_bis',
75 $basePath.'/named_ter',
76 ), $loader->getPaths('named'));
78 $this->assertEquals("path (final)\n", $loader->getSource('index.html'));
79 $this->assertEquals("path (final)\n", $loader->getSource('@__main__/index.html'));
80 $this->assertEquals("named path (final)\n", $loader->getSource('@named/index.html'));
83 public function testEmptyConstructor()
85 $loader = new Twig_Loader_Filesystem();
86 $this->assertEquals(array(), $loader->getPaths());
89 public function testGetNamespaces()
91 $loader = new Twig_Loader_Filesystem(sys_get_temp_dir());
92 $this->assertEquals(array(Twig_Loader_Filesystem
::MAIN_NAMESPACE
), $loader->getNamespaces());
94 $loader->addPath(sys_get_temp_dir(), 'named');
95 $this->assertEquals(array(Twig_Loader_Filesystem
::MAIN_NAMESPACE
, 'named'), $loader->getNamespaces());