Fixed bug #11985: Optimize disposal of t3lib_PageRenderer
[Packages/TYPO3.CMS.git] / tests / t3lib / t3lib_pagerenderer_testcase.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 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_PageRenderer_testcase extends tx_phpunit_testcase {
35 /**
36 * @var t3lib_PageRenderer
37 */
38 private $fixture;
39
40 public function setUp() {
41 $this->fixture = new t3lib_PageRenderer();
42 }
43
44 public function tearDown() {
45 unset(
46 $this->fixture
47 );
48 }
49
50
51 //////////////////////////////////////
52 // Tests for the basic functionality
53 //////////////////////////////////////
54
55 /**
56 * @test
57 */
58 public function fixtureCanBeCreated() {
59 $this->assertTrue(
60 $this->fixture instanceof t3lib_PageRenderer
61 );
62 }
63
64 //////////////////////
65 // test functions
66 //////////////////////
67
68 /**
69 * test set xml prolog and doctype
70 *
71 */
72 public function testSetXmlPrologAndDocType() {
73
74 $expectedReturnValue = '<?xml version="1.0" encoding="utf-8" ?>';
75 $this->fixture->setXmlPrologAndDocType('<?xml version="1.0" encoding="utf-8" ?>');
76 $out = $this->fixture->render();
77
78 $this->assertContains(
79 $expectedReturnValue,
80 $out
81 );
82 }
83
84 /**
85 * test set title
86 *
87 */
88 public function testSetTitle() {
89
90 $expectedReturnValue = '<title>This is the title</title>';
91 $this->fixture->setTitle('This is the title');
92 $out = $this->fixture->render();
93
94 $this->assertContains(
95 $expectedReturnValue,
96 $out
97 );
98 }
99
100 /**
101 * test set charset
102 *
103 */
104 public function testSetCharset() {
105
106 $expectedReturnValue = '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
107 $this->fixture->setCharset('utf-8');
108 $out = $this->fixture->render();
109
110 $this->assertContains(
111 $expectedReturnValue,
112 $out
113 );
114 }
115
116 /**
117 * test set favicon
118 *
119 */
120 public function testSetFavIcon() {
121
122 $expectedReturnValue1 = '<link rel="shortcut icon" href="http://google.com/favicon.ico" />';
123 $expectedReturnValue2 = '<link rel="icon" href="http://google.com/favicon.ico" />';
124 $this->fixture->setFavIcon('http://google.com/favicon.ico');
125 $out = $this->fixture->render();
126
127 $this->assertContains(
128 $expectedReturnValue1,
129 $out
130 );
131 $this->assertContains(
132 $expectedReturnValue2,
133 $out
134 );
135
136 }
137
138 /**
139 * test set baseUrl
140 *
141 */
142 public function testSetBaseUrl() {
143
144 $expectedReturnValue = '<base href="http://ggogle.com/" />';
145 $this->fixture->setBaseUrl('http://ggogle.com/');
146 $out = $this->fixture->render();
147
148 $this->assertContains(
149 $expectedReturnValue,
150 $out
151 );
152 }
153
154 /**
155 * test add meta tag
156 *
157 */
158 public function testAddMetaTag() {
159
160 $expectedReturnValue = '<meta name="author" content="Anna Lyse">';
161 $this->fixture->addMetaTag('<meta name="author" content="Anna Lyse">');
162 $out = $this->fixture->render();
163
164 $this->assertContains(
165 $expectedReturnValue,
166 $out
167 );
168 }
169
170 /**
171 * test add inline comment
172 *
173 */
174 public function testAddInlineComment() {
175
176 $expectedReturnValue = 'this is an inline comment written by unit test';
177 $this->fixture->addInlineComment('this is an inline comment written by unit test');
178 $out = $this->fixture->render();
179
180 $this->assertContains(
181 $expectedReturnValue,
182 $out
183 );
184 }
185
186 /**
187 * test add header data
188 *
189 */
190 public function testAddHeaderData() {
191
192 $expectedReturnValue = '<tag method="private" name="test" />';
193 $this->fixture->addHeaderData('<tag method="private" name="test" />');
194 $out = $this->fixture->render();
195
196 $this->assertContains(
197 $expectedReturnValue,
198 $out
199 );
200 }
201
202 /**
203 * test add footer data
204 *
205 */
206 public function testAddFooterData() {
207
208 $expectedReturnValue = '<tag method="private" name="test" />';
209 $this->fixture->addFooterData('<tag method="private" name="test" />');
210 $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
211
212 $this->assertContains(
213 $expectedReturnValue,
214 $out
215 );
216 }
217
218 /**
219 * test add JS library file
220 *
221 */
222 public function testAddJsLibrary() {
223
224 $expectedReturnValue = '<script src="fileadmin/test.js" type="text/javascript"></script>';
225 $this->fixture->addJsLibrary('test', 'fileadmin/test.js');
226 $out = $this->fixture->render();
227
228 $this->assertContains(
229 $expectedReturnValue,
230 $out
231 );
232 }
233
234
235 /**
236 * test add JS footer library file
237 *
238 */
239 public function testAddJsFooterLibrary() {
240
241 $expectedReturnValue = '<script src="fileadmin/test.js" type="text/javascript"></script>';
242 $this->fixture->addJsFooterLibrary('test', 'fileadmin/test.js');
243 $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
244
245 $this->assertContains(
246 $expectedReturnValue,
247 $out
248 );
249 }
250
251 /**
252 * test add JS file
253 *
254 */
255 public function testAddJsFile() {
256
257 $expectedReturnValue = '<script src="fileadmin/test.js" type="text/javascript"></script>';
258 $this->fixture->addJsFile('fileadmin/test.js');
259 $out = $this->fixture->render();
260
261 $this->assertContains(
262 $expectedReturnValue,
263 $out
264 );
265 }
266
267 /**
268 * test add JS file for footer
269 *
270 */
271 public function testAddJsFooterFile() {
272
273 $expectedReturnValue = '<script src="fileadmin/test.js" type="text/javascript"></script>';
274 $this->fixture->addJsFooterFile('fileadmin/test.js');
275 $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
276
277 $this->assertContains(
278 $expectedReturnValue,
279 $out
280 );
281 }
282
283 /**
284 * test add JS inline
285 *
286 */
287 public function testAddJsInlineCode() {
288
289 $expectedReturnValue = 'var x = "testvar"';
290 $this->fixture->addJsInlineCode('test', 'var x = "testvar"');
291 $out = $this->fixture->render();
292
293 $this->assertContains(
294 $expectedReturnValue,
295 $out
296 );
297 }
298
299 /**
300 * test add JS inline for footer
301 *
302 */
303 public function testAddJsFooterInlineCode() {
304
305 $expectedReturnValue = 'var x = "testvar"';
306 $this->fixture->addJsFooterInlineCode('test', 'var x = "testvar"');
307 $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
308
309 $this->assertContains(
310 $expectedReturnValue,
311 $out
312 );
313 }
314
315 /**
316 * test add JS handler
317 *
318 */
319 public function testAddExtOnReadyCode() {
320
321 $expectedReturnValue1 = 'Ext.onReady(function() {';
322 $expectedReturnValue2 = 'var x = "testvar";';
323 $this->fixture->loadExtJS();
324 $this->fixture->addExtOnReadyCode('var x = "testvar";');
325 $out = $this->fixture->render();
326
327 $this->assertContains(
328 $expectedReturnValue1,
329 $out
330 );
331
332 $this->assertContains(
333 $expectedReturnValue2,
334 $out
335 );
336
337 }
338
339 /**
340 * test add CSS file
341 *
342 */
343 public function testAddCssFile() {
344
345 $expectedReturnValue = '<link rel="stylesheet" type="text/css" href="fileadmin/test.css" media="screen" />';
346 $this->fixture->addCssFile('fileadmin/test.css');
347 $out = $this->fixture->render();
348
349 $this->assertContains(
350 $expectedReturnValue,
351 $out
352 );
353 }
354
355 /**
356 * test add CSS inline
357 *
358 */
359 public function testAddCssInlineBlock() {
360
361 $expectedReturnValue = 'body {margin:20px;}';
362 $this->fixture->addCssInlineBlock('general', 'body {margin:20px;}');
363 $out = $this->fixture->render();
364
365 $this->assertContains(
366 $expectedReturnValue,
367 $out
368 );
369 }
370
371 /**
372 * test add CSS inline and force on top
373 *
374 */
375 public function testAddCssInlineBlockForceOnTop() {
376
377 $expectedReturnValue = '/*general1*/' . chr(10) . 'h1 {margin:20px;}' . chr(10) . '/*general*/' . chr(10) . 'body {margin:20px;}';
378 $this->fixture->addCssInlineBlock('general', 'body {margin:20px;}');
379 $this->fixture->addCssInlineBlock('general1', 'h1 {margin:20px;}', NULL, TRUE);
380 $out = $this->fixture->render();
381
382 $this->assertContains(
383 $expectedReturnValue,
384 $out
385 );
386 }
387
388 /**
389 * test load prototype
390 *
391 */
392 public function testLoadPrototype() {
393
394 $expectedReturnValue = '<script src="contrib/prototype/prototype.js" type="text/javascript"></script>';
395 $this->fixture->loadPrototype();
396 $out = $this->fixture->render();
397
398 $this->assertContains(
399 $expectedReturnValue,
400 $out
401 );
402 }
403
404 /**
405 * test load Scriptaculous
406 *
407 */
408 public function testLoadScriptaculous() {
409
410 $expectedReturnValue = '<script src="contrib/scriptaculous/scriptaculous.js?load=effects,controls,slider" type="text/javascript"></script>';
411 $this->fixture->loadScriptaculous('slider,controls');
412 $out = $this->fixture->render();
413
414 $this->assertContains(
415 $expectedReturnValue,
416 $out
417 );
418 }
419
420 /**
421 * test load ExtJS
422 *
423 */
424 public function testLoadExtJS() {
425
426 $expectedReturnValue = '<script src="contrib/extjs/adapter/jquery/ext-jquery-adapter.js" type="text/javascript"></script>' . chr(10) . '<script src="contrib/extjs/ext-all.js" type="text/javascript"></script>';
427 $this->fixture->loadExtJS(TRUE, TRUE, 'jquery');
428 $out = $this->fixture->render();
429
430 $this->assertContains(
431 $expectedReturnValue,
432 $out
433 );
434 }
435
436 /**
437 * test load ExtCore
438 *
439 */
440 public function testLoadExtCore() {
441
442 $expectedReturnValue = '<script src="contrib/extjs/ext-core.js" type="text/javascript"></script>';
443 $this->fixture->loadExtCore();
444 $out = $this->fixture->render();
445
446 $this->assertContains(
447 $expectedReturnValue,
448 $out
449 );
450 }
451
452 /**
453 * test enable ExtJsDebug
454 *
455 */
456 public function testEnableExtJsDebug() {
457
458 $expectedReturnValue = '<script src="contrib/extjs/adapter/jquery/ext-jquery-adapter.js" type="text/javascript"></script>' . chr(10) . '<script src="contrib/extjs/ext-all-debug.js" type="text/javascript"></script>';
459 $this->fixture->loadExtJS(TRUE, TRUE, 'jquery');
460 $this->fixture->enableExtJsDebug();
461 $out = $this->fixture->render();
462
463 $this->assertContains(
464 $expectedReturnValue,
465 $out
466 );
467 }
468
469 /**
470 * test enable ExtCoreDebug
471 *
472 */
473 public function testEnableExtCoreDebug() {
474
475 $expectedReturnValue = '<script src="contrib/extjs/ext-core-debug.js" type="text/javascript"></script>';
476 $this->fixture->loadExtCore();
477 $this->fixture->enableExtCoreDebug();
478 $out = $this->fixture->render();
479
480 $this->assertContains(
481 $expectedReturnValue,
482 $out
483 );
484 }
485
486 /**
487 * test inline language label
488 *
489 */
490 public function testAddInlineLanguageLabel() {
491
492 $expectedReturnValue = 'TYPO3.lang = {"myKey":"myValue"}';
493 $this->fixture->loadExtJS();
494 $this->fixture->addInlineLanguageLabel('myKey', 'myValue');
495 $out = $this->fixture->enableMoveJsFromHeaderToFooter();
496 $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
497
498 $this->assertContains(
499 $expectedReturnValue,
500 $out
501 );
502 }
503
504 /**
505 * test inline language label as array
506 *
507 */
508 public function testAddInlineLanguageLabelArray() {
509
510 $expectedReturnValue = 'TYPO3.lang = {"myKey1":"myValue1","myKey2":"myValue2"}';
511 $this->fixture->loadExtJS();
512 $this->fixture->addInlineLanguageLabelArray(array('myKey1' => 'myValue1', 'myKey2' => 'myValue2',));
513 $out = $this->fixture->enableMoveJsFromHeaderToFooter();
514 $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
515
516 $this->assertContains(
517 $expectedReturnValue,
518 $out
519 );
520 }
521
522 /**
523 * test inline language label as array get merged
524 *
525 */
526 public function testAddInlineLanguageLabelArrayMerged() {
527
528 $expectedReturnValue = 'TYPO3.lang = {"myKey1":"myValue1","myKey2":"myValue2"}';
529 $this->fixture->loadExtJS();
530 $this->fixture->addInlineLanguageLabelArray(array('myKey1' => 'myValue1',));
531 $this->fixture->addInlineLanguageLabelArray(array('myKey2' => 'myValue2',));
532 $out = $this->fixture->enableMoveJsFromHeaderToFooter();
533 $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
534
535 $this->assertContains(
536 $expectedReturnValue,
537 $out
538 );
539 }
540
541 /**
542 * test inline setting
543 *
544 */
545 public function testAddInlineSetting() {
546
547 $expectedReturnValue = 'TYPO3.settings = {"myApp":{"myKey":"myValue"}};';
548 $this->fixture->loadExtJS();
549 $this->fixture->addInlineSetting('myApp', 'myKey', 'myValue');
550 $out = $this->fixture->enableMoveJsFromHeaderToFooter();
551 $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
552
553 $this->assertContains(
554 $expectedReturnValue,
555 $out
556 );
557 }
558
559 /**
560 * test inline settings with array
561 *
562 */
563 public function testAddInlineSettingArray() {
564
565 $expectedReturnValue = 'TYPO3.settings = {"myApp":{"myKey1":"myValue1","myKey2":"myValue2"}};';
566 $this->fixture->loadExtJS();
567 $this->fixture->addInlineSettingArray('myApp', array('myKey1' => 'myValue1', 'myKey2' => 'myValue2',));
568 $out = $this->fixture->enableMoveJsFromHeaderToFooter();
569 $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
570
571 $this->assertContains(
572 $expectedReturnValue,
573 $out
574 );
575 }
576
577 /**
578 * test inline settings with array get merged
579 *
580 */
581 public function testAddInlineSettingArrayMerged() {
582
583 $expectedReturnValue = 'TYPO3.settings = {"myApp":{"myKey1":"myValue1","myKey2":"myValue2"}};';
584 $this->fixture->loadExtJS();
585 $this->fixture->addInlineSettingArray('myApp', array('myKey1' => 'myValue1',));
586 $this->fixture->addInlineSettingArray('myApp', array('myKey2' => 'myValue2',));
587 $out = $this->fixture->enableMoveJsFromHeaderToFooter();
588 $out = $this->fixture->render(t3lib_PageRenderer::PART_FOOTER);
589
590 $this->assertContains(
591 $expectedReturnValue,
592 $out
593 );
594 }
595
596 /**
597 * test add body content
598 *
599 */
600 public function testAddBodyContent() {
601 $expectedReturnValue = 'ABCDE';
602 $this->fixture->addBodyContent('A');
603 $this->fixture->addBodyContent('B');
604 $this->fixture->addBodyContent('C');
605 $this->fixture->addBodyContent('D');
606 $this->fixture->addBodyContent('E');
607
608 $out = $this->fixture->getBodyContent();
609 $this->assertEquals(
610 $expectedReturnValue,
611 $out
612 );
613 }
614
615
616 /**
617 * test set body content
618 *
619 */
620 public function testSetBodyContent() {
621 $expectedReturnValue = 'ABCDE';
622 $this->fixture->setBodyContent('ABCDE');
623
624 $out = $this->fixture->getBodyContent();
625 $this->assertEquals(
626 $expectedReturnValue,
627 $out
628 );
629
630 $out = $this->fixture->render();
631
632 $this->assertContains(
633 $expectedReturnValue,
634 $out
635 );
636 }
637
638
639
640 }
641 ?>