Follow-up to bug #11239: Added testcase for t3lib_div::arrayDiffAssocRecursive()
[Packages/TYPO3.CMS.git] / tests / t3lib / t3lib_div_testcase.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_div_testcase extends tx_phpunit_testcase {
36 /**
37 * @test
38 */
39 public function checkIntExplodeConvertsStringsToInteger() {
40 $testString = '1,foo,2';
41 $expectedArray = array(1, 0, 2);
42 $actualArray = t3lib_div::intExplode(',', $testString);
43
44 $this->assertEquals($expectedArray, $actualArray);
45 }
46
47 /**
48 * @test
49 */
50 public function checkTrimExplodeTrimsSpacesAtElementStartAndEnd() {
51 $testString = ' a , b , c ,d ,, e,f,';
52 $expectedArray = array('a', 'b', 'c', 'd', '', 'e', 'f', '');
53 $actualArray = t3lib_div::trimExplode(',', $testString);
54
55 $this->assertEquals($expectedArray, $actualArray);
56 }
57
58 /**
59 * @test
60 */
61 public function checkTrimExplodeRemovesNewLines() {
62 $testString = ' a , b , ' . chr(10) . ' ,d ,, e,f,';
63 $expectedArray = array('a', 'b', 'd', 'e', 'f');
64 $actualArray = t3lib_div::trimExplode(',', $testString, true);
65
66 $this->assertEquals($expectedArray, $actualArray);
67 }
68
69 /**
70 * @test
71 */
72 public function checkTrimExplodeRemovesEmptyElements() {
73 $testString = 'a , b , c , ,d ,, ,e,f,';
74 $expectedArray = array('a', 'b', 'c', 'd', 'e', 'f');
75 $actualArray = t3lib_div::trimExplode(',', $testString, true);
76
77 $this->assertEquals($expectedArray, $actualArray);
78 }
79
80 /**
81 * @test
82 */
83 public function checkTrimExplodeKeepsRemainingResultsWithEmptyItemsAfterReachingLimitWithPositiveParameter() {
84 $testString = ' a , b , c , , d,, ,e ';
85 $expectedArray = array('a', 'b', 'c,,d,,,e'); // limiting returns the rest of the string as the last element
86 $actualArray = t3lib_div::trimExplode(',', $testString, false, 3);
87
88 $this->assertEquals($expectedArray, $actualArray);
89 }
90
91 /**
92 * @test
93 */
94 public function checkTrimExplodeKeepsRemainingResultsWithoutEmptyItemsAfterReachingLimitWithPositiveParameter() {
95 $testString = ' a , b , c , , d,, ,e ';
96 $expectedArray = array('a', 'b', 'c,d,e'); // limiting returns the rest of the string as the last element
97 $actualArray = t3lib_div::trimExplode(',', $testString, true, 3);
98
99 $this->assertEquals($expectedArray, $actualArray);
100 }
101
102 /**
103 * @test
104 */
105 public function checkTrimExplodeKeepsRamainingResultsWithEmptyItemsAfterReachingLimitWithNegativeParameter() {
106 $testString = ' a , b , c , d, ,e, f , , ';
107 $expectedArray = array('a', 'b', 'c', 'd', '', 'e'); // limiting returns the rest of the string as the last element
108 $actualArray = t3lib_div::trimExplode(',', $testString, false, -3);
109
110 $this->assertEquals($expectedArray, $actualArray);
111 }
112
113 /**
114 * @test
115 */
116 public function checkTrimExplodeKeepsRamainingResultsWithoutEmptyItemsAfterReachingLimitWithNegativeParameter() {
117 $testString = ' a , b , c , d, ,e, f , , ';
118 $expectedArray = array('a', 'b', 'c'); // limiting returns the rest of the string as the last element
119 $actualArray = t3lib_div::trimExplode(',', $testString, true, -3);
120
121 $this->assertEquals($expectedArray, $actualArray);
122 }
123
124 /**
125 * @test
126 */
127 public function checkTrimExplodeReturnsExactResultsWithoutReachingLimitWithPositiveParameter() {
128 $testString = ' a , b , , c , , , ';
129 $expectedArray = array('a', 'b', 'c'); // limiting returns the rest of the string as the last element
130 $actualArray = t3lib_div::trimExplode(',', $testString, true, 4);
131
132 $this->assertEquals($expectedArray, $actualArray);
133 }
134
135 /**
136 * @test
137 */
138 public function checkTrimExplodeKeepsZeroAsString() {
139 $testString = 'a , b , c , ,d ,, ,e,f, 0 ,';
140 $expectedArray = array('a', 'b', 'c', 'd', 'e', 'f', '0');
141 $actualArray = t3lib_div::trimExplode(',', $testString, true);
142
143 $this->assertEquals($expectedArray, $actualArray);
144 }
145
146 /**
147 * Checks whether measurement strings like "100k" return the accordant
148 * byte representation like 102400 in this case.
149 *
150 * @test
151 */
152 public function checkGetBytesFromSizeMeasurement() {
153 $this->assertEquals(
154 '102400',
155 t3lib_div::getBytesFromSizeMeasurement('100k')
156 );
157
158 $this->assertEquals(
159 '104857600',
160 t3lib_div::getBytesFromSizeMeasurement('100m')
161 );
162
163 $this->assertEquals(
164 '107374182400',
165 t3lib_div::getBytesFromSizeMeasurement('100g')
166 );
167 }
168
169 /**
170 * @test
171 */
172 public function checkIndpEnvTypo3SitePathNotEmpty() {
173 $actualEnv = t3lib_div::getIndpEnv('TYPO3_SITE_PATH');
174 $this->assertTrue(strlen($actualEnv) >= 1);
175 $this->assertEquals('/', $actualEnv{0});
176 $this->assertEquals('/', $actualEnv{strlen($actualEnv) - 1});
177 }
178
179 /**
180 * @test
181 * @see t3lib_div::underscoredToUpperCamelCase
182 */
183 public function canConvertFromUnderscoredToUpperCamelCase() {
184 $this->assertEquals('BlogExample', t3lib_div::underscoredToUpperCamelCase('blog_example'));
185 $this->assertEquals('Blogexample', t3lib_div::underscoredToUpperCamelCase('blogexample'));
186 }
187
188 /**
189 * @test
190 * @see t3lib_div::underscoredToLowerCamelCase
191 */
192 public function canConvertFromUnderscoredToLowerCamelCase() {
193 $this->assertEquals('minimalValue', t3lib_div::underscoredToLowerCamelCase('minimal_value'));
194 $this->assertEquals('minimalvalue', t3lib_div::underscoredToLowerCamelCase('minimalvalue'));
195 }
196
197 /**
198 * @test
199 * @see t3lib_div::camelCaseToLowerCaseUnderscored
200 */
201 public function canConvertFromCamelCaseToLowerCaseUnderscored() {
202 $this->assertEquals('blog_example', t3lib_div::camelCaseToLowerCaseUnderscored('BlogExample'));
203 $this->assertEquals('blogexample', t3lib_div::camelCaseToLowerCaseUnderscored('Blogexample'));
204 $this->assertEquals('blogexample', t3lib_div::camelCaseToLowerCaseUnderscored('blogexample'));
205
206 $this->assertEquals('minimal_value', t3lib_div::camelCaseToLowerCaseUnderscored('minimalValue'));
207 }
208
209 /**
210 * @test
211 * @see t3lib_div::lcfirst
212 */
213 public function canConvertFirstCharacterToBeLowerCase() {
214 $this->assertEquals('blogexample', t3lib_div::lcfirst('Blogexample'));
215 $this->assertEquals('blogExample', t3lib_div::lcfirst('BlogExample'));
216 $this->assertEquals('blogexample', t3lib_div::lcfirst('blogexample'));
217 }
218
219 /**
220 * Tests whether whitespaces are encoded correctly in a quoted-printable mail header.
221 * @test
222 */
223 public function areWhitespacesEncodedInQuotedPrintableMailHeader() {
224 $this->assertEquals(
225 '=?utf-8?Q?We_test_whether_the_copyright_character_=C2=A9_is_encoded_correctly?=',
226 t3lib_div::encodeHeader(
227 "We test whether the copyright character \xc2\xa9 is encoded correctly",
228 'quoted-printable',
229 'utf-8'
230 )
231 );
232 }
233
234 /**
235 * Tests whether question marks are encoded correctly in a quoted-printable mail header.
236 * @test
237 */
238 public function areQuestionMarksEncodedInQuotedPrintableMailHeader() {
239 $this->assertEquals(
240 '=?utf-8?Q?Is_the_copyright_character_=C2=A9_really_encoded_correctly=3F_Really=3F?=',
241 t3lib_div::encodeHeader(
242 "Is the copyright character \xc2\xa9 really encoded correctly? Really?",
243 'quoted-printable',
244 'utf-8'
245 )
246 );
247 }
248
249 /**
250 * Data provider for valid URLs, like PHP's source code test cases
251 */
252 public function validUrlDataProvider() {
253 return array(
254 array('http://example.com/index.html'),
255 array('http://www.example.com/index.php'),
256 array('http://www.example/img/test.png'),
257 array('http://www.example/img/dir/'),
258 array('http://www.example/img/dir'),
259 array('file:///tmp/test.c'),
260 array('ftp://ftp.example.com/tmp/'),
261 array('mailto:foo@bar.com'),
262 array('news:news.php.net'),
263 array('file://foo/bar'),
264 array('http://qwe'),
265 );
266 }
267
268 /**
269 * Data provider for invalid URLs, like PHP's source code test cases
270 */
271 public function invalidUrlDataProvider() {
272 return array(
273 array('http//www.example/wrong/url/'),
274 array('http:/www.example'),
275 array('/tmp/test.c'),
276 array('/'),
277 array('http://'),
278 array('http:/'),
279 array('http:'),
280 array('http'),
281 array(''),
282 array('-1'),
283 array('array()'),
284 array('qwe'),
285 );
286 }
287
288 /**
289 * @test
290 * @dataProvider validUrlDataProvider
291 * @see t3lib_div::isValidUrl()
292 */
293 public function checkisValidURL($url) {
294 $this->assertTrue(t3lib_div::isValidUrl($url));
295 }
296
297 /**
298 * @test
299 * @dataProvider invalidUrlDataProvider
300 * @see t3lib_div::isValidUrl()
301 */
302 public function checkisInValidURL($url) {
303 $this->assertFalse(t3lib_div::isValidUrl($url));
304 }
305
306 /**
307 * @test
308 * @see t3lib_div::isValidUrl()
309 */
310 public function checkisValidURLSucceedsWithWebRessource() {
311 $testUrl = 'http://www.example.org/';
312 $this->assertTrue(t3lib_div::isValidUrl($testUrl));
313 }
314
315 /**
316 * @test
317 * @see t3lib_div::isValidUrl()
318 */
319 public function checkisValidURLSucceedsWithExtentedWebRessource() {
320 $testUrl = 'https://user:pw@www.example.org:80/path?arg=value#fragment';
321 $this->assertTrue(t3lib_div::isValidUrl($testUrl));
322 }
323
324 /**
325 * @test
326 * @see t3lib_div::isValidUrl()
327 */
328 public function checkisValidURLSucceedsWithTelnetRessource() {
329 $testUrl = 'telnet://192.0.2.16:80/';
330 $this->assertTrue(t3lib_div::isValidUrl($testUrl));
331 }
332
333 /**
334 * @test
335 */
336 public function checkisValidURLSucceedsWithLdapRessource() {
337 $testUrl = 'ldap://[2001:db8::7]/c=GB?objectClass?one';
338 $this->assertTrue(t3lib_div::isValidUrl($testUrl));
339 }
340
341 /**
342 * @test
343 * @see t3lib_div::isValidUrl()
344 */
345 public function checkisValidURLSucceedsWithFileRessource() {
346 $testUrl = 'file:///etc/passwd';
347 $this->assertTrue(t3lib_div::isValidUrl($testUrl));
348 }
349
350 /**
351 * @test
352 * @see t3lib_div::isValidUrl()
353 */
354 public function checkisValidURLFailsWithHostnameOnly() {
355 $testUrl = 'www.example.org/';
356 $this->assertFalse(t3lib_div::isValidUrl($testUrl));
357 }
358
359 /**
360 * @test
361 * @see t3lib_div::isOnCurrentHost()
362 */
363 public function checkisOnCurrentHostFailsWithLocalhostIPOnly() {
364 $testUrl = '127.0.0.1';
365 $this->assertFalse(t3lib_div::isOnCurrentHost($testUrl));
366 }
367
368 /**
369 * @test
370 * @see t3lib_div::isOnCurrentHost()
371 */
372 public function checkisOnCurrentHostFailsWithPathsOnly() {
373 $testUrl = './relpath/file.txt';
374 $this->assertFalse(t3lib_div::isOnCurrentHost($testUrl));
375 $testUrl = '/abspath/file.txt?arg=value';
376 $this->assertFalse(t3lib_div::isOnCurrentHost($testUrl));
377 }
378
379 /**
380 * @test
381 * @see t3lib_div::isOnCurrentHost()
382 */
383 public function checkisOnCurrentHostFailsWithArbitraryString() {
384 $testUrl = 'arbitrary string';
385 $this->assertFalse(t3lib_div::isOnCurrentHost($testUrl));
386 }
387
388 /**
389 * @test
390 * @see t3lib_div::isOnCurrentHost()
391 */
392 public function checkisOnCurrentHostFailsWithEmptyUrl() {
393 $testUrl = '';
394 $this->assertFalse(t3lib_div::isOnCurrentHost($testUrl));
395 }
396
397 /**
398 * @test
399 * @see t3lib_div::isOnCurrentHost()
400 */
401 public function checkisOnCurrentHostFailsWithDifferentHost() {
402 $testUrl = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST') . '.example.org';
403 $this->assertFalse(t3lib_div::isOnCurrentHost($testUrl));
404 }
405
406 /**
407 * @test
408 * @see t3lib_div::isOnCurrentHost()
409 */
410 public function checkisOnCurrentHostSucceedsWithCurrentHost() {
411 $testUrl = t3lib_div::getIndpEnv('TYPO3_REQUEST_URL');
412 $this->assertTrue(t3lib_div::isOnCurrentHost($testUrl));
413 }
414
415
416 ////////////////////////////////////////
417 // Tests concerning sanitizeLocalUrl
418 ////////////////////////////////////////
419
420 /**
421 * Data provider for valid URLs.
422 * @see sanitizeLocalUrlAcceptsValidUrls
423 */
424 public function validLocalUrlDataProvider() {
425 return array(
426 array('alt_intro.php'),
427 array('alt_intro.php?foo=1&bar=2'),
428 array('/typo3/alt_intro.php'),
429 array('/index.php'),
430 array('../index.php'),
431 array('../typo3/alt_intro.php'),
432 array('../~userDirectory/index.php'),
433 array('../typo3/mod.php?var1=test-case&var2=~user'),
434 array(PATH_site . 'typo3/alt_intro.php'),
435 array(t3lib_div::getIndpEnv('TYPO3_SITE_URL') . 'typo3/alt_intro.php'),
436 array(t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST') . '/index.php'),
437 );
438 }
439
440 /**
441 * Data provider for invalid URLs.
442 * @see sanitizeLocalUrlDeniesInvalidUrls
443 */
444 public function invalidLocalUrlDataProvider() {
445 return array(
446 array(''),
447 array('http://www.google.de/'),
448 array('https://www.google.de/'),
449 array('../typo3/whatever.php?argument=javascript:alert(0)'),
450 );
451 }
452
453 /**
454 * Tests whether valid local URLs are handled correctly.
455 * @dataProvider validLocalUrlDataProvider
456 * @test
457 */
458 public function sanitizeLocalUrlAcceptsPlainValidUrls($url) {
459 $this->assertEquals($url, t3lib_div::sanitizeLocalUrl($url));
460 }
461
462 /**
463 * Tests whether valid local URLs are handled correctly.
464 * @dataProvider validLocalUrlDataProvider
465 * @test
466 */
467 public function sanitizeLocalUrlAcceptsEncodedValidUrls($url) {
468 $this->assertEquals(rawurlencode($url), t3lib_div::sanitizeLocalUrl(rawurlencode($url)));
469 }
470
471 /**
472 * Tests whether valid local URLs are handled correctly.
473 * @dataProvider invalidLocalUrlDataProvider
474 * @test
475 */
476 public function sanitizeLocalUrlDeniesPlainInvalidUrls($url) {
477 $this->assertEquals('', t3lib_div::sanitizeLocalUrl($url));
478 }
479
480 /**
481 * Tests whether valid local URLs are handled correctly.
482 * @dataProvider invalidLocalUrlDataProvider
483 * @test
484 */
485 public function sanitizeLocalUrlDeniesEncodedInvalidUrls($url) {
486 $this->assertEquals('', t3lib_div::sanitizeLocalUrl(rawurlencode($url)));
487 }
488
489 //////////////////////////////////////
490 // Tests concerning arrayDiffAssocRecursive
491 //////////////////////////////////////
492
493 /**
494 * Test if a one dimensional array is correctly diffed.
495 *
496 * @test
497 * @see t3lib_div::arrayDiffAssocRecursive
498 */
499 public function doesArrayDiffAssocRecursiveCorrectlyHandleOneDimensionalArrays() {
500 $array1 = array(
501 'key1' => 'value1',
502 'key2' => 'value2',
503 'key3' => 'value3',
504 );
505 $array2 = array(
506 'key1' => 'value1',
507 'key3' => 'value3',
508 );
509 $expectedResult = array(
510 'key2' => 'value2',
511 );
512 $actualResult = t3lib_div::arrayDiffAssocRecursive($array1, $array2);
513 $this->assertEquals($expectedResult, $actualResult);
514 }
515
516 /**
517 * Test if a three dimensional array is correctly diffed.
518 *
519 * @test
520 * @see t3lib_div::arrayDiffAssocRecursive
521 */
522 public function doesArrayDiffAssocRecursiveCorrectlyHandleMultiDimensionalArrays() {
523 $array1 = array(
524 'key1' => 'value1',
525 'key2' => array(
526 'key21' => 'value21',
527 'key22' => 'value22',
528 'key23' => array(
529 'key231' => 'value231',
530 'key232' => 'value232',
531 ),
532 ),
533 );
534 $array2 = array(
535 'key1' => 'value1',
536 'key2' => array(
537 'key21' => 'value21',
538 'key23' => array(
539 'key231' => 'value231',
540 ),
541 ),
542 );
543 $expectedResult = array(
544 'key2' => array(
545 'key22' => 'value22',
546 'key23' => array(
547 'key232' => 'value232',
548 ),
549 ),
550 );
551 $actualResult = t3lib_div::arrayDiffAssocRecursive($array1, $array2);
552 $this->assertEquals($expectedResult, $actualResult);
553 }
554
555 /**
556 * Test if arrays are correctly diffed if types are different.
557 *
558 * @test
559 * @see t3lib_div::arrayDiffAssocRecursive
560 */
561 public function doesArrayDiffAssocRecursiveCorrectlyHandleMixedArrays() {
562 $array1 = array(
563 'key1' => array(
564 'key11' => 'value11',
565 'key12' => 'value12',
566 ),
567 'key2' => 'value2',
568 'key3' => 'value3',
569 );
570 $array2 = array(
571 'key1' => 'value1',
572 'key2' => array(
573 'key21' => 'value21',
574 ),
575 );
576 $expectedResult = array(
577 'key3' => 'value3',
578 );
579 $actualResult = t3lib_div::arrayDiffAssocRecursive($array1, $array2);
580 $this->assertEquals($expectedResult, $actualResult);
581 }
582
583 //////////////////////////////////////
584 // Tests concerning removeDotsFromTS
585 //////////////////////////////////////
586
587 /**
588 * Tests whether removeDotsFromTS() behaves correctly.
589 * @test
590 * @see t3lib_div::removeDotsFromTS()
591 */
592 public function doesRemoveDotsFromTypoScriptSucceed() {
593 $typoScript = array(
594 'propertyA.' => array(
595 'keyA.' => array(
596 'valueA' => 1,
597 ),
598 'keyB' => 2,
599 ),
600 'propertyB' => 3,
601 );
602
603 $expectedResult = array(
604 'propertyA' => array(
605 'keyA' => array(
606 'valueA' => 1,
607 ),
608 'keyB' => 2,
609 ),
610 'propertyB' => 3,
611 );
612
613 $this->assertEquals($expectedResult, t3lib_div::removeDotsFromTS($typoScript));
614 }
615
616 /**
617 * Tests whether removeDotsFromTS() behaves correctly.
618 * @test
619 * @see t3lib_div::removeDotsFromTS()
620 */
621 public function doesRemoveDotsFromTypoScriptCorrectlyOverrideWithArray() {
622 $typoScript = array(
623 'propertyA.' => array(
624 'keyA' => 'getsOverridden',
625 'keyA.' => array(
626 'valueA' => 1,
627 ),
628 'keyB' => 2,
629 ),
630 'propertyB' => 3,
631 );
632
633 $expectedResult = array(
634 'propertyA' => array(
635 'keyA' => array(
636 'valueA' => 1,
637 ),
638 'keyB' => 2,
639 ),
640 'propertyB' => 3,
641 );
642
643 $this->assertEquals($expectedResult, t3lib_div::removeDotsFromTS($typoScript));
644 }
645
646 /**
647 * Tests whether removeDotsFromTS() behaves correctly.
648 * @test
649 * @see t3lib_div::removeDotsFromTS()
650 */
651 public function doesRemoveDotsFromTypoScriptCorrectlyOverrideWithScalar() {
652 $typoScript = array(
653 'propertyA.' => array(
654 'keyA.' => array(
655 'valueA' => 1,
656 ),
657 'keyA' => 'willOverride',
658 'keyB' => 2,
659 ),
660 'propertyB' => 3,
661 );
662
663 $expectedResult = array(
664 'propertyA' => array(
665 'keyA' => 'willOverride',
666 'keyB' => 2,
667 ),
668 'propertyB' => 3,
669 );
670
671 $this->assertEquals($expectedResult, t3lib_div::removeDotsFromTS($typoScript));
672 }
673
674 /**
675 * Tests whether getDirs() returns an array of diretories from a given path
676 * @test
677 * @see t3lib_div::getDirs($path)
678 */
679 public function checkGetDirsReturnsArrayOfDirectoriesFromGivenDirectory() {
680 $path = PATH_t3lib;
681 $directories = t3lib_div::get_dirs($path);
682
683 $this->assertType('array', $directories);
684 }
685
686 /**
687 * Tests whether getDirs() returns the string 'error' in case of problems reading from the given path
688 * @test
689 * @see t3lib_div::getDirs($path)
690 */
691 public function checkGetDirsReturnsStringErrorOnPathFailure() {
692 $path = 'foo';
693 $result = t3lib_div::get_dirs($path);
694 $expectedResult = 'error';
695
696 $this->assertEquals($expectedResult, $result);
697 }
698
699
700 //////////////////////////////////
701 // Tests concerning quoteJSvalue
702 //////////////////////////////////
703
704 /**
705 * @test
706 */
707 public function quoteJSvalueHtmlspecialcharsDataByDefault() {
708 $this->assertContains(
709 '&gt;',
710 t3lib_div::quoteJSvalue('>')
711 );
712 }
713
714 /**
715 * @test
716 */
717 public function quoteJSvaluetHtmlspecialcharsDataWithinCDataSetToFalse() {
718 $this->assertContains(
719 '&gt;',
720 t3lib_div::quoteJSvalue('>', false)
721 );
722 }
723
724 /**
725 * @test
726 */
727 public function quoteJSvaluetNotHtmlspecialcharsDataWithinCDataSetToTrue() {
728 $this->assertContains(
729 '>',
730 t3lib_div::quoteJSvalue('>', true)
731 );
732 }
733
734 /**
735 * @test
736 */
737 public function quoteJSvalueReturnsEmptyStringQuotedInSingleQuotes() {
738 $this->assertEquals(
739 "''",
740 t3lib_div::quoteJSvalue("", true)
741 );
742 }
743
744 /**
745 * @test
746 */
747 public function quoteJSvalueNotModifiesStringWithoutSpecialCharacters() {
748 $this->assertEquals(
749 "'Hello world!'",
750 t3lib_div::quoteJSvalue("Hello world!", true)
751 );
752 }
753
754 /**
755 * @test
756 */
757 public function quoteJSvalueEscapesSingleQuote() {
758 $this->assertEquals(
759 "'\\''",
760 t3lib_div::quoteJSvalue("'", true)
761 );
762 }
763
764 /**
765 * @test
766 */
767 public function quoteJSvalueEscapesDoubleQuoteWithinCDataSetToTrue() {
768 $this->assertEquals(
769 "'\\\"'",
770 t3lib_div::quoteJSvalue('"', true)
771 );
772 }
773
774 /**
775 * @test
776 */
777 public function quoteJSvalueEscapesAndHtmlspecialcharsDoubleQuoteWithinCDataSetToFalse() {
778 $this->assertEquals(
779 "'\\&quot;'",
780 t3lib_div::quoteJSvalue('"', false)
781 );
782 }
783
784 /**
785 * @test
786 */
787 public function quoteJSvalueEscapesTab() {
788 $this->assertEquals(
789 "'" . '\t' . "'",
790 t3lib_div::quoteJSvalue(chr(9))
791 );
792 }
793
794 /**
795 * @test
796 */
797 public function quoteJSvalueEscapesLinefeed() {
798 $this->assertEquals(
799 "'" . '\n' . "'",
800 t3lib_div::quoteJSvalue(chr(10))
801 );
802 }
803
804 /**
805 * @test
806 */
807 public function quoteJSvalueEscapesCarriageReturn() {
808 $this->assertEquals(
809 "'" . '\r' . "'",
810 t3lib_div::quoteJSvalue(chr(13))
811 );
812 }
813
814 /**
815 * @test
816 */
817 public function quoteJSvalueEscapesBackslah() {
818 $this->assertEquals(
819 "'\\\\'",
820 t3lib_div::quoteJSvalue('\\')
821 );
822 }
823
824 /**
825 * Tests the locallangXMLOverride feature of readLLfile()
826 * @test
827 */
828 public function readLLfileLocallangXMLOverride() {
829 $unique = uniqid('locallangXMLOverrideTest');
830
831 $xml = '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
832 <T3locallang>
833 <data type="array">
834 <languageKey index="default" type="array">
835 <label index="buttons.logout">EXIT</label>
836 </languageKey>
837 </data>
838 </T3locallang>';
839
840 $file = PATH_site . 'typo3temp/' . $unique . '.xml';
841 t3lib_div::writeFileToTypo3tempDir($file, $xml);
842
843 // get default value
844 $defaultLL = t3lib_div::readLLfile('EXT:lang/locallang_core.xml', 'default');
845
846 // set override file
847 $GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']['EXT:lang/locallang_core.xml'][$unique] = $file;
848
849 // get override value
850 $overrideLL = t3lib_div::readLLfile('EXT:lang/locallang_core.xml', 'default');
851
852 $this->assertNotEquals($overrideLL['default']['buttons.logout'], '');
853 $this->assertNotEquals($defaultLL['default']['buttons.logout'], $overrideLL['default']['buttons.logout']);
854 $this->assertEquals($overrideLL['default']['buttons.logout'], 'EXIT');
855
856 unlink($file);
857 }
858 }
859
860 ?>