‪TYPO3CMS  ‪main
TcaFlexPrepareTest.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 Psr\EventDispatcher\EventDispatcherInterface;
27 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
28 
29 final class ‪TcaFlexPrepareTest extends UnitTestCase
30 {
32 
33  protected function ‪setUp(): void
34  {
35  parent::setUp();
36  // Suppress cache foo in xml helpers of GeneralUtility
37  $cacheManager = new ‪CacheManager();
38  $cacheManager->registerCache(new ‪NullFrontend('runtime'));
39  GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManager);
40 
41  $eventDispatcher = new ‪MockEventDispatcher();
42  GeneralUtility::addInstance(EventDispatcherInterface::class, $eventDispatcher);
43  GeneralUtility::addInstance(FlexFormTools::class, new ‪FlexFormTools($eventDispatcher));
44 
45  $this->subject = new ‪TcaFlexPrepare();
46  }
47 
48  protected function ‪tearDown(): void
49  {
50  GeneralUtility::purgeInstances();
51  parent::tearDown();
52  }
53 
57  public function ‪addDataMigratesFlexformTca(): void
58  {
59  $input = [
60  'systemLanguageRows' => [],
61  'tableName' => 'aTableName',
62  'databaseRow' => [
63  'aField' => [
64  'data' => [],
65  'meta' => [],
66  ],
67  ],
68  'processedTca' => [
69  'columns' => [
70  'aField' => [
71  'config' => [
72  'type' => 'flex',
73  'ds' => [
74  'default' => '
75  <T3DataStructure>
76  <sheets>
77  <sDEF>
78  <ROOT>
79  <type>array</type>
80  <el>
81  <aFlexField>
82  <TCEforms>
83  <label>aFlexFieldLabel</label>
84  <config>
85  </config>
86  </TCEforms>
87  </aFlexField>
88  </el>
89  </ROOT>
90  </sDEF>
91  </sheets>
92  </T3DataStructure>
93  ',
94  ],
95  ],
96  ],
97  ],
98  ],
99  ];
100 
101  ‪$GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns'];
102 
103  $expected = $input;
104  $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier']
105  = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}';
106  $expected['processedTca']['columns']['aField']['config']['ds'] = [
107  'sheets' => [
108  'sDEF' => [
109  'ROOT' => [
110  'type' => 'array',
111  'el' => [
112  'aFlexField' => [
113  'label' => 'aFlexFieldLabel',
114  'config' => [
115  'type' => 'none',
116  ],
117  ],
118  ],
119  ],
120  ],
121  ],
122  'meta' => [],
123  ];
124 
125  self::assertEquals($expected, $this->subject->addData($input));
126  }
127 
132  {
133  $input = [
134  'systemLanguageRows' => [],
135  'tableName' => 'aTableName',
136  'databaseRow' => [
137  'aField' => [
138  'data' => [],
139  'meta' => [],
140  ],
141  ],
142  'processedTca' => [
143  'columns' => [
144  'aField' => [
145  'config' => [
146  'type' => 'flex',
147  'ds' => [
148  'default' => '
149  <T3DataStructure>
150  <sheets>
151  <sDEF>
152  <ROOT>
153  <type>array</type>
154  <el>
155  <section_1>
156  <title>section_1</title>
157  <type>array</type>
158  <section>1</section>
159  <el>
160  <aFlexContainer>
161  <type>array</type>
162  <title>aFlexContainerLabel</title>
163  <el>
164  <aFlexField>
165  <TCEforms>
166  <label>aFlexFieldLabel</label>
167  <config>
168  </config>
169  </TCEforms>
170  </aFlexField>
171  </el>
172  </aFlexContainer>
173  </el>
174  </section_1>
175  </el>
176  </ROOT>
177  </sDEF>
178  </sheets>
179  </T3DataStructure>
180  ',
181  ],
182  ],
183  ],
184  ],
185  ],
186  ];
187 
188  ‪$GLOBALS['TCA']['aTableName']['columns'] = $input['processedTca']['columns'];
189 
190  $expected = $input;
191  $expected['processedTca']['columns']['aField']['config']['dataStructureIdentifier']
192  = '{"type":"tca","tableName":"aTableName","fieldName":"aField","dataStructureKey":"default"}';
193  $expected['processedTca']['columns']['aField']['config']['ds'] = [
194  'sheets' => [
195  'sDEF' => [
196  'ROOT' => [
197  'type' => 'array',
198  'el' => [
199  'section_1' => [
200  'title' => 'section_1',
201  'type' => 'array',
202  'section' => '1',
203  'el' => [
204  'aFlexContainer' => [
205  'type' => 'array',
206  'title' => 'aFlexContainerLabel',
207  'el' => [
208  'aFlexField' => [
209  'label' => 'aFlexFieldLabel',
210  'config' => [
211  'type' => 'none',
212  ],
213  ],
214  ],
215  ],
216  ],
217  ],
218  ],
219  ],
220  ],
221  ],
222  'meta' => [],
223  ];
224 
225  self::assertEquals($expected, $this->subject->addData($input));
226  }
227 }
‪TYPO3\CMS\Backend\Tests\UnitDeprecated\Form\FormDataProvider\TcaFlexPrepareTest
Definition: TcaFlexPrepareTest.php:30
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaFlexPrepare
Definition: TcaFlexPrepare.php:33
‪TYPO3\CMS\Core\Cache\Frontend\NullFrontend
Definition: NullFrontend.php:30
‪TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools
Definition: FlexFormTools.php:57
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:36
‪TYPO3\CMS\Backend\Tests\UnitDeprecated\Form\FormDataProvider\TcaFlexPrepareTest\addDataMigratesFlexformTcaInContainer
‪addDataMigratesFlexformTcaInContainer()
Definition: TcaFlexPrepareTest.php:131
‪TYPO3\CMS\Backend\Tests\UnitDeprecated\Form\FormDataProvider
Definition: TcaFlexPrepareTest.php:18
‪TYPO3\CMS\Backend\Tests\UnitDeprecated\Form\FormDataProvider\TcaFlexPrepareTest\$subject
‪TcaFlexPrepare $subject
Definition: TcaFlexPrepareTest.php:31
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Tests\UnitDeprecated\Form\FormDataProvider\TcaFlexPrepareTest\tearDown
‪tearDown()
Definition: TcaFlexPrepareTest.php:48
‪TYPO3\CMS\Core\Tests\Unit\Fixtures\EventDispatcher\MockEventDispatcher
Definition: MockEventDispatcher.php:30
‪TYPO3\CMS\Backend\Tests\UnitDeprecated\Form\FormDataProvider\TcaFlexPrepareTest\addDataMigratesFlexformTca
‪addDataMigratesFlexformTca()
Definition: TcaFlexPrepareTest.php:57
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\Backend\Tests\UnitDeprecated\Form\FormDataProvider\TcaFlexPrepareTest\setUp
‪setUp()
Definition: TcaFlexPrepareTest.php:33