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