|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2009-2011 Ingo Renner <ingo@typo3.org> 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * 00017 * This script is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU General Public License for more details. 00021 * 00022 * This copyright notice MUST APPEAR in all copies of the script! 00023 ***************************************************************/ 00024 00025 /** 00026 * Testcase for class t3lib_div 00027 * 00028 * @author Ingo Renner <ingo@typo3.org> 00029 * @author Oliver Klee <typo3-coding@oliverklee.de> 00030 * 00031 * @package TYPO3 00032 * @subpackage t3lib 00033 */ 00034 class t3lib_divTest extends tx_phpunit_testcase { 00035 00036 /** 00037 * Enable backup of global and system variables 00038 * 00039 * @var boolean 00040 */ 00041 protected $backupGlobals = TRUE; 00042 00043 /** 00044 * Exclude TYPO3_DB from backup/ restore of $GLOBALS 00045 * because resource types cannot be handled during serializing 00046 * 00047 * @var array 00048 */ 00049 protected $backupGlobalsBlacklist = array('TYPO3_DB'); 00050 00051 public function tearDown() { 00052 t3lib_div::purgeInstances(); 00053 } 00054 00055 00056 /////////////////////////////// 00057 // Tests concerning gif_compress 00058 /////////////////////////////// 00059 00060 /** 00061 * @test 00062 */ 00063 public function gifCompressFixesPermissionOfConvertedFileIfUsingImagemagick() { 00064 if (TYPO3_OS == 'WIN') { 00065 $this->markTestSkipped('gifCompressFixesPermissionOfConvertedFileIfUsingImagemagick() test not available on Windows.'); 00066 } 00067 00068 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['im'] || !$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path_lzw']) { 00069 $this->markTestSkipped('gifCompressFixesPermissionOfConvertedFileIfUsingImagemagick() test not available without imagemagick setup.'); 00070 } 00071 00072 $testFinder = t3lib_div::makeInstance('Tx_Phpunit_Service_TestFinder'); 00073 $fixtureGifFile = $testFinder->getAbsoluteCoreTestsPath() . 't3lib/fixtures/clear.gif'; 00074 00075 $GLOBALS['TYPO3_CONF_VARS']['GFX']['gif_compress'] = TRUE; 00076 00077 // Copy file to unique filename in typo3temp, set target permissions and run method 00078 $testFilename = PATH_site . 'typo3temp/' . uniqid('test_') . '.gif'; 00079 @copy($fixtureGifFile, $testFilename); 00080 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0777'; 00081 t3lib_div::gif_compress($testFilename, 'IM'); 00082 00083 // Get actual permissions and clean up 00084 clearstatcache(); 00085 $resultFilePermissions = substr(decoct(fileperms($testFilename)), 2); 00086 t3lib_div::unlink_tempfile($testFilename); 00087 00088 $this->assertEquals($resultFilePermissions, '0777'); 00089 } 00090 00091 /** 00092 * @test 00093 */ 00094 public function gifCompressFixesPermissionOfConvertedFileIfUsingGd() { 00095 if (TYPO3_OS == 'WIN') { 00096 $this->markTestSkipped('gifCompressFixesPermissionOfConvertedFileIfUsingImagemagick() test not available on Windows.'); 00097 } 00098 00099 $testFinder = t3lib_div::makeInstance('Tx_Phpunit_Service_TestFinder'); 00100 $fixtureGifFile = $testFinder->getAbsoluteCoreTestsPath() . 't3lib/fixtures/clear.gif'; 00101 00102 $GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib'] = TRUE; 00103 $GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png'] = FALSE; 00104 00105 // Copy file to unique filename in typo3temp, set target permissions and run method 00106 $testFilename = PATH_site . 'typo3temp/' . uniqid('test_') . '.gif'; 00107 @copy($fixtureGifFile, $testFilename); 00108 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0777'; 00109 t3lib_div::gif_compress($testFilename, 'GD'); 00110 00111 // Get actual permissions and clean up 00112 clearstatcache(); 00113 $resultFilePermissions = substr(decoct(fileperms($testFilename)), 2); 00114 t3lib_div::unlink_tempfile($testFilename); 00115 00116 $this->assertEquals($resultFilePermissions, '0777'); 00117 } 00118 00119 /////////////////////////////// 00120 // Tests concerning png_to_gif_by_imagemagick 00121 /////////////////////////////// 00122 00123 /** 00124 * @test 00125 */ 00126 public function pngToGifByImagemagickFixesPermissionsOfConvertedFile() { 00127 if (TYPO3_OS == 'WIN') { 00128 $this->markTestSkipped('pngToGifByImagemagickFixesPermissionsOfConvertedFile() test not available on Windows.'); 00129 } 00130 00131 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['im'] || !$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path_lzw']) { 00132 $this->markTestSkipped('pngToGifByImagemagickFixesPermissionsOfConvertedFile() test not available without imagemagick setup.'); 00133 } 00134 00135 $testFinder = t3lib_div::makeInstance('Tx_Phpunit_Service_TestFinder'); 00136 $fixturePngFile = $testFinder->getAbsoluteCoreTestsPath() . 't3lib/fixtures/clear.png'; 00137 00138 $GLOBALS['TYPO3_CONF_VARS']['FE']['png_to_gif'] = TRUE; 00139 00140 // Copy file to unique filename in typo3temp, set target permissions and run method 00141 $testFilename = PATH_site . 'typo3temp/' . uniqid('test_') . '.png'; 00142 @copy($fixturePngFile, $testFilename); 00143 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0777'; 00144 $newGifFile = t3lib_div::png_to_gif_by_imagemagick($testFilename); 00145 00146 // Get actual permissions and clean up 00147 clearstatcache(); 00148 $resultFilePermissions = substr(decoct(fileperms($newGifFile)), 2); 00149 t3lib_div::unlink_tempfile($newGifFile); 00150 00151 $this->assertEquals($resultFilePermissions, '0777'); 00152 } 00153 00154 /////////////////////////////// 00155 // Tests concerning read_png_gif 00156 /////////////////////////////// 00157 00158 /** 00159 * @test 00160 */ 00161 public function readPngGifFixesPermissionsOfConvertedFile() { 00162 if (TYPO3_OS == 'WIN') { 00163 $this->markTestSkipped('readPngGifFixesPermissionsOfConvertedFile() test not available on Windows.'); 00164 } 00165 00166 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['im']) { 00167 $this->markTestSkipped('readPngGifFixesPermissionsOfConvertedFile() test not available without imagemagick setup.'); 00168 } 00169 00170 $testFinder = t3lib_div::makeInstance('Tx_Phpunit_Service_TestFinder'); 00171 $testGifFile = $testFinder->getAbsoluteCoreTestsPath() . 't3lib/fixtures/clear.gif'; 00172 00173 // Set target permissions and run method 00174 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0777'; 00175 $newPngFile = t3lib_div::read_png_gif($testGifFile, TRUE); 00176 00177 // Get actual permissions and clean up 00178 clearstatcache(); 00179 $resultFilePermissions = substr(decoct(fileperms($newPngFile)), 2); 00180 t3lib_div::unlink_tempfile($newPngFile); 00181 00182 $this->assertEquals($resultFilePermissions, '0777'); 00183 } 00184 00185 /////////////////////////////// 00186 // Tests concerning validIP 00187 /////////////////////////////// 00188 00189 /** 00190 * Data provider for checkValidIpReturnsTrueForValidIp 00191 * 00192 * @return array Data sets 00193 */ 00194 public static function validIpDataProvider() { 00195 return array( 00196 '0.0.0.0' => array('0.0.0.0'), 00197 'private IPv4 class C' => array('192.168.0.1'), 00198 'private IPv4 class A' => array('10.0.13.1'), 00199 'private IPv6' => array('fe80::daa2:5eff:fe8b:7dfb'), 00200 ); 00201 } 00202 00203 /** 00204 * @test 00205 * @dataProvider validIpDataProvider 00206 */ 00207 public function validIpReturnsTrueForValidIp($ip) { 00208 $this->assertTrue(t3lib_div::validIP($ip)); 00209 } 00210 00211 /** 00212 * Data provider for checkValidIpReturnsFalseForInvalidIp 00213 * 00214 * @return array Data sets 00215 */ 00216 public static function invalidIpDataProvider() { 00217 return array( 00218 'null' => array(null), 00219 'zero' => array(0), 00220 'string' => array('test'), 00221 'string empty' => array(''), 00222 'string null' => array('null'), 00223 'out of bounds IPv4' => array('300.300.300.300'), 00224 'dotted decimal notation with only two dots' => array('127.0.1'), 00225 ); 00226 } 00227 00228 /** 00229 * @test 00230 * @dataProvider invalidIpDataProvider 00231 */ 00232 public function validIpReturnsFalseForInvalidIp($ip) { 00233 $this->assertFalse(t3lib_div::validIP($ip)); 00234 } 00235 00236 00237 /////////////////////////////// 00238 // Tests concerning testInt 00239 /////////////////////////////// 00240 00241 /** 00242 * Data provider for testIntReturnsTrue 00243 * 00244 * @return array Data sets 00245 */ 00246 public function functionTestIntValidDataProvider() { 00247 return array( 00248 'int' => array(32425), 00249 'negative int' => array(-32425), 00250 'largest int' => array(PHP_INT_MAX), 00251 'int as string' => array('32425'), 00252 'negative int as string' => array('-32425'), 00253 'zero' => array(0), 00254 'zero as string' => array('0'), 00255 ); 00256 } 00257 00258 /** 00259 * @test 00260 * @dataProvider functionTestIntValidDataProvider 00261 */ 00262 public function testIntReturnsTrue($int) { 00263 $this->assertTrue(t3lib_div::testInt($int)); 00264 } 00265 00266 /** 00267 * Data provider for testIntReturnsFalse 00268 * 00269 * @return array Data sets 00270 */ 00271 public function functionTestIntInvalidDataProvider() { 00272 return array( 00273 'int as string with leading zero' => array('01234'), 00274 'positive int as string with plus modifier' => array('+1234'), 00275 'negative int as string with leading zero' => array('-01234'), 00276 'largest int plus one' => array(PHP_INT_MAX + 1), 00277 'string' => array('testInt'), 00278 'empty string' => array(''), 00279 'int in string' => array('5 times of testInt'), 00280 'int as string with space after' => array('5 '), 00281 'int as string with space before' => array(' 5'), 00282 'int as string with many spaces before' => array(' 5'), 00283 'float' => array(3.14159), 00284 'float as string' => array('3.14159'), 00285 'float as string only a dot' => array('10.'), 00286 'float as string trailing zero would evaluate to int 10' => array('10.0'), 00287 'float as string trailing zeros would evaluate to int 10' => array('10.00'), 00288 'null' => array(NULL), 00289 'empty array' => array(array()), 00290 'int in array' => array(array(32425)), 00291 'int as string in array' => array(array('32425')), 00292 ); 00293 } 00294 00295 /** 00296 * @test 00297 * @dataProvider functionTestIntInvalidDataProvider 00298 */ 00299 public function testIntReturnsFalse($int) { 00300 $this->assertFalse(t3lib_div::testInt($int)); 00301 } 00302 00303 00304 /////////////////////////////// 00305 // Tests concerning isFirstPartOfStr 00306 /////////////////////////////// 00307 00308 /** 00309 * Data provider for isFirstPartOfStrReturnsTrueForMatchingFirstParts 00310 * 00311 * @return array 00312 */ 00313 public function isFirstPartOfStrReturnsTrueForMatchingFirstPartDataProvider() { 00314 return array( 00315 'match first part of string' => array('hello world', 'hello'), 00316 'match whole string' => array('hello', 'hello'), 00317 'integer is part of string with same number' => array('24', 24), 00318 'string is part of integer with same number' => array(24, '24'), 00319 'integer is part of string starting with same number' => array('24 beer please', 24), 00320 ); 00321 } 00322 00323 /** 00324 * @test 00325 * @dataProvider isFirstPartOfStrReturnsTrueForMatchingFirstPartDataProvider 00326 */ 00327 public function isFirstPartOfStrReturnsTrueForMatchingFirstPart($string, $part) { 00328 $this->assertTrue(t3lib_div::isFirstPartOfStr($string, $part)); 00329 } 00330 00331 /** 00332 * Data provider for checkIsFirstPartOfStrReturnsFalseForNotMatchingFirstParts 00333 * 00334 * @return array 00335 */ 00336 public function isFirstPartOfStrReturnsFalseForNotMatchingFirstPartDataProvider() { 00337 return array( 00338 'no string match' => array('hello', 'bye'), 00339 'no case sensitive string match' => array('hello world', 'Hello'), 00340 'array is not part of string' => array('string', array()), 00341 'string is not part of array' => array(array(), 'string'), 00342 'null is not part of string' => array('string', NULL), 00343 'string is not part of array' => array(NULL, 'string'), 00344 'null is not part of array' => array(array(), NULL), 00345 'array is not part of string' => array(NULL, array()), 00346 'empty string is not part of empty string' => array('', ''), 00347 'null is not part of empty string' => array('', NULL), 00348 'false is not part of empty string' => array('', FALSE), 00349 'empty string is not part of null' => array(NULL, ''), 00350 'empty string is not part of false' => array(FALSE, ''), 00351 'empty string is not part of zero integer' => array(0, ''), 00352 'zero integer is not part of null' => array(NULL, 0), 00353 'zero integer is not part of empty string' => array('', 0), 00354 ); 00355 } 00356 00357 /** 00358 * @test 00359 * @dataProvider isFirstPartOfStrReturnsFalseForNotMatchingFirstPartDataProvider 00360 */ 00361 public function isFirstPartOfStrReturnsFalseForNotMatchingFirstPart($string, $part) { 00362 $this->assertFalse(t3lib_div::isFirstPartOfStr($string, $part)); 00363 } 00364 00365 00366 /////////////////////////////// 00367 // Tests concerning splitCalc 00368 /////////////////////////////// 00369 00370 /** 00371 * Data provider for splitCalc 00372 * 00373 * @return array expected values, arithmetic expression 00374 */ 00375 public function splitCalcDataProvider() { 00376 return array( 00377 'empty string returns empty array' => array( 00378 array(), 00379 '', 00380 ), 00381 'number without operator returns array with plus and number' => array( 00382 array(array('+', 42)), 00383 '42', 00384 ), 00385 'two numbers with asterisk return first number with plus and second number with asterisk' => array( 00386 array(array('+', 42), array('*', 31)), 00387 '42 * 31', 00388 ), 00389 ); 00390 } 00391 00392 /** 00393 * @test 00394 * @dataProvider splitCalcDataProvider 00395 */ 00396 public function splitCalcCorrectlySplitsExpression($expected, $expression) { 00397 $this->assertEquals($expected, t3lib_div::splitCalc($expression, '+-*/')); 00398 } 00399 00400 00401 ////////////////////////////////// 00402 // Tests concerning calcPriority 00403 ////////////////////////////////// 00404 00405 /** 00406 * Data provider for calcPriority 00407 * 00408 * @return array expected values, arithmetic expression 00409 */ 00410 public function calcPriorityDataProvider() { 00411 return array( 00412 'add' => array(9, '6 + 3'), 00413 'substract with positive result' => array(3, '6 - 3'), 00414 'substract with negative result' => array(-3, '3 - 6'), 00415 'multiply' => array(6, '2 * 3'), 00416 'divide' => array(2.5, '5 / 2'), 00417 'modulus' => array(1, '5 % 2'), 00418 'power' => array(8, '2 ^ 3'), 00419 'three operands with non integer result' => array(6.5, '5 + 3 / 2'), 00420 'three operands with power' => array(14, '5 + 3 ^ 2'), 00421 'three operads with modulus' => array(4, '5 % 2 + 3'), 00422 'four operands' => array(3, '2 + 6 / 2 - 2'), 00423 ); 00424 } 00425 00426 /** 00427 * @test 00428 * @dataProvider calcPriorityDataProvider 00429 */ 00430 public function calcPriorityCorrectlyCalculatesExpression($expected, $expression) { 00431 $this->assertEquals($expected, t3lib_div::calcPriority($expression)); 00432 } 00433 00434 00435 ////////////////////////////////// 00436 // Tests concerning calcPriority 00437 ////////////////////////////////// 00438 00439 /** 00440 * Data provider for valid validEmail's 00441 * 00442 * @return array Valid email addresses 00443 */ 00444 public function validEmailValidDataProvider() { 00445 return array( 00446 'short mail address' => array('a@b.c'), 00447 'simple mail address' => array('test@example.com'), 00448 'uppercase characters' => array('QWERTYUIOPASDFGHJKLZXCVBNM@QWERTYUIOPASDFGHJKLZXCVBNM.NET'), 00449 // Fix / change if TYPO3 php requirement changed: Address ok with 5.2.6 and 5.3.2 but fails with 5.3.0 on windows 00450 // 'equal sign in local part' => array('test=mail@example.com'), 00451 'dash in local part' => array('test-mail@example.com'), 00452 'plus in local part' => array('test+mail@example.com'), 00453 // Fix / change if TYPO3 php requirement changed: Address ok with 5.2.6 and 5.3.2 but fails with 5.3.0 on windows 00454 // 'question mark in local part' => array('test?mail@example.com'), 00455 'slash in local part' => array('foo/bar@example.com'), 00456 'hash in local part' => array('foo#bar@example.com'), 00457 // Fix / change if TYPO3 php requirement changed: Address ok with 5.2.6 and 5.3.2 but fails with 5.3.0 on windows 00458 // 'dot in local part' => array('firstname.lastname@employee.2something.com'), 00459 // Fix / change if TYPO3 php requirement changed: Address ok with 5.2.6, but not ok with 5.3.2 00460 // 'dash as local part' => array('-@foo.com'), 00461 ); 00462 } 00463 00464 /** 00465 * @test 00466 * @dataProvider validEmailValidDataProvider 00467 */ 00468 public function validEmailReturnsTrueForValidMailAddress($address) { 00469 $this->assertTrue(t3lib_div::validEmail($address)); 00470 } 00471 00472 /** 00473 * Data provider for invalid validEmail's 00474 * 00475 * @return array Invalid email addresses 00476 */ 00477 public function validEmailInvalidDataProvider() { 00478 return array( 00479 '@ sign only' => array('@'), 00480 'duplicate @' => array('test@@example.com'), 00481 'duplicate @ combined with further special characters in local part' => array('test!.!@#$%^&*@example.com'), 00482 'opening parenthesis in local part' => array('foo(bar@example.com'), 00483 'closing parenthesis in local part' => array('foo)bar@example.com'), 00484 'opening square bracket in local part' => array('foo[bar@example.com'), 00485 'closing square bracket as local part' => array(']@example.com'), 00486 // Fix / change if TYPO3 php requirement changed: Address ok with 5.2.6, but not ok with 5.3.2 00487 // 'top level domain only' => array('test@com'), 00488 'dash as second level domain' => array('foo@-.com'), 00489 'domain part starting with dash' => array('foo@-foo.com'), 00490 'domain part ending with dash' => array('foo@foo-.com'), 00491 'number as top level domain' => array('foo@bar.123'), 00492 // Fix / change if TYPO3 php requirement changed: Address not ok with 5.2.6, but ok with 5.3.2 (?) 00493 // 'dash as top level domain' => array('foo@bar.-'), 00494 'dot at beginning of domain part' => array('test@.com'), 00495 // Fix / change if TYPO3 php requirement changed: Address ok with 5.2.6, but not ok with 5.3.2 00496 // 'local part ends with dot' => array('e.x.a.m.p.l.e.@example.com'), 00497 'trailing whitespace' => array('test@example.com '), 00498 'trailing carriage return' => array('test@example.com' . CR), 00499 'trailing linefeed' => array('test@example.com' . LF), 00500 'trailing carriage return linefeed' => array('test@example.com' . CRLF), 00501 'trailing tab' => array('test@example.com' . TAB), 00502 ); 00503 } 00504 00505 /** 00506 * @test 00507 * @dataProvider validEmailInvalidDataProvider 00508 */ 00509 public function validEmailReturnsFalseForInvalidMailAddress($address) { 00510 $this->assertFalse(t3lib_div::validEmail($address)); 00511 } 00512 00513 00514 ////////////////////////////////// 00515 // Tests concerning intExplode 00516 ////////////////////////////////// 00517 00518 /** 00519 * @test 00520 */ 00521 public function intExplodeConvertsStringsToInteger() { 00522 $testString = '1,foo,2'; 00523 $expectedArray = array(1, 0, 2); 00524 $actualArray = t3lib_div::intExplode(',', $testString); 00525 00526 $this->assertEquals($expectedArray, $actualArray); 00527 } 00528 00529 00530 ////////////////////////////////// 00531 // Tests concerning revExplode 00532 ////////////////////////////////// 00533 00534 /** 00535 * @test 00536 */ 00537 public function revExplodeExplodesString() { 00538 $testString = 'my:words:here'; 00539 $expectedArray = array('my:words', 'here'); 00540 $actualArray = t3lib_div::revExplode(':', $testString, 2); 00541 00542 $this->assertEquals($expectedArray, $actualArray); 00543 } 00544 00545 00546 ////////////////////////////////// 00547 // Tests concerning trimExplode 00548 ////////////////////////////////// 00549 00550 /** 00551 * @test 00552 */ 00553 public function checkTrimExplodeTrimsSpacesAtElementStartAndEnd() { 00554 $testString = ' a , b , c ,d ,, e,f,'; 00555 $expectedArray = array('a', 'b', 'c', 'd', '', 'e', 'f', ''); 00556 $actualArray = t3lib_div::trimExplode(',', $testString); 00557 00558 $this->assertEquals($expectedArray, $actualArray); 00559 } 00560 00561 /** 00562 * @test 00563 */ 00564 public function checkTrimExplodeRemovesNewLines() { 00565 $testString = ' a , b , ' . LF . ' ,d ,, e,f,'; 00566 $expectedArray = array('a', 'b', 'd', 'e', 'f'); 00567 $actualArray = t3lib_div::trimExplode(',', $testString, TRUE); 00568 00569 $this->assertEquals($expectedArray, $actualArray); 00570 } 00571 00572 /** 00573 * @test 00574 */ 00575 public function checkTrimExplodeRemovesEmptyElements() { 00576 $testString = 'a , b , c , ,d ,, ,e,f,'; 00577 $expectedArray = array('a', 'b', 'c', 'd', 'e', 'f'); 00578 $actualArray = t3lib_div::trimExplode(',', $testString, TRUE); 00579 00580 $this->assertEquals($expectedArray, $actualArray); 00581 } 00582 00583 /** 00584 * @test 00585 */ 00586 public function checkTrimExplodeKeepsRemainingResultsWithEmptyItemsAfterReachingLimitWithPositiveParameter() { 00587 $testString = ' a , b , c , , d,, ,e '; 00588 $expectedArray = array('a', 'b', 'c,,d,,,e'); 00589 // Limiting returns the rest of the string as the last element 00590 $actualArray = t3lib_div::trimExplode(',', $testString, FALSE, 3); 00591 00592 $this->assertEquals($expectedArray, $actualArray); 00593 } 00594 00595 /** 00596 * @test 00597 */ 00598 public function checkTrimExplodeKeepsRemainingResultsWithoutEmptyItemsAfterReachingLimitWithPositiveParameter() { 00599 $testString = ' a , b , c , , d,, ,e '; 00600 $expectedArray = array('a', 'b', 'c,d,e'); 00601 // Limiting returns the rest of the string as the last element 00602 $actualArray = t3lib_div::trimExplode(',', $testString, TRUE, 3); 00603 00604 $this->assertEquals($expectedArray, $actualArray); 00605 } 00606 00607 /** 00608 * @test 00609 */ 00610 public function checkTrimExplodeKeepsRamainingResultsWithEmptyItemsAfterReachingLimitWithNegativeParameter() { 00611 $testString = ' a , b , c , d, ,e, f , , '; 00612 $expectedArray = array('a', 'b', 'c', 'd', '', 'e'); 00613 // limiting returns the rest of the string as the last element 00614 $actualArray = t3lib_div::trimExplode(',', $testString, FALSE, -3); 00615 00616 $this->assertEquals($expectedArray, $actualArray); 00617 } 00618 00619 /** 00620 * @test 00621 */ 00622 public function checkTrimExplodeKeepsRamainingResultsWithoutEmptyItemsAfterReachingLimitWithNegativeParameter() { 00623 $testString = ' a , b , c , d, ,e, f , , '; 00624 $expectedArray = array('a', 'b', 'c'); 00625 // Limiting returns the rest of the string as the last element 00626 $actualArray = t3lib_div::trimExplode(',', $testString, TRUE, -3); 00627 00628 $this->assertEquals($expectedArray, $actualArray); 00629 } 00630 00631 /** 00632 * @test 00633 */ 00634 public function checkTrimExplodeReturnsExactResultsWithoutReachingLimitWithPositiveParameter() { 00635 $testString = ' a , b , , c , , , '; 00636 $expectedArray = array('a', 'b', 'c'); 00637 // Limiting returns the rest of the string as the last element 00638 $actualArray = t3lib_div::trimExplode(',', $testString, TRUE, 4); 00639 00640 $this->assertEquals($expectedArray, $actualArray); 00641 } 00642 00643 /** 00644 * @test 00645 */ 00646 public function checkTrimExplodeKeepsZeroAsString() { 00647 $testString = 'a , b , c , ,d ,, ,e,f, 0 ,'; 00648 $expectedArray = array('a', 'b', 'c', 'd', 'e', 'f', '0'); 00649 $actualArray = t3lib_div::trimExplode(',', $testString, TRUE); 00650 00651 $this->assertEquals($expectedArray, $actualArray); 00652 } 00653 00654 00655 ////////////////////////////////// 00656 // Tests concerning removeArrayEntryByValue 00657 ////////////////////////////////// 00658 00659 /** 00660 * @test 00661 */ 00662 public function checkRemoveArrayEntryByValueRemovesEntriesFromOneDimensionalArray() { 00663 $inputArray = array( 00664 '0' => 'test1', 00665 '1' => 'test2', 00666 '2' => 'test3', 00667 '3' => 'test2', 00668 ); 00669 $compareValue = 'test2'; 00670 $expectedResult = array( 00671 '0' => 'test1', 00672 '2' => 'test3', 00673 ); 00674 $actualResult = t3lib_div::removeArrayEntryByValue($inputArray, $compareValue); 00675 $this->assertEquals($expectedResult, $actualResult); 00676 } 00677 00678 /** 00679 * @test 00680 */ 00681 public function checkRemoveArrayEntryByValueRemovesEntriesFromMultiDimensionalArray() { 00682 $inputArray = array( 00683 '0' => 'foo', 00684 '1' => array( 00685 '10' => 'bar', 00686 ), 00687 '2' => 'bar', 00688 ); 00689 $compareValue = 'bar'; 00690 $expectedResult = array( 00691 '0' => 'foo', 00692 '1' => array(), 00693 ); 00694 $actualResult = t3lib_div::removeArrayEntryByValue($inputArray, $compareValue); 00695 $this->assertEquals($expectedResult, $actualResult); 00696 } 00697 00698 /** 00699 * @test 00700 */ 00701 public function checkRemoveArrayEntryByValueRemovesEntryWithEmptyString() { 00702 $inputArray = array( 00703 '0' => 'foo', 00704 '1' => '', 00705 '2' => 'bar', 00706 ); 00707 $compareValue = ''; 00708 $expectedResult = array( 00709 '0' => 'foo', 00710 '2' => 'bar', 00711 ); 00712 $actualResult = t3lib_div::removeArrayEntryByValue($inputArray, $compareValue); 00713 $this->assertEquals($expectedResult, $actualResult); 00714 } 00715 00716 ////////////////////////////////// 00717 // Tests concerning getBytesFromSizeMeasurement 00718 ////////////////////////////////// 00719 00720 /** 00721 * Data provider for getBytesFromSizeMeasurement 00722 * 00723 * @return array expected value, input string 00724 */ 00725 public function getBytesFromSizeMeasurementDataProvider() { 00726 return array( 00727 '100 kilo Bytes' => array('102400', '100k'), 00728 '100 mega Bytes' => array('104857600', '100m'), 00729 '100 giga Bytes' => array('107374182400', '100g'), 00730 ); 00731 } 00732 00733 /** 00734 * @test 00735 * @dataProvider getBytesFromSizeMeasurementDataProvider 00736 */ 00737 public function getBytesFromSizeMeasurementCalculatesCorrectByteValue($expected, $byteString) { 00738 $this->assertEquals($expected, t3lib_div::getBytesFromSizeMeasurement($byteString)); 00739 } 00740 00741 00742 ////////////////////////////////// 00743 // Tests concerning getIndpEnv 00744 ////////////////////////////////// 00745 00746 /** 00747 * @test 00748 */ 00749 public function getIndpEnvTypo3SitePathReturnNonEmptyString() { 00750 $this->assertTrue(strlen(t3lib_div::getIndpEnv('TYPO3_SITE_PATH')) >= 1); 00751 } 00752 00753 /** 00754 * @test 00755 */ 00756 public function getIndpEnvTypo3SitePathReturnsStringStartingWithSlash() { 00757 $result = t3lib_div::getIndpEnv('TYPO3_SITE_PATH'); 00758 $this->assertEquals('/', $result[0]); 00759 } 00760 00761 /** 00762 * @test 00763 */ 00764 public function getIndpEnvTypo3SitePathReturnsStringEndingWithSlash() { 00765 $result = t3lib_div::getIndpEnv('TYPO3_SITE_PATH'); 00766 $this->assertEquals('/', $result[strlen($result) - 1]); 00767 } 00768 00769 /** 00770 * @return array 00771 */ 00772 public static function hostnameAndPortDataProvider() { 00773 return array( 00774 'localhost ipv4 without port' => array('127.0.0.1', '127.0.0.1', ''), 00775 'localhost ipv4 with port' => array('127.0.0.1:81', '127.0.0.1', '81'), 00776 'localhost ipv6 without port' => array('[::1]', '[::1]', ''), 00777 'localhost ipv6 with port' => array('[::1]:81', '[::1]', '81'), 00778 'ipv6 without port' => array('[2001:DB8::1]', '[2001:DB8::1]', ''), 00779 'ipv6 with port' => array('[2001:DB8::1]:81', '[2001:DB8::1]', '81'), 00780 'hostname without port' => array('lolli.did.this', 'lolli.did.this', ''), 00781 'hostname with port' => array('lolli.did.this:42', 'lolli.did.this', '42'), 00782 ); 00783 } 00784 00785 /** 00786 * @test 00787 * @dataProvider hostnameAndPortDataProvider 00788 */ 00789 public function getIndpEnvTypo3HostOnlyParsesHostnamesAndIpAdresses($httpHost, $expectedIp) { 00790 $_SERVER['HTTP_HOST'] = $httpHost; 00791 $this->assertEquals($expectedIp, t3lib_div::getIndpEnv('TYPO3_HOST_ONLY')); 00792 } 00793 00794 /** 00795 * @test 00796 * @dataProvider hostnameAndPortDataProvider 00797 */ 00798 public function getIndpEnvTypo3PortParsesHostnamesAndIpAdresses($httpHost, $dummy, $expectedPort) { 00799 $_SERVER['HTTP_HOST'] = $httpHost; 00800 $this->assertEquals($expectedPort, t3lib_div::getIndpEnv('TYPO3_PORT')); 00801 } 00802 00803 00804 ////////////////////////////////// 00805 // Tests concerning underscoredToUpperCamelCase 00806 ////////////////////////////////// 00807 00808 /** 00809 * Data provider for underscoredToUpperCamelCase 00810 * 00811 * @return array expected, input string 00812 */ 00813 public function underscoredToUpperCamelCaseDataProvider() { 00814 return array( 00815 'single word' => array('Blogexample', 'blogexample'), 00816 'multiple words' => array('BlogExample', 'blog_example'), 00817 ); 00818 } 00819 00820 /** 00821 * @test 00822 * @dataProvider underscoredToUpperCamelCaseDataProvider 00823 */ 00824 public function underscoredToUpperCamelCase($expected, $inputString) { 00825 $this->assertEquals($expected, t3lib_div::underscoredToUpperCamelCase($inputString)); 00826 } 00827 00828 00829 ////////////////////////////////// 00830 // Tests concerning underscoredToLowerCamelCase 00831 ////////////////////////////////// 00832 00833 /** 00834 * Data provider for underscoredToLowerCamelCase 00835 * 00836 * @return array expected, input string 00837 */ 00838 public function underscoredToLowerCamelCaseDataProvider() { 00839 return array( 00840 'single word' => array('minimalvalue', 'minimalvalue'), 00841 'multiple words' => array('minimalValue', 'minimal_value'), 00842 ); 00843 } 00844 00845 /** 00846 * @test 00847 * @dataProvider underscoredToLowerCamelCaseDataProvider 00848 */ 00849 public function underscoredToLowerCamelCase($expected, $inputString) { 00850 $this->assertEquals($expected, t3lib_div::underscoredToLowerCamelCase($inputString)); 00851 } 00852 00853 ////////////////////////////////// 00854 // Tests concerning camelCaseToLowerCaseUnderscored 00855 ////////////////////////////////// 00856 00857 /** 00858 * Data provider for camelCaseToLowerCaseUnderscored 00859 * 00860 * @return array expected, input string 00861 */ 00862 public function camelCaseToLowerCaseUnderscoredDataProvider() { 00863 return array( 00864 'single word' => array('blogexample', 'blogexample'), 00865 'single word starting upper case' => array('blogexample', 'Blogexample'), 00866 'two words starting lower case' => array('minimal_value', 'minimalValue'), 00867 'two words starting upper case' => array('blog_example', 'BlogExample'), 00868 ); 00869 } 00870 00871 /** 00872 * @test 00873 * @dataProvider camelCaseToLowerCaseUnderscoredDataProvider 00874 */ 00875 public function camelCaseToLowerCaseUnderscored($expected, $inputString) { 00876 $this->assertEquals($expected, t3lib_div::camelCaseToLowerCaseUnderscored($inputString)); 00877 } 00878 00879 00880 ////////////////////////////////// 00881 // Tests concerning lcFirst 00882 ////////////////////////////////// 00883 00884 /** 00885 * Data provider for lcFirst 00886 * 00887 * @return array expected, input string 00888 */ 00889 public function lcfirstDataProvider() { 00890 return array( 00891 'single word' => array('blogexample', 'blogexample'), 00892 'single Word starting upper case' => array('blogexample', 'Blogexample'), 00893 'two words' => array('blogExample', 'BlogExample'), 00894 ); 00895 } 00896 00897 /** 00898 * @test 00899 * @dataProvider lcfirstDataProvider 00900 */ 00901 public function lcFirst($expected, $inputString) { 00902 $this->assertEquals($expected, t3lib_div::lcfirst($inputString)); 00903 } 00904 00905 00906 ////////////////////////////////// 00907 // Tests concerning encodeHeader 00908 ////////////////////////////////// 00909 00910 /** 00911 * @test 00912 */ 00913 public function encodeHeaderEncodesWhitespacesInQuotedPrintableMailHeader() { 00914 $this->assertEquals( 00915 '=?utf-8?Q?We_test_whether_the_copyright_character_=C2=A9_is_encoded_correctly?=', 00916 t3lib_div::encodeHeader( 00917 "We test whether the copyright character \xc2\xa9 is encoded correctly", 00918 'quoted-printable', 00919 'utf-8' 00920 ) 00921 ); 00922 } 00923 00924 /** 00925 * @test 00926 */ 00927 public function encodeHeaderEncodesQuestionmarksInQuotedPrintableMailHeader() { 00928 $this->assertEquals( 00929 '=?utf-8?Q?Is_the_copyright_character_=C2=A9_really_encoded_correctly=3F_Really=3F?=', 00930 t3lib_div::encodeHeader( 00931 "Is the copyright character \xc2\xa9 really encoded correctly? Really?", 00932 'quoted-printable', 00933 'utf-8' 00934 ) 00935 ); 00936 } 00937 00938 00939 ////////////////////////////////// 00940 // Tests concerning isValidUrl 00941 ////////////////////////////////// 00942 00943 /** 00944 * Data provider for valid isValidUrl's 00945 * 00946 * @return array Valid ressource 00947 */ 00948 public function validUrlValidRessourceDataProvider() { 00949 return array( 00950 'http' => array('http://www.example.org/'), 00951 'http without trailing slash' => array('http://qwe'), 00952 'http directory with trailing slash' => array('http://www.example/img/dir/'), 00953 'http directory without trailing slash' => array('http://www.example/img/dir'), 00954 'http index.html' => array('http://example.com/index.html'), 00955 'http index.php' => array('http://www.example.com/index.php'), 00956 'http test.png' => array('http://www.example/img/test.png'), 00957 'http username password querystring and ancher' => array('https://user:pw@www.example.org:80/path?arg=value#fragment'), 00958 'file' => array('file:///tmp/test.c'), 00959 'file directory' => array('file://foo/bar'), 00960 'ftp directory' => array('ftp://ftp.example.com/tmp/'), 00961 'mailto' => array('mailto:foo@bar.com'), 00962 'news' => array('news:news.php.net'), 00963 'telnet'=> array('telnet://192.0.2.16:80/'), 00964 'ldap' => array('ldap://[2001:db8::7]/c=GB?objectClass?one'), 00965 ); 00966 } 00967 00968 /** 00969 * @test 00970 * @dataProvider validUrlValidRessourceDataProvider 00971 */ 00972 public function validURLReturnsTrueForValidRessource($url) { 00973 $this->assertTrue(t3lib_div::isValidUrl($url)); 00974 } 00975 00976 /** 00977 * Data provider for invalid isValidUrl's 00978 * 00979 * @return array Invalid ressource 00980 */ 00981 public function isValidUrlInvalidRessourceDataProvider() { 00982 return array( 00983 'http missing colon' => array('http//www.example/wrong/url/'), 00984 'http missing slash' => array('http:/www.example'), 00985 'hostname only' => array('www.example.org/'), 00986 'file missing protocol specification' => array('/tmp/test.c'), 00987 'slash only' => array('/'), 00988 'string http://' => array('http://'), 00989 'string http:/' => array('http:/'), 00990 'string http:' => array('http:'), 00991 'string http' => array('http'), 00992 'empty string' => array(''), 00993 'string -1' => array('-1'), 00994 'string array()' => array('array()'), 00995 'random string' => array('qwe'), 00996 ); 00997 } 00998 00999 /** 01000 * @test 01001 * @dataProvider isValidUrlInvalidRessourceDataProvider 01002 */ 01003 public function validURLReturnsFalseForInvalidRessoure($url) { 01004 $this->assertFalse(t3lib_div::isValidUrl($url)); 01005 } 01006 01007 01008 ////////////////////////////////// 01009 // Tests concerning isOnCurrentHost 01010 ////////////////////////////////// 01011 01012 /** 01013 * @test 01014 */ 01015 public function isOnCurrentHostReturnsTrueWithCurrentHost() { 01016 $testUrl = t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'); 01017 $this->assertTrue(t3lib_div::isOnCurrentHost($testUrl)); 01018 } 01019 01020 /** 01021 * Data provider for invalid isOnCurrentHost's 01022 * 01023 * @return array Invalid Hosts 01024 */ 01025 public function checkisOnCurrentHostInvalidHosts() { 01026 return array( 01027 'empty string' => array(''), 01028 'arbitrary string' => array('arbitrary string'), 01029 'localhost IP' => array('127.0.0.1'), 01030 'relative path' => array('./relpath/file.txt'), 01031 'absolute path' => array('/abspath/file.txt?arg=value'), 01032 'differnt host' => array(t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST') . '.example.org'), 01033 ); 01034 } 01035 01036 01037 //////////////////////////////////////// 01038 // Tests concerning sanitizeLocalUrl 01039 //////////////////////////////////////// 01040 01041 /** 01042 * Data provider for valid sanitizeLocalUrl's 01043 * 01044 * @return array Valid url 01045 */ 01046 public function sanitizeLocalUrlValidUrlDataProvider() { 01047 $subDirectory = t3lib_div::getIndpEnv('TYPO3_SITE_PATH'); 01048 $typo3SiteUrl = t3lib_div::getIndpEnv('TYPO3_SITE_URL'); 01049 $typo3RequestHost = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST'); 01050 01051 return array( 01052 'alt_intro.php' => array('alt_intro.php'), 01053 'alt_intro.php?foo=1&bar=2' => array('alt_intro.php?foo=1&bar=2'), 01054 $subDirectory . 'typo3/alt_intro.php' => array($subDirectory . 'typo3/alt_intro.php'), 01055 $subDirectory . 'index.php' => array($subDirectory . 'index.php'), 01056 '../index.php' => array('../index.php'), 01057 '../typo3/alt_intro.php' => array('../typo3/alt_intro.php'), 01058 '../~userDirectory/index.php' => array('../~userDirectory/index.php'), 01059 '../typo3/mod.php?var1=test-case&var2=~user' => array('../typo3/mod.php?var1=test-case&var2=~user'), 01060 PATH_site . 'typo3/alt_intro.php' => array(PATH_site . 'typo3/alt_intro.php'), 01061 $typo3SiteUrl . 'typo3/alt_intro.php' => array($typo3SiteUrl . 'typo3/alt_intro.php'), 01062 $typo3RequestHost . $subDirectory . '/index.php' => array($typo3RequestHost . $subDirectory . '/index.php'), 01063 ); 01064 } 01065 01066 /** 01067 * @test 01068 * @dataProvider sanitizeLocalUrlValidUrlDataProvider 01069 */ 01070 public function sanitizeLocalUrlAcceptsNotEncodedValidUrls($url) { 01071 $this->assertEquals($url, t3lib_div::sanitizeLocalUrl($url)); 01072 } 01073 01074 /** 01075 * @test 01076 * @dataProvider sanitizeLocalUrlValidUrlDataProvider 01077 */ 01078 public function sanitizeLocalUrlAcceptsEncodedValidUrls($url) { 01079 $this->assertEquals(rawurlencode($url), t3lib_div::sanitizeLocalUrl(rawurlencode($url))); 01080 } 01081 01082 /** 01083 * Data provider for invalid sanitizeLocalUrl's 01084 * 01085 * @return array Valid url 01086 */ 01087 public function sanitizeLocalUrlInvalidDataProvider() { 01088 return array( 01089 'empty string' => array(''), 01090 'http domain' => array('http://www.google.de/'), 01091 'https domain' => array('https://www.google.de/'), 01092 'relative path with XSS' => array('../typo3/whatever.php?argument=javascript:alert(0)'), 01093 ); 01094 } 01095 01096 /** 01097 * @test 01098 * @dataProvider sanitizeLocalUrlInvalidDataProvider 01099 */ 01100 public function sanitizeLocalUrlDeniesPlainInvalidUrls($url) { 01101 $this->assertEquals('', t3lib_div::sanitizeLocalUrl($url)); 01102 } 01103 01104 /** 01105 * @test 01106 * @dataProvider sanitizeLocalUrlInvalidDataProvider 01107 */ 01108 public function sanitizeLocalUrlDeniesEncodedInvalidUrls($url) { 01109 $this->assertEquals('', t3lib_div::sanitizeLocalUrl(rawurlencode($url))); 01110 } 01111 01112 01113 ////////////////////////////////////// 01114 // Tests concerning arrayDiffAssocRecursive 01115 ////////////////////////////////////// 01116 01117 /** 01118 * @test 01119 */ 01120 public function arrayDiffAssocRecursiveHandlesOneDimensionalArrays() { 01121 $array1 = array( 01122 'key1' => 'value1', 01123 'key2' => 'value2', 01124 'key3' => 'value3', 01125 ); 01126 $array2 = array( 01127 'key1' => 'value1', 01128 'key3' => 'value3', 01129 ); 01130 $expectedResult = array( 01131 'key2' => 'value2', 01132 ); 01133 $actualResult = t3lib_div::arrayDiffAssocRecursive($array1, $array2); 01134 $this->assertEquals($expectedResult, $actualResult); 01135 } 01136 01137 /** 01138 * @test 01139 */ 01140 public function arrayDiffAssocRecursiveHandlesMultiDimensionalArrays() { 01141 $array1 = array( 01142 'key1' => 'value1', 01143 'key2' => array( 01144 'key21' => 'value21', 01145 'key22' => 'value22', 01146 'key23' => array( 01147 'key231' => 'value231', 01148 'key232' => 'value232', 01149 ), 01150 ), 01151 ); 01152 $array2 = array( 01153 'key1' => 'value1', 01154 'key2' => array( 01155 'key21' => 'value21', 01156 'key23' => array( 01157 'key231' => 'value231', 01158 ), 01159 ), 01160 ); 01161 $expectedResult = array( 01162 'key2' => array( 01163 'key22' => 'value22', 01164 'key23' => array( 01165 'key232' => 'value232', 01166 ), 01167 ), 01168 ); 01169 $actualResult = t3lib_div::arrayDiffAssocRecursive($array1, $array2); 01170 $this->assertEquals($expectedResult, $actualResult); 01171 } 01172 01173 /** 01174 * @test 01175 */ 01176 public function arrayDiffAssocRecursiveHandlesMixedArrays() { 01177 $array1 = array( 01178 'key1' => array( 01179 'key11' => 'value11', 01180 'key12' => 'value12', 01181 ), 01182 'key2' => 'value2', 01183 'key3' => 'value3', 01184 ); 01185 $array2 = array( 01186 'key1' => 'value1', 01187 'key2' => array( 01188 'key21' => 'value21', 01189 ), 01190 ); 01191 $expectedResult = array( 01192 'key3' => 'value3', 01193 ); 01194 $actualResult = t3lib_div::arrayDiffAssocRecursive($array1, $array2); 01195 $this->assertEquals($expectedResult, $actualResult); 01196 } 01197 01198 01199 ////////////////////////////////////// 01200 // Tests concerning removeDotsFromTS 01201 ////////////////////////////////////// 01202 01203 /** 01204 * @test 01205 */ 01206 public function removeDotsFromTypoScriptSucceedsWithDottedArray() { 01207 $typoScript = array( 01208 'propertyA.' => array( 01209 'keyA.' => array( 01210 'valueA' => 1, 01211 ), 01212 'keyB' => 2, 01213 ), 01214 'propertyB' => 3, 01215 ); 01216 01217 $expectedResult = array( 01218 'propertyA' => array( 01219 'keyA' => array( 01220 'valueA' => 1, 01221 ), 01222 'keyB' => 2, 01223 ), 01224 'propertyB' => 3, 01225 ); 01226 01227 $this->assertEquals($expectedResult, t3lib_div::removeDotsFromTS($typoScript)); 01228 } 01229 01230 /** 01231 * @test 01232 */ 01233 public function removeDotsFromTypoScriptOverridesSubArray() { 01234 $typoScript = array( 01235 'propertyA.' => array( 01236 'keyA' => 'getsOverridden', 01237 'keyA.' => array( 01238 'valueA' => 1, 01239 ), 01240 'keyB' => 2, 01241 ), 01242 'propertyB' => 3, 01243 ); 01244 01245 $expectedResult = array( 01246 'propertyA' => array( 01247 'keyA' => array( 01248 'valueA' => 1, 01249 ), 01250 'keyB' => 2, 01251 ), 01252 'propertyB' => 3, 01253 ); 01254 01255 $this->assertEquals($expectedResult, t3lib_div::removeDotsFromTS($typoScript)); 01256 } 01257 01258 /** 01259 * @test 01260 */ 01261 public function removeDotsFromTypoScriptOverridesWithScalar() { 01262 $typoScript = array( 01263 'propertyA.' => array( 01264 'keyA.' => array( 01265 'valueA' => 1, 01266 ), 01267 'keyA' => 'willOverride', 01268 'keyB' => 2, 01269 ), 01270 'propertyB' => 3, 01271 ); 01272 01273 $expectedResult = array( 01274 'propertyA' => array( 01275 'keyA' => 'willOverride', 01276 'keyB' => 2, 01277 ), 01278 'propertyB' => 3, 01279 ); 01280 01281 $this->assertEquals($expectedResult, t3lib_div::removeDotsFromTS($typoScript)); 01282 } 01283 01284 01285 ////////////////////////////////////// 01286 // Tests concerning get_dirs 01287 ////////////////////////////////////// 01288 01289 /** 01290 * @test 01291 */ 01292 public function getDirsReturnsArrayOfDirectoriesFromGivenDirectory() { 01293 $path = PATH_t3lib; 01294 $directories = t3lib_div::get_dirs($path); 01295 01296 $this->assertType('array', $directories); 01297 } 01298 01299 /** 01300 * @test 01301 */ 01302 public function getDirsReturnsStringErrorOnPathFailure() { 01303 $path = 'foo'; 01304 $result = t3lib_div::get_dirs($path); 01305 $expectedResult = 'error'; 01306 01307 $this->assertEquals($expectedResult, $result); 01308 } 01309 01310 01311 ////////////////////////////////// 01312 // Tests concerning hmac 01313 ////////////////////////////////// 01314 01315 /** 01316 * @test 01317 */ 01318 public function hmacReturnsHashOfProperLength() { 01319 $hmac = t3lib_div::hmac('message'); 01320 $this->assertTrue(!empty($hmac) && is_string($hmac)); 01321 $this->assertTrue(strlen($hmac) == 40); 01322 } 01323 01324 /** 01325 * @test 01326 */ 01327 public function hmacReturnsEqualHashesForEqualInput() { 01328 $msg0 = 'message'; 01329 $msg1 = 'message'; 01330 $this->assertEquals(t3lib_div::hmac($msg0), t3lib_div::hmac($msg1)); 01331 } 01332 01333 /** 01334 * @test 01335 */ 01336 public function hmacReturnsNoEqualHashesForNonEqualInput() { 01337 $msg0 = 'message0'; 01338 $msg1 = 'message1'; 01339 $this->assertNotEquals(t3lib_div::hmac($msg0), t3lib_div::hmac($msg1)); 01340 } 01341 01342 01343 ////////////////////////////////// 01344 // Tests concerning quoteJSvalue 01345 ////////////////////////////////// 01346 01347 /** 01348 * @test 01349 */ 01350 public function quoteJSvalueHtmlspecialcharsDataByDefault() { 01351 $this->assertContains( 01352 '>', 01353 t3lib_div::quoteJSvalue('>') 01354 ); 01355 } 01356 01357 /** 01358 * @test 01359 */ 01360 public function quoteJSvaluetHtmlspecialcharsDataWithinCDataSetToFalse() { 01361 $this->assertContains( 01362 '>', 01363 t3lib_div::quoteJSvalue('>', false) 01364 ); 01365 } 01366 01367 /** 01368 * @test 01369 */ 01370 public function quoteJSvaluetNotHtmlspecialcharsDataWithinCDataSetToTrue() { 01371 $this->assertContains( 01372 '>', 01373 t3lib_div::quoteJSvalue('>', true) 01374 ); 01375 } 01376 01377 /** 01378 * @test 01379 */ 01380 public function quoteJSvalueReturnsEmptyStringQuotedInSingleQuotes() { 01381 $this->assertEquals( 01382 "''", 01383 t3lib_div::quoteJSvalue("", true) 01384 ); 01385 } 01386 01387 /** 01388 * @test 01389 */ 01390 public function quoteJSvalueNotModifiesStringWithoutSpecialCharacters() { 01391 $this->assertEquals( 01392 "'Hello world!'", 01393 t3lib_div::quoteJSvalue("Hello world!", true) 01394 ); 01395 } 01396 01397 /** 01398 * @test 01399 */ 01400 public function quoteJSvalueEscapesSingleQuote() { 01401 $this->assertEquals( 01402 "'\\''", 01403 t3lib_div::quoteJSvalue("'", true) 01404 ); 01405 } 01406 01407 /** 01408 * @test 01409 */ 01410 public function quoteJSvalueEscapesDoubleQuoteWithinCDataSetToTrue() { 01411 $this->assertEquals( 01412 "'\\\"'", 01413 t3lib_div::quoteJSvalue('"', true) 01414 ); 01415 } 01416 01417 /** 01418 * @test 01419 */ 01420 public function quoteJSvalueEscapesAndHtmlspecialcharsDoubleQuoteWithinCDataSetToFalse() { 01421 $this->assertEquals( 01422 "'\\"'", 01423 t3lib_div::quoteJSvalue('"', false) 01424 ); 01425 } 01426 01427 /** 01428 * @test 01429 */ 01430 public function quoteJSvalueEscapesTab() { 01431 $this->assertEquals( 01432 "'" . '\t' . "'", 01433 t3lib_div::quoteJSvalue(TAB) 01434 ); 01435 } 01436 01437 /** 01438 * @test 01439 */ 01440 public function quoteJSvalueEscapesLinefeed() { 01441 $this->assertEquals( 01442 "'" . '\n' . "'", 01443 t3lib_div::quoteJSvalue(LF) 01444 ); 01445 } 01446 01447 /** 01448 * @test 01449 */ 01450 public function quoteJSvalueEscapesCarriageReturn() { 01451 $this->assertEquals( 01452 "'" . '\r' . "'", 01453 t3lib_div::quoteJSvalue(CR) 01454 ); 01455 } 01456 01457 /** 01458 * @test 01459 */ 01460 public function quoteJSvalueEscapesBackslah() { 01461 $this->assertEquals( 01462 "'\\\\'", 01463 t3lib_div::quoteJSvalue('\\') 01464 ); 01465 } 01466 01467 ////////////////////////////////// 01468 // Tests concerning readLLfile 01469 ////////////////////////////////// 01470 01471 /** 01472 * @test 01473 */ 01474 public function readLLfileHandlesLocallangXMLOverride() { 01475 $unique = uniqid('locallangXMLOverrideTest'); 01476 01477 $xml = '<?xml version="1.0" encoding="utf-8" standalone="yes" ?> 01478 <T3locallang> 01479 <data type="array"> 01480 <languageKey index="default" type="array"> 01481 <label index="buttons.logout">EXIT</label> 01482 </languageKey> 01483 </data> 01484 </T3locallang>'; 01485 01486 $file = PATH_site . 'typo3temp/' . $unique . '.xml'; 01487 t3lib_div::writeFileToTypo3tempDir($file, $xml); 01488 01489 // Get default value 01490 $defaultLL = t3lib_div::readLLfile('EXT:lang/locallang_core.xml', 'default'); 01491 01492 // Set override file 01493 $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']['EXT:lang/locallang_core.xml'][$unique] = $file; 01494 01495 // Get override value 01496 $overrideLL = t3lib_div::readLLfile('EXT:lang/locallang_core.xml', 'default'); 01497 01498 // Clean up again 01499 unlink($file); 01500 01501 $this->assertNotEquals($overrideLL['default']['buttons.logout'], ''); 01502 $this->assertNotEquals($defaultLL['default']['buttons.logout'], $overrideLL['default']['buttons.logout']); 01503 $this->assertEquals($overrideLL['default']['buttons.logout'], 'EXIT'); 01504 } 01505 01506 01507 /////////////////////////////// 01508 // Tests concerning _GETset() 01509 /////////////////////////////// 01510 01511 /** 01512 * @test 01513 */ 01514 public function getSetWritesArrayToGetSystemVariable() { 01515 $_GET = array(); 01516 $GLOBALS['HTTP_GET_VARS'] = array(); 01517 01518 $getParameters = array('foo' => 'bar'); 01519 t3lib_div::_GETset($getParameters); 01520 $this->assertSame($getParameters, $_GET); 01521 } 01522 01523 /** 01524 * @test 01525 */ 01526 public function getSetWritesArrayToGlobalsHttpGetVars() { 01527 $_GET = array(); 01528 $GLOBALS['HTTP_GET_VARS'] = array(); 01529 01530 $getParameters = array('foo' => 'bar'); 01531 t3lib_div::_GETset($getParameters); 01532 $this->assertSame($getParameters, $GLOBALS['HTTP_GET_VARS']); 01533 } 01534 01535 /** 01536 * @test 01537 */ 01538 public function getSetForArrayDropsExistingValues() { 01539 $_GET = array(); 01540 $GLOBALS['HTTP_GET_VARS'] = array(); 01541 01542 t3lib_div::_GETset(array('foo' => 'bar')); 01543 01544 t3lib_div::_GETset(array('oneKey' => 'oneValue')); 01545 01546 $this->assertEquals( 01547 array('oneKey' => 'oneValue'), 01548 $GLOBALS['HTTP_GET_VARS'] 01549 ); 01550 } 01551 01552 /** 01553 * @test 01554 */ 01555 public function getSetAssignsOneValueToOneKey() { 01556 $_GET = array(); 01557 $GLOBALS['HTTP_GET_VARS'] = array(); 01558 01559 t3lib_div::_GETset('oneValue', 'oneKey'); 01560 01561 $this->assertEquals( 01562 'oneValue', 01563 $GLOBALS['HTTP_GET_VARS']['oneKey'] 01564 ); 01565 } 01566 01567 /** 01568 * @test 01569 */ 01570 public function getSetForOneValueDoesNotDropUnrelatedValues() { 01571 $_GET = array(); 01572 $GLOBALS['HTTP_GET_VARS'] = array(); 01573 01574 t3lib_div::_GETset(array('foo' => 'bar')); 01575 t3lib_div::_GETset('oneValue', 'oneKey'); 01576 01577 $this->assertEquals( 01578 array('foo' => 'bar', 'oneKey' => 'oneValue'), 01579 $GLOBALS['HTTP_GET_VARS'] 01580 ); 01581 } 01582 01583 /** 01584 * @test 01585 */ 01586 public function getSetCanAssignsAnArrayToASpecificArrayElement() { 01587 $_GET = array(); 01588 $GLOBALS['HTTP_GET_VARS'] = array(); 01589 01590 t3lib_div::_GETset(array('childKey' => 'oneValue'), 'parentKey'); 01591 01592 $this->assertEquals( 01593 array('parentKey' => array('childKey' => 'oneValue')), 01594 $GLOBALS['HTTP_GET_VARS'] 01595 ); 01596 } 01597 01598 /** 01599 * @test 01600 */ 01601 public function getSetCanAssignAStringValueToASpecificArrayChildElement() { 01602 $_GET = array(); 01603 $GLOBALS['HTTP_GET_VARS'] = array(); 01604 01605 t3lib_div::_GETset('oneValue', 'parentKey|childKey'); 01606 01607 $this->assertEquals( 01608 array('parentKey' => array('childKey' => 'oneValue')), 01609 $GLOBALS['HTTP_GET_VARS'] 01610 ); 01611 } 01612 01613 /** 01614 * @test 01615 */ 01616 public function getSetCanAssignAnArrayToASpecificArrayChildElement() { 01617 $_GET = array(); 01618 $GLOBALS['HTTP_GET_VARS'] = array(); 01619 01620 t3lib_div::_GETset( 01621 array('key1' => 'value1', 'key2' => 'value2'), 01622 'parentKey|childKey' 01623 ); 01624 01625 $this->assertEquals( 01626 array( 01627 'parentKey' => array( 01628 'childKey' => array('key1' => 'value1', 'key2' => 'value2') 01629 ) 01630 ), 01631 $GLOBALS['HTTP_GET_VARS'] 01632 ); 01633 } 01634 01635 01636 /////////////////////////////// 01637 // Tests concerning fixPermissions 01638 /////////////////////////////// 01639 01640 /** 01641 * @test 01642 */ 01643 public function fixPermissionsCorrectlySetsGroup() { 01644 if (TYPO3_OS == 'WIN') { 01645 $this->markTestSkipped('fixPermissionsCorrectlySetsGroupOwnerOfFile() tests not available on Windows'); 01646 } 01647 if (!function_exists('posix_getegid')) { 01648 $this->markTestSkipped('Function posix_getegid() not available, fixPermissionsCorrectlySetsGroupOwnerOfFile() tests skipped'); 01649 } 01650 01651 // Create and prepare test file 01652 $filename = PATH_site . 'typo3temp/' . uniqid('test_'); 01653 t3lib_div::writeFileToTypo3tempDir($filename, '42'); 01654 01655 // Set target group and run method 01656 $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup'] = posix_getegid(); 01657 $fixPermissionsResult = t3lib_div::fixPermissions($filename); 01658 01659 clearstatcache(); 01660 $resultFileGroup = filegroup($filename); 01661 unlink($filename); 01662 01663 $this->assertEquals($resultFileGroup, posix_getegid()); 01664 } 01665 01666 /** 01667 * @test 01668 */ 01669 public function fixPermissionsCorrectlySetsPermissionsToFile() { 01670 if (TYPO3_OS == 'WIN') { 01671 $this->markTestSkipped('fixPermissions() tests not available on Windows'); 01672 } 01673 01674 // Create and prepare test file 01675 $filename = PATH_site . 'typo3temp/' . uniqid('test_'); 01676 t3lib_div::writeFileToTypo3tempDir($filename, '42'); 01677 chmod($filename, 0742); 01678 01679 // Set target permissions and run method 01680 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0660'; 01681 $fixPermissionsResult = t3lib_div::fixPermissions($filename); 01682 01683 // Get actual permissions and clean up 01684 clearstatcache(); 01685 $resultFilePermissions = substr(decoct(fileperms($filename)), 2); 01686 unlink($filename); 01687 01688 // Test if everything was ok 01689 $this->assertTrue($fixPermissionsResult); 01690 $this->assertEquals($resultFilePermissions, '0660'); 01691 } 01692 01693 /** 01694 * @test 01695 */ 01696 public function fixPermissionsCorrectlySetsPermissionsToHiddenFile() { 01697 if (TYPO3_OS == 'WIN') { 01698 $this->markTestSkipped('fixPermissions() tests not available on Windows'); 01699 } 01700 01701 // Create and prepare test file 01702 $filename = PATH_site . 'typo3temp/' . uniqid('.test_'); 01703 t3lib_div::writeFileToTypo3tempDir($filename, '42'); 01704 chmod($filename, 0742); 01705 01706 // Set target permissions and run method 01707 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0660'; 01708 $fixPermissionsResult = t3lib_div::fixPermissions($filename); 01709 01710 // Get actual permissions and clean up 01711 clearstatcache(); 01712 $resultFilePermissions = substr(decoct(fileperms($filename)), 2); 01713 unlink($filename); 01714 01715 // Test if everything was ok 01716 $this->assertTrue($fixPermissionsResult); 01717 $this->assertEquals($resultFilePermissions, '0660'); 01718 } 01719 01720 /** 01721 * @test 01722 */ 01723 public function fixPermissionsCorrectlySetsPermissionsToDirectory() { 01724 if (TYPO3_OS == 'WIN') { 01725 $this->markTestSkipped('fixPermissions() tests not available on Windows'); 01726 } 01727 01728 // Create and prepare test directory 01729 $directory = PATH_site . 'typo3temp/' . uniqid('test_'); 01730 t3lib_div::mkdir($directory); 01731 chmod($directory, 1551); 01732 01733 // Set target permissions and run method 01734 $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] = '0770'; 01735 $fixPermissionsResult = t3lib_div::fixPermissions($directory . '/'); 01736 01737 // Get actual permissions and clean up 01738 clearstatcache(); 01739 $resultDirectoryPermissions = substr(decoct(fileperms($directory)), 1); 01740 t3lib_div::rmdir($directory); 01741 01742 // Test if everything was ok 01743 $this->assertTrue($fixPermissionsResult); 01744 $this->assertEquals($resultDirectoryPermissions, '0770'); 01745 } 01746 01747 /** 01748 * @test 01749 */ 01750 public function fixPermissionsCorrectlySetsPermissionsToHiddenDirectory() { 01751 if (TYPO3_OS == 'WIN') { 01752 $this->markTestSkipped('fixPermissions() tests not available on Windows'); 01753 } 01754 01755 // Create and prepare test directory 01756 $directory = PATH_site . 'typo3temp/' . uniqid('.test_'); 01757 t3lib_div::mkdir($directory); 01758 chmod($directory, 1551); 01759 01760 // Set target permissions and run method 01761 $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] = '0770'; 01762 $fixPermissionsResult = t3lib_div::fixPermissions($directory); 01763 01764 // Get actual permissions and clean up 01765 clearstatcache(); 01766 $resultDirectoryPermissions = substr(decoct(fileperms($directory)), 1); 01767 t3lib_div::rmdir($directory); 01768 01769 // Test if everything was ok 01770 $this->assertTrue($fixPermissionsResult); 01771 $this->assertEquals($resultDirectoryPermissions, '0770'); 01772 } 01773 01774 /** 01775 * @test 01776 */ 01777 public function fixPermissionsCorrectlySetsPermissionsRecursive() { 01778 if (TYPO3_OS == 'WIN') { 01779 $this->markTestSkipped('fixPermissions() tests not available on Windows'); 01780 } 01781 01782 // Create and prepare test directory and file structure 01783 $baseDirectory = PATH_site . 'typo3temp/' . uniqid('test_'); 01784 t3lib_div::mkdir($baseDirectory); 01785 chmod($baseDirectory, 1751); 01786 t3lib_div::writeFileToTypo3tempDir($baseDirectory . '/file', '42'); 01787 chmod($baseDirectory . '/file', 0742); 01788 t3lib_div::mkdir($baseDirectory . '/foo'); 01789 chmod($baseDirectory . '/foo', 1751); 01790 t3lib_div::writeFileToTypo3tempDir($baseDirectory . '/foo/file', '42'); 01791 chmod($baseDirectory . '/foo/file', 0742); 01792 t3lib_div::mkdir($baseDirectory . '/.bar'); 01793 chmod($baseDirectory . '/.bar', 1751); 01794 // Use this if writeFileToTypo3tempDir is fixed to create hidden files in subdirectories 01795 // t3lib_div::writeFileToTypo3tempDir($baseDirectory . '/.bar/.file', '42'); 01796 // t3lib_div::writeFileToTypo3tempDir($baseDirectory . '/.bar/..file2', '42'); 01797 touch($baseDirectory . '/.bar/.file', '42'); 01798 chmod($baseDirectory . '/.bar/.file', 0742); 01799 touch($baseDirectory . '/.bar/..file2', '42'); 01800 chmod($baseDirectory . '/.bar/..file2', 0742); 01801 01802 // Set target permissions and run method 01803 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0660'; 01804 $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] = '0770'; 01805 $fixPermissionsResult = t3lib_div::fixPermissions($baseDirectory, TRUE); 01806 01807 // Get actual permissions 01808 clearstatcache(); 01809 $resultBaseDirectoryPermissions = substr(decoct(fileperms($baseDirectory)), 1); 01810 $resultBaseFilePermissions = substr(decoct(fileperms($baseDirectory . '/file')), 2); 01811 $resultFooDirectoryPermissions = substr(decoct(fileperms($baseDirectory . '/foo')), 1); 01812 $resultFooFilePermissions = substr(decoct(fileperms($baseDirectory . '/foo/file')), 2); 01813 $resultBarDirectoryPermissions = substr(decoct(fileperms($baseDirectory . '/.bar')), 1); 01814 $resultBarFilePermissions = substr(decoct(fileperms($baseDirectory . '/.bar/.file')), 2); 01815 $resultBarFile2Permissions = substr(decoct(fileperms($baseDirectory . '/.bar/..file2')), 2); 01816 01817 // Clean up 01818 unlink($baseDirectory . '/file'); 01819 unlink($baseDirectory . '/foo/file'); 01820 unlink($baseDirectory . '/.bar/.file'); 01821 unlink($baseDirectory . '/.bar/..file2'); 01822 t3lib_div::rmdir($baseDirectory . '/foo'); 01823 t3lib_div::rmdir($baseDirectory . '/.bar'); 01824 t3lib_div::rmdir($baseDirectory); 01825 01826 // Test if everything was ok 01827 $this->assertTrue($fixPermissionsResult); 01828 $this->assertEquals($resultBaseDirectoryPermissions, '0770'); 01829 $this->assertEquals($resultBaseFilePermissions, '0660'); 01830 $this->assertEquals($resultFooDirectoryPermissions, '0770'); 01831 $this->assertEquals($resultFooFilePermissions, '0660'); 01832 $this->assertEquals($resultBarDirectoryPermissions, '0770'); 01833 $this->assertEquals($resultBarFilePermissions, '0660'); 01834 $this->assertEquals($resultBarFile2Permissions, '0660'); 01835 } 01836 01837 /** 01838 * @test 01839 */ 01840 public function fixPermissionsDoesNotSetPermissionsToNotAllowedPath() { 01841 if (TYPO3_OS == 'WIN') { 01842 $this->markTestSkipped('fixPermissions() tests not available on Windows'); 01843 } 01844 01845 // Create and prepare test file 01846 $filename = PATH_site . 'typo3temp/../typo3temp/' . uniqid('test_'); 01847 touch($filename); 01848 chmod($filename, 0742); 01849 01850 // Set target permissions and run method 01851 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0660'; 01852 $fixPermissionsResult = t3lib_div::fixPermissions($filename); 01853 01854 // Get actual permissions and clean up 01855 clearstatcache(); 01856 $resultFilePermissions = substr(decoct(fileperms($filename)), 2); 01857 unlink($filename); 01858 01859 // Test if everything was ok 01860 $this->assertFalse($fixPermissionsResult); 01861 } 01862 01863 /** 01864 * @test 01865 */ 01866 public function fixPermissionsSetsPermissionsWithRelativeFileReference() { 01867 if (TYPO3_OS == 'WIN') { 01868 $this->markTestSkipped('fixPermissions() tests not available on Windows'); 01869 } 01870 01871 $filename = 'typo3temp/' . uniqid('test_'); 01872 t3lib_div::writeFileToTypo3tempDir(PATH_site . $filename, '42'); 01873 chmod($filename, 0742); 01874 01875 // Set target permissions and run method 01876 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0660'; 01877 $fixPermissionsResult = t3lib_div::fixPermissions($filename); 01878 01879 // Get actual permissions and clean up 01880 clearstatcache(); 01881 $resultFilePermissions = substr(decoct(fileperms(PATH_site . $filename)), 2); 01882 unlink(PATH_site . $filename); 01883 01884 // Test if everything was ok 01885 $this->assertTrue($fixPermissionsResult); 01886 $this->assertEquals($resultFilePermissions, '0660'); 01887 } 01888 01889 01890 /////////////////////////////// 01891 // Tests concerning mkdir 01892 /////////////////////////////// 01893 01894 /** 01895 * @test 01896 */ 01897 public function mkdirCorrectlyCreatesDirectory() { 01898 $directory = PATH_site . 'typo3temp/' . uniqid('test_'); 01899 $mkdirResult = t3lib_div::mkdir($directory); 01900 $directoryCreated = is_dir($directory); 01901 t3lib_div::rmdir($directory); 01902 $this->assertTrue($mkdirResult); 01903 $this->assertTrue($directoryCreated); 01904 } 01905 01906 /** 01907 * @test 01908 */ 01909 public function mkdirCorrectlyCreatesHiddenDirectory() { 01910 $directory = PATH_site . 'typo3temp/' . uniqid('.test_'); 01911 $mkdirResult = t3lib_div::mkdir($directory); 01912 $directoryCreated = is_dir($directory); 01913 t3lib_div::rmdir($directory); 01914 $this->assertTrue($mkdirResult); 01915 $this->assertTrue($directoryCreated); 01916 } 01917 01918 /** 01919 * @test 01920 */ 01921 public function mkdirCorrectlyCreatesDirectoryWithTrailingSlash() { 01922 $directory = PATH_site . 'typo3temp/' . uniqid('test_'); 01923 $mkdirResult = t3lib_div::mkdir($directory); 01924 $directoryCreated = is_dir($directory); 01925 t3lib_div::rmdir($directory); 01926 $this->assertTrue($mkdirResult); 01927 $this->assertTrue($directoryCreated); 01928 } 01929 01930 /** 01931 * Data provider for ImageMagick shell commands 01932 * @see explodeAndUnquoteImageMagickCommands 01933 */ 01934 public function imageMagickCommandsDataProvider() { 01935 return array( 01936 // Some theoretical tests first 01937 array( 01938 'aa bb "cc" "dd"', 01939 array('aa', 'bb', '"cc"', '"dd"'), 01940 array('aa', 'bb', 'cc', 'dd'), 01941 ), 01942 array( 01943 'aa bb "cc dd"', 01944 array('aa', 'bb', '"cc dd"'), 01945 array('aa', 'bb', 'cc dd'), 01946 ), 01947 array( 01948 '\'aa bb\' "cc dd"', 01949 array('\'aa bb\'', '"cc dd"'), 01950 array('aa bb', 'cc dd'), 01951 ), 01952 array( 01953 '\'aa bb\' cc "dd"', 01954 array('\'aa bb\'', 'cc', '"dd"'), 01955 array('aa bb', 'cc', 'dd'), 01956 ), 01957 // Now test against some real world examples 01958 array( 01959 '/opt/local/bin/gm.exe convert +profile \'*\' -geometry 170x136! -negate "C:/Users/Someuser.Domain/Documents/Htdocs/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]" "C:/Users/Someuser.Domain/Documents/Htdocs/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif"', 01960 array( 01961 '/opt/local/bin/gm.exe', 01962 'convert', 01963 '+profile', 01964 '\'*\'', 01965 '-geometry', 01966 '170x136!', 01967 '-negate', 01968 '"C:/Users/Someuser.Domain/Documents/Htdocs/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]"', 01969 '"C:/Users/Someuser.Domain/Documents/Htdocs/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif"' 01970 ), 01971 array( 01972 '/opt/local/bin/gm.exe', 01973 'convert', 01974 '+profile', 01975 '*', 01976 '-geometry', 01977 '170x136!', 01978 '-negate', 01979 'C:/Users/Someuser.Domain/Documents/Htdocs/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]', 01980 'C:/Users/Someuser.Domain/Documents/Htdocs/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif' 01981 ), 01982 ), 01983 array( 01984 'C:/opt/local/bin/gm.exe convert +profile \'*\' -geometry 170x136! -negate "C:/Program Files/Apache2/htdocs/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]" "C:/Program Files/Apache2/htdocs/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif"', 01985 array( 01986 'C:/opt/local/bin/gm.exe', 01987 'convert', 01988 '+profile', 01989 '\'*\'', 01990 '-geometry', 01991 '170x136!', 01992 '-negate', 01993 '"C:/Program Files/Apache2/htdocs/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]"', 01994 '"C:/Program Files/Apache2/htdocs/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif"' 01995 ), 01996 array( 01997 'C:/opt/local/bin/gm.exe', 01998 'convert', 01999 '+profile', 02000 '*', 02001 '-geometry', 02002 '170x136!', 02003 '-negate', 02004 'C:/Program Files/Apache2/htdocs/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]', 02005 'C:/Program Files/Apache2/htdocs/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif' 02006 ), 02007 ), 02008 array( 02009 '/usr/bin/gm convert +profile \'*\' -geometry 170x136! -negate "/Shared Items/Data/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]" "/Shared Items/Data/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif"', 02010 array( 02011 '/usr/bin/gm', 02012 'convert', 02013 '+profile', 02014 '\'*\'', 02015 '-geometry', 02016 '170x136!', 02017 '-negate', 02018 '"/Shared Items/Data/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]"', 02019 '"/Shared Items/Data/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif"' 02020 ), 02021 array( 02022 '/usr/bin/gm', 02023 'convert', 02024 '+profile', 02025 '*', 02026 '-geometry', 02027 '170x136!', 02028 '-negate', 02029 '/Shared Items/Data/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]', 02030 '/Shared Items/Data/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif' 02031 ), 02032 ), 02033 array( 02034 '/usr/bin/gm convert +profile \'*\' -geometry 170x136! -negate "/Network/Servers/server01.internal/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]" "/Network/Servers/server01.internal/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif"', 02035 array( 02036 '/usr/bin/gm', 02037 'convert', 02038 '+profile', 02039 '\'*\'', 02040 '-geometry', 02041 '170x136!', 02042 '-negate', 02043 '"/Network/Servers/server01.internal/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]"', 02044 '"/Network/Servers/server01.internal/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif"' 02045 ), 02046 array( 02047 '/usr/bin/gm', 02048 'convert', 02049 '+profile', 02050 '*', 02051 '-geometry', 02052 '170x136!', 02053 '-negate', 02054 '/Network/Servers/server01.internal/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]', 02055 '/Network/Servers/server01.internal/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif' 02056 ), 02057 ), 02058 array( 02059 '/usr/bin/gm convert +profile \'*\' -geometry 170x136! -negate \'/Network/Servers/server01.internal/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]\' \'/Network/Servers/server01.internal/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif\'', 02060 array( 02061 '/usr/bin/gm', 02062 'convert', 02063 '+profile', 02064 '\'*\'', 02065 '-geometry', 02066 '170x136!', 02067 '-negate', 02068 '\'/Network/Servers/server01.internal/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]\'', 02069 '\'/Network/Servers/server01.internal/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif\'' 02070 ), 02071 array( 02072 '/usr/bin/gm', 02073 'convert', 02074 '+profile', 02075 '*', 02076 '-geometry', 02077 '170x136!', 02078 '-negate', 02079 '/Network/Servers/server01.internal/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif[0]', 02080 '/Network/Servers/server01.internal/Projects/typo3temp/temp/61401f5c16c63d58e1d92e8a2449f2fe_maskNT.gif' 02081 ), 02082 ), 02083 ); 02084 } 02085 02086 /** 02087 * Tests if the commands are exploded and unquoted correctly 02088 * 02089 * @dataProvider imageMagickCommandsDataProvider 02090 * @test 02091 */ 02092 public function explodeAndUnquoteImageMagickCommands($source, $expectedQuoted, $expectedUnquoted) { 02093 $actualQuoted = t3lib_div::unQuoteFilenames($source); 02094 $acutalUnquoted = t3lib_div::unQuoteFilenames($source, TRUE); 02095 02096 $this->assertEquals($expectedQuoted, $actualQuoted, 'The exploded command does not match the expected'); 02097 $this->assertEquals($expectedUnquoted, $acutalUnquoted, 'The exploded and unquoted command does not match the expected'); 02098 } 02099 02100 02101 /////////////////////////////// 02102 // Tests concerning split_fileref 02103 /////////////////////////////// 02104 02105 /** 02106 * @test 02107 */ 02108 public function splitFileRefReturnsFileTypeNotForFolders(){ 02109 $directoryName = uniqid('test_') . '.com'; 02110 $directoryPath = PATH_site . 'typo3temp/'; 02111 $directory = $directoryPath . $directoryName; 02112 mkdir($directory, octdec($GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'])); 02113 02114 $fileInfo = t3lib_div::split_fileref($directory); 02115 02116 $directoryCreated = is_dir($directory); 02117 rmdir($directory); 02118 02119 $this->assertTrue($directoryCreated); 02120 $this->assertType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $fileInfo); 02121 $this->assertEquals($directoryPath, $fileInfo['path']); 02122 $this->assertEquals($directoryName, $fileInfo['file']); 02123 $this->assertEquals($directoryName, $fileInfo['filebody']); 02124 $this->assertEquals('', $fileInfo['fileext']); 02125 $this->assertArrayNotHasKey('realFileext', $fileInfo); 02126 } 02127 02128 /** 02129 * @test 02130 */ 02131 public function splitFileRefReturnsFileTypeForFilesWithoutPathSite() { 02132 $testFile = 'fileadmin/media/someFile.png'; 02133 02134 $fileInfo = t3lib_div::split_fileref($testFile); 02135 $this->assertType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $fileInfo); 02136 $this->assertEquals('fileadmin/media/', $fileInfo['path']); 02137 $this->assertEquals('someFile.png', $fileInfo['file']); 02138 $this->assertEquals('someFile', $fileInfo['filebody']); 02139 $this->assertEquals('png', $fileInfo['fileext']); 02140 } 02141 02142 02143 ///////////////////////////// 02144 // Tests concerning dirname 02145 ///////////////////////////// 02146 02147 /** 02148 * @see dirnameWithDataProvider 02149 * 02150 * @return array<array> 02151 */ 02152 public function dirnameDataProvider() { 02153 return array( 02154 'absolute path with multiple part and file' => array('/dir1/dir2/script.php', '/dir1/dir2'), 02155 'absolute path with one part' => array('/dir1/', '/dir1'), 02156 'absolute path to file without extension' => array('/dir1/something', '/dir1'), 02157 'relative path with one part and file' => array('dir1/script.php', 'dir1'), 02158 'relative one-character path with one part and file' => array('d/script.php', 'd'), 02159 'absolute zero-part path with file' => array('/script.php', ''), 02160 'empty string' => array('', ''), 02161 ); 02162 } 02163 02164 /** 02165 * @test 02166 * 02167 * @dataProvider dirnameDataProvider 02168 * 02169 * @param string $input the input for dirname 02170 * @param string $expectedValue the expected return value expected from dirname 02171 */ 02172 public function dirnameWithDataProvider($input, $expectedValue) { 02173 $this->assertEquals( 02174 $expectedValue, 02175 t3lib_div::dirname($input) 02176 ); 02177 } 02178 02179 02180 ///////////////////////////////////// 02181 // Tests concerning resolveBackPath 02182 ///////////////////////////////////// 02183 02184 /** 02185 * @see resolveBackPathWithDataProvider 02186 * 02187 * @return array<array> 02188 */ 02189 public function resolveBackPathDataProvider() { 02190 return array( 02191 'empty path' => array('', ''), 02192 'this directory' => array('./', './'), 02193 'relative directory without ..' => array('dir1/dir2/dir3/', 'dir1/dir2/dir3/'), 02194 'relative path without ..' => array('dir1/dir2/script.php', 'dir1/dir2/script.php'), 02195 'absolute directory without ..' => array('/dir1/dir2/dir3/', '/dir1/dir2/dir3/'), 02196 'absolute path without ..' => array('/dir1/dir2/script.php', '/dir1/dir2/script.php'), 02197 'only one directory upwards without trailing slash' => array('..', '..'), 02198 'only one directory upwards with trailing slash' => array('../', '../'), 02199 'one level with trailing ..' => array('dir1/..', ''), 02200 'one level with trailing ../' => array('dir1/../', ''), 02201 'two levels with trailing ..' => array('dir1/dir2/..', 'dir1'), 02202 'two levels with trailing ../' => array('dir1/dir2/../', 'dir1/'), 02203 'leading ../ without trailing /' => array('../dir1', '../dir1'), 02204 'leading ../ with trailing /' => array('../dir1/', '../dir1/'), 02205 'leading ../ and inside path' => array('../dir1/dir2/../dir3/', '../dir1/dir3/'), 02206 'one times ../ in relative directory' => array('dir1/../dir2/', 'dir2/'), 02207 'one times ../ in absolute directory' => array('/dir1/../dir2/', '/dir2/'), 02208 'one times ../ in relative path' => array('dir1/../dir2/script.php', 'dir2/script.php'), 02209 'one times ../ in absolute path' => array('/dir1/../dir2/script.php', '/dir2/script.php'), 02210 'consecutive ../' => array('dir1/dir2/dir3/../../../dir4', 'dir4'), 02211 'distrubuted ../ with trailing /' => array('dir1/../dir2/dir3/../', 'dir2/'), 02212 'distributed ../ without trailing /' => array('dir1/../dir2/dir3/..', 'dir2'), 02213 'multiple distributed and consecutive ../ together' => array('dir1/dir2/dir3/dir4/../../dir5/dir6/dir7/../dir8/', 'dir1/dir2/dir5/dir6/dir8/'), 02214 'multiple distributed and consecutive ../ together' => array('dir1/dir2/dir3/dir4/../../dir5/dir6/dir7/../dir8/', 'dir1/dir2/dir5/dir6/dir8/'), 02215 'dirname with leading ..' => array('dir1/..dir2/dir3/', 'dir1/..dir2/dir3/'), 02216 'dirname with trailing ..' => array('dir1/dir2../dir3/', 'dir1/dir2../dir3/'), 02217 'more times upwards than downwards in directory' => array('dir1/../../', '../'), 02218 'more times upwards than downwards in path' => array('dir1/../../script.php', '../script.php'), 02219 ); 02220 } 02221 02222 /** 02223 * @test 02224 * 02225 * @dataProvider resolveBackPathDataProvider 02226 * 02227 * @param string $input the input for resolveBackPath 02228 * @param $expectedValue the expected return value from resolveBackPath 02229 */ 02230 public function resolveBackPathWithDataProvider($input, $expectedValue) { 02231 $this->assertEquals( 02232 $expectedValue, 02233 t3lib_div::resolveBackPath($input) 02234 ); 02235 } 02236 02237 02238 ///////////////////////////////////////////////////////////////////////////////////// 02239 // Tests concerning makeInstance, setSingletonInstance, addInstance, purgeInstances 02240 ///////////////////////////////////////////////////////////////////////////////////// 02241 02242 /** 02243 * @test 02244 * 02245 * @expectedException InvalidArgumentException 02246 */ 02247 public function makeInstanceWithEmptyClassNameThrowsException() { 02248 t3lib_div::makeInstance(''); 02249 } 02250 02251 /** 02252 * @test 02253 */ 02254 public function makeInstanceReturnsClassInstance() { 02255 $className = get_class($this->getMock('foo')); 02256 02257 $this->assertTrue( 02258 t3lib_div::makeInstance($className) instanceof $className 02259 ); 02260 } 02261 02262 /** 02263 * @test 02264 */ 02265 public function makeInstancePassesParametersToConstructor() { 02266 $className = 'testingClass' . uniqid(); 02267 if (!class_exists($className, FALSE)) { 02268 eval( 02269 'class ' . $className . ' {' . 02270 ' public $constructorParameter1;' . 02271 ' public $constructorParameter2;' . 02272 ' public function __construct($parameter1, $parameter2) {' . 02273 ' $this->constructorParameter1 = $parameter1;' . 02274 ' $this->constructorParameter2 = $parameter2;' . 02275 ' }' . 02276 '}' 02277 ); 02278 } 02279 02280 $instance = t3lib_div::makeInstance($className, 'one parameter', 'another parameter'); 02281 02282 $this->assertEquals( 02283 'one parameter', 02284 $instance->constructorParameter1, 02285 'The first constructor parameter has not been set.' 02286 ); 02287 $this->assertEquals( 02288 'another parameter', 02289 $instance->constructorParameter2, 02290 'The second constructor parameter has not been set.' 02291 ); 02292 } 02293 02294 /** 02295 * @test 02296 */ 02297 public function makeInstanceCalledTwoTimesForNonSingletonClassReturnsDifferentInstances() { 02298 $className = get_class($this->getMock('foo')); 02299 02300 $this->assertNotSame( 02301 t3lib_div::makeInstance($className), 02302 t3lib_div::makeInstance($className) 02303 ); 02304 } 02305 02306 /** 02307 * @test 02308 */ 02309 public function makeInstanceCalledTwoTimesForSingletonClassReturnsSameInstance() { 02310 $className = get_class($this->getMock('t3lib_Singleton')); 02311 02312 $this->assertSame( 02313 t3lib_div::makeInstance($className), 02314 t3lib_div::makeInstance($className) 02315 ); 02316 } 02317 02318 /** 02319 * @test 02320 */ 02321 public function makeInstanceCalledTwoTimesForSingletonClassWithPurgeInstancesInbetweenReturnsDifferentInstances() { 02322 $className = get_class($this->getMock('t3lib_Singleton')); 02323 02324 $instance = t3lib_div::makeInstance($className); 02325 t3lib_div::purgeInstances(); 02326 02327 $this->assertNotSame( 02328 $instance, 02329 t3lib_div::makeInstance($className) 02330 ); 02331 } 02332 02333 /** 02334 * @test 02335 * @expectedException InvalidArgumentException 02336 */ 02337 public function setSingletonInstanceForEmptyClassNameThrowsException() { 02338 $instance = $this->getMock('t3lib_Singleton'); 02339 02340 t3lib_div::setSingletonInstance('', $instance); 02341 } 02342 02343 /** 02344 * @test 02345 * @expectedException InvalidArgumentException 02346 */ 02347 public function setSingletonInstanceForClassThatIsNoSubclassOfProvidedClassThrowsException() { 02348 $instance = $this->getMock('t3lib_Singleton', array('foo')); 02349 $singletonClassName = get_class($this->getMock('t3lib_Singleton')); 02350 02351 t3lib_div::setSingletonInstance($singletonClassName, $instance); 02352 } 02353 02354 /** 02355 * @test 02356 */ 02357 public function setSingletonInstanceMakesMakeInstanceReturnThatInstance() { 02358 $instance = $this->getMock('t3lib_Singleton'); 02359 $singletonClassName = get_class($instance); 02360 02361 t3lib_div::setSingletonInstance($singletonClassName, $instance); 02362 02363 $this->assertSame( 02364 $instance, 02365 t3lib_div::makeInstance($singletonClassName) 02366 ); 02367 } 02368 02369 /** 02370 * @test 02371 */ 02372 public function setSingletonInstanceCalledTwoTimesMakesMakeInstanceReturnLastSetInstance() { 02373 $instance1 = $this->getMock('t3lib_Singleton'); 02374 $singletonClassName = get_class($instance1); 02375 $instance2 = new $singletonClassName(); 02376 02377 t3lib_div::setSingletonInstance($singletonClassName, $instance1); 02378 t3lib_div::setSingletonInstance($singletonClassName, $instance2); 02379 02380 $this->assertSame( 02381 $instance2, 02382 t3lib_div::makeInstance($singletonClassName) 02383 ); 02384 } 02385 02386 /** 02387 * @test 02388 * @expectedException InvalidArgumentException 02389 */ 02390 public function addInstanceForEmptyClassNameThrowsException() { 02391 $instance = $this->getMock('foo'); 02392 02393 t3lib_div::addInstance('', $instance); 02394 } 02395 02396 /** 02397 * @test 02398 * @expectedException InvalidArgumentException 02399 */ 02400 public function addInstanceForClassThatIsNoSubclassOfProvidedClassThrowsException() { 02401 $instance = $this->getMock('foo', array('bar')); 02402 $singletonClassName = get_class($this->getMock('foo')); 02403 02404 t3lib_div::addInstance($singletonClassName, $instance); 02405 } 02406 02407 /** 02408 * @test 02409 * @expectedException InvalidArgumentException 02410 */ 02411 public function addInstanceWithSingletonInstanceThrowsException() { 02412 $instance = $this->getMock('t3lib_Singleton'); 02413 02414 t3lib_div::addInstance(get_class($instance), $instance); 02415 } 02416 02417 /** 02418 * @test 02419 */ 02420 public function addInstanceMakesMakeInstanceReturnThatInstance() { 02421 $instance = $this->getMock('foo'); 02422 $className = get_class($instance); 02423 02424 t3lib_div::addInstance($className, $instance); 02425 02426 $this->assertSame( 02427 $instance, 02428 t3lib_div::makeInstance($className) 02429 ); 02430 } 02431 02432 /** 02433 * @test 02434 */ 02435 public function makeInstanceCalledTwoTimesAfterAddInstanceReturnTwoDifferentInstances() { 02436 $instance = $this->getMock('foo'); 02437 $className = get_class($instance); 02438 02439 t3lib_div::addInstance($className, $instance); 02440 02441 $this->assertNotSame( 02442 t3lib_div::makeInstance($className), 02443 t3lib_div::makeInstance($className) 02444 ); 02445 } 02446 02447 /** 02448 * @test 02449 */ 02450 public function addInstanceCalledTwoTimesMakesMakeInstanceReturnBothInstancesInAddingOrder() { 02451 $instance1 = $this->getMock('foo'); 02452 $className = get_class($instance1); 02453 t3lib_div::addInstance($className, $instance1); 02454 02455 $instance2 = new $className(); 02456 t3lib_div::addInstance($className, $instance2); 02457 02458 $this->assertSame( 02459 $instance1, 02460 t3lib_div::makeInstance($className), 02461 'The first returned instance does not match the first added instance.' 02462 ); 02463 $this->assertSame( 02464 $instance2, 02465 t3lib_div::makeInstance($className), 02466 'The second returned instance does not match the second added instance.' 02467 ); 02468 } 02469 02470 /** 02471 * @test 02472 */ 02473 public function purgeInstancesDropsAddedInstance() { 02474 $instance = $this->getMock('foo'); 02475 $className = get_class($instance); 02476 02477 t3lib_div::addInstance($className, $instance); 02478 t3lib_div::purgeInstances(); 02479 02480 $this->assertNotSame( 02481 $instance, 02482 t3lib_div::makeInstance($className) 02483 ); 02484 } 02485 02486 /** 02487 * Data provider for validPathStrDetectsInvalidCharacters. 02488 * 02489 * @return array 02490 */ 02491 public function validPathStrInvalidCharactersDataProvider() { 02492 return array( 02493 'double slash in path' => array('path//path'), 02494 'backslash in path' => array('path\\path'), 02495 'directory up in path' => array('path/../path'), 02496 'directory up at the beginning' => array('../path'), 02497 'NUL character in path' => array("path\x00path"), 02498 'BS character in path' => array("path\x08path"), 02499 ); 02500 } 02501 02502 /** 02503 * Tests whether invalid characters are detected. 02504 * 02505 * @param string $path 02506 * @dataProvider validPathStrInvalidCharactersDataProvider 02507 * @test 02508 */ 02509 public function validPathStrDetectsInvalidCharacters($path) { 02510 $this->assertNull(t3lib_div::validPathStr($path)); 02511 } 02512 02513 /** 02514 * Tests whether verifyFilenameAgainstDenyPattern detects the null character. 02515 * 02516 * @test 02517 */ 02518 public function verifyFilenameAgainstDenyPatternDetectsNullCharacter() { 02519 $this->assertFalse(t3lib_div::verifyFilenameAgainstDenyPattern("image\x00.gif")); 02520 } 02521 02522 02523 ///////////////////////////////////////////////////////////////////////////////////// 02524 // Tests concerning sysLog 02525 ///////////////////////////////////////////////////////////////////////////////////// 02526 02527 /** 02528 * @test 02529 */ 02530 public function syslogFixesPermissionsOnFileIfUsingFileLogging() { 02531 if (TYPO3_OS == 'WIN') { 02532 $this->markTestSkipped('syslogFixesPermissionsOnFileIfUsingFileLogging() test not available on Windows.'); 02533 } 02534 02535 // Fake all required settings 02536 $GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLogLevel'] = 0; 02537 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLogInit'] = TRUE; 02538 unset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_div.php']['systemLog']); 02539 $testLogFilename = PATH_site . 'typo3temp/' . uniqid('test_') . '.txt'; 02540 $GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLog'] = 'file,' . $testLogFilename . ',0'; 02541 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0777'; 02542 02543 // Call method, get actual permissions and clean up 02544 t3lib_div::syslog('testLog', 'test', 1); 02545 clearstatcache(); 02546 $resultFilePermissions = substr(decoct(fileperms($testLogFilename)), 2); 02547 t3lib_div::unlink_tempfile($testLogFilename); 02548 02549 $this->assertEquals($resultFilePermissions, '0777'); 02550 } 02551 02552 /** 02553 * @test 02554 */ 02555 public function deprecationLogFixesPermissionsOnLogFile() { 02556 if (TYPO3_OS == 'WIN') { 02557 $this->markTestSkipped('deprecationLogFixesPermissionsOnLogFile() test not available on Windows.'); 02558 } 02559 02560 // Fake all required settings and get an unique logfilename 02561 $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = uniqid('test_'); 02562 $deprecationLogFilename = t3lib_div::getDeprecationLogFileName(); 02563 $GLOBALS['TYPO3_CONF_VARS']['SYS']['enableDeprecationLog'] = TRUE; 02564 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0777'; 02565 02566 // Call method, get actual permissions and clean up 02567 t3lib_div::deprecationLog('foo'); 02568 clearstatcache(); 02569 $resultFilePermissions = substr(decoct(fileperms($deprecationLogFilename)), 2); 02570 @unlink($deprecationLogFilename); 02571 02572 $this->assertEquals($resultFilePermissions, '0777'); 02573 } 02574 } 02575 ?>
1.8.0