2 /***************************************************************
5 * (c) 2009 Steffen Kamper (info@sk-typo3.de)
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.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
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.
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
27 * Testcase for the t3lib_pageIncludes class in the TYPO3 core.
32 * @author Steffen Kamper (info@sk-typo3.de)
34 class t3lib_pageRenderer_testcase
extends tx_phpunit_testcase
{
36 * @var t3lib_pageIncludes
40 const PART_COMPLETE
= 0;
41 const PART_HEADER
= 1;
42 const PART_FOOTER
= 2;
44 public function setUp() {
45 $className = 't3lib_pageRenderer_' . uniqid('test');
47 class ' . $className . ' extends t3lib_pageRenderer {
50 $this->fixture
= new $className();
53 public function tearDown() {
60 //////////////////////////////////////
61 // Tests for the basic functionality
62 //////////////////////////////////////
67 public function fixtureCanBeCreated() {
69 $this->fixture
instanceof t3lib_pageRenderer
73 //////////////////////
75 //////////////////////
78 * test set xml prolog and doctype
81 public function testSetXmlPrologAndDocType() {
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();
87 $this->assertContains(
97 public function testSetTitle() {
99 $expectedReturnValue = '<title>This is the title</title>';
100 $this->fixture
->setTitle('This is the title');
101 $out = $this->fixture
->render();
103 $this->assertContains(
104 $expectedReturnValue,
113 public function testSetCharset() {
115 $expectedReturnValue = '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
116 $this->fixture
->setCharset('utf-8');
117 $out = $this->fixture
->render();
119 $this->assertContains(
120 $expectedReturnValue,
129 public function testSetFavIcon() {
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();
136 $this->assertContains(
137 $expectedReturnValue1,
140 $this->assertContains(
141 $expectedReturnValue2,
151 public function testSetBaseUrl() {
153 $expectedReturnValue = '<base href="http://ggogle.com/" />';
154 $this->fixture
->setBaseUrl('http://ggogle.com/');
155 $out = $this->fixture
->render();
157 $this->assertContains(
158 $expectedReturnValue,
167 public function testAddMetaTag() {
169 $expectedReturnValue = '<meta name="author" content="Anna Lyse">';
170 $this->fixture
->addMetaTag('<meta name="author" content="Anna Lyse">');
171 $out = $this->fixture
->render();
173 $this->assertContains(
174 $expectedReturnValue,
180 * test add inline comment
183 public function testAddInlineComment() {
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();
189 $this->assertContains(
190 $expectedReturnValue,
196 * test add header data
199 public function testAddHeaderData() {
201 $expectedReturnValue = '<tag method="private" name="test" />';
202 $this->fixture
->addHeaderData('<tag method="private" name="test" />');
203 $out = $this->fixture
->render();
205 $this->assertContains(
206 $expectedReturnValue,
212 * test add footer data
215 public function testAddFooterData() {
217 $expectedReturnValue = '<tag method="private" name="test" />';
218 $this->fixture
->addFooterData('<tag method="private" name="test" />');
219 $out = $this->fixture
->render(self
::PART_FOOTER
);
221 $this->assertContains(
222 $expectedReturnValue,
228 * test add JS library file
231 public function testAddJsLibrary() {
233 $expectedReturnValue = '<script src="fileadmin/test.js" type="text/javascript"></script>';
234 $this->fixture
->addJsLibrary('test', 'fileadmin/test.js');
235 $out = $this->fixture
->render();
237 $this->assertContains(
238 $expectedReturnValue,
245 * test add JS footer library file
248 public function testAddJsFooterLibrary() {
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
);
254 $this->assertContains(
255 $expectedReturnValue,
264 public function testAddJsFile() {
266 $expectedReturnValue = '<script src="fileadmin/test.js" type="text/javascript"></script>';
267 $this->fixture
->addJsFile('fileadmin/test.js');
268 $out = $this->fixture
->render();
270 $this->assertContains(
271 $expectedReturnValue,
277 * test add JS file for footer
280 public function testAddJsFooterFile() {
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
);
286 $this->assertContains(
287 $expectedReturnValue,
296 public function testAddJsInlineCode() {
298 $expectedReturnValue = 'var x = "testvar"';
299 $this->fixture
->addJsInlineCode('test', 'var x = "testvar"');
300 $out = $this->fixture
->render();
302 $this->assertContains(
303 $expectedReturnValue,
309 * test add JS inline for footer
312 public function testAddJsFooterInlineCode() {
314 $expectedReturnValue = 'var x = "testvar"';
315 $this->fixture
->addJsFooterInlineCode('test', 'var x = "testvar"');
316 $out = $this->fixture
->render(self
::PART_FOOTER
);
318 $this->assertContains(
319 $expectedReturnValue,
325 * test add JS handler
328 public function testAddExtOnReadyCode() {
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();
336 $this->assertContains(
337 $expectedReturnValue1,
341 $this->assertContains(
342 $expectedReturnValue2,
352 public function testAddCssFile() {
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();
358 $this->assertContains(
359 $expectedReturnValue,
365 * test add CSS inline
368 public function testAddCssInlineBlock() {
370 $expectedReturnValue = 'body {margin:20px;}';
371 $this->fixture
->addCssInlineBlock('general', 'body {margin:20px;}');
372 $out = $this->fixture
->render();
374 $this->assertContains(
375 $expectedReturnValue,
381 * test add CSS inline and force on top
384 public function testAddCssInlineBlockForceOnTop() {
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();
391 $this->assertContains(
392 $expectedReturnValue,
398 * test load prototype
401 public function testLoadPrototype() {
403 $expectedReturnValue = '<script src="contrib/prototype/prototype.js" type="text/javascript"></script>';
404 $this->fixture
->loadPrototype();
405 $out = $this->fixture
->render();
407 $this->assertContains(
408 $expectedReturnValue,
414 * test load Scriptaculous
417 public function testLoadScriptaculous() {
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();
423 $this->assertContains(
424 $expectedReturnValue,
433 public function testLoadExtJS() {
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();
439 $this->assertContains(
440 $expectedReturnValue,
449 public function testLoadExtCore() {
451 $expectedReturnValue = '<script src="contrib/extjs/ext-core.js" type="text/javascript"></script>';
452 $this->fixture
->loadExtCore();
453 $out = $this->fixture
->render();
455 $this->assertContains(
456 $expectedReturnValue,
462 * test enable ExtJsDebug
465 public function testEnableExtJsDebug() {
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();
472 $this->assertContains(
473 $expectedReturnValue,
479 * test enable ExtCoreDebug
482 public function testEnableExtCoreDebug() {
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();
489 $this->assertContains(
490 $expectedReturnValue,
496 * test inline language label
499 public function testAddInlineLanguageLabel() {
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
);
507 $this->assertContains(
508 $expectedReturnValue,
514 * test inline language label as array
517 public function testAddInlineLanguageLabelArray() {
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
);
525 $this->assertContains(
526 $expectedReturnValue,
532 * test inline language label as array get merged
535 public function testAddInlineLanguageLabelArrayMerged() {
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
);
544 $this->assertContains(
545 $expectedReturnValue,
551 * test inline setting
554 public function testAddInlineSetting() {
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
);
562 $this->assertContains(
563 $expectedReturnValue,
569 * test inline settings with array
572 public function testAddInlineSettingArray() {
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
);
580 $this->assertContains(
581 $expectedReturnValue,
587 * test inline settings with array get merged
590 public function testAddInlineSettingArrayMerged() {
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
);
599 $this->assertContains(
600 $expectedReturnValue,
606 * test add body content
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');
617 $out = $this->fixture
->getBodyContent();
619 $expectedReturnValue,
626 * test set body content
629 public function testSetBodyContent() {
630 $expectedReturnValue = 'ABCDE';
631 $this->fixture
->setBodyContent('ABCDE');
633 $out = $this->fixture
->getBodyContent();
635 $expectedReturnValue,
639 $out = $this->fixture
->render();
641 $this->assertContains(
642 $expectedReturnValue,