From 6f8b1cf4df59d9bba7aa71cbebe71b517f6c9053 Mon Sep 17 00:00:00 2001 From: Ernesto Baschny Date: Fri, 21 Jan 2011 22:06:11 +0000 Subject: [PATCH] Fixed bug #17201: The unit test for t3lib_formprotection_BackendFormProtection is broken (Thanks to Helmut Hummel) git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@10230 709f56b5-9817-0410-a4d7-c38de5d9e867 --- ChangeLog | 1 + ...rmprotection_BackendFormProtectionTest.php | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/ChangeLog b/ChangeLog index 6310f56012c1..53ff11d26734 100755 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,7 @@ 2011-01-21 Ernesto Baschny + * 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) diff --git a/tests/t3lib/formprotection/t3lib_formprotection_BackendFormProtectionTest.php b/tests/t3lib/formprotection/t3lib_formprotection_BackendFormProtectionTest.php index e2c2cd8aa797..a622df5fdf40 100644 --- a/tests/t3lib/formprotection/t3lib_formprotection_BackendFormProtectionTest.php +++ b/tests/t3lib/formprotection/t3lib_formprotection_BackendFormProtectionTest.php @@ -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(); -- 2.20.1