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