‪TYPO3CMS  10.4
DataStructureIdentifierHookTest.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 Prophecy\Argument;
28 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
29 
33 class ‪DataStructureIdentifierHookTest extends UnitTestCase
34 {
38  protected ‪$resetSingletonInstances = true;
39 
43  public function ‪setUp(): void
44  {
45  parent::setUp();
46  $cacheManagerProphecy = $this->prophesize(CacheManager::class);
47  $cacheProphecy = $this->prophesize(FrontendInterface::class);
48  $cacheManagerProphecy->getCache('runtime')->willReturn($cacheProphecy->reveal());
49  $cacheProphecy->get(Argument::cetera())->willReturn(false);
50  $cacheProphecy->set(Argument::cetera())->willReturn(false);
51  GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
52  }
53 
58  {
59  $givenIdentifier = ['aKey' => 'aValue'];
60  $result = (new ‪DataStructureIdentifierHook())->getDataStructureIdentifierPostProcess(
61  [],
62  'aTable',
63  'aField',
64  [],
65  $givenIdentifier
66  );
67  self::assertEquals($givenIdentifier, $result);
68  }
69 
74  {
75  $result = (new ‪DataStructureIdentifierHook())->getDataStructureIdentifierPostProcess(
76  [],
77  'tt_content',
78  'pi_flexform',
79  ['CType' => 'form_formframework'],
80  []
81  );
82  self::assertEquals(
83  ['ext-form-persistenceIdentifier' => '', 'ext-form-overrideFinishers' => ''],
84  $result
85  );
86  }
87 
92  {
93  $row = [
94  'CType' => 'form_formframework',
95  'pi_flexform' => '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
96  <T3FlexForms>
97  <data>
98  <sheet index="sDEF">
99  <language index="lDEF">
100  <field index="settings.persistenceIdentifier">
101  <value index="vDEF">1:user_upload/karl.yml</value>
102  </field>
103  </language>
104  </sheet>
105  </data>
106  </T3FlexForms>
107  ',
108  ];
109  $incomingIdentifier = [
110  'aKey' => 'aValue',
111  ];
112  $expected = [
113  'aKey' => 'aValue',
114  'ext-form-persistenceIdentifier' => '1:user_upload/karl.yml',
115  'ext-form-overrideFinishers' => '',
116  ];
117  $result = (new ‪DataStructureIdentifierHook())->getDataStructureIdentifierPostProcess(
118  [],
119  'tt_content',
120  'pi_flexform',
121  $row,
122  $incomingIdentifier
123  );
124  self::assertEquals($expected, $result);
125  }
126 
131  {
132  $row = [
133  'CType' => 'form_formframework',
134  'pi_flexform' => '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
135  <T3FlexForms>
136  <data>
137  <sheet index="sDEF">
138  <language index="lDEF">
139  <field index="settings.overrideFinishers">
140  <value index="vDEF">1</value>
141  </field>
142  </language>
143  </sheet>
144  </data>
145  </T3FlexForms>
146  ',
147  ];
148  $expected = [
149  'ext-form-persistenceIdentifier' => '',
150  'ext-form-overrideFinishers' => 'enabled',
151  ];
152  $result = (new ‪DataStructureIdentifierHook())->getDataStructureIdentifierPostProcess(
153  [],
154  'tt_content',
155  'pi_flexform',
156  $row,
157  []
158  );
159  self::assertEquals($expected, $result);
160  }
161 
166  {
167  $dataStructure = ['foo' => 'bar'];
168  $expected = $dataStructure;
169  $result = (new ‪DataStructureIdentifierHook())->parseDataStructureByIdentifierPostProcess(
170  $dataStructure,
171  []
172  );
173  self::assertEquals($expected, $result);
174  }
175 
183  public function ‪parseDataStructureByIdentifierPostProcessAddsExistingFormItems(array $formDefinition, array $expectedItem): void
184  {
185  $objectManagerProphecy = $this->prophesize(ObjectManager::class);
186  GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal());
187  $formPersistenceManagerProphecy = $this->prophesize(FormPersistenceManager::class);
188  $objectManagerProphecy->get(FormPersistenceManagerInterface::class)
189  ->willReturn($formPersistenceManagerProphecy->reveal());
190 
191  $formPersistenceManagerProphecy->listForms()->shouldBeCalled()->willReturn([$formDefinition]);
192 
193  $incomingDataStructure = [
194  'sheets' => [
195  'sDEF' => [
196  'ROOT' => [
197  'el' => [
198  'settings.persistenceIdentifier' => [
199  'TCEforms' => [
200  'config' => [
201  'items' => [
202  0 => [
203  0 => 'default, no value',
204  1 => '',
205  ],
206  ],
207  ],
208  ],
209  ],
210  ],
211  ],
212  ],
213  ],
214  ];
215 
216  $expected = [
217  'sheets' => [
218  'sDEF' => [
219  'ROOT' => [
220  'el' => [
221  'settings.persistenceIdentifier' => [
222  'TCEforms' => [
223  'config' => [
224  'items' => [
225  0 => [
226  0 => 'default, no value',
227  1 => '',
228  ],
229  1 => $expectedItem,
230  ],
231  ],
232  ],
233  ],
234  ],
235  ],
236  ],
237  ],
238  ];
239 
240  $result = (new ‪DataStructureIdentifierHook())->parseDataStructureByIdentifierPostProcess(
241  $incomingDataStructure,
242  ['ext-form-persistenceIdentifier' => '']
243  );
244 
245  self::assertEquals($expected, $result);
246  }
247 
252  {
253  return [
254  'simple' => [
255  [
256  'persistenceIdentifier' => 'hugo1',
257  'name' => 'myHugo1',
258  'location' => 'extension',
259  ],
260  [
261  'myHugo1 (hugo1)',
262  'hugo1',
263  'content-form',
264  ],
265  ],
266  'invalid' => [
267  [
268  'persistenceIdentifier' => 'Error.yaml',
269  'label' => 'Test Error Label',
270  'name' => 'Test Error Name',
271  'location' => 'extension',
272  'invalid' => true,
273  ],
274  [
275  'Test Error Name (Error.yaml)',
276  'Error.yaml',
277  'overlay-missing',
278  ],
279  ],
280  ];
281  }
282 }
‪TYPO3\CMS\Form\Tests\Unit\Hooks\DataStructureIdentifierHookTest\parseDataStructureByIdentifierPostProcessReturnsDataStructureUnchanged
‪parseDataStructureByIdentifierPostProcessReturnsDataStructureUnchanged()
Definition: DataStructureIdentifierHookTest.php:164
‪TYPO3\CMS\Form\Tests\Unit\Hooks\DataStructureIdentifierHookTest\getDataStructureIdentifierPostProcessAddsGivenPersistenceIdentifier
‪getDataStructureIdentifierPostProcessAddsGivenPersistenceIdentifier()
Definition: DataStructureIdentifierHookTest.php:90
‪TYPO3\CMS\Form\Hooks\DataStructureIdentifierHook
Definition: DataStructureIdentifierHook.php:47
‪TYPO3\CMS\Form\Tests\Unit\Hooks\DataStructureIdentifierHookTest\getDataStructureIdentifierPostProcessAddDefaultValuesForNewRecord
‪getDataStructureIdentifierPostProcessAddDefaultValuesForNewRecord()
Definition: DataStructureIdentifierHookTest.php:72
‪TYPO3\CMS\Form\Tests\Unit\Hooks\DataStructureIdentifierHookTest\getDataStructureIdentifierPostProcessAddsOverrideFinisherValue
‪getDataStructureIdentifierPostProcessAddsOverrideFinisherValue()
Definition: DataStructureIdentifierHookTest.php:129
‪TYPO3\CMS\Form\Tests\Unit\Hooks\DataStructureIdentifierHookTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: DataStructureIdentifierHookTest.php:37
‪TYPO3\CMS\Form\Tests\Unit\Hooks\DataStructureIdentifierHookTest\parseDataStructureByIdentifierPostProcessDataProvider
‪array parseDataStructureByIdentifierPostProcessDataProvider()
Definition: DataStructureIdentifierHookTest.php:250
‪TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManager
Definition: FormPersistenceManager.php:54
‪TYPO3\CMS\Form\Tests\Unit\Hooks
Definition: DataStructureIdentifierHookTest.php:18
‪TYPO3\CMS\Form\Tests\Unit\Hooks\DataStructureIdentifierHookTest
Definition: DataStructureIdentifierHookTest.php:34
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:35
‪TYPO3\CMS\Form\Tests\Unit\Hooks\DataStructureIdentifierHookTest\parseDataStructureByIdentifierPostProcessAddsExistingFormItems
‪parseDataStructureByIdentifierPostProcessAddsExistingFormItems(array $formDefinition, array $expectedItem)
Definition: DataStructureIdentifierHookTest.php:182
‪TYPO3\CMS\Form\Tests\Unit\Hooks\DataStructureIdentifierHookTest\setUp
‪setUp()
Definition: DataStructureIdentifierHookTest.php:42
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪TYPO3\CMS\Form\Tests\Unit\Hooks\DataStructureIdentifierHookTest\getDataStructureIdentifierPostProcessReturnsIdentifierForNotMatchingScenario
‪getDataStructureIdentifierPostProcessReturnsIdentifierForNotMatchingScenario()
Definition: DataStructureIdentifierHookTest.php:56
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface
Definition: FormPersistenceManagerInterface.php:32
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:28