added some unit tests for the filesystem loader
authorFabien Potencier <fabien.potencier@gmail.com>
Tue, 14 Dec 2010 13:28:47 +0000 (14:28 +0100)
committerFabien Potencier <fabien.potencier@gmail.com>
Tue, 14 Dec 2010 13:28:47 +0000 (14:28 +0100)
test/Twig/Tests/Loader/Filesystem.php [new file with mode: 0644]

diff --git a/test/Twig/Tests/Loader/Filesystem.php b/test/Twig/Tests/Loader/Filesystem.php
new file mode 100644 (file)
index 0000000..caf0d68
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+class Twig_Tests_Loader_FilesystemTest extends PHPUnit_Framework_TestCase
+{
+    /**
+     * @dataProvider getSecurityTests
+     * @expectedException Twig_Error_Loader
+     */
+    public function testSecurity($template)
+    {
+        $loader = new Twig_Loader_Filesystem(array(__DIR__.'/../Fixtures'));
+        $loader->getCacheKey($template);
+    }
+
+    public function getSecurityTests()
+    {
+        return array(
+            array('..\\AutoloaderTest.php'),
+            array('../AutoloaderTest.php'),
+            array('./../AutoloaderTest.php'),
+            array('.\\..\\AutoloaderTest.php'),
+            array('././././././../AutoloaderTest.php'),
+            array('.\\./.\\./.\\./../AutoloaderTest.php'),
+            array('foo/../../AutoloaderTest.php'),
+            array('foo\\..\\..\\AutoloaderTest.php'),
+            array('foo/../bar/../../AutoloaderTest.php'),
+            array('foo/bar/../../../AutoloaderTest.php'),
+        );
+    }
+}