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