[BUGFIX] Remove obsolete safe_mode hacks from t3lib_div
authorChristian Kuhn <lolli@schwarzbu.ch>
Sun, 24 Apr 2011 10:49:57 +0000 (12:49 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Mon, 25 Apr 2011 19:36:23 +0000 (21:36 +0200)
Remove code from t3lib_div::fixPermissions and t3lib_div::mkdir that remove
a trailing slash from a given directory. This was a workaraund for PHP functions
like mkdir, they fail with trailing slashes if safe_mode is on.
Additionally the according unit tests are cleaned up and completed.

Change-Id: I44b330a3542bfd172736b103feec895b46494346
Resolves: #26228
Related: #25332
Releases: 4.6
Reviewed-on: http://review.typo3.org/1713
Reviewed-by: Susanne Moog
Tested-by: Susanne Moog
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
t3lib/class.t3lib_div.php
tests/t3lib/class.t3lib_divTest.php

index 5c4506c..92533d0 100644 (file)
@@ -2955,7 +2955,6 @@ final class t3lib_div {
                                                // "@" is there because file is not necessarily OWNED by the user
                                        $result = @chmod($path, octdec($GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask']));
                                } elseif (@is_dir($path)) {
-                                       $path = preg_replace('|/$|', '', $path);
                                                // "@" is there because file is not necessarily OWNED by the user
                                        $result = @chmod($path, octdec($GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask']));
                                }
@@ -3061,7 +3060,6 @@ final class t3lib_div {
         * @return      boolean         TRUE if @mkdir went well!
         */
        public static function mkdir($newFolder) {
-               $newFolder = preg_replace('|/$|', '', $newFolder);
                $result = @mkdir($newFolder, octdec($GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask']));
                if ($result) {
                        self::fixPermissions($newFolder);
index e5003b6..73a0ca6 100644 (file)
@@ -1640,7 +1640,7 @@ class t3lib_divTest extends tx_phpunit_testcase {
        /**
         * @test
         */
-       public function fixPermissionsCorrectlySetsGroup() {
+       public function fixPermissionsSetsGroup() {
                if (TYPO3_OS == 'WIN') {
                        $this->markTestSkipped('fixPermissionsCorrectlySetsGroupOwnerOfFile() tests not available on Windows');
                }
@@ -1666,7 +1666,7 @@ class t3lib_divTest extends tx_phpunit_testcase {
        /**
         * @test
         */
-       public function fixPermissionsCorrectlySetsPermissionsToFile() {
+       public function fixPermissionsSetsPermissionsToFile() {
                if (TYPO3_OS == 'WIN') {
                        $this->markTestSkipped('fixPermissions() tests not available on Windows');
                }
@@ -1693,7 +1693,7 @@ class t3lib_divTest extends tx_phpunit_testcase {
        /**
         * @test
         */
-       public function fixPermissionsCorrectlySetsPermissionsToHiddenFile() {
+       public function fixPermissionsSetsPermissionsToHiddenFile() {
                if (TYPO3_OS == 'WIN') {
                        $this->markTestSkipped('fixPermissions() tests not available on Windows');
                }
@@ -1720,7 +1720,34 @@ class t3lib_divTest extends tx_phpunit_testcase {
        /**
         * @test
         */
-       public function fixPermissionsCorrectlySetsPermissionsToDirectory() {
+       public function fixPermissionsSetsPermissionsToDirectory() {
+               if (TYPO3_OS == 'WIN') {
+                       $this->markTestSkipped('fixPermissions() tests not available on Windows');
+               }
+
+                       // Create and prepare test directory
+               $directory = PATH_site . 'typo3temp/' . uniqid('test_');
+               t3lib_div::mkdir($directory);
+               chmod($directory, 1551);
+
+                       // Set target permissions and run method
+               $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] = '0770';
+               $fixPermissionsResult = t3lib_div::fixPermissions($directory);
+
+                       // Get actual permissions and clean up
+               clearstatcache();
+               $resultDirectoryPermissions = substr(decoct(fileperms($directory)), 1);
+               t3lib_div::rmdir($directory);
+
+                       // Test if everything was ok
+               $this->assertTrue($fixPermissionsResult);
+               $this->assertEquals($resultDirectoryPermissions, '0770');
+       }
+
+       /**
+        * @test
+        */
+       public function fixPermissionsSetsPermissionsToDirectoryWithTrailingSlash() {
                if (TYPO3_OS == 'WIN') {
                        $this->markTestSkipped('fixPermissions() tests not available on Windows');
                }
@@ -1747,7 +1774,7 @@ class t3lib_divTest extends tx_phpunit_testcase {
        /**
         * @test
         */
-       public function fixPermissionsCorrectlySetsPermissionsToHiddenDirectory() {
+       public function fixPermissionsSetsPermissionsToHiddenDirectory() {
                if (TYPO3_OS == 'WIN') {
                        $this->markTestSkipped('fixPermissions() tests not available on Windows');
                }
@@ -1894,11 +1921,12 @@ class t3lib_divTest extends tx_phpunit_testcase {
        /**
         * @test
         */
-       public function mkdirCorrectlyCreatesDirectory() {
+       public function mkdirCreatesDirectory() {
                $directory = PATH_site . 'typo3temp/' . uniqid('test_');
                $mkdirResult = t3lib_div::mkdir($directory);
+               clearstatcache();
                $directoryCreated = is_dir($directory);
-               t3lib_div::rmdir($directory);
+               @rmdir($directory);
                $this->assertTrue($mkdirResult);
                $this->assertTrue($directoryCreated);
        }
@@ -1906,11 +1934,12 @@ class t3lib_divTest extends tx_phpunit_testcase {
        /**
         * @test
         */
-       public function mkdirCorrectlyCreatesHiddenDirectory() {
+       public function mkdirCreatesHiddenDirectory() {
                $directory = PATH_site . 'typo3temp/' . uniqid('.test_');
                $mkdirResult = t3lib_div::mkdir($directory);
+               clearstatcache();
                $directoryCreated = is_dir($directory);
-               t3lib_div::rmdir($directory);
+               @rmdir($directory);
                $this->assertTrue($mkdirResult);
                $this->assertTrue($directoryCreated);
        }
@@ -1918,16 +1947,39 @@ class t3lib_divTest extends tx_phpunit_testcase {
        /**
         * @test
         */
-       public function mkdirCorrectlyCreatesDirectoryWithTrailingSlash() {
-               $directory = PATH_site . 'typo3temp/' . uniqid('test_');
+       public function mkdirCreatesDirectoryWithTrailingSlash() {
+               $directory = PATH_site . 'typo3temp/' . uniqid('test_') . '/';
                $mkdirResult = t3lib_div::mkdir($directory);
+               clearstatcache();
                $directoryCreated = is_dir($directory);
-               t3lib_div::rmdir($directory);
+               @rmdir($directory);
                $this->assertTrue($mkdirResult);
                $this->assertTrue($directoryCreated);
        }
 
        /**
+        * @test
+        */
+       public function mkdirSetsPermissionsOfCreatedDirectory() {
+               if (TYPO3_OS == 'WIN') {
+                       $this->markTestSkipped('mkdirSetsPermissionsOfCreatedDirectory() test not available on Windows');
+               }
+
+               $directory = PATH_site . 'typo3temp/' . uniqid('test_');
+               $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] = '0770';
+               t3lib_div::mkdir($directory);
+               clearstatcache();
+               $resultDirectoryPermissions = substr(decoct(fileperms($directory)), 1);
+               rmdir($directory);
+               $this->assertEquals($resultDirectoryPermissions, '0770');
+       }
+
+
+       ///////////////////////////////
+       // Tests concerning unQuoteFilenames
+       ///////////////////////////////
+
+       /**
         * Data provider for ImageMagick shell commands
         * @see explodeAndUnquoteImageMagickCommands
         */