Fixed bug #17490: After introducing the locking in #17289 no CSRF token will ever...
[Packages/TYPO3.CMS.git] / tests / t3lib / t3lib_divTest.php
index d9b288b..f3fec1a 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 2009-2010 Ingo Renner <ingo@typo3.org>
+*  (c) 2009-2011 Ingo Renner <ingo@typo3.org>
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -766,6 +766,40 @@ class t3lib_divTest extends tx_phpunit_testcase {
                $this->assertEquals('/', $result[strlen($result) - 1]);
        }
 
+       /**
+        * @return array
+        */
+       public static function hostnameAndPortDataProvider() {
+               return array(
+                       'localhost ipv4 without port' => array('127.0.0.1', '127.0.0.1', ''),
+                       'localhost ipv4 with port' => array('127.0.0.1:81', '127.0.0.1', '81'),
+                       'localhost ipv6 without port' => array('[::1]', '[::1]', ''),
+                       'localhost ipv6 with port' => array('[::1]:81', '[::1]', '81'),
+                       'ipv6 without port' => array('[2001:DB8::1]', '[2001:DB8::1]', ''),
+                       'ipv6 with port' => array('[2001:DB8::1]:81', '[2001:DB8::1]', '81'),
+                       'hostname without port' => array('lolli.did.this', 'lolli.did.this', ''),
+                       'hostname with port' => array('lolli.did.this:42', 'lolli.did.this', '42'),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider hostnameAndPortDataProvider
+        */
+       public function getIndpEnvTypo3HostOnlyParsesHostnamesAndIpAdresses($httpHost, $expectedIp) {
+               $_SERVER['HTTP_HOST'] = $httpHost;
+               $this->assertEquals($expectedIp, t3lib_div::getIndpEnv('TYPO3_HOST_ONLY'));
+       }
+
+       /**
+        * @test
+        * @dataProvider hostnameAndPortDataProvider
+        */
+       public function getIndpEnvTypo3PortParsesHostnamesAndIpAdresses($httpHost, $dummy, $expectedPort) {
+               $_SERVER['HTTP_HOST'] = $httpHost;
+               $this->assertEquals($expectedPort, t3lib_div::getIndpEnv('TYPO3_PORT'));
+       }
+
 
        //////////////////////////////////
        // Tests concerning underscoredToUpperCamelCase
@@ -1826,6 +1860,32 @@ class t3lib_divTest extends tx_phpunit_testcase {
                $this->assertFalse($fixPermissionsResult);
        }
 
+       /**
+        * @test
+        */
+       public function fixPermissionsSetsPermissionsWithRelativeFileReference() {
+               if (TYPO3_OS == 'WIN') {
+                       $this->markTestSkipped('fixPermissions() tests not available on Windows');
+               }
+
+               $filename = 'typo3temp/' . uniqid('test_');
+               t3lib_div::writeFileToTypo3tempDir(PATH_site . $filename, '42');
+               chmod($filename, 0742);
+
+                       // Set target permissions and run method
+               $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0660';
+               $fixPermissionsResult = t3lib_div::fixPermissions($filename);
+
+                       // Get actual permissions and clean up
+               clearstatcache();
+               $resultFilePermissions = substr(decoct(fileperms(PATH_site . $filename)), 2);
+               unlink(PATH_site . $filename);
+
+                       // Test if everything was ok
+               $this->assertTrue($fixPermissionsResult);
+               $this->assertEquals($resultFilePermissions, '0660');
+       }
+
 
        ///////////////////////////////
        // Tests concerning mkdir