Added tests #12382: Feature/Code cleanup: Add some more unit tests (Thanks to Oliver...
authorSteffen Kamper <info@sk-typo3.de>
Tue, 17 Nov 2009 22:52:22 +0000 (22:52 +0000)
committerSteffen Kamper <info@sk-typo3.de>
Tue, 17 Nov 2009 22:52:22 +0000 (22:52 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@6468 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
tests/t3lib/t3lib_befunc_testcase.php [new file with mode: 0644]
tests/t3lib/t3lib_extmgm_testcase.php
tests/t3lib/t3lib_pageselect_testcase.php
tests/t3lib/t3lib_tcemain_testcase.php
tests/typo3/sysext/cms/tslib/tslib_content_testcase.php
tests/typo3/sysext/cms/tslib/tslib_fe_testcase.php [new file with mode: 0644]

index d410aa6..30deda2 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -25,6 +25,7 @@
 
 2009-11-17  Steffen Kamper  <info@sk-typo3.de>
 
+       * Added tests #12382: Feature/Code cleanup: Add some more unit tests (Thanks to Oliver Klee)
        * Fixed bug #12611: Add preRenderHook in pageRenderer
        * Fixed bug #12610: Inconsistent naming of "includeFooterJS"
        * Fixed bug #10119: Broken fe_adminLib.inc
diff --git a/tests/t3lib/t3lib_befunc_testcase.php b/tests/t3lib/t3lib_befunc_testcase.php
new file mode 100644 (file)
index 0000000..fd9030a
--- /dev/null
@@ -0,0 +1,68 @@
+<?php\r
+/***************************************************************\r
+* Copyright notice\r
+*\r
+* (c) 2009 Oliver Klee (typo3-coding@oliverklee.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_befunc.php');\r
+\r
+/**\r
+ * Testcase for the t3lib_BEfunc class in the TYPO3 core.\r
+ *\r
+ * @package TYPO3\r
+ * @subpackage t3lib\r
+ *\r
+ * @author Oliver Klee <typo3-coding@oliverklee.de>\r
+ */\r
+class t3lib_befunc_testcase extends tx_phpunit_testcase {\r
+       /**\r
+        * @var t3lib_BEfunc\r
+        */\r
+       private $fixture;\r
+\r
+       public function setUp() {\r
+               $this->fixture = new t3lib_BEfunc();\r
+       }\r
+\r
+       public function tearDown() {\r
+               unset($this->fixture);\r
+       }\r
+\r
+\r
+       ///////////////////////////////////////\r
+       // Tests concerning getProcessedValue\r
+       ///////////////////////////////////////\r
+\r
+       /**\r
+        * @test\r
+        *\r
+        * @see http://bugs.typo3.org/view.php?id=11875\r
+        */\r
+       public function getProcessedValueForZeroStringIsZero() {\r
+               $this->assertEquals(\r
+                       '0',\r
+                       $this->fixture->getProcessedValue(\r
+                               'tt_content', 'header', '0'\r
+                       )\r
+               );\r
+       }\r
+}\r
+?>\r
index 15896c3..736cd7a 100644 (file)
@@ -40,6 +40,7 @@ class t3lib_extmgm_testcase extends tx_phpunit_testcase {
        public function setUp() {
                $this->globals = array(
                        'TYPO3_LOADED_EXT' => serialize($GLOBALS['TYPO3_LOADED_EXT']),
+                       'TCA' => serialize($GLOBALS['TCA']),
                );
        }
 
index 95f894c..3d5247e 100644 (file)
@@ -95,6 +95,20 @@ class t3lib_pageselect_testcase extends tx_phpunit_testcase {
                $this->assertFalse($disableGroupAccessCheck);
                $this->assertTrue($parent instanceof t3lib_pageSelect);
        }
-}
 
+
+       /////////////////////////////////////////
+       // Tests concerning getPathFromRootline
+       /////////////////////////////////////////
+
+       /**
+        * @test
+        */
+       public function getPathFromRootLineForEmptyRootLineReturnsEmptyString() {
+               $this->assertEquals(
+                       '',
+                       $this->pageSelectObject->getPathFromRootline(array())
+               );
+       }
+}
 ?>
