‪TYPO3CMS  ‪main
FormDefinitionConversionServiceTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\Test;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
25 final class ‪FormDefinitionConversionServiceTest extends UnitTestCase
26 {
27  protected bool ‪$resetSingletonInstances = true;
28 
29  #[Test]
30  public function ‪addHmacDataAddsHmacHashes(): void
31  {
32  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = '';
33  $formDefinitionConversionService = $this->getAccessibleMock(
34  FormDefinitionConversionService::class,
35  [
36  'generateSessionToken',
37  'persistSessionToken',
38  ],
39  [],
40  '',
41  false
42  );
43 
44  $sessionToken = '123';
45  $formDefinitionConversionService->method(
46  'generateSessionToken'
47  )->willReturn($sessionToken);
48 
49  $formDefinitionConversionService->method(
50  'persistSessionToken'
51  )->willReturn(null);
52 
53  GeneralUtility::setSingletonInstance(FormDefinitionConversionService::class, $formDefinitionConversionService);
54 
55  $input = [
56  'prototypeName' => 'standard',
57  'identifier' => 'test',
58  'type' => 'Form',
59  'heinz' => 1,
60  'klaus' => [],
61  'klaus1' => [
62  '_label' => 'x',
63  '_value' => 'y',
64  ],
65  'sabine' => [
66  'heinz' => '2',
67  'klaus' => [],
68  'horst' => [
69  'heinz' => '',
70  'paul' => [[]],
71  ],
72  ],
73  ];
74 
75  $data = $formDefinitionConversionService->addHmacData($input);
76 
77  $expected = [
78  'prototypeName' => 'standard',
79  'identifier' => 'test',
80  'type' => 'Form',
81  'heinz' => 1,
82  'klaus' => [],
83  'klaus1' => [
84  '_label' => 'x',
85  '_value' => 'y',
86  '_orig__label' => [
87  'value' => 'x',
88  'hmac' => '8b62cd2971adeac49e8900530c9c2067a81e8b53',
89  ],
90  '_orig__value' => [
91  'value' => 'y',
92  'hmac' => '582e4c76c9e6589b4ca1a85860ac774af6c5a5e0',
93  ],
94  ],
95  'sabine' => [
96  'heinz' => '2',
97  'klaus' => [],
98  'horst' => [
99  'heinz' => '',
100  'paul' => [[]],
101  '_orig_heinz' => [
102  'value' => '',
103  'hmac' => $data['sabine']['horst']['_orig_heinz']['hmac'],
104  ],
105  ],
106  '_orig_heinz' => [
107  'value' => '2',
108  'hmac' => $data['sabine']['_orig_heinz']['hmac'],
109  ],
110  ],
111  '_orig_prototypeName' => [
112  'value' => 'standard',
113  'hmac' => $data['_orig_prototypeName']['hmac'],
114  ],
115  '_orig_identifier' => [
116  'value' => 'test',
117  'hmac' => $data['_orig_identifier']['hmac'],
118  ],
119  '_orig_type' => [
120  'value' => 'Form',
121  'hmac' => $data['_orig_type']['hmac'],
122  ],
123  '_orig_heinz' => [
124  'value' => 1,
125  'hmac' => $data['_orig_heinz']['hmac'],
126  ],
127  ];
128 
129  self::assertSame($expected, $data);
130  }
131 
132  #[Test]
133  public function ‪removeHmacDataRemoveHmacs(): void
134  {
135  $formDefinitionConversionService = new ‪FormDefinitionConversionService();
136  GeneralUtility::setSingletonInstance(FormDefinitionConversionService::class, $formDefinitionConversionService);
137 
138  $input = [
139  'prototypeName' => 'standard',
140  'identifier' => 'test',
141  'heinz' => 1,
142  'klaus' => [],
143  'klaus1' => [
144  '_label' => 'x',
145  '_value' => 'y',
146  '_orig__label' => [
147  'value' => 'x',
148  'hmac' => '8b62cd2971adeac49e8900530c9c2067a81e8b53',
149  ],
150  '_orig__value' => [
151  'value' => 'y',
152  'hmac' => '582e4c76c9e6589b4ca1a85860ac774af6c5a5e0',
153  ],
154  ],
155  'sabine' => [
156  'heinz' => '2',
157  'klaus' => [],
158  'horst' => [
159  'heinz' => '',
160  'paul' => [[]],
161  '_orig_heinz' => [
162  'value' => '',
163  'hmac' => '12345',
164  ],
165  ],
166  '_orig_heinz' => [
167  'value' => '2',
168  'hmac' => '12345',
169  ],
170  ],
171  '_orig_prototypeName' => [
172  'value' => 'standard',
173  'hmac' => '12345',
174  ],
175  '_orig_identifier' => [
176  'value' => 'test',
177  'hmac' => '12345',
178  ],
179  '_orig_heinz' => [
180  'value' => 1,
181  'hmac' => '12345',
182  ],
183  ];
184 
185  $expected = [
186  'prototypeName' => 'standard',
187  'identifier' => 'test',
188  'heinz' => 1,
189  'klaus' => [],
190  'klaus1' => [
191  '_label' => 'x',
192  '_value' => 'y',
193  ],
194  'sabine' => [
195  'heinz' => '2',
196  'klaus' => [],
197  'horst' => [
198  'heinz' => '',
199  'paul' => [[]],
200  ],
201  ],
202  ];
203 
204  self::assertSame($expected, $formDefinitionConversionService->removeHmacData($input));
205  }
206 }
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinitionConversionService
Definition: FormDefinitionConversionService.php:35
‪TYPO3\CMS\Form\Tests\Unit\Domain\Configuration
Definition: ConfigurationServiceTest.php:18
‪TYPO3\CMS\Form\Tests\Unit\Domain\Configuration\FormDefinitionConversionServiceTest\addHmacDataAddsHmacHashes
‪addHmacDataAddsHmacHashes()
Definition: FormDefinitionConversionServiceTest.php:30
‪TYPO3\CMS\Form\Tests\Unit\Domain\Configuration\FormDefinitionConversionServiceTest
Definition: FormDefinitionConversionServiceTest.php:26
‪TYPO3\CMS\Form\Tests\Unit\Domain\Configuration\FormDefinitionConversionServiceTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: FormDefinitionConversionServiceTest.php:27
‪TYPO3\CMS\Form\Tests\Unit\Domain\Configuration\FormDefinitionConversionServiceTest\removeHmacDataRemoveHmacs
‪removeHmacDataRemoveHmacs()
Definition: FormDefinitionConversionServiceTest.php:133
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52