2 /***************************************************************
5 * (c) 2010-2011 Oliver Klee (typo3-coding@oliverklee.de)
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
25 require_once(t3lib_extMgm
::extPath('install') . 'mod/class.tx_install.php');
28 * Testcase for the t3lib_formprotection_InstallToolFormProtection class.
33 * @author Oliver Klee <typo3-coding@oliverklee.de>
35 class t3lib_formprotection_InstallToolFormProtectionTest
extends tx_phpunit_testcase
{
37 * @var t3lib_formprotection_InstallToolFormProtection
46 private $sessionBackup;
48 public function setUp() {
49 $this->sessionBackup
= $_SESSION;
51 $className = $this->createAccessibleProxyClass();
52 $this->fixture
= new $className();
55 public function tearDown() {
56 $this->fixture
->__destruct();
57 unset($this->fixture
);
59 t3lib_FlashMessageQueue
::getAllMessagesAndFlush();
61 $_SESSION = $this->sessionBackup
;
65 //////////////////////
67 //////////////////////
70 * Creates a subclass t3lib_formprotection_InstallToolFormProtection with retrieveTokens made
73 * @return string the name of the created class, will not be empty
75 private function createAccessibleProxyClass() {
76 $className = 't3lib_formprotection_InstallToolFormProtectionAccessibleProxy';
77 if (!class_exists($className)) {
79 'class ' . $className . ' extends t3lib_formprotection_InstallToolFormProtection {' .
80 ' public $sessionToken;' .
81 ' public function createValidationErrorMessage() {' .
82 ' parent::createValidationErrorMessage();' .
84 ' public function retrieveSessionToken() {' .
85 ' parent::retrieveSessionToken();' .
95 ////////////////////////////////////
96 // Tests for the utility functions
97 ////////////////////////////////////
102 public function createAccessibleProxyCreatesInstallToolFormProtectionSubclass() {
103 $className = $this->createAccessibleProxyClass();
106 (new $className()) instanceof t3lib_formprotection_InstallToolFormProtection
111 //////////////////////////////////////////////////////////
112 // Tests concerning the reading and saving of the tokens
113 //////////////////////////////////////////////////////////
118 public function tokenFromSessionDataIsAvailableForValidateToken() {
119 $sessionToken = '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd';
122 $formInstanceName = '42';
124 $tokenId = t3lib_div
::hmac($formName . $action . $formInstanceName . $sessionToken);
126 $_SESSION['installToolFormToken'] = $sessionToken;
128 $this->fixture
->retrieveSessionToken();
131 $this->fixture
->validateToken($tokenId, $formName, $action, $formInstanceName)
138 public function persistSessionTokenWritesTokensToSession() {
139 $_SESSION['installToolFormToken'] = 'foo';
141 $this->fixture
->sessionToken
= '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd';
143 $this->fixture
->persistSessionToken();
146 '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd',
147 $_SESSION['installToolFormToken']
152 //////////////////////////////////////////////////
153 // Tests concerning createValidationErrorMessage
154 //////////////////////////////////////////////////
159 public function createValidationErrorMessageAddsErrorMessage() {
160 $installTool = $this->getMock(
161 'tx_install', array('addErrorMessage'), array(), '', FALSE
163 $installTool->expects($this->once())->method('addErrorMessage')
165 'Validating the security token of this form has failed. ' .
166 'Please reload the form and submit it again.'
168 $this->fixture
->injectInstallTool($installTool);
170 $this->fixture
->createValidationErrorMessage();