index 9f8b82b..814ea7c 100644 (file)
@@ -46,12 +46,12 @@ class t3lib_tcemain_testcase extends tx_phpunit_testcase {
        private $fixture;
 
        /**
-        * @var t3lib_beUserAuth a simulated logged-in back-end user
+        * @var t3lib_beUserAuth a mock logged-in back-end user
         */
        private $backEndUser;
 
        public function setUp() {
-               $this->backEndUser = $this->createBackEndUser();
+               $this->backEndUser = $this->getMock('t3lib_beUserAuth');
 
                $this->fixture = new t3lib_TCEmain();
                $this->fixture->start(array(), '', $this->backEndUser);
@@ -64,37 +64,6 @@ class t3lib_tcemain_testcase extends tx_phpunit_testcase {
        }
 
 
-       //////////////////////
-       // Utility functions
-       //////////////////////
-
-       /**
-        * Creates a back-end user.
-        *
-        * @return t3lib_beUserAuth a back-end user
-        */
-       private function createBackEndUser() {
-               $user = new t3lib_beUserAuth();
-               $user->user = array();
-
-               return $user;
-       }
-
-
-       ////////////////////////////////////
-       // Tests for the utility functions
-       ////////////////////////////////////
-
-       /**
-        * @test
-        */
-       public function createBackEndUserCreatesBeUserAuthInstance() {
-               $this->assertTrue(
-                       $this->createBackEndUser() instanceof t3lib_beUserAuth
-               );
-       }
-
-
        //////////////////////////////////////
        // Tests for the basic functionality
        //////////////////////////////////////
@@ -202,6 +171,11 @@ class t3lib_tcemain_testcase extends tx_phpunit_testcase {
                }
        }
 
+
+       ///////////////////////////////////////////
+       // Tests concerning checkModifyAccessList
+       ///////////////////////////////////////////
+
        /**
         * Tests whether a wrong interface on the 'checkModifyAccessList' hook throws an exception.
         * @test
index 80f9d16..9081a7f 100644 (file)
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/
 
-
 /**
- * Testcase for class tslib_cObj.
+ * Testcase for the "tslib_cObj" in the TYPO3 Core.
  *
- * @author     Oliver Hader <oliver@typo3.org>
  * @package TYPO3
+ * @subpackage tslib
+ *
+ * @author Oliver Hader <oliver@typo3.org>
+ * @author Oliver Klee <typo3-coding@oliverklee.de>
+ *
  */
 class tslib_content_testcase extends tx_phpunit_testcase {
        /**
@@ -56,10 +59,13 @@ class tslib_content_testcase extends tx_phpunit_testcase {
        private $typoScriptImage;
 
        public function setUp() {
-               $this->template = $this->getMock('t3lib_TStemplate', array('getFileName'));
+               $this->template = $this->getMock(
+                       't3lib_TStemplate', array('getFileName', 'linkData')
+               );
                $this->tsfe = $this->getMock('tslib_fe', array(), array(), '', false);
                $this->tsfe->tmpl = $this->template;
                $this->tsfe->config = array();
+               $GLOBALS['TSFE'] = $this->tsfe;
 
                $className = 'tslib_cObj_' . uniqid('test');
                eval('
@@ -78,19 +84,17 @@ class tslib_content_testcase extends tx_phpunit_testcase {
        }
 
        public function tearDown() {
-               unset($this->cObj);
-               unset($this->tsfe);
-               unset($this->template);
-               unset($this->typoScriptImage);
+               $GLOBALS['TSFE'] = null;
+
+               unset($this->cObj, $this->tsfe, $this->template,$this->typoScriptImage);
        }
 
        /**
         * Tests whether the getImgResource hook is called correctly.
-        * 
+        *
         * @test
         */
        public function isGetImgResourceHookCalled() {
-               $GLOBALS['TSFE'] = $this->tsfe;
                $this->template->expects($this->atLeastOnce())->method('getFileName')
                        ->with('typo3/clear.gif')->will($this->returnValue('typo3/clear.gif'));
 
@@ -124,5 +128,40 @@ class tslib_content_testcase extends tx_phpunit_testcase {
 
                return $imageResource;
        }
+
+
+       //////////////////////////
+       // Tests concerning FORM
+       //////////////////////////
+
+       /**
+        * @test
+        */
+       public function formWithSecureFormMailEnabledDoesNotContainRecipientField() {
+               $GLOBALS['TYPO3_CONF_VARS']['FE']['secureFormmail'] = TRUE;
+
+               $this->assertNotContains(
+                       'name="recipient',
+                       $this->cObj->FORM(
+                               array('recipient' => 'foo@bar.com', 'recipient.' => array()),
+                               array()
+                       )
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function formWithSecureFormMailDisabledDoesNotContainRecipientField() {
+               $GLOBALS['TYPO3_CONF_VARS']['FE']['secureFormmail'] = FALSE;
+
+               $this->assertContains(
+                       'name="recipient',
+                       $this->cObj->FORM(
+                               array('recipient' => 'foo@bar.com', 'recipient.' => array()),
+                               array()
+                       )
+               );
+       }
 }
 ?>
\ No newline at end of file
diff --git a/tests/typo3/sysext/cms/tslib/tslib_fe_testcase.php b/tests/typo3/sysext/cms/tslib/tslib_fe_testcase.php
new file mode 100644 (file)
index 0000000..02bfe96
--- /dev/null
@@ -0,0 +1,134 @@
+<?php\r
+/***************************************************************\r
+* Copyright notice\r
+*\r
+* (c) 2009 Oliver Klee (typo3-coding@oliverklee.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
+/**\r
+ * Testcase for the "tslib_fe" class in the TYPO3 Core.\r
+ *\r
+ * @package TYPO3\r
+ * @subpackage tslib\r
+ *\r
+ * @author Oliver Klee <typo3-coding@oliverklee.de>\r
+ */\r
+class tslib_fe_testcase extends tx_phpunit_testcase {\r
+       /**\r
+        * @var tslib_fe\r
+        */\r
+       private $fixture;\r
+\r
+       public function setUp() {\r
+                       // This creates an instance of the class without calling the\r
+                       // original constructor.\r
+               $className = uniqid('tslib_fe');\r
+               eval(\r
+                       'class ' . $className . ' extends tslib_fe {' .\r
+                       'public function ' . $className . '() {}' .\r
+                       'public function roundTripCryptString($string) {' .\r
+                       'return parent::roundTripCryptString($string);' .\r
+                       '}' .\r
+                       '}'\r
+               );\r
+\r
+               $this->fixture = new $className();\r
+               $this->fixture->TYPO3_CONF_VARS = $GLOBALS['TYPO3_CONF_VARS'];\r
+               $this->fixture->TYPO3_CONF_VARS['SYS']['encryptionKey']\r
+                       = '170928423746123078941623042360abceb12341234231';\r
+       }\r
+\r
+       public function tearDown() {\r
+               unset($this->fixture);\r
+       }\r
+\r
+\r
+       ////////////////////////////////\r
+       // Tests concerning codeString\r
+       ////////////////////////////////\r
+\r
+       /**\r
+        * @test\r
+        */\r
+       public function codeStringForNonEmptyStringReturns10CharacterHashAndCodedString() {\r
+               $this->assertRegExp(\r
+                       '/^[0-9a-f]{10}:[a-zA-Z0-9+=\/]+$/',\r
+                       $this->fixture->codeString('Hello world!')\r
+               );\r
+       }\r
+\r
+       /**\r
+        * @test\r
+        */\r
+       public function decodingCodedStringReturnsOriginalString() {\r
+               $clearText = 'Hello world!';\r
+\r
+               $this->assertEquals(\r
+                       $clearText,\r
+                       $this->fixture->codeString(\r
+                               $this->fixture->codeString($clearText), TRUE\r
+                       )\r
+               );\r
+       }\r
+\r
+\r
+       //////////////////////////////////////////\r
+       // Tests concerning roundTripCryptString\r
+       //////////////////////////////////////////\r
+\r
+       /**\r
+        * @test\r
+        */\r
+       public function roundTripCryptStringCreatesStringWithSameLengthAsInputString() {\r
+               $clearText = 'Hello world!';\r
+\r
+               $this->assertEquals(\r
+                       strlen($clearText),\r
+                       strlen($this->fixture->roundTripCryptString($clearText))\r
+               );\r
+       }\r
+\r
+       /**\r
+        * @test\r
+        */\r
+       public function roundTripCryptStringCreatesResultDifferentFromInputString() {\r
+               $clearText = 'Hello world!';\r
+\r
+               $this->assertNotEquals(\r
+                       $clearText,\r
+                       $this->fixture->roundTripCryptString($clearText)\r
+               );\r
+       }\r
+\r
+       /**\r
+        * @test\r
+        */\r
+       public function roundTripCryptStringAppliedTwoTimesReturnsOriginalString() {\r
+               $clearText = 'Hello world!';\r
+\r
+               $this->assertEquals(\r
+                       $clearText,\r
+                       $this->fixture->roundTripCryptString(\r
+                               $this->fixture->roundTripCryptString($clearText)\r
+                       )\r
+               );\r
+       }\r
+}\r
+?>\r