Fixed bug #17201: The unit test for t3lib_formprotection_BackendFormProtection is...
authorErnesto Baschny <ernst@cron-it.de>
Fri, 21 Jan 2011 22:06:11 +0000 (22:06 +0000)
committerErnesto Baschny <ernst@cron-it.de>
Fri, 21 Jan 2011 22:06:11 +0000 (22:06 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@10230 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
tests/t3lib/formprotection/t3lib_formprotection_BackendFormProtectionTest.php

index 6310f56..53ff11d 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -15,6 +15,7 @@
 
 2011-01-21  Ernesto Baschny  <ernst@cron-it.de>
 
+       * Fixed bug #17201: The unit test for t3lib_formprotection_BackendFormProtection is broken (Thanks to Helmut Hummel)
        * Follow-up to issue #15589: Move debug functions to own utility class, missing t3lib_div commit from original patch, and declared all relevant methods "static" (Thanks to Stefan Galinski)
        * Fixed issue #17065: Use Swift Mailer in core (t3lib_mail_*) and deprecate t3lib_htmlmail and related settings (Thanks to Jigal van Hemert)
        * Fixed bug #17173: CSRF: In the user settings module, saving form data is not possible if simulate user option is used (Thanks to Helmut Hummel)
index e2c2cd8..a622df5 100644 (file)
@@ -94,6 +94,29 @@ class t3lib_formprotection_BackendFormProtectionTest extends tx_phpunit_testcase
                return $className;
        }
 
+       /**
+        * Mock session methods in t3lib_beUserAuth
+        *
+        * @return t3lib_beUserAuth Instance of BE_USER object with mocked session storage methods
+        */
+       private function createBackendUserSessionStorageStub() {
+               $className = 't3lib_beUserAuthMocked';
+               if (!class_exists($className)) {
+                       eval(
+                               'class ' . $className . ' extends t3lib_beUserAuth {' .
+                               '  protected $session=array();' .
+                               '  public function getSessionData($key) {' .
+                               '    return $this->session[$key];' .
+                               '  }' .
+                               '  public function setAndSaveSessionData($key,$data) {' .
+                               '    $this->session[$key] = $data;' .
+                               '  }' .
+                               '}'
+                       );
+               }
+
+               return $this->getMock($className, array('foo'));// $className;
+       }
 
        ////////////////////////////////////
        // Tests for the utility functions
@@ -110,6 +133,25 @@ class t3lib_formprotection_BackendFormProtectionTest extends tx_phpunit_testcase
                );
        }
 
+       /**
+        * @test
+        */
+       public function createBackendUserSessionStorageStubWorkProperly() {
+               $GLOBALS['BE_USER'] = $this->createBackendUserSessionStorageStub();
+
+               $allTokens = array(
+                       '12345678' => array(
+                                       'formName' => 'foo',
+                                       'action' => 'edit',
+                                       'formInstanceName' => '42'
+                               ),
+               );
+
+               $GLOBALS['BE_USER']->setAndSaveSessionData('tokens', $allTokens);
+
+               $this->assertEquals($GLOBALS['BE_USER']->getSessionData('tokens'), $allTokens);
+       }
+
 
        //////////////////////////////////////////////////////////
        // Tests concerning the reading and saving of the tokens
@@ -184,6 +226,7 @@ class t3lib_formprotection_BackendFormProtectionTest extends tx_phpunit_testcase
         * @test
         */
        public function createValidationErrorMessageAddsErrorFlashMessage() {
+               $GLOBALS['BE_USER'] = $this->createBackendUserSessionStorageStub();
                $this->fixture->createValidationErrorMessage();
 
                $messages = t3lib_FlashMessageQueue::getAllMessagesAndFlush();