[TASK] Shorten the extend class in all unit tests
[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 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
18
19 /**
20 * Testcase
21 */
22 class InstallToolFormProtectionTest extends UnitTestCase
23 {
24 /**
25 * @var \TYPO3\CMS\Core\FormProtection\InstallToolFormProtection|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface
26 */
27 protected $subject;
28
29 /**
30 * Set up
31 */
32 protected function setUp()
33 {
34 $this->subject = $this->getAccessibleMock(
35 \TYPO3\CMS\Core\FormProtection\InstallToolFormProtection::class,
36 ['dummy']
37 );
38 }
39
40 //////////////////////////////////////////////////////////
41 // Tests concerning the reading and saving of the tokens
42 //////////////////////////////////////////////////////////
43
44 /**
45 * @test
46 */
47 public function tokenFromSessionDataIsAvailableForValidateToken()
48 {
49 $sessionToken = '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd';
50 $formName = 'foo';
51 $action = 'edit';
52 $formInstanceName = '42';
53
54 $tokenId = \TYPO3\CMS\Core\Utility\GeneralUtility::hmac($formName . $action . $formInstanceName . $sessionToken);
55
56 $_SESSION['installToolFormToken'] = $sessionToken;
57
58 $this->subject->_call('retrieveSessionToken');
59
60 $this->assertTrue(
61 $this->subject->validateToken($tokenId, $formName, $action, $formInstanceName)
62 );
63 }
64
65 /**
66 * @test
67 */
68 public function persistSessionTokenWritesTokensToSession()
69 {
70 $_SESSION['installToolFormToken'] = 'foo';
71
72 $this->subject->_set('sessionToken', '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd');
73
74 $this->subject->persistSessionToken();
75
76 $this->assertEquals(
77 '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd',
78 $_SESSION['installToolFormToken']
79 );
80 }
81 }