[FEATURE] Add jQuery API to the pagerenderer
[Packages/TYPO3.CMS.git] / tests / Unit / t3lib / class.t3lib_pagerendererTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2011 Steffen Kamper (info@sk-typo3.de)
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 the t3lib_PageRenderer class in the TYPO3 core.
28 *
29 * @package TYPO3
30 * @subpackage t3lib
31 *
32 * @author Steffen Kamper (info@sk-typo3.de)
33 */
34 class t3lib_PageRendererTest extends tx_phpunit_testcase {
35
36 /**
37 * Enable backup of global and system variables
38 *
39 * @var boolean
40 */
41 protected $backupGlobals = TRUE;
42
43 /**
44 * Exclude TYPO3_DB from backup/ restore of $GLOBALS
45 * because resource types cannot be handled during serializing
46 *
47 * @var array
48 */
49 protected $backupGlobalsBlacklist = array('TYPO3_DB');
50
51 /**
52 * @var t3lib_PageRenderer
53 */
54 private $fixture;
55
56 public function setUp() {
57 $this->fixture = new t3lib_PageRenderer();
58 $this->fixture->setCharSet($GLOBALS['LANG']->charSet);
59 }
60
61 public function tearDown() {
62 unset(
63 $this->fixture
64 );
65 }
66
67
68 //////////////////////////////////////
69 // Tests for the basic functionality
70 //////////////////////////////////////
71
72 /**
73 * @test
74 */
75 public function fixtureCanBeCreated() {
76 $this->assertTrue(
77 $this->fixture instanceof t3lib_PageRenderer
78 );
79 }
80
81 //////////////////////
82 // test functions
83 //////////////////////
84
85 /**
86 * test set xml prolog and doctype
87 *
88 */
89 public function testSetXmlPrologAndDocType() {
90
91 $expectedReturnValue = '<?xml version="1.0" encoding="utf-8" ?>';
92 $this->fixture->setXmlPrologAndDocType('<?xml version="1.0" encoding="utf-8" ?>');
93 $out = $this->fixture->render();
94
95 $this->assertContains(
96 $expectedReturnValue,
97 $out
98 );
99 }
100
101 /**
102 * test set title
103 *
104 */
105 public function testSetTitle() {
106
107 $expectedReturnValue = '<title>This is the title</title>';
108 $this->fixture->setTitle('This is the title');
109 $out = $this->fixture->render();
110
111 $this->assertContains(
112 $expectedReturnValue,
113 $out
114 );
115 }
116
117 /**
118 * test set charset
119 *
120 */
121 public function testSetCharset() {
122
123 $expectedReturnValue = '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
124 $this->fixture->setCharset('utf-8');
125 $out = $this->fixture->render();
126
127 $this->assertContains(
128 $expectedReturnValue,
129 $out
130 );
131 }
132
133 /**
134 * test set favicon
135 *
136 */
137 public function testSetFavIcon() {
138
139 $expectedReturnValue1 = '<link rel="shortcut icon" href="http://google.com/favicon.ico" />';
140 $expectedReturnValue2 = '<link rel="icon" href="http://google.com/favicon.ico" />';
141 $this->fixture->setFavIcon('http://google.com/favicon.ico');
142 $out = $this->fixture->render();
143
144 $this->assertContains(
145 $expectedReturnValue1,
146 $out
147 );
148 $this->assertContains(
149 $expectedReturnValue2,
150 $out
151 );
152
153 }
154
155 /**
156 * test set baseUrl
157 *
158 */
159 public function testSetBaseUrl() {
160
161 $expectedReturnValue = '<base href="http://ggogle.com/" />';
162 $this->fixture->setBaseUrl('http://ggogle.com/');
163 $out = $this->fixture->render();
164
165 $this->assertContains(
166 $expectedReturnValue,
167 $out
168 );
169 }
170
171 /**
172 * test add meta tag
173 *
174 */
175 public function testAddMetaTag() {
176
177 $expectedReturnValue = '<meta name="author" content="Anna Lyse">';
178 $this->fixture->addMetaTag('<meta name="author" content="Anna Lyse">');
179 $out = $this->fixture->render();
180
181 $this->assertContains(
182 $expectedReturnValue,
183 $out
184 );
185 }
186
187 /**
188 * test add inline comment
189 *
190 */
191 public function testAddInlineComment() {
192
193 $expectedReturnValue = 'this is an inline comment written by unit test';
194 $this->fixture->addInlineComment('this is an inline comment written by unit test');
195 $out = $this->fixture->render();
196
197 $this->assertContains(
198 $expectedReturnValue,
199 $out
200 );
201 }
202
203 /**
204 * test add header data
205 *
206 */
207 public function testAddHeaderData() {
208
209 $expectedReturnValue = '<tag method="private" name="test" />';
210 $this->fixture->addHeaderData('<tag method="private" name="test" />');
211 $out = $this->fixture->render();
212
213 $this->assertContains(
214 $expectedReturnValue,
215 $out
216 );
217 }
218
219 /**
220 * test add footer data
221 *
222 */
223 public function testAddFooterData() {
224
225 $expectedReturnValue = '<tag method="private" name="test" />';
226 $this->fixture->addFooterData('<tag method="private" name="test" />');
227 $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
228
229 $this->assertContains(
230 $expectedReturnValue,
231 $out
232 );
233 }
234
235 /**
236 * test add JS library file
237 *
238 */
239 public function testAddJsLibrary() {
240
241 $expectedRegExp = '#<script src="fileadmin/test\.(js|\d+\.js|js\?\d+)" type="text/javascript"></script>#';
242 $this->fixture->addJsLibrary('test', 'fileadmin/test.js');
243 $out = $this->fixture->render();
244
245 $this->assertRegExp(
246 $expectedRegExp,
247 $out
248 );
249 }
250
251
252 /**
253 * test add JS footer library file
254 *
255 */
256 public function testAddJsFooterLibrary() {
257
258 $expectedRegExp = '#<script src="fileadmin/test\.(js|\d+\.js|js\?\d+)" type="text/javascript"></script>#';
259 $this->fixture->addJsFooterLibrary('test', 'fileadmin/test.js');
260 $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
261
262 $this->assertRegExp(
263 $expectedRegExp,
264 $out
265 );
266 }
267
268 /**
269 * test add JS file
270 *
271 */
272 public function testAddJsFile() {
273
274 $expectedRegExp = '#<script src="fileadmin/test\.(js|\d+\.js|js\?\d+)" type="text/javascript"></script>#';
275 $this->fixture->addJsFile('fileadmin/test.js');
276 $out = $this->fixture->render();
277
278 $this->assertRegExp(
279 $expectedRegExp,
280 $out
281 );
282 }
283
284 /**
285 * test add JS file for footer
286 *
287 */
288 public function testAddJsFooterFile() {
289
290 $expectedRegExp = '#<script src="fileadmin/test\.(js|\d+\.js|js\?\d+)" type="text/javascript"></script>#';
291 $this->fixture->addJsFooterFile('fileadmin/test.js');
292 $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
293
294 $this->assertRegExp(
295 $expectedRegExp,
296 $out
297 );
298 }
299
300 /**
301 * test add JS inline
302 *
303 */
304 public function testAddJsInlineCode() {
305
306 $expectedReturnValue = 'var x = "testvar"';
307 $this->fixture->addJsInlineCode('test', 'var x = "testvar"');
308 $out = $this->fixture->render();
309
310 $this->assertContains(
311 $expectedReturnValue,
312 $out
313 );
314 }
315
316 /**
317 * test add JS inline for footer
318 *
319 */
320 public function testAddJsFooterInlineCode() {
321
322 $expectedReturnValue = 'var x = "testvar"';
323 $this->fixture->addJsFooterInlineCode('test', 'var x = "testvar"');
324 $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
325
326 $this->assertContains(
327 $expectedReturnValue,
328 $out
329 );
330 }
331
332 /**
333 * test add JS handler
334 *
335 */
336 public function testAddExtOnReadyCode() {
337
338 $expectedReturnValue1 = 'Ext.onReady(function() {';
339 $expectedReturnValue2 = 'var x = "testvar";';
340 $this->fixture->loadExtJS();
341 $this->fixture->addExtOnReadyCode('var x = "testvar";');
342 $out = $this->fixture->render();
343
344 $this->assertContains(
345 $expectedReturnValue1,
346 $out
347 );
348
349 $this->assertContains(
350 $expectedReturnValue2,
351 $out
352 );
353
354 }
355
356 /**
357 * test add CSS file
358 *
359 */
360 public function testAddCssFile() {
361
362 $expectedReturnValue = '<link rel="stylesheet" type="text/css" href="fileadmin/test.css" media="all" />';
363 $this->fixture->addCssFile('fileadmin/test.css');
364 $out = $this->fixture->render();
365
366 $this->assertContains(
367 $expectedReturnValue,
368 $out
369 );
370 }
371
372 /**
373 * test add CSS inline
374 *
375 */
376 public function testAddCssInlineBlock() {
377
378 $expectedReturnValue = 'body {margin:20px;}';
379 $this->fixture->addCssInlineBlock('general', 'body {margin:20px;}');
380 $out = $this->fixture->render();
381
382 $this->assertContains(
383 $expectedReturnValue,
384 $out
385 );
386 }
387
388 /**
389 * test add CSS inline and force on top
390 *
391 */
392 public function testAddCssInlineBlockForceOnTop() {
393
394 $expectedReturnValue = '/*general1*/' . LF . 'h1 {margin:20px;}' . LF . '/*general*/' . LF . 'body {margin:20px;}';
395 $this->fixture->addCssInlineBlock('general', 'body {margin:20px;}');
396 $this->fixture->addCssInlineBlock('general1', 'h1 {margin:20px;}', NULL, TRUE);
397 $out = $this->fixture->render();
398
399 $this->assertContains(
400 $expectedReturnValue,
401 $out
402 );
403 }
404
405 /**
406 * test load prototype
407 *
408 */
409 public function testLoadPrototype() {
410
411 $expectedRegExp = '#<script src="contrib/prototype/prototype\.(js|\d+\.js|js\?\d+)" type="text/javascript"></script>#';
412 $this->fixture->loadPrototype();
413 $out = $this->fixture->render();
414
415 $this->assertRegExp(
416 $expectedRegExp,
417 $out
418 );
419 }
420
421 /**
422 * test load Scriptaculous
423 *
424 */
425 public function testLoadScriptaculous() {
426 $this->fixture->loadScriptaculous('slider,controls');
427 $out = $this->fixture->render();
428
429 $this->assertContains(
430 '<script src="contrib/scriptaculous/scriptaculous.js" type="text/javascript"></script>',
431 $out
432 );
433 $this->assertContains(
434 '<script src="contrib/scriptaculous/effects.js" type="text/javascript"></script>',
435 $out
436 );
437 $this->assertContains(
438 '<script src="contrib/scriptaculous/controls.js" type="text/javascript"></script>',
439 $out
440 );
441 $this->assertContains(
442 '<script src="contrib/scriptaculous/slider.js" type="text/javascript"></script>',
443 $out
444 );
445 }
446
447 /**
448 * Tests whether scriptaculous is loaded correctly when compression is enabled.
449 *
450 * @test
451 */
452 public function isScriptaculousLoadedCompressedIfConfiguredAndClientIsCapable() {
453 $_SERVER['HTTP_ACCEPT_ENCODING'] = 'gzip,deflate';
454 $GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel'] = '5';
455
456 $this->fixture->loadScriptaculous('slider,controls');
457 $this->fixture->enableCompressJavascript();
458 $out = $this->fixture->render();
459
460 $this->assertRegExp(
461 '#<script src="[^"]*/typo3temp/compressor/scriptaculous-[a-f0-9]+.js.gzip" type="text/javascript"></script>#',
462 $out
463 );
464 $this->assertRegExp(
465 '#<script src="[^"]*/typo3temp/compressor/effects-[a-f0-9]+.js.gzip" type="text/javascript"></script>#',
466 $out
467 );
468 $this->assertRegExp(
469 '#<script src="[^"]*/typo3temp/compressor/controls-[a-f0-9]+.js.gzip" type="text/javascript"></script>#',
470 $out
471 );
472 $this->assertRegExp(
473 '#<script src="[^"]*/typo3temp/compressor/slider-[a-f0-9]+.js.gzip" type="text/javascript"></script>#',
474 $out
475 );
476 }
477
478 /**
479 * Tests whether scriptaculous is correctly loaded, but without compression
480 * if the browser did not send the appropriate headers.
481 *
482 * @test
483 */
484 public function isScriptaculousNotLoadedCompressedIfClientCannotHandleCompression() {
485 $_SERVER['HTTP_ACCEPT_ENCODING'] = '';
486 $GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel'] = '5';
487
488 $this->fixture->loadScriptaculous('slider,controls');
489 $this->fixture->enableCompressJavascript();
490 $out = $this->fixture->render();
491
492 $this->assertRegExp(
493 '#<script src="[^"]*/typo3temp/compressor/scriptaculous-[a-f0-9]+.js" type="text/javascript"></script>#',
494 $out
495 );
496 $this->assertRegExp(
497 '#<script src="[^"]*/typo3temp/compressor/effects-[a-f0-9]+.js" type="text/javascript"></script>#',
498 $out
499 );
500 $this->assertRegExp(
501 '#<script src="[^"]*/typo3temp/compressor/controls-[a-f0-9]+.js" type="text/javascript"></script>#',
502 $out
503 );
504 $this->assertRegExp(
505 '#<script src="[^"]*/typo3temp/compressor/slider-[a-f0-9]+.js" type="text/javascript"></script>#',
506 $out
507 );
508 }
509
510 /**
511 * Tests whether scriptaculous is correctly loaded, but without compression
512 * if no compression is configured.
513 *
514 * @test
515 */
516 public function isScriptaculousNotLoadedCompressedIfCompressionIsNotConfigured() {
517 $_SERVER['HTTP_ACCEPT_ENCODING'] = 'gzip,deflate';
518 $GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel'] = '';
519
520 $this->fixture->loadScriptaculous('slider,controls');
521 $this->fixture->enableCompressJavascript();
522 $out = $this->fixture->render();
523
524 $this->assertRegExp(
525 '#<script src="[^"]*/typo3temp/compressor/scriptaculous-[a-f0-9]+.js" type="text/javascript"></script>#',
526 $out
527 );
528 $this->assertRegExp(
529 '#<script src="[^"]*/typo3temp/compressor/effects-[a-f0-9]+.js" type="text/javascript"></script>#',
530 $out
531 );
532 $this->assertRegExp(
533 '#<script src="[^"]*/typo3temp/compressor/controls-[a-f0-9]+.js" type="text/javascript"></script>#',
534 $out
535 );
536 $this->assertRegExp(
537 '#<script src="[^"]*/typo3temp/compressor/slider-[a-f0-9]+.js" type="text/javascript"></script>#',
538 $out
539 );
540 }
541
542 /**
543 * test load jQuery
544 * @test
545 */
546 public function loadJqueryLoadsTheLatestJqueryMinifiedVersionInNoConflictMode() {
547 $expectedRegExp =
548 '#<script src="contrib/jquery/jquery-' . t3lib_PageRenderer::JQUERY_VERSION_LATEST . '\.min\.(js|\d+\.js|js\?\d+)" type="text/javascript"></script>#';
549 $expectedStatement = 'var TYPO3 = TYPO3 || {}; TYPO3.jQuery = jQuery = jQuery.noConflict(true);';
550
551 $this->fixture->loadJquery();
552 $out = $this->fixture->render();
553
554 $this->assertRegExp(
555 $expectedRegExp,
556 $out
557 );
558
559 $this->assertContains(
560 $expectedStatement,
561 $out
562 );
563 }
564
565 /**
566 * test load jQuery
567 * @test
568 */
569 public function loadJqueryRespectsGivenNamespace() {
570 $expectedRegExp =
571 '#<script src="contrib/jquery/jquery-' . t3lib_PageRenderer::JQUERY_VERSION_LATEST . '\.min\.(js|\d+\.js|js\?\d+)" type="text/javascript"></script>#';
572 $expectedStatement = 'var TYPO3 = TYPO3 || {}; TYPO3.MyNameSpace = jQuery = jQuery.noConflict(true);';
573
574 $this->fixture->loadJquery(NULL, NULL, 'MyNameSpace');
575 $out = $this->fixture->render();
576
577 $this->assertRegExp(
578 $expectedRegExp,
579 $out
580 );
581
582 $this->assertContains(
583 $expectedStatement,
584 $out
585 );
586 }
587
588 /**
589 * test load jQuery
590 * @test
591 */
592 public function loadJqueryWithNamespaceFalseDoesNotIncludeNoConflictHandling() {
593 $expectedRegExp =
594 '#<script src="contrib/jquery/jquery-' . t3lib_PageRenderer::JQUERY_VERSION_LATEST . '\.min\.(js|\d+\.js|js\?\d+)" type="text/javascript"></script>#';
595
596 $this->fixture->loadJquery(NULL, NULL, FALSE);
597 $out = $this->fixture->render();
598
599 $this->assertRegExp(
600 $expectedRegExp,
601 $out
602 );
603
604 $this->assertNotContains('jQuery.noConflict(true);', $out);
605 }
606
607 /**
608 * test load jQuery
609 * @test
610 */
611 public function loadJqueryLoadsTheLatestJqueryVersionInNoConflictModeUncompressedInDebugMode() {
612 $expectedRegExp =
613 '#<script src="contrib/jquery/jquery-' . t3lib_PageRenderer::JQUERY_VERSION_LATEST . '\.(js|\d+\.js|js\?\d+)" type="text/javascript"></script>#';
614 $expectedStatement = 'var TYPO3 = TYPO3 || {}; TYPO3.jQuery = jQuery = jQuery.noConflict(true);';
615
616 $this->fixture->loadJquery();
617 $this->fixture->enableDebugMode();
618 $out = $this->fixture->render();
619
620 $this->assertRegExp(
621 $expectedRegExp,
622 $out
623 );
624
625 $this->assertContains(
626 $expectedStatement,
627 $out
628 );
629 }
630
631 /**
632 * @expectedException UnexpectedValueException
633 * @test
634 */
635 public function includingNotAvailableLocalJqueryVersionThrowsException() {
636 $this->fixture->loadJquery('1.3.34');
637 $this->fixture->render();
638 }
639
640 /**
641 * @expectedException UnexpectedValueException
642 * @test
643 */
644 public function includingJqueryWithNonAlphnumericNamespaceThrowsException() {
645 $this->fixture->loadJquery(NULL, NULL, '12sd.12fsd');
646 $this->fixture->render();
647 }
648
649 /**
650 * @return array
651 */
652 public function loadJqueryFromSourceDataProvider() {
653 $specificVersion = '1.6.3';
654 return array(
655 'google with no version number' => array(NULL, 'google', '#<script src="//ajax.googleapis.com/ajax/libs/jquery/' . t3lib_PageRenderer::JQUERY_VERSION_LATEST . '/jquery.js" type="text/javascript"></script>#'),
656 'google with version number' => array($specificVersion, 'google', '#<script src="//ajax.googleapis.com/ajax/libs/jquery/' . $specificVersion . '/jquery.js" type="text/javascript"></script>#'),
657 'msn with no version number' => array(NULL, 'msn', '#<script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-' . t3lib_PageRenderer::JQUERY_VERSION_LATEST . '.js" type="text/javascript"></script>#'),
658 'msn with version number' => array($specificVersion, 'msn', '#<script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-' . $specificVersion . '.js" type="text/javascript"></script>#'),
659 'jquery with no version number' => array(NULL, 'jquery', '#<script src="http://code.jquery.com/jquery-' . t3lib_PageRenderer::JQUERY_VERSION_LATEST . '.js" type="text/javascript"></script>#'),
660 'jquery with version number' => array($specificVersion, 'jquery', '#<script src="http://code.jquery.com/jquery-' . $specificVersion . '.js" type="text/javascript"></script>#'),
661 'jquery with custom URL' => array($specificVersion, 'http://my.cool.cdn/foo/jquery.js', '#<script src="http://my.cool.cdn/foo/jquery.js" type="text/javascript"></script>#'),
662 );
663 }
664
665
666 /**
667 * Tests whether jQuery is correctly loaded, from the respective CDNs
668 *
669 * @dataProvider loadJqueryFromSourceDataProvider
670 * @test
671 */
672 public function isJqueryLoadedFromSourceUncompressedIfDebugModeIsEnabled($version, $source, $regex) {
673 $this->fixture->loadJquery($version, $source);
674 $this->fixture->enableDebugMode();
675 $out = $this->fixture->render();
676
677 $this->assertRegExp(
678 $regex,
679 $out
680 );
681 }
682
683
684 /**
685 * @return array
686 */
687 public function loadJqueryMinifiedFromSourceDataProvider() {
688 $specificVersion = '1.6.3';
689 return array(
690 'google with no version number' => array(NULL, 'google', '#<script src="//ajax.googleapis.com/ajax/libs/jquery/' . t3lib_PageRenderer::JQUERY_VERSION_LATEST . '/jquery.min.js" type="text/javascript"></script>#'),
691 'google with version number' => array($specificVersion, 'google', '#<script src="//ajax.googleapis.com/ajax/libs/jquery/' . $specificVersion . '/jquery.min.js" type="text/javascript"></script>#'),
692 'msn with no version number' => array(NULL, 'msn', '#<script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-' . t3lib_PageRenderer::JQUERY_VERSION_LATEST . '.min.js" type="text/javascript"></script>#'),
693 'msn with version number' => array($specificVersion, 'msn', '#<script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-' . $specificVersion . '.min.js" type="text/javascript"></script>#'),
694 'jquery with no version number' => array(NULL, 'jquery', '#<script src="http://code.jquery.com/jquery-' . t3lib_PageRenderer::JQUERY_VERSION_LATEST . '.min.js" type="text/javascript"></script>#'),
695 'jquery with version number' => array($specificVersion, 'jquery', '#<script src="http://code.jquery.com/jquery-' . $specificVersion . '.min.js" type="text/javascript"></script>#'),
696 );
697 }
698
699
700 /**
701 * Tests whether jQuery is correctly loaded, from the respective CDNs
702 *
703 * @dataProvider loadJqueryMinifiedFromSourceDataProvider
704 * @test
705 */
706 public function isJqueryLoadedMinifiedFromSourceByDefault($version, $cdn, $regex) {
707 $this->fixture->loadJquery($version, $cdn);
708 $out = $this->fixture->render();
709
710 $this->assertRegExp(
711 $regex,
712 $out
713 );
714 }
715
716 /**
717 * test load ExtJS
718 *
719 */
720 public function testLoadExtJS() {
721
722 $expectedRegExp = '#<script src="contrib/extjs/adapter/jquery/ext-jquery-adapter\.(js|\d+\.js|js\?\d+)" type="text/javascript"></script>' . LF . '<script src="contrib/extjs/ext-all\.(js|\d+\.js|js\?\d+)" type="text/javascript"></script>#m';
723 $this->fixture->loadExtJS(TRUE, TRUE, 'jquery');
724 $out = $this->fixture->render();
725
726 $this->assertRegExp(
727 $expectedRegExp,
728 $out
729 );
730 }
731
732 /**
733 * test load ExtCore
734 *
735 */
736 public function testLoadExtCore() {
737
738 $expectedRegExp = '#<script src="contrib/extjs/ext-core\.(js|\d+\.js|js\?\d+)" type="text/javascript"></script>#';
739 $this->fixture->loadExtCore();
740 $out = $this->fixture->render();
741
742 $this->assertRegExp(
743 $expectedRegExp,
744 $out
745 );
746 }
747
748 /**
749 * test enable ExtJsDebug
750 *
751 */
752 public function testEnableExtJsDebug() {
753
754 $expectedRegExp = '#<script src="contrib/extjs/ext-all-debug\.(js|\d+\.js|js\?\d+)" type="text/javascript"></script>#';
755 $this->fixture->loadExtJS(TRUE, TRUE, 'jquery');
756 $this->fixture->enableExtJsDebug();
757 $out = $this->fixture->render();
758
759 $this->assertRegExp(
760 $expectedRegExp,
761 $out
762 );
763 }
764
765 /**
766 * test enable ExtCoreDebug
767 *
768 */
769 public function testEnableExtCoreDebug() {
770
771 $expectedRegExp = '#<script src="contrib/extjs/ext-core-debug\.(js|\d+\.js|js\?\d+)" type="text/javascript"></script>#';
772 $this->fixture->loadExtCore();
773 $this->fixture->enableExtCoreDebug();
774 $out = $this->fixture->render();
775
776 $this->assertRegExp(
777 $expectedRegExp,
778 $out
779 );
780 }
781
782 /**
783 * test inline language label
784 *
785 */
786 public function testAddInlineLanguageLabel() {
787
788 $expectedReturnValue = 'TYPO3.lang = {"myKey":"myValue"}';
789 $this->fixture->loadExtJS();
790 $this->fixture->addInlineLanguageLabel('myKey', 'myValue');
791 $out = $this->fixture->enableMoveJsFromHeaderToFooter();
792 $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
793
794 $this->assertContains(
795 $expectedReturnValue,
796 $out
797 );
798 }
799
800 /**
801 * test inline language label as array
802 *
803 */
804 public function testAddInlineLanguageLabelArray() {
805
806 $expectedReturnValue = 'TYPO3.lang = {"myKey1":"myValue1","myKey2":"myValue2"}';
807 $this->fixture->loadExtJS();
808 $this->fixture->addInlineLanguageLabelArray(array('myKey1' => 'myValue1', 'myKey2' => 'myValue2',));
809 $out = $this->fixture->enableMoveJsFromHeaderToFooter();
810 $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
811
812 $this->assertContains(
813 $expectedReturnValue,
814 $out
815 );
816 }
817
818 /**
819 * test inline language label as array get merged
820 *
821 */
822 public function testAddInlineLanguageLabelArrayMerged() {
823
824 $expectedReturnValue = 'TYPO3.lang = {"myKey1":"myValue1","myKey2":"myValue2"}';
825 $this->fixture->loadExtJS();
826 $this->fixture->addInlineLanguageLabelArray(array('myKey1' => 'myValue1',));
827 $this->fixture->addInlineLanguageLabelArray(array('myKey2' => 'myValue2',));
828 $out = $this->fixture->enableMoveJsFromHeaderToFooter();
829 $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
830
831 $this->assertContains(
832 $expectedReturnValue,
833 $out
834 );
835 }
836
837 /**
838 * test inline setting
839 *
840 */
841 public function testAddInlineSetting() {
842
843 $expectedReturnValue = 'TYPO3.settings = {"myApp":{"myKey":"myValue"}};';
844 $this->fixture->loadExtJS();
845 $this->fixture->addInlineSetting('myApp', 'myKey', 'myValue');
846 $out = $this->fixture->enableMoveJsFromHeaderToFooter();
847 $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
848
849 $this->assertContains(
850 $expectedReturnValue,
851 $out
852 );
853 }
854
855 /**
856 * test inline settings with array
857 *
858 */
859 public function testAddInlineSettingArray() {
860
861 $expectedReturnValue = 'TYPO3.settings = {"myApp":{"myKey1":"myValue1","myKey2":"myValue2"}};';
862 $this->fixture->loadExtJS();
863 $this->fixture->addInlineSettingArray('myApp', array('myKey1' => 'myValue1', 'myKey2' => 'myValue2',));
864 $out = $this->fixture->enableMoveJsFromHeaderToFooter();
865 $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
866
867 $this->assertContains(
868 $expectedReturnValue,
869 $out
870 );
871 }
872
873 /**
874 * test inline settings with array get merged
875 *
876 */
877 public function testAddInlineSettingArrayMerged() {
878
879 $expectedReturnValue = 'TYPO3.settings = {"myApp":{"myKey1":"myValue1","myKey2":"myValue2"}};';
880 $this->fixture->loadExtJS();
881 $this->fixture->addInlineSettingArray('myApp', array('myKey1' => 'myValue1',));
882 $this->fixture->addInlineSettingArray('myApp', array('myKey2' => 'myValue2',));
883 $out = $this->fixture->enableMoveJsFromHeaderToFooter();
884 $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
885
886 $this->assertContains(
887 $expectedReturnValue,
888 $out
889 );
890 }
891
892 /**
893 * test add body content
894 *
895 */
896 public function testAddBodyContent() {
897 $expectedReturnValue = 'ABCDE';
898 $this->fixture->addBodyContent('A');
899 $this->fixture->addBodyContent('B');
900 $this->fixture->addBodyContent('C');
901 $this->fixture->addBodyContent('D');
902 $this->fixture->addBodyContent('E');
903
904 $out = $this->fixture->getBodyContent();
905 $this->assertEquals(
906 $expectedReturnValue,
907 $out
908 );
909 }
910
911
912 /**
913 * test set body content
914 *
915 */
916 public function testSetBodyContent() {
917 $expectedReturnValue = 'ABCDE';
918 $this->fixture->setBodyContent('ABCDE');
919
920 $out = $this->fixture->getBodyContent();
921 $this->assertEquals(
922 $expectedReturnValue,
923 $out
924 );
925
926 $out = $this->fixture->render();
927
928 $this->assertContains(
929 $expectedReturnValue,
930 $out
931 );
932 }
933
934 /**
935 * Tests the addInlineLanguageLabelFile() method.
936 *
937 * @test
938 * @expectedException RuntimeException
939 */
940 public function areInlineLanguageLabelsNotProcessable() {
941 $this->fixture->setLanguage(NULL);
942 $this->fixture->addInlineLanguageLabelFile(
943 'EXT:lang/locallang_core.xml'
944 );
945 $out = $this->fixture->render();
946 }
947
948 /**
949 * Tests the addInlineLanguageLabelFile() method.
950 *
951 * @test
952 */
953 public function areInlineLanguageLabelsPassed() {
954 $this->fixture->setLanguage($GLOBALS['LANG']->lang);
955 $this->fixture->addInlineLanguageLabelFile(
956 'EXT:lang/locallang_core.xml'
957 );
958
959 $out = $this->fixture->render();
960
961 $this->assertContains('labels.beUser', $out);
962 $this->assertContains('labels.feUser', $out);
963 }
964
965 /**
966 * Tests the addInlineLanguageLabelFile() method.
967 *
968 * @test
969 */
970 public function areInlineLanguageLabelsEmptyOnNonExistingFile() {
971 $this->fixture->addInlineLanguageLabelFile(
972 ''
973 );
974
975 $inlineLanguageLabelFiles = $this->fixture->getInlineLanguageLabelFiles();
976 $this->assertEquals(array(), $inlineLanguageLabelFiles);
977 }
978
979 /**
980 * Tests the addInlineLanguageLabelFile() method.
981 *
982 * @test
983 */
984 public function areInlineLanguageLabelsSelected() {
985 $this->fixture->setLanguage($GLOBALS['LANG']->lang);
986 $this->fixture->addInlineLanguageLabelFile(
987 'EXT:lang/locallang_core.xml',
988 'labels.'
989 );
990
991 $out = $this->fixture->render();
992 $this->assertContains('labels.beUser', $out);
993 $this->assertContains('labels.feUser', $out);
994 }
995
996 /**
997 * Tests the addInlineLanguageLabelFile() method.
998 *
999 * @test
1000 */
1001 public function areInlineLanguageLabelsSelectedAndStripped() {
1002 $this->fixture->setLanguage($GLOBALS['LANG']->lang);
1003 $this->fixture->addInlineLanguageLabelFile(
1004 'EXT:lang/locallang_core.xml',
1005 'labels.',
1006 'lock'
1007 );
1008
1009 $out = $this->fixture->render();
1010
1011 $this->assertContains('edRecord', $out);
1012 $this->assertContains('edRecord_content', $out);
1013 $this->assertContains('edRecordUser', $out);
1014 }
1015 }
1016 ?>