TYPO3 CMS  TYPO3_8-7
DataStructureIdentifierHookTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
22 
26 class DataStructureIdentifierHookTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
27 {
31  protected $singletonInstances = [];
32 
36  public function setUp()
37  {
38  $this->singletonInstances = GeneralUtility::getSingletonInstances();
39  }
40 
44  public function tearDown()
45  {
46  GeneralUtility::resetSingletonInstances($this->singletonInstances);
47  parent::tearDown();
48  }
49 
54  {
55  $givenIdentifier = ['aKey' => 'aValue'];
56  $result = (new DataStructureIdentifierHook())->getDataStructureIdentifierPostProcess(
57  [],
58  'aTable',
59  'aField',
60  [],
61  $givenIdentifier
62  );
63  $this->assertEquals($givenIdentifier, $result);
64  }
65 
70  {
71  $result = (new DataStructureIdentifierHook())->getDataStructureIdentifierPostProcess(
72  [],
73  'tt_content',
74  'pi_flexform',
75  ['CType' => 'form_formframework'],
76  []
77  );
78  $this->assertEquals(
79  ['ext-form-persistenceIdentifier' => '', 'ext-form-overrideFinishers' => false],
80  $result
81  );
82  }
83 
88  {
89  $row = [
90  'CType' => 'form_formframework',
91  'pi_flexform' => '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
92  <T3FlexForms>
93  <data>
94  <sheet index="sDEF">
95  <language index="lDEF">
96  <field index="settings.persistenceIdentifier">
97  <value index="vDEF">1:user_upload/karl.yml</value>
98  </field>
99  </language>
100  </sheet>
101  </data>
102  </T3FlexForms>
103  ',
104  ];
105  $incomingIdentifier = [
106  'aKey' => 'aValue',
107  ];
108  $expected = [
109  'aKey' => 'aValue',
110  'ext-form-persistenceIdentifier' => '1:user_upload/karl.yml',
111  'ext-form-overrideFinishers' => false,
112  ];
113  $result = (new DataStructureIdentifierHook())->getDataStructureIdentifierPostProcess(
114  [],
115  'tt_content',
116  'pi_flexform',
117  $row,
118  $incomingIdentifier
119  );
120  $this->assertEquals($expected, $result);
121  }
122 
127  {
128  $row = [
129  'CType' => 'form_formframework',
130  'pi_flexform' => '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
131  <T3FlexForms>
132  <data>
133  <sheet index="sDEF">
134  <language index="lDEF">
135  <field index="settings.overrideFinishers">
136  <value index="vDEF">1</value>
137  </field>
138  </language>
139  </sheet>
140  </data>
141  </T3FlexForms>
142  ',
143  ];
144  $expected = [
145  'ext-form-persistenceIdentifier' => '',
146  'ext-form-overrideFinishers' => true,
147  ];
148  $result = (new DataStructureIdentifierHook())->getDataStructureIdentifierPostProcess(
149  [],
150  'tt_content',
151  'pi_flexform',
152  $row,
153  []
154  );
155  $this->assertEquals($expected, $result);
156  }
157 
162  {
163  $dataStructure = ['foo' => 'bar'];
164  $expected = $dataStructure;
165  $result = (new DataStructureIdentifierHook())->parseDataStructureByIdentifierPostProcess(
166  $dataStructure,
167  []
168  );
169  $this->assertEquals($expected, $result);
170  }
171 
179  public function parseDataStructureByIdentifierPostProcessAddsExistingFormItems(array $formDefinition, array $expectedItem)
180  {
181  $objectMangerProphecy = $this->prophesize(ObjectManager::class);
182  GeneralUtility::setSingletonInstance(ObjectManager::class, $objectMangerProphecy->reveal());
183  $formPersistenceManagerProphecy = $this->prophesize(FormPersistenceManager::class);
184  $objectMangerProphecy->get(FormPersistenceManagerInterface::class)
185  ->willReturn($formPersistenceManagerProphecy->reveal());
186 
187  $formPersistenceManagerProphecy->listForms()->shouldBeCalled()->willReturn([$formDefinition]);
188 
189  $incomingDataStructure = [
190  'sheets' => [
191  'sDEF' => [
192  'ROOT' => [
193  'el' => [
194  'settings.persistenceIdentifier' => [
195  'TCEforms' => [
196  'config' => [
197  'items' => [
198  0 => [
199  0 => 'default, no value',
200  1 => '',
201  ],
202  ],
203  ],
204  ],
205  ],
206  ],
207  ],
208  ],
209  ],
210  ];
211 
212  $expected = [
213  'sheets' => [
214  'sDEF' => [
215  'ROOT' => [
216  'el' => [
217  'settings.persistenceIdentifier' => [
218  'TCEforms' => [
219  'config' => [
220  'items' => [
221  0 => [
222  0 => 'default, no value',
223  1 => '',
224  ],
225  1 => $expectedItem,
226  ],
227  ],
228  ],
229  ],
230  ],
231  ],
232  ],
233  ],
234  ];
235 
236  $result = (new DataStructureIdentifierHook())->parseDataStructureByIdentifierPostProcess(
237  $incomingDataStructure,
238  ['ext-form-persistenceIdentifier' => '']
239  );
240 
241  $this->assertEquals($expected, $result);
242  }
243 
248  {
249  return [
250  'simple' => [
251  [
252  'persistenceIdentifier' => 'hugo1',
253  'name' => 'myHugo1',
254  'location' => 'extension',
255  ],
256  [
257  'myHugo1 (hugo1)',
258  'hugo1',
259  'content-form',
260  ],
261  ],
262  'invalid' => [
263  [
264  'persistenceIdentifier' => 'Error.yaml',
265  'label' => 'Test Error Label',
266  'name' => 'Test Error Name',
267  'location' => 'extension',
268  'invalid' => true,
269  ],
270  [
271  'Test Error Name (Error.yaml)',
272  'Error.yaml',
273  'overlay-missing',
274  ],
275  ],
276  ];
277  }
278 
285  {
286  return [
287  'One string' => [
288  [
289  'a' => 'b',
290  ],
291  'a'
292  ],
293  'Two strings' => [
294  [
295  'a' => [
296  'b' => 'c'
297  ],
298  ],
299  'a.b'
300  ],
301  'One integer' => [
302  [
303  20 => 'a',
304  ],
305  '20'
306  ],
307  'Two integers' => [
308  [
309  20 => [
310  30 => 'a'
311  ],
312  ],
313  '20.30'
314  ],
315  'Mixed' => [
316  [
317  20 => [
318  'a' => 'b'
319  ],
320  ],
321  '20.a'
322  ],
323  'Multiple Entries' => [
324  [
325  1 => [
326  'a' => 'b',
327  'b' => 'foo',
328  ],
329  ],
330  '1.a'
331  ],
332  'four levels' => [
333  [
334  1 => [
335  'a' => [
336  '2' => [
337  42 => 'foo',
338  ],
339  ],
340  'b' => 22,
341  ],
342  ],
343  '1.a.2.42',
344  ],
345  ];
346  }
347 
352  public function implodeArrayKeysReturnsString($array, $expectation)
353  {
354  $hookMock = $this->getAccessibleMock(DataStructureIdentifierHook::class, [ 'dummy' ], [], '', false);
355  $this->assertEquals($expectation, $hookMock->_call('implodeArrayKeys', $array));
356  }
357 }
static setSingletonInstance($className, SingletonInterface $instance)
static resetSingletonInstances(array $newSingletonInstances)
parseDataStructureByIdentifierPostProcessAddsExistingFormItems(array $formDefinition, array $expectedItem)