[TASK] FormEngine inline refactoring
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / InlineStackProcessorTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Form;
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
17 use TYPO3\CMS\Core\Database\DatabaseConnection;
18 use TYPO3\CMS\Core\Tests\UnitTestCase;
19 use TYPO3\CMS\Backend\Form\InlineStackProcessor;
20
21 /**
22 * Test case
23 */
24 class InlineStackProcessorTest extends UnitTestCase {
25
26 protected function setUp() {
27 // @todo: Remove if stack processor does not fiddle with tsConfig anymore and no longer sets 'config'
28 $dbProphecy = $this->prophesize(DatabaseConnection::class);
29 $GLOBALS['TYPO3_DB'] = $dbProphecy->reveal();
30 }
31
32 /**
33 * @return array
34 */
35 public function structureStringIsParsedDataProvider() {
36 return array(
37 'simple 1-level table structure' => array(
38 'data-pageId-childTable',
39 array(
40 'unstable' => array(
41 'table' => 'childTable',
42 ),
43 ),
44 array()
45 ),
46 'simple 1-level table-uid structure' => array(
47 'data-pageId-childTable-childUid',
48 array(
49 'unstable' => array(
50 'table' => 'childTable',
51 'uid' => 'childUid',
52 ),
53 ),
54 array()
55 ),
56 'simple 1-level table-uid-field structure' => array(
57 'data-pageId-childTable-childUid-childField',
58 array(
59 'unstable' => array(
60 'table' => 'childTable',
61 'uid' => 'childUid',
62 'field' => 'childField',
63 ),
64 ),
65 array(),
66 ),
67 'simple 2-level table structure' => array(
68 'data-pageId-parentTable-parentUid-parentField-childTable',
69 array(
70 'stable' => array(
71 array(
72 'table' => 'parentTable',
73 'uid' => 'parentUid',
74 'field' => 'parentField',
75 'config' => null,
76 'localizationMode' => false,
77 ),
78 ),
79 'unstable' => array(
80 'table' => 'childTable',
81 ),
82 ),
83 array(
84 'form' => 'data[parentTable][parentUid][parentField]',
85 'object' => 'data-pageId-parentTable-parentUid-parentField',
86 ),
87 ),
88 'simple 2-level table-uid structure' => array(
89 'data-pageId-parentTable-parentUid-parentField-childTable-childUid',
90 array(
91 'stable' => array(
92 array(
93 'table' => 'parentTable',
94 'uid' => 'parentUid',
95 'field' => 'parentField',
96 'config' => null,
97 'localizationMode' => false,
98 ),
99 ),
100 'unstable' => array(
101 'table' => 'childTable',
102 'uid' => 'childUid',
103 ),
104 ),
105 array(
106 'form' => 'data[parentTable][parentUid][parentField]',
107 'object' => 'data-pageId-parentTable-parentUid-parentField',
108 ),
109 ),
110 'simple 2-level table-uid-field structure' => array(
111 'data-pageId-parentTable-parentUid-parentField-childTable-childUid-childField',
112 array(
113 'stable' => array(
114 array(
115 'table' => 'parentTable',
116 'uid' => 'parentUid',
117 'field' => 'parentField',
118 'config' => null,
119 'localizationMode' => false,
120 ),
121 ),
122 'unstable' => array(
123 'table' => 'childTable',
124 'uid' => 'childUid',
125 'field' => 'childField',
126 ),
127 ),
128 array(
129 'form' => 'data[parentTable][parentUid][parentField]',
130 'object' => 'data-pageId-parentTable-parentUid-parentField',
131 ),
132 ),
133 'simple 3-level table structure' => array(
134 'data-pageId-grandParentTable-grandParentUid-grandParentField-parentTable-parentUid-parentField-childTable',
135 array(
136 'stable' => array(
137 array(
138 'table' => 'grandParentTable',
139 'uid' => 'grandParentUid',
140 'field' => 'grandParentField',
141 'config' => null,
142 'localizationMode' => false,
143 ),
144 array(
145 'table' => 'parentTable',
146 'uid' => 'parentUid',
147 'field' => 'parentField',
148 'config' => null,
149 'localizationMode' => false,
150 ),
151 ),
152 'unstable' => array(
153 'table' => 'childTable',
154 ),
155 ),
156 array(
157 'form' => 'data[parentTable][parentUid][parentField]',
158 'object' => 'data-pageId-grandParentTable-grandParentUid-grandParentField-parentTable-parentUid-parentField',
159 ),
160 ),
161 'simple 3-level table-uid structure' => array(
162 'data-pageId-grandParentTable-grandParentUid-grandParentField-parentTable-parentUid-parentField-childTable-childUid',
163 array(
164 'stable' => array(
165 array(
166 'table' => 'grandParentTable',
167 'uid' => 'grandParentUid',
168 'field' => 'grandParentField',
169 'config' => null,
170 'localizationMode' => false,
171 ),
172 array(
173 'table' => 'parentTable',
174 'uid' => 'parentUid',
175 'field' => 'parentField',
176 'config' => null,
177 'localizationMode' => false,
178 ),
179 ),
180 'unstable' => array(
181 'table' => 'childTable',
182 'uid' => 'childUid',
183 ),
184 ),
185 array(
186 'form' => 'data[parentTable][parentUid][parentField]',
187 'object' => 'data-pageId-grandParentTable-grandParentUid-grandParentField-parentTable-parentUid-parentField',
188 ),
189 ),
190 'simple 3-level table-uid-field structure' => array(
191 'data-pageId-grandParentTable-grandParentUid-grandParentField-parentTable-parentUid-parentField-childTable-childUid-childField',
192 array(
193 'stable' => array(
194 array(
195 'table' => 'grandParentTable',
196 'uid' => 'grandParentUid',
197 'field' => 'grandParentField',
198 'config' => null,
199 'localizationMode' => false,
200 ),
201 array(
202 'table' => 'parentTable',
203 'uid' => 'parentUid',
204 'field' => 'parentField',
205 'config' => null,
206 'localizationMode' => false,
207 ),
208 ),
209 'unstable' => array(
210 'table' => 'childTable',
211 'uid' => 'childUid',
212 'field' => 'childField',
213 ),
214 ),
215 array(
216 'form' => 'data[parentTable][parentUid][parentField]',
217 'object' => 'data-pageId-grandParentTable-grandParentUid-grandParentField-parentTable-parentUid-parentField',
218 ),
219 ),
220 'flexform 3-level table-uid structure' => array(
221 'data-pageId-grandParentTable-grandParentUid-grandParentField---data---sDEF---lDEF---grandParentFlexForm---vDEF-parentTable-parentUid-parentField-childTable-childUid',
222 array(
223 'stable' => array(
224 array(
225 'table' => 'grandParentTable',
226 'uid' => 'grandParentUid',
227 'field' => 'grandParentField',
228 'flexform' => array(
229 'data', 'sDEF', 'lDEF', 'grandParentFlexForm', 'vDEF',
230 ),
231 'config' => null,
232 'localizationMode' => false,
233 ),
234 array(
235 'table' => 'parentTable',
236 'uid' => 'parentUid',
237 'field' => 'parentField',
238 'config' => null,
239 'localizationMode' => false,
240 ),
241 ),
242 'unstable' => array(
243 'table' => 'childTable',
244 'uid' => 'childUid',
245 ),
246 ),
247 array(
248 'form' => 'data[parentTable][parentUid][parentField]',
249 'object' => 'data-pageId-grandParentTable-grandParentUid-grandParentField---data---sDEF---lDEF---grandParentFlexForm---vDEF-parentTable-parentUid-parentField',
250 ),
251 ),
252 );
253 }
254
255 /**
256 * @dataProvider structureStringIsParsedDataProvider
257 * @test
258 */
259 public function initializeByParsingDomObjectIdStringParsesStructureString($string, array $expectedInlineStructure, array $_) {
260 /** @var InlineStackProcessor|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $subject */
261 $subject = $this->getAccessibleMock(InlineStackProcessor::class, array('dummy'));
262 $subject->initializeByParsingDomObjectIdString($string);
263 $structure = $subject->_get('inlineStructure');
264 $this->assertEquals($expectedInlineStructure, $structure);
265 }
266
267 /**
268 * @dataProvider structureStringIsParsedDataProvider
269 * @test
270 */
271 public function getCurrentStructureFormPrefixReturnsExceptedStringAfterInitializationByStructureString($string, array $_, array $expectedFormName) {
272 /** @var InlineStackProcessor|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $subject */
273 $subject = new InlineStackProcessor;
274 $subject->initializeByParsingDomObjectIdString($string);
275 $this->assertEquals($expectedFormName['form'], $subject->getCurrentStructureFormPrefix());
276 }
277
278 /**
279 * @dataProvider structureStringIsParsedDataProvider
280 * @test
281 */
282 public function getCurrentStructureDomObjectIdPrefixReturnsExceptedStringAfterInitializationByStructureString($string, array $_, array $expectedFormName) {
283 /** @var InlineStackProcessor|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $subject */
284 $subject = new InlineStackProcessor;
285 $subject->initializeByParsingDomObjectIdString($string);
286 $this->assertEquals($expectedFormName['object'], $subject->getCurrentStructureDomObjectIdPrefix('pageId'));
287 }
288
289 }