‪TYPO3CMS  11.5
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 
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
24 class ‪FormDefinitionConversionServiceTest extends UnitTestCase
25 {
29  protected ‪$resetSingletonInstances = true;
30 
34  public function ‪addHmacDataAddsHmacHashes(): void
35  {
36  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = '';
37  $formDefinitionConversionService = $this->getAccessibleMock(
38  FormDefinitionConversionService::class,
39  [
40  'generateSessionToken',
41  'persistSessionToken',
42  ],
43  [],
44  '',
45  false
46  );
47 
48  $sessionToken = '123';
49  $formDefinitionConversionService->method(
50  'generateSessionToken'
51  )->willReturn($sessionToken);
52 
53  $formDefinitionConversionService->method(
54  'persistSessionToken'
55  )->willReturn(null);
56 
57  GeneralUtility::setSingletonInstance(FormDefinitionConversionService::class, $formDefinitionConversionService);
58 
59  $input = [
60  'prototypeName' => 'standard',
61  'identifier' => 'test',
62  'type' => 'Form',
63  'heinz' => 1,
64  'klaus' => [],
65  'klaus1' => [
66  '_label' => 'x',
67  '_value' => 'y',
68  ],
69  'sabine' => [
70  'heinz' => '2',
71  'klaus' => [],
72  'horst' => [
73  'heinz' => '',
74  'paul' => [[]],
75  ],
76  ],
77  ];
78 
79  $data = $formDefinitionConversionService->addHmacData($input);
80 
81  $expected = [
82  'prototypeName' => 'standard',
83  'identifier' => 'test',
84  'type' => 'Form',
85  'heinz' => 1,
86  'klaus' => [],
87  'klaus1' => [
88  '_label' => 'x',
89  '_value' => 'y',
90  '_orig__label' => [
91  'value' => 'x',
92  'hmac' => '8b62cd2971adeac49e8900530c9c2067a81e8b53',
93  ],
94  '_orig__value' => [
95  'value' => 'y',
96  'hmac' => '582e4c76c9e6589b4ca1a85860ac774af6c5a5e0',
97  ],
98  ],
99  'sabine' => [
100  'heinz' => '2',
101  'klaus' => [],
102  'horst' => [
103  'heinz' => '',
104  'paul' => [[]],
105  '_orig_heinz' => [
106  'value' => '',
107  'hmac' => $data['sabine']['horst']['_orig_heinz']['hmac'],
108  ],
109  ],
110  '_orig_heinz' => [
111  'value' => '2',
112  'hmac' => $data['sabine']['_orig_heinz']['hmac'],
113  ],
114  ],
115  '_orig_prototypeName' => [
116  'value' => 'standard',
117  'hmac' => $data['_orig_prototypeName']['hmac'],
118  ],
119  '_orig_identifier' => [
120  'value' => 'test',
121  'hmac' => $data['_orig_identifier']['hmac'],
122  ],
123  '_orig_type' => [
124  'value' => 'Form',
125  'hmac' => $data['_orig_type']['hmac'],
126  ],
127  '_orig_heinz' => [
128  'value' => 1,
129  'hmac' => $data['_orig_heinz']['hmac'],
130  ],
131  ];
132 
133  self::assertSame($expected, $data);
134  }
135 
139  public function ‪removeHmacDataRemoveHmacs(): void
140  {
141  $formDefinitionConversionService = new ‪FormDefinitionConversionService();
142  GeneralUtility::setSingletonInstance(FormDefinitionConversionService::class, $formDefinitionConversionService);
143 
144  $input = [
145  'prototypeName' => 'standard',
146  'identifier' => 'test',
147  'heinz' => 1,
148  'klaus' => [],
149  'klaus1' => [
150  '_label' => 'x',
151  '_value' => 'y',
152  '_orig__label' => [
153  'value' => 'x',
154  'hmac' => '8b62cd2971adeac49e8900530c9c2067a81e8b53',
155  ],
156  '_orig__value' => [
157  'value' => 'y',
158  'hmac' => '582e4c76c9e6589b4ca1a85860ac774af6c5a5e0',
159  ],
160  ],
161  'sabine' => [
162  'heinz' => '2',
163  'klaus' => [],
164  'horst' => [
165  'heinz' => '',
166  'paul' => [[]],
167  '_orig_heinz' => [
168  'value' => '',
169  'hmac' => '12345',
170  ],
171  ],
172  '_orig_heinz' => [
173  'value' => '2',
174  'hmac' => '12345',
175  ],
176  ],
177  '_orig_prototypeName' => [
178  'value' => 'standard',
179  'hmac' => '12345',
180  ],
181  '_orig_identifier' => [
182  'value' => 'test',
183  'hmac' => '12345',
184  ],
185  '_orig_heinz' => [
186  'value' => 1,
187  'hmac' => '12345',
188  ],
189  ];
190 
191  $expected = [
192  'prototypeName' => 'standard',
193  'identifier' => 'test',
194  'heinz' => 1,
195  'klaus' => [],
196  'klaus1' => [
197  '_label' => 'x',
198  '_value' => 'y',
199  ],
200  'sabine' => [
201  'heinz' => '2',
202  'klaus' => [],
203  'horst' => [
204  'heinz' => '',
205  'paul' => [[]],
206  ],
207  ],
208  ];
209 
210  self::assertSame($expected, $formDefinitionConversionService->removeHmacData($input));
211  }
212 }
‪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:33
‪TYPO3\CMS\Form\Tests\Unit\Domain\Configuration\FormDefinitionConversionServiceTest
Definition: FormDefinitionConversionServiceTest.php:25
‪TYPO3\CMS\Form\Tests\Unit\Domain\Configuration\FormDefinitionConversionServiceTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: FormDefinitionConversionServiceTest.php:28
‪TYPO3\CMS\Form\Tests\Unit\Domain\Configuration\FormDefinitionConversionServiceTest\removeHmacDataRemoveHmacs
‪removeHmacDataRemoveHmacs()
Definition: FormDefinitionConversionServiceTest.php:138
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50