Added Test #17495: Add Unit Tests for t3lib_div::resolveBackPath()
authorSteffen Gebert <steffen.gebert@typo3.org>
Sun, 13 Feb 2011 09:15:41 +0000 (09:15 +0000)
committerSteffen Gebert <steffen.gebert@typo3.org>
Sun, 13 Feb 2011 09:15:41 +0000 (09:15 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@10456 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
tests/t3lib/t3lib_divTest.php

index ae1e9c7..a7e0996 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2011-02-13  Steffen Gebert  <steffen.gebert@typo3.org>
+
+       * Added Test #17495: Add Unit Tests for t3lib_div::resolveBackPath()
+
 2011-02-11  Stanislas Rolland  <typo3@sjbr.ca>
 
        * Fixed issue #17552: htmlArea RTE: Delete deprecated class HTMLArea.Dialog
index f3fec1a..873d8a5 100644 (file)
@@ -2177,6 +2177,64 @@ class t3lib_divTest extends tx_phpunit_testcase {
        }
 
 
+       /////////////////////////////////////
+       // Tests concerning resolveBackPath
+       /////////////////////////////////////
+
+       /**
+        * @see resolveBackPathWithDataProvider
+        * 
+        * @return array<array>
+        */
+       public function resolveBackPathDataProvider() {
+               return array(
+                       'empty path' => array('', ''),
+                       'this directory' => array('./', './'),
+                       'relative directory without ..' => array('dir1/dir2/dir3/', 'dir1/dir2/dir3/'),
+                       'relative path without ..' => array('dir1/dir2/script.php', 'dir1/dir2/script.php'),
+                       'absolute directory without ..' => array('/dir1/dir2/dir3/', '/dir1/dir2/dir3/'),
+                       'absolute path without ..' => array('/dir1/dir2/script.php', '/dir1/dir2/script.php'),
+                       'only one directory upwards without trailing slash' => array('..', '..'),
+                       'only one directory upwards with trailing slash' => array('../', '../'),
+                       'one level with trailing ..' => array('dir1/..', ''),
+                       'one level with trailing ../' => array('dir1/../', ''),
+                       'two levels with trailing ..' => array('dir1/dir2/..', 'dir1'),
+                       'two levels with trailing ../' => array('dir1/dir2/../', 'dir1/'),
+                       'leading ../ without trailing /' => array('../dir1', '../dir1'),
+                       'leading ../ with trailing /' => array('../dir1/', '../dir1/'),
+                       'leading ../ and inside path' => array('../dir1/dir2/../dir3/', '../dir1/dir3/'),
+                       'one times ../ in relative directory' => array('dir1/../dir2/', 'dir2/'),
+                       'one times ../ in absolute directory' => array('/dir1/../dir2/', '/dir2/'),
+                       'one times ../ in relative path' => array('dir1/../dir2/script.php', 'dir2/script.php'),
+                       'one times ../ in absolute path' => array('/dir1/../dir2/script.php', '/dir2/script.php'),
+                       'consecutive ../' => array('dir1/dir2/dir3/../../../dir4', 'dir4'),
+                       'distrubuted ../ with trailing /' => array('dir1/../dir2/dir3/../', 'dir2/'),
+                       'distributed ../ without trailing /' => array('dir1/../dir2/dir3/..', 'dir2'),
+                       'multiple distributed and consecutive ../ together' => array('dir1/dir2/dir3/dir4/../../dir5/dir6/dir7/../dir8/', 'dir1/dir2/dir5/dir6/dir8/'),
+                       'multiple distributed and consecutive ../ together' => array('dir1/dir2/dir3/dir4/../../dir5/dir6/dir7/../dir8/', 'dir1/dir2/dir5/dir6/dir8/'),
+                       'dirname with leading ..' => array('dir1/..dir2/dir3/', 'dir1/..dir2/dir3/'),
+                       'dirname with trailing ..' => array('dir1/dir2../dir3/', 'dir1/dir2../dir3/'),
+                       'more times upwards than downwards in directory' => array('dir1/../../', '../'),
+                       'more times upwards than downwards in path' => array('dir1/../../script.php', '../script.php'),
+               );
+       }
+
+       /**
+        * @test
+        *
+        * @dataProvider resolveBackPathDataProvider
+        *
+        * @param string $input the input for resolveBackPath
+        * @param $expectedValue the expected return value from resolveBackPath
+        */
+       public function resolveBackPathWithDataProvider($input, $expectedValue) {
+               $this->assertEquals(
+                       $expectedValue,
+                       t3lib_div::resolveBackPath($input)
+               );
+       }
+
+
        /////////////////////////////////////////////////////////////////////////////////////
        // Tests concerning makeInstance, setSingletonInstance, addInstance, purgeInstances
        /////////////////////////////////////////////////////////////////////////////////////