ab6e078997fc6eb1975570d5372741febca31166
2 /***************************************************************
5 * (c) 2009 Ingo Renner <ingo@typo3.org>
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
27 * Testcase for class t3lib_div
29 * @author Ingo Renner <ingo@typo3.org>
30 * @author Oliver Klee <typo3-coding@oliverklee.de>
35 class t3lib_div_testcase
extends tx_phpunit_testcase
{
37 * backup of the global variables _GET, _POST, _SERVER
41 private $backupGlobalVariables;
43 public function setUp() {
44 $this->backupGlobalVariables
= array(
47 '_SERVER' => $_SERVER,
48 'TYPO3_CONF_VARS' => $GLOBALS['TYPO3_CONF_VARS'],
52 public function tearDown() {
53 foreach ($this->backupGlobalVariables
as $key => $data) {
54 $GLOBALS[$key] = $data;
62 public function checkIntExplodeConvertsStringsToInteger() {
63 $testString = '1,foo,2';
64 $expectedArray = array(1, 0, 2);
65 $actualArray = t3lib_div
::intExplode(',', $testString);
67 $this->assertEquals($expectedArray, $actualArray);
73 public function checkRevExplodeCorrectlyExplodesString() {
74 $testString = 'my:words:here';
75 $expectedArray = array('my:words', 'here');
76 $actualArray = t3lib_div
::revExplode(':', $testString, 2);
78 $this->assertEquals($expectedArray, $actualArray);
84 public function checkTrimExplodeTrimsSpacesAtElementStartAndEnd() {
85 $testString = ' a , b , c ,d ,, e,f,';
86 $expectedArray = array('a', 'b', 'c', 'd', '', 'e', 'f', '');
87 $actualArray = t3lib_div
::trimExplode(',', $testString);
89 $this->assertEquals($expectedArray, $actualArray);
95 public function checkTrimExplodeRemovesNewLines() {
96 $testString = ' a , b , ' . LF
. ' ,d ,, e,f,';
97 $expectedArray = array('a', 'b', 'd', 'e', 'f');
98 $actualArray = t3lib_div
::trimExplode(',', $testString, true);
100 $this->assertEquals($expectedArray, $actualArray);
106 public function checkTrimExplodeRemovesEmptyElements() {
107 $testString = 'a , b , c , ,d ,, ,e,f,';
108 $expectedArray = array('a', 'b', 'c', 'd', 'e', 'f');
109 $actualArray = t3lib_div
::trimExplode(',', $testString, true);
111 $this->assertEquals($expectedArray, $actualArray);
117 public function checkTrimExplodeKeepsRemainingResultsWithEmptyItemsAfterReachingLimitWithPositiveParameter() {
118 $testString = ' a , b , c , , d,, ,e ';
119 $expectedArray = array('a', 'b', 'c,,d,,,e'); // limiting returns the rest of the string as the last element
120 $actualArray = t3lib_div
::trimExplode(',', $testString, false, 3);
122 $this->assertEquals($expectedArray, $actualArray);
128 public function checkTrimExplodeKeepsRemainingResultsWithoutEmptyItemsAfterReachingLimitWithPositiveParameter() {
129 $testString = ' a , b , c , , d,, ,e ';
130 $expectedArray = array('a', 'b', 'c,d,e'); // limiting returns the rest of the string as the last element
131 $actualArray = t3lib_div
::trimExplode(',', $testString, true, 3);
133 $this->assertEquals($expectedArray, $actualArray);
139 public function checkTrimExplodeKeepsRamainingResultsWithEmptyItemsAfterReachingLimitWithNegativeParameter() {
140 $testString = ' a , b , c , d, ,e, f , , ';
141 $expectedArray = array('a', 'b', 'c', 'd', '', 'e'); // limiting returns the rest of the string as the last element
142 $actualArray = t3lib_div
::trimExplode(',', $testString, false, -3);
144 $this->assertEquals($expectedArray, $actualArray);
150 public function checkTrimExplodeKeepsRamainingResultsWithoutEmptyItemsAfterReachingLimitWithNegativeParameter() {
151 $testString = ' a , b , c , d, ,e, f , , ';
152 $expectedArray = array('a', 'b', 'c'); // limiting returns the rest of the string as the last element
153 $actualArray = t3lib_div
::trimExplode(',', $testString, true, -3);
155 $this->assertEquals($expectedArray, $actualArray);
161 public function checkTrimExplodeReturnsExactResultsWithoutReachingLimitWithPositiveParameter() {
162 $testString = ' a , b , , c , , , ';
163 $expectedArray = array('a', 'b', 'c'); // limiting returns the rest of the string as the last element
164 $actualArray = t3lib_div
::trimExplode(',', $testString, true, 4);
166 $this->assertEquals($expectedArray, $actualArray);
172 public function checkTrimExplodeKeepsZeroAsString() {
173 $testString = 'a , b , c , ,d ,, ,e,f, 0 ,';
174 $expectedArray = array('a', 'b', 'c', 'd', 'e', 'f', '0');
175 $actualArray = t3lib_div
::trimExplode(',', $testString, true);
177 $this->assertEquals($expectedArray, $actualArray);
181 * Checks whether measurement strings like "100k" return the accordant
182 * byte representation like 102400 in this case.
186 public function checkGetBytesFromSizeMeasurement() {
189 t3lib_div
::getBytesFromSizeMeasurement('100k')
194 t3lib_div
::getBytesFromSizeMeasurement('100m')
199 t3lib_div
::getBytesFromSizeMeasurement('100g')
206 public function checkIndpEnvTypo3SitePathNotEmpty() {
207 $actualEnv = t3lib_div
::getIndpEnv('TYPO3_SITE_PATH');
208 $this->assertTrue(strlen($actualEnv) >= 1);
209 $this->assertEquals('/', $actualEnv{0});
210 $this->assertEquals('/', $actualEnv{strlen($actualEnv) - 1});
215 * @see t3lib_div::underscoredToUpperCamelCase
217 public function canConvertFromUnderscoredToUpperCamelCase() {
218 $this->assertEquals('BlogExample', t3lib_div
::underscoredToUpperCamelCase('blog_example'));
219 $this->assertEquals('Blogexample', t3lib_div
::underscoredToUpperCamelCase('blogexample'));
224 * @see t3lib_div::underscoredToLowerCamelCase
226 public function canConvertFromUnderscoredToLowerCamelCase() {
227 $this->assertEquals('minimalValue', t3lib_div
::underscoredToLowerCamelCase('minimal_value'));
228 $this->assertEquals('minimalvalue', t3lib_div
::underscoredToLowerCamelCase('minimalvalue'));
233 * @see t3lib_div::camelCaseToLowerCaseUnderscored
235 public function canConvertFromCamelCaseToLowerCaseUnderscored() {
236 $this->assertEquals('blog_example', t3lib_div
::camelCaseToLowerCaseUnderscored('BlogExample'));
237 $this->assertEquals('blogexample', t3lib_div
::camelCaseToLowerCaseUnderscored('Blogexample'));
238 $this->assertEquals('blogexample', t3lib_div
::camelCaseToLowerCaseUnderscored('blogexample'));
240 $this->assertEquals('minimal_value', t3lib_div
::camelCaseToLowerCaseUnderscored('minimalValue'));
245 * @see t3lib_div::lcfirst
247 public function canConvertFirstCharacterToBeLowerCase() {
248 $this->assertEquals('blogexample', t3lib_div
::lcfirst('Blogexample'));
249 $this->assertEquals('blogExample', t3lib_div
::lcfirst('BlogExample'));
250 $this->assertEquals('blogexample', t3lib_div
::lcfirst('blogexample'));
254 * Tests whether whitespaces are encoded correctly in a quoted-printable mail header.
257 public function areWhitespacesEncodedInQuotedPrintableMailHeader() {
259 '=?utf-8?Q?We_test_whether_the_copyright_character_=C2=A9_is_encoded_correctly?=',
260 t3lib_div
::encodeHeader(
261 "We test whether the copyright character \xc2\xa9 is encoded correctly",
269 * Tests whether question marks are encoded correctly in a quoted-printable mail header.
272 public function areQuestionMarksEncodedInQuotedPrintableMailHeader() {
274 '=?utf-8?Q?Is_the_copyright_character_=C2=A9_really_encoded_correctly=3F_Really=3F?=',
275 t3lib_div
::encodeHeader(
276 "Is the copyright character \xc2\xa9 really encoded correctly? Really?",
284 * Data provider for valid URLs, like PHP's source code test cases
286 public function validUrlDataProvider() {
288 array('http://example.com/index.html'),
289 array('http://www.example.com/index.php'),
290 array('http://www.example/img/test.png'),
291 array('http://www.example/img/dir/'),
292 array('http://www.example/img/dir'),
293 array('file:///tmp/test.c'),
294 array('ftp://ftp.example.com/tmp/'),
295 array('mailto:foo@bar.com'),
296 array('news:news.php.net'),
297 array('file://foo/bar'),
303 * Data provider for invalid URLs, like PHP's source code test cases
305 public function invalidUrlDataProvider() {
307 array('http//www.example/wrong/url/'),
308 array('http:/www.example'),
309 array('/tmp/test.c'),
324 * @dataProvider validUrlDataProvider
325 * @see t3lib_div::isValidUrl()
327 public function checkisValidURL($url) {
328 $this->assertTrue(t3lib_div
::isValidUrl($url));
333 * @dataProvider invalidUrlDataProvider
334 * @see t3lib_div::isValidUrl()
336 public function checkisInValidURL($url) {
337 $this->assertFalse(t3lib_div
::isValidUrl($url));
342 * @see t3lib_div::isValidUrl()
344 public function checkisValidURLSucceedsWithWebRessource() {
345 $testUrl = 'http://www.example.org/';
346 $this->assertTrue(t3lib_div
::isValidUrl($testUrl));
351 * @see t3lib_div::isValidUrl()
353 public function checkisValidURLSucceedsWithExtentedWebRessource() {
354 $testUrl = 'https://user:pw@www.example.org:80/path?arg=value#fragment';
355 $this->assertTrue(t3lib_div
::isValidUrl($testUrl));
360 * @see t3lib_div::isValidUrl()
362 public function checkisValidURLSucceedsWithTelnetRessource() {
363 $testUrl = 'telnet://192.0.2.16:80/';
364 $this->assertTrue(t3lib_div
::isValidUrl($testUrl));
370 public function checkisValidURLSucceedsWithLdapRessource() {
371 $testUrl = 'ldap://[2001:db8::7]/c=GB?objectClass?one';
372 $this->assertTrue(t3lib_div
::isValidUrl($testUrl));
377 * @see t3lib_div::isValidUrl()
379 public function checkisValidURLSucceedsWithFileRessource() {
380 $testUrl = 'file:///etc/passwd';
381 $this->assertTrue(t3lib_div
::isValidUrl($testUrl));
386 * @see t3lib_div::isValidUrl()
388 public function checkisValidURLFailsWithHostnameOnly() {
389 $testUrl = 'www.example.org/';
390 $this->assertFalse(t3lib_div
::isValidUrl($testUrl));
395 * @see t3lib_div::isOnCurrentHost()
397 public function checkisOnCurrentHostFailsWithLocalhostIPOnly() {
398 $testUrl = '127.0.0.1';
399 $this->assertFalse(t3lib_div
::isOnCurrentHost($testUrl));
404 * @see t3lib_div::isOnCurrentHost()
406 public function checkisOnCurrentHostFailsWithPathsOnly() {
407 $testUrl = './relpath/file.txt';
408 $this->assertFalse(t3lib_div
::isOnCurrentHost($testUrl));
409 $testUrl = '/abspath/file.txt?arg=value';
410 $this->assertFalse(t3lib_div
::isOnCurrentHost($testUrl));
415 * @see t3lib_div::isOnCurrentHost()
417 public function checkisOnCurrentHostFailsWithArbitraryString() {
418 $testUrl = 'arbitrary string';
419 $this->assertFalse(t3lib_div
::isOnCurrentHost($testUrl));
424 * @see t3lib_div::isOnCurrentHost()
426 public function checkisOnCurrentHostFailsWithEmptyUrl() {
428 $this->assertFalse(t3lib_div
::isOnCurrentHost($testUrl));
433 * @see t3lib_div::isOnCurrentHost()
435 public function checkisOnCurrentHostFailsWithDifferentHost() {
436 $testUrl = t3lib_div
::getIndpEnv('TYPO3_REQUEST_HOST') . '.example.org';
437 $this->assertFalse(t3lib_div
::isOnCurrentHost($testUrl));
442 * @see t3lib_div::isOnCurrentHost()
444 public function checkisOnCurrentHostSucceedsWithCurrentHost() {
445 $testUrl = t3lib_div
::getIndpEnv('TYPO3_REQUEST_URL');
446 $this->assertTrue(t3lib_div
::isOnCurrentHost($testUrl));
450 ////////////////////////////////////////
451 // Tests concerning sanitizeLocalUrl
452 ////////////////////////////////////////
455 * Data provider for valid URLs.
456 * @see sanitizeLocalUrlAcceptsValidUrls
458 public function validLocalUrlDataProvider() {
460 array('alt_intro.php'),
461 array('alt_intro.php?foo=1&bar=2'),
462 array('/typo3/alt_intro.php'),
464 array('../index.php'),
465 array('../typo3/alt_intro.php'),
466 array('../~userDirectory/index.php'),
467 array('../typo3/mod.php?var1=test-case&var2=~user'),
468 array(PATH_site
. 'typo3/alt_intro.php'),
469 array(t3lib_div
::getIndpEnv('TYPO3_SITE_URL') . 'typo3/alt_intro.php'),
470 array(t3lib_div
::getIndpEnv('TYPO3_REQUEST_HOST') . '/index.php'),
475 * Data provider for invalid URLs.
476 * @see sanitizeLocalUrlDeniesInvalidUrls
478 public function invalidLocalUrlDataProvider() {
481 array('http://www.google.de/'),
482 array('https://www.google.de/'),
483 array('../typo3/whatever.php?argument=javascript:alert(0)'),
488 * Tests whether valid local URLs are handled correctly.
489 * @dataProvider validLocalUrlDataProvider
492 public function sanitizeLocalUrlAcceptsPlainValidUrls($url) {
493 $this->assertEquals($url, t3lib_div
::sanitizeLocalUrl($url));
497 * Tests whether valid local URLs are handled correctly.
498 * @dataProvider validLocalUrlDataProvider
501 public function sanitizeLocalUrlAcceptsEncodedValidUrls($url) {
502 $this->assertEquals(rawurlencode($url), t3lib_div
::sanitizeLocalUrl(rawurlencode($url)));
506 * Tests whether valid local URLs are handled correctly.
507 * @dataProvider invalidLocalUrlDataProvider
510 public function sanitizeLocalUrlDeniesPlainInvalidUrls($url) {
511 $this->assertEquals('', t3lib_div
::sanitizeLocalUrl($url));
515 * Tests whether valid local URLs are handled correctly.
516 * @dataProvider invalidLocalUrlDataProvider
519 public function sanitizeLocalUrlDeniesEncodedInvalidUrls($url) {
520 $this->assertEquals('', t3lib_div
::sanitizeLocalUrl(rawurlencode($url)));
523 //////////////////////////////////////
524 // Tests concerning arrayDiffAssocRecursive
525 //////////////////////////////////////
528 * Test if a one dimensional array is correctly diffed.
531 * @see t3lib_div::arrayDiffAssocRecursive
533 public function doesArrayDiffAssocRecursiveCorrectlyHandleOneDimensionalArrays() {
543 $expectedResult = array(
546 $actualResult = t3lib_div
::arrayDiffAssocRecursive($array1, $array2);
547 $this->assertEquals($expectedResult, $actualResult);
551 * Test if a three dimensional array is correctly diffed.
554 * @see t3lib_div::arrayDiffAssocRecursive
556 public function doesArrayDiffAssocRecursiveCorrectlyHandleMultiDimensionalArrays() {
560 'key21' => 'value21',
561 'key22' => 'value22',
563 'key231' => 'value231',
564 'key232' => 'value232',
571 'key21' => 'value21',
573 'key231' => 'value231',
577 $expectedResult = array(
579 'key22' => 'value22',
581 'key232' => 'value232',
585 $actualResult = t3lib_div
::arrayDiffAssocRecursive($array1, $array2);
586 $this->assertEquals($expectedResult, $actualResult);
590 * Test if arrays are correctly diffed if types are different.
593 * @see t3lib_div::arrayDiffAssocRecursive
595 public function doesArrayDiffAssocRecursiveCorrectlyHandleMixedArrays() {
598 'key11' => 'value11',
599 'key12' => 'value12',
607 'key21' => 'value21',
610 $expectedResult = array(
613 $actualResult = t3lib_div
::arrayDiffAssocRecursive($array1, $array2);
614 $this->assertEquals($expectedResult, $actualResult);
617 //////////////////////////////////////
618 // Tests concerning removeDotsFromTS
619 //////////////////////////////////////
622 * Tests whether removeDotsFromTS() behaves correctly.
624 * @see t3lib_div::removeDotsFromTS()
626 public function doesRemoveDotsFromTypoScriptSucceed() {
628 'propertyA.' => array(
637 $expectedResult = array(
638 'propertyA' => array(
647 $this->assertEquals($expectedResult, t3lib_div
::removeDotsFromTS($typoScript));
651 * Tests whether removeDotsFromTS() behaves correctly.
653 * @see t3lib_div::removeDotsFromTS()
655 public function doesRemoveDotsFromTypoScriptCorrectlyOverrideWithArray() {
657 'propertyA.' => array(
658 'keyA' => 'getsOverridden',
667 $expectedResult = array(
668 'propertyA' => array(
677 $this->assertEquals($expectedResult, t3lib_div
::removeDotsFromTS($typoScript));
681 * Tests whether removeDotsFromTS() behaves correctly.
683 * @see t3lib_div::removeDotsFromTS()
685 public function doesRemoveDotsFromTypoScriptCorrectlyOverrideWithScalar() {
687 'propertyA.' => array(
691 'keyA' => 'willOverride',
697 $expectedResult = array(
698 'propertyA' => array(
699 'keyA' => 'willOverride',
705 $this->assertEquals($expectedResult, t3lib_div
::removeDotsFromTS($typoScript));
709 * Tests whether getDirs() returns an array of diretories from a given path
711 * @see t3lib_div::getDirs($path)
713 public function checkGetDirsReturnsArrayOfDirectoriesFromGivenDirectory() {
715 $directories = t3lib_div
::get_dirs($path);
717 $this->assertType('array', $directories);
721 * Tests whether getDirs() returns the string 'error' in case of problems reading from the given path
723 * @see t3lib_div::getDirs($path)
725 public function checkGetDirsReturnsStringErrorOnPathFailure() {
727 $result = t3lib_div
::get_dirs($path);
728 $expectedResult = 'error';
730 $this->assertEquals($expectedResult, $result);
734 //////////////////////////////////
735 // Tests concerning quoteJSvalue
736 //////////////////////////////////
741 public function quoteJSvalueHtmlspecialcharsDataByDefault() {
742 $this->assertContains(
744 t3lib_div
::quoteJSvalue('>')
751 public function quoteJSvaluetHtmlspecialcharsDataWithinCDataSetToFalse() {
752 $this->assertContains(
754 t3lib_div
::quoteJSvalue('>', false)
761 public function quoteJSvaluetNotHtmlspecialcharsDataWithinCDataSetToTrue() {
762 $this->assertContains(
764 t3lib_div
::quoteJSvalue('>', true)
771 public function quoteJSvalueReturnsEmptyStringQuotedInSingleQuotes() {
774 t3lib_div
::quoteJSvalue("", true)
781 public function quoteJSvalueNotModifiesStringWithoutSpecialCharacters() {
784 t3lib_div
::quoteJSvalue("Hello world!", true)
791 public function quoteJSvalueEscapesSingleQuote() {
794 t3lib_div
::quoteJSvalue("'", true)
801 public function quoteJSvalueEscapesDoubleQuoteWithinCDataSetToTrue() {
804 t3lib_div
::quoteJSvalue('"', true)
811 public function quoteJSvalueEscapesAndHtmlspecialcharsDoubleQuoteWithinCDataSetToFalse() {
814 t3lib_div
::quoteJSvalue('"', false)
821 public function quoteJSvalueEscapesTab() {
824 t3lib_div
::quoteJSvalue(TAB
)
831 public function quoteJSvalueEscapesLinefeed() {
834 t3lib_div
::quoteJSvalue(LF
)
841 public function quoteJSvalueEscapesCarriageReturn() {
844 t3lib_div
::quoteJSvalue(CR
)
851 public function quoteJSvalueEscapesBackslah() {
854 t3lib_div
::quoteJSvalue('\\')
859 * Tests the locallangXMLOverride feature of readLLfile()
862 public function readLLfileLocallangXMLOverride() {
863 $unique = uniqid('locallangXMLOverrideTest');
865 $xml = '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
868 <languageKey index="default" type="array">
869 <label index="buttons.logout">EXIT</label>
874 $file = PATH_site
. 'typo3temp/' . $unique . '.xml';
875 t3lib_div
::writeFileToTypo3tempDir($file, $xml);
878 $defaultLL = t3lib_div
::readLLfile('EXT:lang/locallang_core.xml', 'default');
881 $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']['EXT:lang/locallang_core.xml'][$unique] = $file;
883 // get override value
884 $overrideLL = t3lib_div
::readLLfile('EXT:lang/locallang_core.xml', 'default');
886 $this->assertNotEquals($overrideLL['default']['buttons.logout'], '');
887 $this->assertNotEquals($defaultLL['default']['buttons.logout'], $overrideLL['default']['buttons.logout']);
888 $this->assertEquals($overrideLL['default']['buttons.logout'], 'EXIT');
894 ///////////////////////////////
895 // Tests concerning _GETset()
896 ///////////////////////////////
901 public function getSetCanSetWholeArray() {
903 $GLOBALS['HTTP_GET_VARS'] = array();
904 t3lib_div
::_GETset(array('oneKey' => 'oneValue'));
907 array('oneKey' => 'oneValue'),
911 array('oneKey' => 'oneValue'),
912 $GLOBALS['HTTP_GET_VARS']
919 public function getSetForArrayDropsExistingValues() {
921 $GLOBALS['HTTP_GET_VARS'] = array();
923 t3lib_div
::_GETset(array('foo' => 'bar'));
924 t3lib_div
::_GETset(array('oneKey' => 'oneValue'));
927 array('oneKey' => 'oneValue'),
931 array('oneKey' => 'oneValue'),
932 $GLOBALS['HTTP_GET_VARS']
939 public function getSetCanAssignOneValueToOneKey() {
941 $GLOBALS['HTTP_GET_VARS'] = array();
943 t3lib_div
::_GETset('oneValue', 'oneKey');
951 $GLOBALS['HTTP_GET_VARS']['oneKey']
958 public function getSetForOneValueNotDropsExistingValues() {
960 $GLOBALS['HTTP_GET_VARS'] = array();
962 t3lib_div
::_GETset(array('foo' => 'bar'));
963 t3lib_div
::_GETset('oneValue', 'oneKey');
966 array('foo' => 'bar', 'oneKey' => 'oneValue'),
970 array('foo' => 'bar', 'oneKey' => 'oneValue'),
971 $GLOBALS['HTTP_GET_VARS']
978 public function getSetCanAssignAnArrayToSpecificArrayElement() {
980 $GLOBALS['HTTP_GET_VARS'] = array();
982 t3lib_div
::_GETset(array('childKey' => 'oneValue'), 'parentKey');
985 array('parentKey' => array('childKey' => 'oneValue')),
989 array('parentKey' => array('childKey' => 'oneValue')),
990 $GLOBALS['HTTP_GET_VARS']
997 public function getSetCanAssignAValueToSpecificArrayChildElement() {
999 $GLOBALS['HTTP_GET_VARS'] = array();
1001 t3lib_div
::_GETset('oneValue', 'parentKey|childKey');
1003 $this->assertEquals(
1004 array('parentKey' => array('childKey' => 'oneValue')),
1007 $this->assertEquals(
1008 array('parentKey' => array('childKey' => 'oneValue')),
1009 $GLOBALS['HTTP_GET_VARS']
1016 public function getSetCanAssignAnArrayToSpecificArrayChildElement() {
1018 $GLOBALS['HTTP_GET_VARS'] = array();
1021 array('key1' => 'value1', 'key2' => 'value2'),
1022 'parentKey|childKey'
1025 $this->assertEquals(
1027 'parentKey' => array(
1028 'childKey' => array('key1' => 'value1', 'key2' => 'value2')
1033 $this->assertEquals(
1035 'parentKey' => array(
1036 'childKey' => array('key1' => 'value1', 'key2' => 'value2')
1039 $GLOBALS['HTTP_GET_VARS']
1044 * Checks if t3lib_div::fixPermissions() correctly sets permissions to single file
1045 * This test assumes directory 'PATH_site'/typo3temp exists
1046 * This test is not available on windows OS
1049 * @see t3lib_div::fixPermissions()
1051 public function checkFixPermissionsCorrectlySetsPermissionsToFile() {
1052 if (TYPO3_OS
== 'WIN') {
1053 $this->markTestSkipped('fixPermissions() tests not available on Windows');
1056 // Create and prepare test file
1057 $filename = PATH_site
. 'typo3temp/' . uniqid('test_');
1058 t3lib_div
::writeFileToTypo3tempDir($filename, '42');
1059 chmod($filename, 0742);
1061 // Set target permissions and run method
1062 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0660';
1063 $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup'] = posix_getegid();
1064 $fixPermissionsResult = t3lib_div
::fixPermissions($filename);
1066 // Get actual permissions and clean up
1068 $resultFilePermissions = substr(decoct(fileperms($filename)), 2);
1069 $resultFileGroup = filegroup($filename);
1072 // Test if everything was ok
1073 $this->assertTrue($fixPermissionsResult);
1074 $this->assertEquals($resultFilePermissions, '0660');
1075 $this->assertEquals($resultFileGroup, posix_getegid());
1079 * Checks if t3lib_div::fixPermissions() correctly sets permissions to hidden file
1080 * This test assumes directory 'PATH_site'/typo3temp exists
1081 * This test is not available on windows OS
1084 * @see t3lib_div::fixPermissions()
1086 public function checkFixPermissionsCorrectlySetsPermissionsToHiddenFile() {
1087 if (TYPO3_OS
== 'WIN') {
1088 $this->markTestSkipped('fixPermissions() tests not available on Windows');
1091 // Create and prepare test file
1092 $filename = PATH_site
. 'typo3temp/' . uniqid('.test_');
1093 t3lib_div
::writeFileToTypo3tempDir($filename, '42');
1094 chmod($filename, 0742);
1096 // Set target permissions and run method
1097 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0660';
1098 $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup'] = posix_getegid();
1099 $fixPermissionsResult = t3lib_div
::fixPermissions($filename);
1101 // Get actual permissions and clean up
1103 $resultFilePermissions = substr(decoct(fileperms($filename)), 2);
1104 $resultFileGroup = filegroup($filename);
1107 // Test if everything was ok
1108 $this->assertTrue($fixPermissionsResult);
1109 $this->assertEquals($resultFilePermissions, '0660');
1110 $this->assertEquals($resultFileGroup, posix_getegid());
1114 * Checks if t3lib_div::fixPermissions() correctly sets permissions to directory with trailing slash
1115 * This test assumes directory 'PATH_site'/typo3temp exists
1116 * This test is not available on windows OS
1119 * @see t3lib_div::fixPermissions()
1121 public function checkFixPermissionsCorrectlySetsPermissionsToDirectory() {
1122 if (TYPO3_OS
== 'WIN') {
1123 $this->markTestSkipped('fixPermissions() tests not available on Windows');
1126 // Create and prepare test directory
1127 $directory = PATH_site
. 'typo3temp/' . uniqid('test_');
1128 t3lib_div
::mkdir($directory);
1129 chmod($directory, 1551);
1131 // Set target permissions and run method
1132 $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] = '2770';
1133 $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup'] = posix_getegid();
1134 $fixPermissionsResult = t3lib_div
::fixPermissions($directory . '/');
1136 // Get actual permissions and clean up
1138 $resultDirectoryPermissions = substr(decoct(fileperms($directory)), 1);
1139 $resultDirectoryGroup = filegroup($directory);
1140 t3lib_div
::rmdir($directory);
1142 // Test if everything was ok
1143 $this->assertTrue($fixPermissionsResult);
1144 $this->assertEquals($resultDirectoryPermissions, '2770');
1145 $this->assertEquals($resultDirectoryGroup, posix_getegid());
1149 * Checks if t3lib_div::fixPermissions() correctly sets permissions to hidden directory
1150 * This test assumes directory 'PATH_site'/typo3temp exists
1151 * This test is not available on windows OS
1154 * @see t3lib_div::fixPermissions()
1156 public function checkFixPermissionsCorrectlySetsPermissionsToHiddenDirectory() {
1157 if (TYPO3_OS
== 'WIN') {
1158 $this->markTestSkipped('fixPermissions() tests not available on Windows');
1161 // Create and prepare test directory
1162 $directory = PATH_site
. 'typo3temp/' . uniqid('.test_');
1163 t3lib_div
::mkdir($directory);
1164 chmod($directory, 1551);
1166 // Set target permissions and run method
1167 $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] = '2770';
1168 $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup'] = posix_getegid();
1169 $fixPermissionsResult = t3lib_div
::fixPermissions($directory);
1171 // Get actual permissions and clean up
1173 $resultDirectoryPermissions = substr(decoct(fileperms($directory)), 1);
1174 $resultDirectoryGroup = filegroup($directory);
1175 t3lib_div
::rmdir($directory);
1177 // Test if everything was ok
1178 $this->assertTrue($fixPermissionsResult);
1179 $this->assertEquals($resultDirectoryPermissions, '2770');
1180 $this->assertEquals($resultDirectoryGroup, posix_getegid());
1184 * Checks if t3lib_div::fixPermissions() correctly sets permissions recursivly
1185 * This test assumes directory 'PATH_site'/typo3temp exists
1186 * This test is not available on windows OS
1189 * @see t3lib_div::fixPermissions()
1191 public function checkFixPermissionsCorrectlySetsPermissionsRecursive() {
1192 if (TYPO3_OS
== 'WIN') {
1193 $this->markTestSkipped('fixPermissions() tests not available on Windows');
1196 // Create and prepare test directory and file structure
1197 $baseDirectory = PATH_site
. 'typo3temp/' . uniqid('test_');
1198 t3lib_div
::mkdir($baseDirectory);
1199 chmod($baseDirectory, 1751);
1200 t3lib_div
::writeFileToTypo3tempDir($baseDirectory . '/file', '42');
1201 chmod($baseDirectory . '/file', 0742);
1202 t3lib_div
::mkdir($baseDirectory . '/foo');
1203 chmod($baseDirectory . '/foo', 1751);
1204 t3lib_div
::writeFileToTypo3tempDir($baseDirectory . '/foo/file', '42');
1205 chmod($baseDirectory . '/foo/file', 0742);
1206 t3lib_div
::mkdir($baseDirectory . '/.bar');
1207 chmod($baseDirectory . '/.bar', 1751);
1208 // Use this if writeFileToTypo3tempDir is fixed to create hidden files in subdirectories
1209 // t3lib_div::writeFileToTypo3tempDir($baseDirectory . '/.bar/.file', '42');
1210 // t3lib_div::writeFileToTypo3tempDir($baseDirectory . '/.bar/..file2', '42');
1211 touch($baseDirectory . '/.bar/.file', '42');
1212 chmod($baseDirectory . '/.bar/.file', 0742);
1213 touch($baseDirectory . '/.bar/..file2', '42');
1214 chmod($baseDirectory . '/.bar/..file2', 0742);
1216 // Set target permissions and run method
1217 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0660';
1218 $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] = '2770';
1219 $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup'] = posix_getegid();
1220 $fixPermissionsResult = t3lib_div
::fixPermissions($baseDirectory, TRUE);
1222 // Get actual permissions
1224 $resultBaseDirectoryPermissions = substr(decoct(fileperms($baseDirectory)), 1);
1225 $resultBaseDirectoryGroup = filegroup($baseDirectory);
1226 $resultBaseFilePermissions = substr(decoct(fileperms($baseDirectory . '/file')), 2);
1227 $resultBaseFileGroup = filegroup($baseDirectory . '/file');
1228 $resultFooDirectoryPermissions = substr(decoct(fileperms($baseDirectory . '/foo')), 1);
1229 $resultFooDirectoryGroup = filegroup($baseDirectory . '/foo');
1230 $resultFooFilePermissions = substr(decoct(fileperms($baseDirectory . '/foo/file')), 2);
1231 $resultFooFileGroup = filegroup($baseDirectory . '/foo/file');
1232 $resultBarDirectoryPermissions = substr(decoct(fileperms($baseDirectory . '/.bar')), 1);
1233 $resultBarDirectoryGroup = filegroup($baseDirectory . '/.bar');
1234 $resultBarFilePermissions = substr(decoct(fileperms($baseDirectory . '/.bar/.file')), 2);
1235 $resultBarFileGroup = filegroup($baseDirectory . '/.bar/.file');
1236 $resultBarFile2Permissions = substr(decoct(fileperms($baseDirectory . '/.bar/..file2')), 2);
1237 $resultBarFile2Group = filegroup($baseDirectory . '/.bar/..file2');
1240 unlink($baseDirectory . '/file');
1241 unlink($baseDirectory . '/foo/file');
1242 unlink($baseDirectory . '/.bar/.file');
1243 unlink($baseDirectory . '/.bar/..file2');
1244 t3lib_div
::rmdir($baseDirectory . '/foo');
1245 t3lib_div
::rmdir($baseDirectory . '/.bar');
1246 t3lib_div
::rmdir($baseDirectory);
1248 // Test if everything was ok
1249 $this->assertTrue($fixPermissionsResult);
1250 $this->assertEquals($resultBaseDirectoryPermissions, '2770');
1251 $this->assertEquals($resultBaseDirectoryGroup, posix_getegid());
1252 $this->assertEquals($resultBaseFilePermissions, '0660');
1253 $this->assertEquals($resultBaseFileGroup, posix_getegid());
1254 $this->assertEquals($resultFooDirectoryPermissions, '2770');
1255 $this->assertEquals($resultFooDirectoryGroup, posix_getegid());
1256 $this->assertEquals($resultFooFilePermissions, '0660');
1257 $this->assertEquals($resultFooFileGroup, posix_getegid());
1258 $this->assertEquals($resultBarDirectoryPermissions, '2770');
1259 $this->assertEquals($resultBarDirectoryGroup, posix_getegid());
1260 $this->assertEquals($resultBarFilePermissions, '0660');
1261 $this->assertEquals($resultBarFileGroup, posix_getegid());
1262 $this->assertEquals($resultBarFile2Permissions, '0660');
1263 $this->assertEquals($resultBarFile2Group, posix_getegid());
1267 * Checks if t3lib_div::fixPermissions() does not fix permissions on not allowed path
1268 * This test assumes directory 'PATH_site'/typo3temp exists
1269 * This test is not available on windows OS
1272 * @see t3lib_div::fixPermissions()
1274 public function checkFixPermissionsDoesNotSetPermissionsToNotAllowedPath() {
1275 if (TYPO3_OS
== 'WIN') {
1276 $this->markTestSkipped('fixPermissions() tests not available on Windows');
1279 // Create and prepare test file
1280 $filename = PATH_site
. 'typo3temp/../typo3temp/' . uniqid('test_');
1282 chmod($filename, 0742);
1284 // Set target permissions and run method
1285 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0660';
1286 $fixPermissionsResult = t3lib_div
::fixPermissions($filename);
1288 // Get actual permissions and clean up
1290 $resultFilePermissions = substr(decoct(fileperms($filename)), 2);
1293 // Test if everything was ok
1294 $this->assertFalse($fixPermissionsResult);
1295 $this->assertEquals($resultFilePermissions, '0742');
1299 * Checks if t3lib_div::mkdir() correctly creates a directory
1300 * This test assumes directory 'PATH_site'/typo3temp exists
1303 * @see t3lib_div::mkdir()
1305 public function checkMkdirCorrectlyCreatesDirectory() {
1306 $directory = PATH_site
. 'typo3temp/' . uniqid('test_');
1307 $mkdirResult = t3lib_div
::mkdir($directory);
1308 $directoryCreated = is_dir($directory);
1309 t3lib_div
::rmdir($directory);
1310 $this->assertTrue($mkdirResult);
1311 $this->assertTrue($directoryCreated);
1315 * Checks if t3lib_div::mkdir() correctly creates a hidden directory
1316 * This test assumes directory 'PATH_site'/typo3temp exists
1319 * @see t3lib_div::mkdir()
1321 public function checkMkdirCorrectlyCreatesHiddenDirectory() {
1322 $directory = PATH_site
. 'typo3temp/' . uniqid('.test_');
1323 $mkdirResult = t3lib_div
::mkdir($directory);
1324 $directoryCreated = is_dir($directory);
1325 t3lib_div
::rmdir($directory);
1326 $this->assertTrue($mkdirResult);
1327 $this->assertTrue($directoryCreated);
1331 * Checks if t3lib_div::mkdir() correctly creates a directory with trailing slash
1332 * This test assumes directory 'PATH_site'/typo3temp exists
1335 * @see t3lib_div::mkdir()
1337 public function checkMkdirCorrectlyCreatesDirectoryWithTrailingSlash() {
1338 $directory = PATH_site
. 'typo3temp/' . uniqid('test_');
1339 $mkdirResult = t3lib_div
::mkdir($directory);
1340 $directoryCreated = is_dir($directory);
1341 t3lib_div
::rmdir($directory);
1342 $this->assertTrue($mkdirResult);
1343 $this->assertTrue($directoryCreated);