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