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