[!!!][TASK] Rewrite install tool
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / FormProtection / InstallToolFormProtectionTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\FormProtection;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2013 Oliver Klee (typo3-coding@oliverklee.de)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Testcase
29 *
30 * @author Oliver Klee <typo3-coding@oliverklee.de>
31 */
32 class InstallToolFormProtectionTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
33
34 /**
35 * @var \TYPO3\CMS\Core\FormProtection\InstallToolFormProtection|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
36 */
37 protected $fixture;
38
39 /**
40 * @var array Backup of $_SESSION
41 */
42 protected $sessionBackup;
43
44 /**
45 * Set up
46 */
47 public function setUp() {
48 $this->sessionBackup = $_SESSION;
49
50 $this->fixture = $this->getAccessibleMock(
51 'TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection',
52 array('dummy')
53 );
54 }
55
56 /**
57 * Tear down
58 */
59 public function tearDown() {
60 $this->fixture->__destruct();
61 $_SESSION = $this->sessionBackup;
62 }
63
64 //////////////////////////////////////////////////////////
65 // Tests concerning the reading and saving of the tokens
66 //////////////////////////////////////////////////////////
67
68 /**
69 * @test
70 */
71 public function tokenFromSessionDataIsAvailableForValidateToken() {
72 $sessionToken = '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd';
73 $formName = 'foo';
74 $action = 'edit';
75 $formInstanceName = '42';
76
77 $tokenId = \TYPO3\CMS\Core\Utility\GeneralUtility::hmac($formName . $action . $formInstanceName . $sessionToken);
78
79 $_SESSION['installToolFormToken'] = $sessionToken;
80
81 $this->fixture->_call('retrieveSessionToken');
82
83 $this->assertTrue(
84 $this->fixture->validateToken($tokenId, $formName, $action, $formInstanceName)
85 );
86 }
87
88 /**
89 * @test
90 */
91 public function persistSessionTokenWritesTokensToSession() {
92 $_SESSION['installToolFormToken'] = 'foo';
93
94 $this->fixture->_set('sessionToken', '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd');
95
96 $this->fixture->persistSessionToken();
97
98 $this->assertEquals(
99 '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd',
100 $_SESSION['installToolFormToken']
101 );
102 }
103
104
105 //////////////////////////////////////////////////
106 // Tests concerning createValidationErrorMessage
107 //////////////////////////////////////////////////
108
109 /**
110 * @test
111 * @deprecated since 6.2. Test can be removed if injectInstallTool method is dropped
112 */
113 public function createValidationErrorMessageAddsErrorMessage() {
114 $installTool = $this->getMock(
115 'stdClass', array('addErrorMessage'), array(), '', FALSE
116 );
117 $installTool->expects($this->once())->method('addErrorMessage')
118 ->with(
119 'Validating the security token of this form has failed. ' .
120 'Please reload the form and submit it again.'
121 );
122 $this->fixture->injectInstallTool($installTool);
123
124 $this->fixture->_call('createValidationErrorMessage');
125 }
126 }
127 ?>