Cleanup #14405: Rename test cases from *_testcase to *Test: Rename classes in tests/
[Packages/TYPO3.CMS.git] / tests / t3lib / t3lib_divTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Ingo Renner <ingo@typo3.org>
6 * All rights reserved
7 *
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.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
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.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25
26 /**
27 * Testcase for class t3lib_div
28 *
29 * @author Ingo Renner <ingo@typo3.org>
30 * @author Oliver Klee <typo3-coding@oliverklee.de>
31 *
32 * @package TYPO3
33 * @subpackage t3lib
34 */
35 class t3lib_divTest extends tx_phpunit_testcase {
36 /**
37 * backup of the global variables _GET, _POST, _SERVER
38 *
39 * @var array
40 */
41 private $backupGlobalVariables;
42
43 public function setUp() {
44 $this->backupGlobalVariables = array(
45 '_GET' => $_GET,
46 '_POST' => $_POST,
47 '_SERVER' => $_SERVER,
48 'TYPO3_CONF_VARS' => $GLOBALS['TYPO3_CONF_VARS'],
49 );
50 }
51
52 public function tearDown() {
53 foreach ($this->backupGlobalVariables as $key => $data) {
54 $GLOBALS[$key] = $data;
55 }
56 }
57
58
59 /**
60 * @test
61 */
62 public function calcPriorityCalculatesBasicArithmeticOperation() {
63 $this->assertEquals(9, t3lib_div::calcPriority('6 + 3'));
64 $this->assertEquals(3, t3lib_div::calcPriority('6 - 3'));
65 $this->assertEquals(-3, t3lib_div::calcPriority('3 - 6'));
66 $this->assertEquals(6, t3lib_div::calcPriority('2 * 3'));
67 $this->assertEquals(2.5, t3lib_div::calcPriority('5 / 2'));
68 $this->assertEquals(1, t3lib_div::calcPriority('5 % 2'));
69 $this->assertEquals(8, t3lib_div::calcPriority('2 ^ 3'));
70 }
71
72 /**
73 * @test
74 */
75 public function calcPriorityCalculatesArithmeticOperationWithMultipleOperands() {
76 $this->assertEquals(6.5, t3lib_div::calcPriority('5 + 3 / 2'));
77 $this->assertEquals(14, t3lib_div::calcPriority('5 + 3 ^ 2'));
78 $this->assertEquals(4, t3lib_div::calcPriority('5 % 2 + 3'));
79 $this->assertEquals(3, t3lib_div::calcPriority('2 + 6 / 2 - 2'));
80 }
81
82 /**
83 * @test
84 */
85 public function checkIntExplodeConvertsStringsToInteger() {
86 $testString = '1,foo,2';
87 $expectedArray = array(1, 0, 2);
88 $actualArray = t3lib_div::intExplode(',', $testString);
89
90 $this->assertEquals($expectedArray, $actualArray);
91 }
92
93 /**
94 * @test
95 */
96 public function checkRevExplodeCorrectlyExplodesString() {
97 $testString = 'my:words:here';
98 $expectedArray = array('my:words', 'here');
99 $actualArray = t3lib_div::revExplode(':', $testString, 2);
100
101 $this->assertEquals($expectedArray, $actualArray);
102 }
103
104 /**
105 * @test
106 */
107 public function checkTrimExplodeTrimsSpacesAtElementStartAndEnd() {
108 $testString = ' a , b , c ,d ,, e,f,';
109 $expectedArray = array('a', 'b', 'c', 'd', '', 'e', 'f', '');
110 $actualArray = t3lib_div::trimExplode(',', $testString);
111
112 $this->assertEquals($expectedArray, $actualArray);
113 }
114
115 /**
116 * @test
117 */
118 public function checkTrimExplodeRemovesNewLines() {
119 $testString = ' a , b , ' . LF . ' ,d ,, e,f,';
120 $expectedArray = array('a', 'b', 'd', 'e', 'f');
121 $actualArray = t3lib_div::trimExplode(',', $testString, true);
122
123 $this->assertEquals($expectedArray, $actualArray);
124 }
125
126 /**
127 * @test
128 */
129 public function checkTrimExplodeRemovesEmptyElements() {
130 $testString = 'a , b , c , ,d ,, ,e,f,';
131 $expectedArray = array('a', 'b', 'c', 'd', 'e', 'f');
132 $actualArray = t3lib_div::trimExplode(',', $testString, true);
133
134 $this->assertEquals($expectedArray, $actualArray);
135 }
136
137 /**
138 * @test
139 */
140 public function checkTrimExplodeKeepsRemainingResultsWithEmptyItemsAfterReachingLimitWithPositiveParameter() {
141 $testString = ' a , b , c , , d,, ,e ';
142 $expectedArray = array('a', 'b', 'c,,d,,,e'); // limiting returns the rest of the string as the last element
143 $actualArray = t3lib_div::trimExplode(',', $testString, false, 3);
144
145 $this->assertEquals($expectedArray, $actualArray);
146 }
147
148 /**
149 * @test
150 */
151 public function checkTrimExplodeKeepsRemainingResultsWithoutEmptyItemsAfterReachingLimitWithPositiveParameter() {
152 $testString = ' a , b , c , , d,, ,e ';
153 $expectedArray = array('a', 'b', 'c,d,e'); // limiting returns the rest of the string as the last element
154 $actualArray = t3lib_div::trimExplode(',', $testString, true, 3);
155
156 $this->assertEquals($expectedArray, $actualArray);
157 }
158
159 /**
160 * @test
161 */
162 public function checkTrimExplodeKeepsRamainingResultsWithEmptyItemsAfterReachingLimitWithNegativeParameter() {
163 $testString = ' a , b , c , d, ,e, f , , ';
164 $expectedArray = array('a', 'b', 'c', 'd', '', 'e'); // limiting returns the rest of the string as the last element
165 $actualArray = t3lib_div::trimExplode(',', $testString, false, -3);
166
167 $this->assertEquals($expectedArray, $actualArray);
168 }
169
170 /**
171 * @test
172 */
173 public function checkTrimExplodeKeepsRamainingResultsWithoutEmptyItemsAfterReachingLimitWithNegativeParameter() {
174 $testString = ' a , b , c , d, ,e, f , , ';
175 $expectedArray = array('a', 'b', 'c'); // limiting returns the rest of the string as the last element
176 $actualArray = t3lib_div::trimExplode(',', $testString, true, -3);
177
178 $this->assertEquals($expectedArray, $actualArray);
179 }
180
181 /**
182 * @test
183 */
184 public function checkTrimExplodeReturnsExactResultsWithoutReachingLimitWithPositiveParameter() {
185 $testString = ' a , b , , c , , , ';
186 $expectedArray = array('a', 'b', 'c'); // limiting returns the rest of the string as the last element
187 $actualArray = t3lib_div::trimExplode(',', $testString, true, 4);
188
189 $this->assertEquals($expectedArray, $actualArray);
190 }
191
192 /**
193 * @test
194 */
195 public function checkTrimExplodeKeepsZeroAsString() {
196 $testString = 'a , b , c , ,d ,, ,e,f, 0 ,';
197 $expectedArray = array('a', 'b', 'c', 'd', 'e', 'f', '0');
198 $actualArray = t3lib_div::trimExplode(',', $testString, true);
199
200 $this->assertEquals($expectedArray, $actualArray);
201 }
202
203 /**
204 * Checks whether measurement strings like "100k" return the accordant
205 * byte representation like 102400 in this case.
206 *
207 * @test
208 */
209 public function checkGetBytesFromSizeMeasurement() {
210 $this->assertEquals(
211 '102400',
212 t3lib_div::getBytesFromSizeMeasurement('100k')
213 );
214
215 $this->assertEquals(
216 '104857600',
217 t3lib_div::getBytesFromSizeMeasurement('100m')
218 );
219
220 $this->assertEquals(
221 '107374182400',
222 t3lib_div::getBytesFromSizeMeasurement('100g')
223 );
224 }
225
226 /**
227 * @test
228 */
229 public function checkIndpEnvTypo3SitePathNotEmpty() {
230 $actualEnv = t3lib_div::getIndpEnv('TYPO3_SITE_PATH');
231 $this->assertTrue(strlen($actualEnv) >= 1);
232 $this->assertEquals('/', $actualEnv{0});
233 $this->assertEquals('/', $actualEnv{strlen($actualEnv) - 1});
234 }
235
236 /**
237 * @test
238 * @see t3lib_div::underscoredToUpperCamelCase
239 */
240 public function canConvertFromUnderscoredToUpperCamelCase() {
241 $this->assertEquals('BlogExample', t3lib_div::underscoredToUpperCamelCase('blog_example'));
242 $this->assertEquals('Blogexample', t3lib_div::underscoredToUpperCamelCase('blogexample'));
243 }
244
245 /**
246 * @test
247 * @see t3lib_div::underscoredToLowerCamelCase
248 */
249 public function canConvertFromUnderscoredToLowerCamelCase() {
250 $this->assertEquals('minimalValue', t3lib_div::underscoredToLowerCamelCase('minimal_value'));
251 $this->assertEquals('minimalvalue', t3lib_div::underscoredToLowerCamelCase('minimalvalue'));
252 }
253
254 /**
255 * @test
256 * @see t3lib_div::camelCaseToLowerCaseUnderscored
257 */
258 public function canConvertFromCamelCaseToLowerCaseUnderscored() {
259 $this->assertEquals('blog_example', t3lib_div::camelCaseToLowerCaseUnderscored('BlogExample'));
260 $this->assertEquals('blogexample', t3lib_div::camelCaseToLowerCaseUnderscored('Blogexample'));
261 $this->assertEquals('blogexample', t3lib_div::camelCaseToLowerCaseUnderscored('blogexample'));
262
263 $this->assertEquals('minimal_value', t3lib_div::camelCaseToLowerCaseUnderscored('minimalValue'));
264 }
265
266 /**
267 * @test
268 * @see t3lib_div::lcfirst
269 */
270 public function canConvertFirstCharacterToBeLowerCase() {
271 $this->assertEquals('blogexample', t3lib_div::lcfirst('Blogexample'));
272 $this->assertEquals('blogExample', t3lib_div::lcfirst('BlogExample'));
273 $this->assertEquals('blogexample', t3lib_div::lcfirst('blogexample'));
274 }
275
276 /**
277 * Tests whether whitespaces are encoded correctly in a quoted-printable mail header.
278 * @test
279 */
280 public function areWhitespacesEncodedInQuotedPrintableMailHeader() {
281 $this->assertEquals(
282 '=?utf-8?Q?We_test_whether_the_copyright_character_=C2=A9_is_encoded_correctly?=',
283 t3lib_div::encodeHeader(
284 "We test whether the copyright character \xc2\xa9 is encoded correctly",
285 'quoted-printable',
286 'utf-8'
287 )
288 );
289 }
290
291 /**
292 * Tests whether question marks are encoded correctly in a quoted-printable mail header.
293 * @test
294 */
295 public function areQuestionMarksEncodedInQuotedPrintableMailHeader() {
296 $this->assertEquals(
297 '=?utf-8?Q?Is_the_copyright_character_=C2=A9_really_encoded_correctly=3F_Really=3F?=',
298 t3lib_div::encodeHeader(
299 "Is the copyright character \xc2\xa9 really encoded correctly? Really?",
300 'quoted-printable',
301 'utf-8'
302 )
303 );
304 }
305
306 /**
307 * Data provider for valid URLs, like PHP's source code test cases
308 */
309 public function validUrlDataProvider() {
310 return array(
311 array('http://example.com/index.html'),
312 array('http://www.example.com/index.php'),
313 array('http://www.example/img/test.png'),
314 array('http://www.example/img/dir/'),
315 array('http://www.example/img/dir'),
316 array('file:///tmp/test.c'),
317 array('ftp://ftp.example.com/tmp/'),
318 array('mailto:foo@bar.com'),
319 array('news:news.php.net'),
320 array('file://foo/bar'),
321 array('http://qwe'),
322 );
323 }
324
325 /**
326 * Data provider for invalid URLs, like PHP's source code test cases
327 */
328 public function invalidUrlDataProvider() {
329 return array(
330 array('http//www.example/wrong/url/'),
331 array('http:/www.example'),
332 array('/tmp/test.c'),
333 array('/'),
334 array('http://'),
335 array('http:/'),
336 array('http:'),
337 array('http'),
338 array(''),
339 array('-1'),
340 array('array()'),
341 array('qwe'),
342 );
343 }
344
345 /**
346 * @test
347 * @dataProvider validUrlDataProvider
348 * @see t3lib_div::isValidUrl()
349 */
350 public function checkisValidURL($url) {
351 $this->assertTrue(t3lib_div::isValidUrl($url));
352 }
353
354 /**
355 * @test
356 * @dataProvider invalidUrlDataProvider
357 * @see t3lib_div::isValidUrl()
358 */
359 public function checkisInValidURL($url) {
360 $this->assertFalse(t3lib_div::isValidUrl($url));
361 }
362
363 /**
364 * @test
365 * @see t3lib_div::isValidUrl()
366 */
367 public function checkisValidURLSucceedsWithWebRessource() {
368 $testUrl = 'http://www.example.org/';
369 $this->assertTrue(t3lib_div::isValidUrl($testUrl));
370 }
371
372 /**
373 * @test
374 * @see t3lib_div::isValidUrl()
375 */
376 public function checkisValidURLSucceedsWithExtentedWebRessource() {
377 $testUrl = 'https://user:pw@www.example.org:80/path?arg=value#fragment';
378 $this->assertTrue(t3lib_div::isValidUrl($testUrl));
379 }
380
381 /**
382 * @test
383 * @see t3lib_div::isValidUrl()
384 */
385 public function checkisValidURLSucceedsWithTelnetRessource() {
386 $testUrl = 'telnet://192.0.2.16:80/';
387 $this->assertTrue(t3lib_div::isValidUrl($testUrl));
388 }
389
390 /**
391 * @test
392 */
393 public function checkisValidURLSucceedsWithLdapRessource() {
394 $testUrl = 'ldap://[2001:db8::7]/c=GB?objectClass?one';
395 $this->assertTrue(t3lib_div::isValidUrl($testUrl));
396 }
397
398 /**
399 * @test
400 * @see t3lib_div::isValidUrl()
401 */
402 public function checkisValidURLSucceedsWithFileRessource() {
403 $testUrl = 'file:///etc/passwd';
404 $this->assertTrue(t3lib_div::isValidUrl($testUrl));
405 }
406
407 /**
408 * @test
409 * @see t3lib_div::isValidUrl()
410 */
411 public function checkisValidURLFailsWithHostnameOnly() {
412 $testUrl = 'www.example.org/';
413 $this->assertFalse(t3lib_div::isValidUrl($testUrl));
414 }
415
416 /**
417 * @test
418 * @see t3lib_div::isOnCurrentHost()
419 */
420 public function checkisOnCurrentHostFailsWithLocalhostIPOnly() {
421 $testUrl = '127.0.0.1';
422 $this->assertFalse(t3lib_div::isOnCurrentHost($testUrl));
423 }
424
425 /**
426 * @test
427 * @see t3lib_div::isOnCurrentHost()
428 */
429 public function checkisOnCurrentHostFailsWithPathsOnly() {
430 $testUrl = './relpath/file.txt';
431 $this->assertFalse(t3lib_div::isOnCurrentHost($testUrl));
432 $testUrl = '/abspath/file.txt?arg=value';
433 $this->assertFalse(t3lib_div::isOnCurrentHost($testUrl));
434 }
435
436 /**
437 * @test
438 * @see t3lib_div::isOnCurrentHost()
439 */
440 public function checkisOnCurrentHostFailsWithArbitraryString() {
441 $testUrl = 'arbitrary string';
442 $this->assertFalse(t3lib_div::isOnCurrentHost($testUrl));
443 }
444
445 /**
446 * @test
447 * @see t3lib_div::isOnCurrentHost()
448 */
449 public function checkisOnCurrentHostFailsWithEmptyUrl() {
450 $testUrl = '';
451 $this->assertFalse(t3lib_div::isOnCurrentHost($testUrl));
452 }
453
454 /**
455 * @test
456 * @see t3lib_div::isOnCurrentHost()
457 */
458 public function checkisOnCurrentHostFailsWithDifferentHost() {
459 $testUrl = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST') . '.example.org';
460 $this->assertFalse(t3lib_div::isOnCurrentHost($testUrl));
461 }
462
463 /**
464 * @test
465 * @see t3lib_div::isOnCurrentHost()
466 */
467 public function checkisOnCurrentHostSucceedsWithCurrentHost() {
468 $testUrl = t3lib_div::getIndpEnv('TYPO3_REQUEST_URL');
469 $this->assertTrue(t3lib_div::isOnCurrentHost($testUrl));
470 }
471
472
473 ////////////////////////////////////////
474 // Tests concerning sanitizeLocalUrl
475 ////////////////////////////////////////
476
477 /**
478 * Data provider for valid URLs.
479 * @see sanitizeLocalUrlAcceptsValidUrls
480 */
481 public function validLocalUrlDataProvider() {
482 return array(
483 array('alt_intro.php'),
484 array('alt_intro.php?foo=1&bar=2'),
485 array('/typo3/alt_intro.php'),
486 array('/index.php'),
487 array('../index.php'),
488 array('../typo3/alt_intro.php'),
489 array('../~userDirectory/index.php'),
490 array('../typo3/mod.php?var1=test-case&var2=~user'),
491 array(PATH_site . 'typo3/alt_intro.php'),
492 array(t3lib_div::getIndpEnv('TYPO3_SITE_URL') . 'typo3/alt_intro.php'),
493 array(t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST') . '/index.php'),
494 );
495 }
496
497 /**
498 * Data provider for invalid URLs.
499 * @see sanitizeLocalUrlDeniesInvalidUrls
500 */
501 public function invalidLocalUrlDataProvider() {
502 return array(
503 array(''),
504 array('http://www.google.de/'),
505 array('https://www.google.de/'),
506 array('../typo3/whatever.php?argument=javascript:alert(0)'),
507 );
508 }
509
510 /**
511 * Tests whether valid local URLs are handled correctly.
512 * @dataProvider validLocalUrlDataProvider
513 * @test
514 */
515 public function sanitizeLocalUrlAcceptsPlainValidUrls($url) {
516 $this->assertEquals($url, t3lib_div::sanitizeLocalUrl($url));
517 }
518
519 /**
520 * Tests whether valid local URLs are handled correctly.
521 * @dataProvider validLocalUrlDataProvider
522 * @test
523 */
524 public function sanitizeLocalUrlAcceptsEncodedValidUrls($url) {
525 $this->assertEquals(rawurlencode($url), t3lib_div::sanitizeLocalUrl(rawurlencode($url)));
526 }
527
528 /**
529 * Tests whether valid local URLs are handled correctly.
530 * @dataProvider invalidLocalUrlDataProvider
531 * @test
532 */
533 public function sanitizeLocalUrlDeniesPlainInvalidUrls($url) {
534 $this->assertEquals('', t3lib_div::sanitizeLocalUrl($url));
535 }
536
537 /**
538 * Tests whether valid local URLs are handled correctly.
539 * @dataProvider invalidLocalUrlDataProvider
540 * @test
541 */
542 public function sanitizeLocalUrlDeniesEncodedInvalidUrls($url) {
543 $this->assertEquals('', t3lib_div::sanitizeLocalUrl(rawurlencode($url)));
544 }
545
546 //////////////////////////////////////
547 // Tests concerning arrayDiffAssocRecursive
548 //////////////////////////////////////
549
550 /**
551 * Test if a one dimensional array is correctly diffed.
552 *
553 * @test
554 * @see t3lib_div::arrayDiffAssocRecursive
555 */
556 public function doesArrayDiffAssocRecursiveCorrectlyHandleOneDimensionalArrays() {
557 $array1 = array(
558 'key1' => 'value1',
559 'key2' => 'value2',
560 'key3' => 'value3',
561 );
562 $array2 = array(
563 'key1' => 'value1',
564 'key3' => 'value3',
565 );
566 $expectedResult = array(
567 'key2' => 'value2',
568 );
569 $actualResult = t3lib_div::arrayDiffAssocRecursive($array1, $array2);
570 $this->assertEquals($expectedResult, $actualResult);
571 }
572
573 /**
574 * Test if a three dimensional array is correctly diffed.
575 *
576 * @test
577 * @see t3lib_div::arrayDiffAssocRecursive
578 */
579 public function doesArrayDiffAssocRecursiveCorrectlyHandleMultiDimensionalArrays() {
580 $array1 = array(
581 'key1' => 'value1',
582 'key2' => array(
583 'key21' => 'value21',
584 'key22' => 'value22',
585 'key23' => array(
586 'key231' => 'value231',
587 'key232' => 'value232',
588 ),
589 ),
590 );
591 $array2 = array(
592 'key1' => 'value1',
593 'key2' => array(
594 'key21' => 'value21',
595 'key23' => array(
596 'key231' => 'value231',
597 ),
598 ),
599 );
600 $expectedResult = array(
601 'key2' => array(
602 'key22' => 'value22',
603 'key23' => array(
604 'key232' => 'value232',
605 ),
606 ),
607 );
608 $actualResult = t3lib_div::arrayDiffAssocRecursive($array1, $array2);
609 $this->assertEquals($expectedResult, $actualResult);
610 }
611
612 /**
613 * Test if arrays are correctly diffed if types are different.
614 *
615 * @test
616 * @see t3lib_div::arrayDiffAssocRecursive
617 */
618 public function doesArrayDiffAssocRecursiveCorrectlyHandleMixedArrays() {
619 $array1 = array(
620 'key1' => array(
621 'key11' => 'value11',
622 'key12' => 'value12',
623 ),
624 'key2' => 'value2',
625 'key3' => 'value3',
626 );
627 $array2 = array(
628 'key1' => 'value1',
629 'key2' => array(
630 'key21' => 'value21',
631 ),
632 );
633 $expectedResult = array(
634 'key3' => 'value3',
635 );
636 $actualResult = t3lib_div::arrayDiffAssocRecursive($array1, $array2);
637 $this->assertEquals($expectedResult, $actualResult);
638 }
639
640 //////////////////////////////////////
641 // Tests concerning removeDotsFromTS
642 //////////////////////////////////////
643
644 /**
645 * Tests whether removeDotsFromTS() behaves correctly.
646 * @test
647 * @see t3lib_div::removeDotsFromTS()
648 */
649 public function doesRemoveDotsFromTypoScriptSucceed() {
650 $typoScript = array(
651 'propertyA.' => array(
652 'keyA.' => array(
653 'valueA' => 1,
654 ),
655 'keyB' => 2,
656 ),
657 'propertyB' => 3,
658 );
659
660 $expectedResult = array(
661 'propertyA' => array(
662 'keyA' => array(
663 'valueA' => 1,
664 ),
665 'keyB' => 2,
666 ),
667 'propertyB' => 3,
668 );
669
670 $this->assertEquals($expectedResult, t3lib_div::removeDotsFromTS($typoScript));
671 }
672
673 /**
674 * Tests whether removeDotsFromTS() behaves correctly.
675 * @test
676 * @see t3lib_div::removeDotsFromTS()
677 */
678 public function doesRemoveDotsFromTypoScriptCorrectlyOverrideWithArray() {
679 $typoScript = array(
680 'propertyA.' => array(
681 'keyA' => 'getsOverridden',
682 'keyA.' => array(
683 'valueA' => 1,
684 ),
685 'keyB' => 2,
686 ),
687 'propertyB' => 3,
688 );
689
690 $expectedResult = array(
691 'propertyA' => array(
692 'keyA' => array(
693 'valueA' => 1,
694 ),
695 'keyB' => 2,
696 ),
697 'propertyB' => 3,
698 );
699
700 $this->assertEquals($expectedResult, t3lib_div::removeDotsFromTS($typoScript));
701 }
702
703 /**
704 * Tests whether removeDotsFromTS() behaves correctly.
705 * @test
706 * @see t3lib_div::removeDotsFromTS()
707 */
708 public function doesRemoveDotsFromTypoScriptCorrectlyOverrideWithScalar() {
709 $typoScript = array(
710 'propertyA.' => array(
711 'keyA.' => array(
712 'valueA' => 1,
713 ),
714 'keyA' => 'willOverride',
715 'keyB' => 2,
716 ),
717 'propertyB' => 3,
718 );
719
720 $expectedResult = array(
721 'propertyA' => array(
722 'keyA' => 'willOverride',
723 'keyB' => 2,
724 ),
725 'propertyB' => 3,
726 );
727
728 $this->assertEquals($expectedResult, t3lib_div::removeDotsFromTS($typoScript));
729 }
730
731 /**
732 * Tests whether getDirs() returns an array of diretories from a given path
733 * @test
734 * @see t3lib_div::getDirs($path)
735 */
736 public function checkGetDirsReturnsArrayOfDirectoriesFromGivenDirectory() {
737 $path = PATH_t3lib;
738 $directories = t3lib_div::get_dirs($path);
739
740 $this->assertType('array', $directories);
741 }
742
743 /**
744 * Tests whether getDirs() returns the string 'error' in case of problems reading from the given path
745 * @test
746 * @see t3lib_div::getDirs($path)
747 */
748 public function checkGetDirsReturnsStringErrorOnPathFailure() {
749 $path = 'foo';
750 $result = t3lib_div::get_dirs($path);
751 $expectedResult = 'error';
752
753 $this->assertEquals($expectedResult, $result);
754 }
755
756
757 //////////////////////////////////
758 // Tests concerning hmac
759 //////////////////////////////////
760
761 /**
762 * @test
763 */
764 public function hmacReturnsHashOfProperLength() {
765 $hmac = t3lib_div::hmac('message');
766 $this->assertTrue(!empty($hmac) && is_string($hmac));
767 $this->assertTrue(strlen($hmac) == 40);
768 }
769
770 /**
771 * @test
772 */
773 public function hmacReturnsEqualHashesForEqualInput() {
774 $msg0 = 'message';
775 $msg1 = 'message';
776 $this->assertEquals(t3lib_div::hmac($msg0), t3lib_div::hmac($msg1));
777 }
778
779 /**
780 * @test
781 */
782 public function hmacReturnsNotEqualHashesForNotEqualInput() {
783 $msg0 = 'message0';
784 $msg1 = 'message1';
785 $this->assertNotEquals(t3lib_div::hmac($msg0), t3lib_div::hmac($msg1));
786 }
787
788
789 //////////////////////////////////
790 // Tests concerning quoteJSvalue
791 //////////////////////////////////
792
793 /**
794 * @test
795 */
796 public function quoteJSvalueHtmlspecialcharsDataByDefault() {
797 $this->assertContains(
798 '&gt;',
799 t3lib_div::quoteJSvalue('>')
800 );
801 }
802
803 /**
804 * @test
805 */
806 public function quoteJSvaluetHtmlspecialcharsDataWithinCDataSetToFalse() {
807 $this->assertContains(
808 '&gt;',
809 t3lib_div::quoteJSvalue('>', false)
810 );
811 }
812
813 /**
814 * @test
815 */
816 public function quoteJSvaluetNotHtmlspecialcharsDataWithinCDataSetToTrue() {
817 $this->assertContains(
818 '>',
819 t3lib_div::quoteJSvalue('>', true)
820 );
821 }
822
823 /**
824 * @test
825 */
826 public function quoteJSvalueReturnsEmptyStringQuotedInSingleQuotes() {
827 $this->assertEquals(
828 "''",
829 t3lib_div::quoteJSvalue("", true)
830 );
831 }
832
833 /**
834 * @test
835 */
836 public function quoteJSvalueNotModifiesStringWithoutSpecialCharacters() {
837 $this->assertEquals(
838 "'Hello world!'",
839 t3lib_div::quoteJSvalue("Hello world!", true)
840 );
841 }
842
843 /**
844 * @test
845 */
846 public function quoteJSvalueEscapesSingleQuote() {
847 $this->assertEquals(
848 "'\\''",
849 t3lib_div::quoteJSvalue("'", true)
850 );
851 }
852
853 /**
854 * @test
855 */
856 public function quoteJSvalueEscapesDoubleQuoteWithinCDataSetToTrue() {
857 $this->assertEquals(
858 "'\\\"'",
859 t3lib_div::quoteJSvalue('"', true)
860 );
861 }
862
863 /**
864 * @test
865 */
866 public function quoteJSvalueEscapesAndHtmlspecialcharsDoubleQuoteWithinCDataSetToFalse() {
867 $this->assertEquals(
868 "'\\&quot;'",
869 t3lib_div::quoteJSvalue('"', false)
870 );
871 }
872
873 /**
874 * @test
875 */
876 public function quoteJSvalueEscapesTab() {
877 $this->assertEquals(
878 "'" . '\t' . "'",
879 t3lib_div::quoteJSvalue(TAB)
880 );
881 }
882
883 /**
884 * @test
885 */
886 public function quoteJSvalueEscapesLinefeed() {
887 $this->assertEquals(
888 "'" . '\n' . "'",
889 t3lib_div::quoteJSvalue(LF)
890 );
891 }
892
893 /**
894 * @test
895 */
896 public function quoteJSvalueEscapesCarriageReturn() {
897 $this->assertEquals(
898 "'" . '\r' . "'",
899 t3lib_div::quoteJSvalue(CR)
900 );
901 }
902
903 /**
904 * @test
905 */
906 public function quoteJSvalueEscapesBackslah() {
907 $this->assertEquals(
908 "'\\\\'",
909 t3lib_div::quoteJSvalue('\\')
910 );
911 }
912
913 /**
914 * Tests the locallangXMLOverride feature of readLLfile()
915 * @test
916 */
917 public function readLLfileLocallangXMLOverride() {
918 $unique = uniqid('locallangXMLOverrideTest');
919
920 $xml = '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
921 <T3locallang>
922 <data type="array">
923 <languageKey index="default" type="array">
924 <label index="buttons.logout">EXIT</label>
925 </languageKey>
926 </data>
927 </T3locallang>';
928
929 $file = PATH_site . 'typo3temp/' . $unique . '.xml';
930 t3lib_div::writeFileToTypo3tempDir($file, $xml);
931
932 // get default value
933 $defaultLL = t3lib_div::readLLfile('EXT:lang/locallang_core.xml', 'default');
934
935 // set override file
936 $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']['EXT:lang/locallang_core.xml'][$unique] = $file;
937
938 // get override value
939 $overrideLL = t3lib_div::readLLfile('EXT:lang/locallang_core.xml', 'default');
940
941 $this->assertNotEquals($overrideLL['default']['buttons.logout'], '');
942 $this->assertNotEquals($defaultLL['default']['buttons.logout'], $overrideLL['default']['buttons.logout']);
943 $this->assertEquals($overrideLL['default']['buttons.logout'], 'EXIT');
944
945 unlink($file);
946 }
947
948
949 ///////////////////////////////
950 // Tests concerning _GETset()
951 ///////////////////////////////
952
953 /**
954 * @test
955 */
956 public function getSetCanSetWholeArray() {
957 $_GET = array();
958 $GLOBALS['HTTP_GET_VARS'] = array();
959 t3lib_div::_GETset(array('oneKey' => 'oneValue'));
960
961 $this->assertEquals(
962 array('oneKey' => 'oneValue'),
963 $_GET
964 );
965 $this->assertEquals(
966 array('oneKey' => 'oneValue'),
967 $GLOBALS['HTTP_GET_VARS']
968 );
969 }
970
971 /**
972 * @test
973 */
974 public function getSetForArrayDropsExistingValues() {
975 $_GET = array();
976 $GLOBALS['HTTP_GET_VARS'] = array();
977
978 t3lib_div::_GETset(array('foo' => 'bar'));
979 t3lib_div::_GETset(array('oneKey' => 'oneValue'));
980
981 $this->assertEquals(
982 array('oneKey' => 'oneValue'),
983 $_GET
984 );
985 $this->assertEquals(
986 array('oneKey' => 'oneValue'),
987 $GLOBALS['HTTP_GET_VARS']
988 );
989 }
990
991 /**
992 * @test
993 */
994 public function getSetCanAssignOneValueToOneKey() {
995 $_GET = array();
996 $GLOBALS['HTTP_GET_VARS'] = array();
997
998 t3lib_div::_GETset('oneValue', 'oneKey');
999
1000 $this->assertEquals(
1001 'oneValue',
1002 $_GET['oneKey']
1003 );
1004 $this->assertEquals(
1005 'oneValue',
1006 $GLOBALS['HTTP_GET_VARS']['oneKey']
1007 );
1008 }
1009
1010 /**
1011 * @test
1012 */
1013 public function getSetForOneValueNotDropsExistingValues() {
1014 $_GET = array();
1015 $GLOBALS['HTTP_GET_VARS'] = array();
1016
1017 t3lib_div::_GETset(array('foo' => 'bar'));
1018 t3lib_div::_GETset('oneValue', 'oneKey');
1019
1020 $this->assertEquals(
1021 array('foo' => 'bar', 'oneKey' => 'oneValue'),
1022 $_GET
1023 );
1024 $this->assertEquals(
1025 array('foo' => 'bar', 'oneKey' => 'oneValue'),
1026 $GLOBALS['HTTP_GET_VARS']
1027 );
1028 }
1029
1030 /**
1031 * @test
1032 */
1033 public function getSetCanAssignAnArrayToSpecificArrayElement() {
1034 $_GET = array();
1035 $GLOBALS['HTTP_GET_VARS'] = array();
1036
1037 t3lib_div::_GETset(array('childKey' => 'oneValue'), 'parentKey');
1038
1039 $this->assertEquals(
1040 array('parentKey' => array('childKey' => 'oneValue')),
1041 $_GET
1042 );
1043 $this->assertEquals(
1044 array('parentKey' => array('childKey' => 'oneValue')),
1045 $GLOBALS['HTTP_GET_VARS']
1046 );
1047 }
1048
1049 /**
1050 * @test
1051 */
1052 public function getSetCanAssignAValueToSpecificArrayChildElement() {
1053 $_GET = array();
1054 $GLOBALS['HTTP_GET_VARS'] = array();
1055
1056 t3lib_div::_GETset('oneValue', 'parentKey|childKey');
1057
1058 $this->assertEquals(
1059 array('parentKey' => array('childKey' => 'oneValue')),
1060 $_GET
1061 );
1062 $this->assertEquals(
1063 array('parentKey' => array('childKey' => 'oneValue')),
1064 $GLOBALS['HTTP_GET_VARS']
1065 );
1066 }
1067
1068 /**
1069 * @test
1070 */
1071 public function getSetCanAssignAnArrayToSpecificArrayChildElement() {
1072 $_GET = array();
1073 $GLOBALS['HTTP_GET_VARS'] = array();
1074
1075 t3lib_div::_GETset(
1076 array('key1' => 'value1', 'key2' => 'value2'),
1077 'parentKey|childKey'
1078 );
1079
1080 $this->assertEquals(
1081 array(
1082 'parentKey' => array(
1083 'childKey' => array('key1' => 'value1', 'key2' => 'value2')
1084 )
1085 ),
1086 $_GET
1087 );
1088 $this->assertEquals(
1089 array(
1090 'parentKey' => array(
1091 'childKey' => array('key1' => 'value1', 'key2' => 'value2')
1092 )
1093 ),
1094 $GLOBALS['HTTP_GET_VARS']
1095 );
1096 }
1097
1098 /**
1099 * Checks if t3lib_div::fixPermissions() correctly sets permissions to single file
1100 * This test assumes directory 'PATH_site'/typo3temp exists
1101 * This test is not available on windows OS
1102 *
1103 * @test
1104 * @see t3lib_div::fixPermissions()
1105 */
1106 public function checkFixPermissionsCorrectlySetsPermissionsToFile() {
1107 if (TYPO3_OS == 'WIN') {
1108 $this->markTestSkipped('fixPermissions() tests not available on Windows');
1109 }
1110
1111 // Create and prepare test file
1112 $filename = PATH_site . 'typo3temp/' . uniqid('test_');
1113 t3lib_div::writeFileToTypo3tempDir($filename, '42');
1114 chmod($filename, 0742);
1115
1116 // Set target permissions and run method
1117 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0660';
1118 $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup'] = posix_getegid();
1119 $fixPermissionsResult = t3lib_div::fixPermissions($filename);
1120
1121 // Get actual permissions and clean up
1122 clearstatcache();
1123 $resultFilePermissions = substr(decoct(fileperms($filename)), 2);
1124 $resultFileGroup = filegroup($filename);
1125 unlink($filename);
1126
1127 // Test if everything was ok
1128 $this->assertTrue($fixPermissionsResult);
1129 $this->assertEquals($resultFilePermissions, '0660');
1130 $this->assertEquals($resultFileGroup, posix_getegid());
1131 }
1132
1133 /**
1134 * Checks if t3lib_div::fixPermissions() correctly sets permissions to hidden file
1135 * This test assumes directory 'PATH_site'/typo3temp exists
1136 * This test is not available on windows OS
1137 *
1138 * @test
1139 * @see t3lib_div::fixPermissions()
1140 */
1141 public function checkFixPermissionsCorrectlySetsPermissionsToHiddenFile() {
1142 if (TYPO3_OS == 'WIN') {
1143 $this->markTestSkipped('fixPermissions() tests not available on Windows');
1144 }
1145
1146 // Create and prepare test file
1147 $filename = PATH_site . 'typo3temp/' . uniqid('.test_');
1148 t3lib_div::writeFileToTypo3tempDir($filename, '42');
1149 chmod($filename, 0742);
1150
1151 // Set target permissions and run method
1152 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0660';
1153 $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup'] = posix_getegid();
1154 $fixPermissionsResult = t3lib_div::fixPermissions($filename);
1155
1156 // Get actual permissions and clean up
1157 clearstatcache();
1158 $resultFilePermissions = substr(decoct(fileperms($filename)), 2);
1159 $resultFileGroup = filegroup($filename);
1160 unlink($filename);
1161
1162 // Test if everything was ok
1163 $this->assertTrue($fixPermissionsResult);
1164 $this->assertEquals($resultFilePermissions, '0660');
1165 $this->assertEquals($resultFileGroup, posix_getegid());
1166 }
1167
1168 /**
1169 * Checks if t3lib_div::fixPermissions() correctly sets permissions to directory with trailing slash
1170 * This test assumes directory 'PATH_site'/typo3temp exists
1171 * This test is not available on windows OS
1172 *
1173 * @test
1174 * @see t3lib_div::fixPermissions()
1175 */
1176 public function checkFixPermissionsCorrectlySetsPermissionsToDirectory() {
1177 if (TYPO3_OS == 'WIN') {
1178 $this->markTestSkipped('fixPermissions() tests not available on Windows');
1179 }
1180
1181 // Create and prepare test directory
1182 $directory = PATH_site . 'typo3temp/' . uniqid('test_');
1183 t3lib_div::mkdir($directory);
1184 chmod($directory, 1551);
1185
1186 // Set target permissions and run method
1187 $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] = '0770';
1188 $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup'] = posix_getegid();
1189 $fixPermissionsResult = t3lib_div::fixPermissions($directory . '/');
1190
1191 // Get actual permissions and clean up
1192 clearstatcache();
1193 $resultDirectoryPermissions = substr(decoct(fileperms($directory)), 1);
1194 $resultDirectoryGroup = filegroup($directory);
1195 t3lib_div::rmdir($directory);
1196
1197 // Test if everything was ok
1198 $this->assertTrue($fixPermissionsResult);
1199 $this->assertEquals($resultDirectoryPermissions, '0770');
1200 $this->assertEquals($resultDirectoryGroup, posix_getegid());
1201 }
1202
1203 /**
1204 * Checks if t3lib_div::fixPermissions() correctly sets permissions to hidden directory
1205 * This test assumes directory 'PATH_site'/typo3temp exists
1206 * This test is not available on windows OS
1207 *
1208 * @test
1209 * @see t3lib_div::fixPermissions()
1210 */
1211 public function checkFixPermissionsCorrectlySetsPermissionsToHiddenDirectory() {
1212 if (TYPO3_OS == 'WIN') {
1213 $this->markTestSkipped('fixPermissions() tests not available on Windows');
1214 }
1215
1216 // Create and prepare test directory
1217 $directory = PATH_site . 'typo3temp/' . uniqid('.test_');
1218 t3lib_div::mkdir($directory);
1219 chmod($directory, 1551);
1220
1221 // Set target permissions and run method
1222 $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] = '0770';
1223 $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup'] = posix_getegid();
1224 $fixPermissionsResult = t3lib_div::fixPermissions($directory);
1225
1226 // Get actual permissions and clean up
1227 clearstatcache();
1228 $resultDirectoryPermissions = substr(decoct(fileperms($directory)), 1);
1229 $resultDirectoryGroup = filegroup($directory);
1230 t3lib_div::rmdir($directory);
1231
1232 // Test if everything was ok
1233 $this->assertTrue($fixPermissionsResult);
1234 $this->assertEquals($resultDirectoryPermissions, '0770');
1235 $this->assertEquals($resultDirectoryGroup, posix_getegid());
1236 }
1237
1238 /**
1239 * Checks if t3lib_div::fixPermissions() correctly sets permissions recursivly
1240 * This test assumes directory 'PATH_site'/typo3temp exists
1241 * This test is not available on windows OS
1242 *
1243 * @test
1244 * @see t3lib_div::fixPermissions()
1245 */
1246 public function checkFixPermissionsCorrectlySetsPermissionsRecursive() {
1247 if (TYPO3_OS == 'WIN') {
1248 $this->markTestSkipped('fixPermissions() tests not available on Windows');
1249 }
1250
1251 // Create and prepare test directory and file structure
1252 $baseDirectory = PATH_site . 'typo3temp/' . uniqid('test_');
1253 t3lib_div::mkdir($baseDirectory);
1254 chmod($baseDirectory, 1751);
1255 t3lib_div::writeFileToTypo3tempDir($baseDirectory . '/file', '42');
1256 chmod($baseDirectory . '/file', 0742);
1257 t3lib_div::mkdir($baseDirectory . '/foo');
1258 chmod($baseDirectory . '/foo', 1751);
1259 t3lib_div::writeFileToTypo3tempDir($baseDirectory . '/foo/file', '42');
1260 chmod($baseDirectory . '/foo/file', 0742);
1261 t3lib_div::mkdir($baseDirectory . '/.bar');
1262 chmod($baseDirectory . '/.bar', 1751);
1263 // Use this if writeFileToTypo3tempDir is fixed to create hidden files in subdirectories
1264 // t3lib_div::writeFileToTypo3tempDir($baseDirectory . '/.bar/.file', '42');
1265 // t3lib_div::writeFileToTypo3tempDir($baseDirectory . '/.bar/..file2', '42');
1266 touch($baseDirectory . '/.bar/.file', '42');
1267 chmod($baseDirectory . '/.bar/.file', 0742);
1268 touch($baseDirectory . '/.bar/..file2', '42');
1269 chmod($baseDirectory . '/.bar/..file2', 0742);
1270
1271 // Set target permissions and run method
1272 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0660';
1273 $GLOBALS['TYPO3_CONF_VARS']['BE']['folderCreateMask'] = '0770';
1274 $GLOBALS['TYPO3_CONF_VARS']['BE']['createGroup'] = posix_getegid();
1275 $fixPermissionsResult = t3lib_div::fixPermissions($baseDirectory, TRUE);
1276
1277 // Get actual permissions
1278 clearstatcache();
1279 $resultBaseDirectoryPermissions = substr(decoct(fileperms($baseDirectory)), 1);
1280 $resultBaseDirectoryGroup = filegroup($baseDirectory);
1281 $resultBaseFilePermissions = substr(decoct(fileperms($baseDirectory . '/file')), 2);
1282 $resultBaseFileGroup = filegroup($baseDirectory . '/file');
1283 $resultFooDirectoryPermissions = substr(decoct(fileperms($baseDirectory . '/foo')), 1);
1284 $resultFooDirectoryGroup = filegroup($baseDirectory . '/foo');
1285 $resultFooFilePermissions = substr(decoct(fileperms($baseDirectory . '/foo/file')), 2);
1286 $resultFooFileGroup = filegroup($baseDirectory . '/foo/file');
1287 $resultBarDirectoryPermissions = substr(decoct(fileperms($baseDirectory . '/.bar')), 1);
1288 $resultBarDirectoryGroup = filegroup($baseDirectory . '/.bar');
1289 $resultBarFilePermissions = substr(decoct(fileperms($baseDirectory . '/.bar/.file')), 2);
1290 $resultBarFileGroup = filegroup($baseDirectory . '/.bar/.file');
1291 $resultBarFile2Permissions = substr(decoct(fileperms($baseDirectory . '/.bar/..file2')), 2);
1292 $resultBarFile2Group = filegroup($baseDirectory . '/.bar/..file2');
1293
1294 // Clean up
1295 unlink($baseDirectory . '/file');
1296 unlink($baseDirectory . '/foo/file');
1297 unlink($baseDirectory . '/.bar/.file');
1298 unlink($baseDirectory . '/.bar/..file2');
1299 t3lib_div::rmdir($baseDirectory . '/foo');
1300 t3lib_div::rmdir($baseDirectory . '/.bar');
1301 t3lib_div::rmdir($baseDirectory);
1302
1303 // Test if everything was ok
1304 $this->assertTrue($fixPermissionsResult);
1305 $this->assertEquals($resultBaseDirectoryPermissions, '0770');
1306 $this->assertEquals($resultBaseDirectoryGroup, posix_getegid());
1307 $this->assertEquals($resultBaseFilePermissions, '0660');
1308 $this->assertEquals($resultBaseFileGroup, posix_getegid());
1309 $this->assertEquals($resultFooDirectoryPermissions, '0770');
1310 $this->assertEquals($resultFooDirectoryGroup, posix_getegid());
1311 $this->assertEquals($resultFooFilePermissions, '0660');
1312 $this->assertEquals($resultFooFileGroup, posix_getegid());
1313 $this->assertEquals($resultBarDirectoryPermissions, '0770');
1314 $this->assertEquals($resultBarDirectoryGroup, posix_getegid());
1315 $this->assertEquals($resultBarFilePermissions, '0660');
1316 $this->assertEquals($resultBarFileGroup, posix_getegid());
1317 $this->assertEquals($resultBarFile2Permissions, '0660');
1318 $this->assertEquals($resultBarFile2Group, posix_getegid());
1319 }
1320
1321 /**
1322 * Checks if t3lib_div::fixPermissions() does not fix permissions on not allowed path
1323 * This test assumes directory 'PATH_site'/typo3temp exists
1324 * This test is not available on windows OS
1325 *
1326 * @test
1327 * @see t3lib_div::fixPermissions()
1328 */
1329 public function checkFixPermissionsDoesNotSetPermissionsToNotAllowedPath() {
1330 if (TYPO3_OS == 'WIN') {
1331 $this->markTestSkipped('fixPermissions() tests not available on Windows');
1332 }
1333
1334 // Create and prepare test file
1335 $filename = PATH_site . 'typo3temp/../typo3temp/' . uniqid('test_');
1336 touch($filename);
1337 chmod($filename, 0742);
1338
1339 // Set target permissions and run method
1340 $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0660';
1341 $fixPermissionsResult = t3lib_div::fixPermissions($filename);
1342
1343 // Get actual permissions and clean up
1344 clearstatcache();
1345 $resultFilePermissions = substr(decoct(fileperms($filename)), 2);
1346 unlink($filename);
1347
1348 // Test if everything was ok
1349 $this->assertFalse($fixPermissionsResult);
1350 $this->assertEquals($resultFilePermissions, '0742');
1351 }
1352
1353 /**
1354 * Checks if t3lib_div::mkdir() correctly creates a directory
1355 * This test assumes directory 'PATH_site'/typo3temp exists
1356 *
1357 * @test
1358 * @see t3lib_div::mkdir()
1359 */
1360 public function checkMkdirCorrectlyCreatesDirectory() {
1361 $directory = PATH_site . 'typo3temp/' . uniqid('test_');
1362 $mkdirResult = t3lib_div::mkdir($directory);
1363 $directoryCreated = is_dir($directory);
1364 t3lib_div::rmdir($directory);
1365 $this->assertTrue($mkdirResult);
1366 $this->assertTrue($directoryCreated);
1367 }
1368
1369 /**
1370 * Checks if t3lib_div::mkdir() correctly creates a hidden directory
1371 * This test assumes directory 'PATH_site'/typo3temp exists
1372 *
1373 * @test
1374 * @see t3lib_div::mkdir()
1375 */
1376 public function checkMkdirCorrectlyCreatesHiddenDirectory() {
1377 $directory = PATH_site . 'typo3temp/' . uniqid('.test_');
1378 $mkdirResult = t3lib_div::mkdir($directory);
1379 $directoryCreated = is_dir($directory);
1380 t3lib_div::rmdir($directory);
1381 $this->assertTrue($mkdirResult);
1382 $this->assertTrue($directoryCreated);
1383 }
1384
1385 /**
1386 * Checks if t3lib_div::mkdir() correctly creates a directory with trailing slash
1387 * This test assumes directory 'PATH_site'/typo3temp exists
1388 *
1389 * @test
1390 * @see t3lib_div::mkdir()
1391 */
1392 public function checkMkdirCorrectlyCreatesDirectoryWithTrailingSlash() {
1393 $directory = PATH_site . 'typo3temp/' . uniqid('test_');
1394 $mkdirResult = t3lib_div::mkdir($directory);
1395 $directoryCreated = is_dir($directory);
1396 t3lib_div::rmdir($directory);
1397 $this->assertTrue($mkdirResult);
1398 $this->assertTrue($directoryCreated);
1399 }
1400 }
1401 ?>