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