[TASK] Clean up form protection tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / FormProtection / InstallToolFormProtectionTest.php
index 0af00d0..fe9cfea 100644 (file)
@@ -24,89 +24,43 @@ namespace TYPO3\CMS\Core\Tests\Unit\FormProtection;
 * This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/
 
-require_once(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('install') . 'mod/class.tx_install.php');
-
 /**
- * Testcase for the \TYPO3\CMS\Core\FormProtection\InstallToolFormProtection class.
+ * Testcase
  *
  * @author Oliver Klee <typo3-coding@oliverklee.de>
  */
 class InstallToolFormProtectionTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+
        /**
-        * @var \TYPO3\CMS\Core\FormProtection\InstallToolFormProtection
+        * @var \TYPO3\CMS\Core\FormProtection\InstallToolFormProtection|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
         */
-       private $fixture;
+       protected $fixture;
 
        /**
-        * backup of $_SESSION
-        *
-        * @var array
+        * @var array Backup of $_SESSION
         */
-       private $sessionBackup;
+       protected $sessionBackup;
 
+       /**
+        * Set up
+        */
        public function setUp() {
                $this->sessionBackup = $_SESSION;
 
-               $className = $this->createAccessibleProxyClass();
-               $this->fixture = new $className();
+               $this->fixture = $this->getAccessibleMock(
+                       'TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection',
+                       array('dummy')
+               );
        }
 
+       /**
+        * Tear down
+        */
        public function tearDown() {
                $this->fixture->__destruct();
-               unset($this->fixture);
-
-               \TYPO3\CMS\Core\Messaging\FlashMessageQueue::getAllMessagesAndFlush();
-
                $_SESSION = $this->sessionBackup;
        }
 
-
-       //////////////////////
-       // Utility functions
-       //////////////////////
-
-       /**
-        * Creates a subclass \TYPO3\CMS\Core\FormProtection\InstallToolFormProtection with retrieveTokens made
-        * public.
-        *
-        * @return string the name of the created class, will not be empty
-        */
-       private function createAccessibleProxyClass() {
-               $className = 't3lib_formprotection_InstallToolFormProtectionAccessibleProxy';
-               if (!class_exists($className)) {
-                       eval(
-                               'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection {' .
-                               '  public $sessionToken;' .
-                               '  public function createValidationErrorMessage() {' .
-                               '    parent::createValidationErrorMessage();' .
-                               '  }' .
-                               '  public function retrieveSessionToken() {' .
-                               '    parent::retrieveSessionToken();' .
-                               '  }' .
-                               '}'
-                       );
-               }
-
-               return $className;
-       }
-
-
-       ////////////////////////////////////
-       // Tests for the utility functions
-       ////////////////////////////////////
-
-       /**
-        * @test
-        */
-       public function createAccessibleProxyCreatesInstallToolFormProtectionSubclass() {
-               $className = $this->createAccessibleProxyClass();
-
-               $this->assertTrue(
-                       (new $className()) instanceof \TYPO3\CMS\Core\FormProtection\InstallToolFormProtection
-               );
-       }
-
-
        //////////////////////////////////////////////////////////
        // Tests concerning the reading and saving of the tokens
        //////////////////////////////////////////////////////////
@@ -124,7 +78,7 @@ class InstallToolFormProtectionTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
                $_SESSION['installToolFormToken'] = $sessionToken;
 
-               $this->fixture->retrieveSessionToken();
+               $this->fixture->_call('retrieveSessionToken');
 
                $this->assertTrue(
                        $this->fixture->validateToken($tokenId, $formName, $action, $formInstanceName)
@@ -137,7 +91,7 @@ class InstallToolFormProtectionTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        public function persistSessionTokenWritesTokensToSession() {
                $_SESSION['installToolFormToken'] = 'foo';
 
-               $this->fixture->sessionToken = '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd';
+               $this->fixture->_set('sessionToken', '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd');
 
                $this->fixture->persistSessionToken();
 
@@ -166,7 +120,7 @@ class InstallToolFormProtectionTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        );
                $this->fixture->injectInstallTool($installTool);
 
-               $this->fixture->createValidationErrorMessage();
+               $this->fixture->_call('createValidationErrorMessage');
        }
 }
 ?>
\ No newline at end of file