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