Follow-up to feature #11397: Added unit tests for t3lib_pageremder
authorSteffen Kamper <info@sk-typo3.de>
Mon, 7 Sep 2009 08:30:40 +0000 (08:30 +0000)
committerSteffen Kamper <info@sk-typo3.de>
Mon, 7 Sep 2009 08:30:40 +0000 (08:30 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@5905 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
tests/t3lib/t3lib_pagerender_testcase.php [new file with mode: 0644]

index 00bb0be..c8dc57a 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-09-07  Steffen Kamper  <info@sk-typo3.de>
+
+       * Follow-up to feature #11397: Added unit tests for t3lib_pageremder
+
 2009-09-06  Rupert Germann  <rupi@gmx.li>
 
        * Added feature #11798: Remove "Login-error or session timed out" screen (thanks to Steffen Gebert)
@@ -18,7 +22,7 @@
 
 2009-09-04  Rupert Germann  <rupi@gmx.li>
 
-       * Fixed bug #11868 (Follow-up to #11828): added forgotten file version/tca.php (thanks to Sven Jürgens)
+       * Fixed bug #11868 (Follow-up to #11828): added forgotten file version/tca.php (thanks to Sven Jürgens)
        * Fixed bug #11827: Update wizard adds _CACHEFILE to extList
 
 2009-09-04  Steffen Kamper  <info@sk-typo3.de>
diff --git a/tests/t3lib/t3lib_pagerender_testcase.php b/tests/t3lib/t3lib_pagerender_testcase.php
new file mode 100644 (file)
index 0000000..abab0ad
--- /dev/null
@@ -0,0 +1,652 @@
+<?php\r
+/***************************************************************\r
+* Copyright notice\r
+*\r
+* (c) 2009 Steffen Kamper (info@sk-typo3.de)\r
+* All rights reserved\r
+*\r
+* This script is part of the TYPO3 project. The TYPO3 project is\r
+* free software; you can redistribute it and/or modify\r
+* it under the terms of the GNU General Public License as published by\r
+* the Free Software Foundation; either version 2 of the License or\r
+* (at your option) any later version.\r
+*\r
+* The GNU General Public License can be found at\r
+* http://www.gnu.org/copyleft/gpl.html.\r
+*\r
+* This script is distributed in the hope that it will be useful\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+* GNU General Public License for more details.\r
+*\r
+* This copyright notice MUST APPEAR in all copies of the script!\r
+***************************************************************/\r
+\r
+require_once(PATH_t3lib . 'class.t3lib_pagerender.php');\r
+class foo extends t3lib_pageRender {\r
+       public function __construct() {\r
+               parent::__construct();\r
+       }               \r
+}\r
+\r
+/**\r
+ * Testcase for the t3lib_pageIncludes class in the TYPO3 core.\r
+ *\r
+ * @package TYPO3\r
+ * @subpackage t3lib\r
+ *\r
+ * @author Steffen Kamper (info@sk-typo3.de)\r
+ */\r
+class t3lib_pageRender_testcase extends tx_phpunit_testcase {\r
+       /**\r
+        * @var t3lib_pageIncludes\r
+        */\r
+       private $fixture;\r
+\r
+       const PART_COMPLETE = 0;\r
+       const PART_HEADER = 1;\r
+       const PART_FOOTER = 2;\r
+\r
+       public function setUp() {\r
+               \r
+               $this->fixture = new foo;\r
+       }\r
+\r
+       public function tearDown() {\r
+               unset(\r
+                       $this->fixture\r
+               );\r
+       }\r
+\r
+\r
+       //////////////////////////////////////\r
+       // Tests for the basic functionality\r
+       //////////////////////////////////////\r
+\r
+       /**\r
+        * @test\r
+        */\r
+       public function fixtureCanBeCreated() {\r
+               $this->assertTrue(\r
+                       $this->fixture instanceof t3lib_pageRender\r
+               );\r
+       }\r
+       \r
+       //////////////////////\r
+       // test functions\r
+       //////////////////////\r
+\r
+       /**\r
+       * test set xml prolog and doctype\r
+       * \r
+       */\r
+       public function testSetXmlPrologAndDocType() {\r
+               \r
+               $expectedReturnValue = '<?xml version="1.0" encoding="utf-8" ?>';\r
+               $this->fixture->setXmlPrologAndDocType('<?xml version="1.0" encoding="utf-8" ?>');\r
+               $out = $this->fixture->render();\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out\r
+               );\r
+       }\r
+\r
+       /**\r
+       * test set title\r
+       * \r
+       */\r
+       public function testSetTitle() {\r
+               \r
+               $expectedReturnValue = '<title>This is the title</title>';\r
+               $this->fixture->setTitle('This is the title');\r
+               $out = $this->fixture->render();\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out\r
+               );\r
+       }\r
+\r
+       /**\r
+       * test set charset\r
+       * \r
+       */\r
+       public function testSetCharset() {\r
+               \r
+               $expectedReturnValue = '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';\r
+               $this->fixture->setCharset('utf-8');\r
+               $out = $this->fixture->render();\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out\r
+               );\r
+       }\r
+\r
+       /**\r
+       * test set favicon\r
+       * \r
+       */\r
+       public function testSetFavIcon() {\r
+               \r
+               $expectedReturnValue1 = '<link rel="shortcut icon" href="http://google.com/favicon.ico" />';\r
+               $expectedReturnValue2 = '<link rel="icon" href="http://google.com/favicon.ico" />';\r
+               $this->fixture->setFavIcon('http://google.com/favicon.ico');\r
+               $out = $this->fixture->render();\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue1,\r
+                       $out\r
+               );\r
+               $this->assertContains(\r
+                       $expectedReturnValue2,\r
+                       $out\r
+               );\r
+               \r
+       }\r
+\r
+       /**\r
+       * test set baseUrl\r
+       * \r
+       */\r
+       public function testSetBaseUrl() {\r
+               \r
+               $expectedReturnValue = '<base href="http://ggogle.com/" />';\r
+               $this->fixture->setBaseUrl('http://ggogle.com/');\r
+               $out = $this->fixture->render();\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out\r
+               );\r
+       }\r
+\r
+       /**\r
+       * test add meta tag\r
+       * \r
+       */\r
+       public function testAddMetaTag() {\r
+               \r
+               $expectedReturnValue = '<meta name="author" content="Anna Lyse">';\r
+               $this->fixture->addMetaTag('<meta name="author" content="Anna Lyse">');\r
+               $out = $this->fixture->render();\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out\r
+               );\r
+       }\r
+\r
+       /**\r
+       * test add inline comment\r
+       * \r
+       */\r
+       public function testAddInlineComment() {\r
+               \r
+               $expectedReturnValue = 'this is an inline comment written by unit test';\r
+               $this->fixture->addInlineComment('this is an inline comment written by unit test');\r
+               $out = $this->fixture->render();\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out\r
+               );\r
+       }\r
+\r
+       /**\r
+       * test add header data\r
+       * \r
+       */\r
+       public function testAddHeaderData() {\r
+               \r
+               $expectedReturnValue = '<tag method="private" name="test" />';\r
+               $this->fixture->addHeaderData('<tag method="private" name="test" />');\r
+               $out = $this->fixture->render();\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out\r
+               );\r
+       }\r
+\r
+       /**\r
+       * test add footer data\r
+       * \r
+       */\r
+       public function testAddFooterData() {\r
+               \r
+               $expectedReturnValue = '<tag method="private" name="test" />';\r
+               $this->fixture->addFooterData('<tag method="private" name="test" />');\r
+               $out = $this->fixture->render(self::PART_FOOTER);\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out  \r
+               );\r
+       }\r
+\r
+       /**\r
+       * test add JS library file\r
+       * \r
+       */\r
+       public function testAddJsLibrary() {\r
+               \r
+               $expectedReturnValue = '<script src="fileadmin/test.js" type="text/javascript"></script>';\r
+               $this->fixture->addJsLibrary('test', 'fileadmin/test.js');\r
+               $out = $this->fixture->render();\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out      \r
+               );\r
+       }\r
+       \r
+       \r
+       /**\r
+       * test add JS footer library file\r
+       * \r
+       */\r
+       public function testAddJsFooterLibrary() {\r
+               \r
+               $expectedReturnValue = '<script src="fileadmin/test.js" type="text/javascript"></script>';\r
+               $this->fixture->addJsFooterLibrary('test', 'fileadmin/test.js');\r
+               $out = $this->fixture->render(self::PART_FOOTER);\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out      \r
+               );\r
+       }\r
+\r
+       /**\r
+       * test add JS file\r
+       * \r
+       */\r
+       public function testAddJsFile() {\r
+               \r
+               $expectedReturnValue = '<script src="fileadmin/test.js" type="text/javascript"></script>';\r
+               $this->fixture->addJsFile('fileadmin/test.js');\r
+               $out = $this->fixture->render();\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out\r
+               );\r
+       }\r
+\r
+       /**\r
+       * test add JS file for footer\r
+       * \r
+       */\r
+       public function testAddJsFooterFile() {\r
+               \r
+               $expectedReturnValue = '<script src="fileadmin/test.js" type="text/javascript"></script>';\r
+               $this->fixture->addJsFooterFile('fileadmin/test.js');\r
+               $out = $this->fixture->render(self::PART_FOOTER);\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out\r
+               );\r
+       }\r
+\r
+       /**\r
+       * test add JS inline\r
+       * \r
+       */\r
+       public function testAddJsInlineCode() {\r
+               \r
+               $expectedReturnValue = 'var x = "testvar"';\r
+               $this->fixture->addJsInlineCode('test', 'var x = "testvar"');\r
+               $out = $this->fixture->render();\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out, '#' . nl2br($out) . '#'\r
+               );\r
+       }\r
+\r
+       /**\r
+       * test add JS inline for footer\r
+       * \r
+       */\r
+       public function testAddJsFooterInlineCode() {\r
+               \r
+               $expectedReturnValue = 'var x = "testvar"';\r
+               $this->fixture->addJsFooterInlineCode('test', 'var x = "testvar"');\r
+               $out = $this->fixture->render(self::PART_FOOTER);\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out\r
+               );\r
+       }\r
+\r
+       /**\r
+       * test add JS handler\r
+       * \r
+       */\r
+       public function testAddExtOnReadyCode() {\r
+               \r
+               $expectedReturnValue1 = 'Ext.onReady(function() {';\r
+               $expectedReturnValue2 = 'var x = "testvar";';\r
+               $this->fixture->loadExtJS();\r
+               $this->fixture->addExtOnReadyCode('var x = "testvar";');\r
+               $out = $this->fixture->render();\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue1,\r
+                       $out, '#' . nl2br($out) . '#'\r
+               );\r
+               \r
+               $this->assertContains(\r
+                       $expectedReturnValue2,\r
+                       $out, '#' . nl2br($out) . '#'\r
+               );\r
+               \r
+       }\r
+\r
+       /**\r
+       * test add CSS file\r
+       * \r
+       */\r
+       public function testAddCssFile() {\r
+               \r
+               $expectedReturnValue = '<link rel="stylesheet" type="text/css" href="fileadmin/test.css" media="screen" />';\r
+               $this->fixture->addCssFile('fileadmin/test.css');\r
+               $out = $this->fixture->render();\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out\r
+               );\r
+       }\r
+\r
+       /**\r
+       * test add CSS inline\r
+       * \r
+       */\r
+       public function testAddCssInlineBlock() {\r
+               \r
+               $expectedReturnValue = 'body {margin:20px;}';\r
+               $this->fixture->addCssInlineBlock('general', 'body {margin:20px;}');\r
+               $out = $this->fixture->render();\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out\r
+               );\r
+       }\r
+\r
+       /**\r
+       * test add CSS inline and force on top\r
+       * \r
+       */\r
+       public function testAddCssInlineBlockForceOnTop() {\r
+               \r
+               $expectedReturnValue = '/*general1*/' . chr(10) . 'h1 {margin:20px;}' . chr(10) . '/*general*/' . chr(10) . 'body {margin:20px;}';\r
+               $this->fixture->addCssInlineBlock('general', 'body {margin:20px;}');\r
+               $this->fixture->addCssInlineBlock('general1', 'h1 {margin:20px;}', NULL, TRUE);\r
+               $out = $this->fixture->render();\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out\r
+               );\r
+       }\r
+\r
+    /**\r
+    * test load prototype\r
+    * \r
+    */\r
+       public function testLoadPrototype() {\r
+               \r
+               $expectedReturnValue = '<script src="contrib/prototype/prototype.js" type="text/javascript"></script>';\r
+               $this->fixture->loadPrototype();\r
+               $out = $this->fixture->render();\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out\r
+               );\r
+       }\r
+\r
+       /**\r
+       * test load Scriptaculous\r
+       * \r
+       */\r
+       public function testLoadScriptaculous() {\r
+               \r
+               $expectedReturnValue = '<script src="contrib/scriptaculous/scriptaculous.js?load=effects,controls,slider" type="text/javascript"></script>';\r
+               $this->fixture->loadScriptaculous('slider,controls');\r
+               $out = $this->fixture->render();\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out\r
+               );\r
+       }\r
+\r
+       /**\r
+       * test load ExtJS\r
+       * \r
+       */\r
+    public function testLoadExtJS() {\r
+               \r
+               $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>';\r
+               $this->fixture->loadExtJS(TRUE, TRUE, 'jquery');\r
+               $out = $this->fixture->render();\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out\r
+               );\r
+       }\r
+       \r
+       /**\r
+       * test load ExtCore\r
+       * \r
+       */\r
+       public function testLoadExtCore() {\r
+               \r
+               $expectedReturnValue = '<script src="contrib/extjs/ext-core.js" type="text/javascript"></script>';\r
+               $this->fixture->loadExtCore();\r
+               $out = $this->fixture->render();\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out\r
+               );\r
+       }\r
+       \r
+       /**\r
+       * test enable ExtJsDebug  \r
+       * \r
+       */\r
+       public function testEnableExtJsDebug() {\r
+               \r
+               $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>';\r
+               $this->fixture->loadExtJS(TRUE, TRUE, 'jquery');\r
+               $this->fixture->enableExtJsDebug();\r
+               $out = $this->fixture->render();\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out\r
+               );\r
+       }\r
+       \r
+       /**\r
+       * test enable ExtCoreDebug\r
+       * \r
+       */\r
+       public function testEnableExtCoreDebug() {      \r
+               \r
+               $expectedReturnValue = '<script src="contrib/extjs/ext-core-debug.js" type="text/javascript"></script>';\r
+               $this->fixture->loadExtCore();\r
+               $this->fixture->enableExtCoreDebug();\r
+               $out = $this->fixture->render();\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out\r
+               );\r
+       }\r
+       \r
+       /**\r
+       * test inline language label\r
+       * \r
+       */\r
+       public function testAddInlineLanguageLabel() {\r
+               \r
+               $expectedReturnValue = 'TYPO3.lang = {"myKey":"myValue"}';\r
+               $this->fixture->loadExtJS();\r
+               $this->fixture->addInlineLanguageLabel('myKey', 'myValue');\r
+               $out = $this->fixture->enableMoveJsFromHeaderToFooter();\r
+               $out = $this->fixture->render(self::PART_FOOTER);\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out\r
+               );\r
+       }\r
+       \r
+       /**\r
+       * test inline language label as array\r
+       * \r
+       */\r
+       public function testAddInlineLanguageLabelArray() {\r
+               \r
+               $expectedReturnValue = 'TYPO3.lang = {"myKey1":"myValue1","myKey2":"myValue2"}';\r
+               $this->fixture->loadExtJS();\r
+               $this->fixture->addInlineLanguageLabelArray(array('myKey1' => 'myValue1', 'myKey2' => 'myValue2',));\r
+               $out = $this->fixture->enableMoveJsFromHeaderToFooter();\r
+               $out = $this->fixture->render(self::PART_FOOTER);\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out\r
+               );\r
+       }\r
+       \r
+       /**\r
+       * test inline language label as array get merged\r
+       * \r
+       */\r
+       public function testAddInlineLanguageLabelArrayMerged() {\r
+               \r
+               $expectedReturnValue = 'TYPO3.lang = {"myKey1":"myValue1","myKey2":"myValue2"}';\r
+               $this->fixture->loadExtJS();\r
+               $this->fixture->addInlineLanguageLabelArray(array('myKey1' => 'myValue1',));\r
+               $this->fixture->addInlineLanguageLabelArray(array('myKey2' => 'myValue2',));\r
+               $out = $this->fixture->enableMoveJsFromHeaderToFooter();\r
+               $out = $this->fixture->render(self::PART_FOOTER);\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out\r
+               );\r
+       }\r
+       \r
+       /**\r
+       * test inline setting\r
+       * \r
+       */\r
+       public function testAddInlineSetting() {\r
+               \r
+               $expectedReturnValue = 'TYPO3.settings = {"myApp":{"myKey":"myValue"}};';\r
+               $this->fixture->loadExtJS();\r
+               $this->fixture->addInlineSetting('myApp', 'myKey', 'myValue');\r
+               $out = $this->fixture->enableMoveJsFromHeaderToFooter();\r
+               $out = $this->fixture->render(self::PART_FOOTER);\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out, '#' . nl2br($out) . '#'      \r
+               );\r
+       }\r
+       \r
+       /**\r
+       * test inline settings with array\r
+       * \r
+       */\r
+       public function testAddInlineSettingArray() {\r
+               \r
+               $expectedReturnValue = 'TYPO3.settings = {"myApp":{"myKey1":"myValue1","myKey2":"myValue2"}};';\r
+               $this->fixture->loadExtJS();\r
+               $this->fixture->addInlineSettingArray('myApp', array('myKey1' => 'myValue1', 'myKey2' => 'myValue2',));\r
+               $out = $this->fixture->enableMoveJsFromHeaderToFooter();\r
+               $out = $this->fixture->render(self::PART_FOOTER);\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out\r
+               );\r
+       }\r
+       \r
+       /**\r
+       * test inline settings with array get merged\r
+       * \r
+       */\r
+       public function testAddInlineSettingArrayMerged() {\r
+               \r
+               $expectedReturnValue = 'TYPO3.settings = {"myApp":{"myKey1":"myValue1","myKey2":"myValue2"}};';\r
+               $this->fixture->loadExtJS();\r
+               $this->fixture->addInlineSettingArray('myApp', array('myKey1' => 'myValue1',));\r
+               $this->fixture->addInlineSettingArray('myApp', array('myKey2' => 'myValue2',));\r
+               $out = $this->fixture->enableMoveJsFromHeaderToFooter();\r
+               $out = $this->fixture->render(self::PART_FOOTER);\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out\r
+               );\r
+       }\r
+       \r
+       /**\r
+       * test add body content\r
+       * \r
+       */\r
+       public function testAddBodyContent() {\r
+               $expectedReturnValue = 'ABCDE';\r
+               $this->fixture->addBodyContent('A');\r
+               $this->fixture->addBodyContent('B');\r
+               $this->fixture->addBodyContent('C');\r
+               $this->fixture->addBodyContent('D');\r
+               $this->fixture->addBodyContent('E');\r
+               \r
+               $out = $this->fixture->getBodyContent();\r
+               $this->assertEquals(\r
+                       $expectedReturnValue,\r
+                       $out\r
+               );\r
+       }\r
+       \r
+       \r
+       /**\r
+       * test set body content\r
+       * \r
+       */\r
+       public function testSetBodyContent() {\r
+               $expectedReturnValue = 'ABCDE';\r
+               $this->fixture->setBodyContent('ABCDE');\r
+               \r
+               $out = $this->fixture->getBodyContent();\r
+               $this->assertEquals(\r
+                       $expectedReturnValue,\r
+                       $out\r
+               );\r
+               \r
+               $out = $this->fixture->render();\r
+\r
+               $this->assertContains(\r
+                       $expectedReturnValue,\r
+                       $out\r
+               );\r
+       }\r
+       \r
+  \r
+\r
+}\r
+?>
\ No newline at end of file