[FEATURE] Enable IRRE fields in FlexForms
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / Element / InlineElementTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Form\Element;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012 Oliver Hader <oliver.hader@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Tests for Inline Relational Record Editing form rendering.
29 *
30 * @author Oliver Hader <oliver.hader@typo3.org>
31 */
32 class InlineElementTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
33 /**
34 * @var \TYPO3\CMS\Backend\Form\Element\InlineElement
35 */
36 protected $fixture;
37
38 /**
39 * Sets up this test case.
40 */
41 protected function setUp() {
42 // @todo Use $this->buildAccessibleProxy() if properties are protected
43 $this->fixture = new \TYPO3\CMS\Backend\Form\Element\InlineElement();
44 $this->fixture->fObj = new \TYPO3\CMS\Backend\Form\FormEngine();
45 }
46
47 /**
48 * Tears down this test case.
49 */
50 protected function tearDown() {
51 unset($this->fixture);
52 }
53
54 /**
55 * @param array $arguments
56 * @param array $expectedInlineStructure
57 * @param array $expectedInlineNames
58 * @dataProvider pushStructureFillsInlineStructureDataProvider
59 * @test
60 */
61 public function pushStructureFillsInlineStructure(array $arguments, array $expectedInlineStructure, array $expectedInlineNames) {
62 $this->fixture->inlineFirstPid = 'pageId';
63
64 call_user_func_array(array($this->fixture, 'pushStructure'), $arguments);
65
66 $this->assertEquals($expectedInlineStructure, $this->fixture->inlineStructure);
67 $this->assertEquals($expectedInlineNames, $this->fixture->inlineNames);
68 }
69
70 public function pushStructureFillsInlineStructureDataProvider() {
71 return array(
72 'regular field' => array(
73 array(
74 'parentTable',
75 'parentUid',
76 'parentField'
77 ),
78 array(
79 'stable' => array(
80 array(
81 'table' => 'parentTable',
82 'uid' => 'parentUid',
83 'field' => 'parentField',
84 'config' => array(),
85 'localizationMode' => FALSE,
86 ),
87 ),
88 ),
89 array(
90 'form' => '[parentTable][parentUid][parentField]',
91 'object' => 'data-pageId-parentTable-parentUid-parentField',
92 )
93 ),
94 'flexform field' => array(
95 array(
96 'parentTable',
97 'parentUid',
98 'parentField',
99 array(),
100 array(
101 'itemFormElName' => 'data[parentTable][parentUid][parentField][data][sDEF][lDEF][grandParentFlexForm][vDEF]'
102 )
103 ),
104 array(
105 'stable' => array(
106 array(
107 'table' => 'parentTable',
108 'uid' => 'parentUid',
109 'field' => 'parentField',
110 'config' => array(),
111 'localizationMode' => FALSE,
112 'flexform' => array(
113 'data', 'sDEF', 'lDEF', 'grandParentFlexForm', 'vDEF',
114 ),
115 ),
116 ),
117 ),
118 array(
119 'form' => '[parentTable][parentUid][parentField][data][sDEF][lDEF][grandParentFlexForm][vDEF]',
120 'object' => 'data-pageId-parentTable-parentUid-parentField---data---sDEF---lDEF---grandParentFlexForm---vDEF',
121 )
122 ),
123 );
124 }
125
126 /**
127 * @param string $string
128 * @param array $expectedInlineStructure
129 * @param array $expectedInlineNames
130 * @dataProvider structureStringIsParsedDataProvider
131 * @test
132 */
133 public function structureStringIsParsed($string, array $expectedInlineStructure, array $expectedInlineNames) {
134 $this->fixture->parseStructureString($string, FALSE);
135
136 $this->assertEquals('pageId', $this->fixture->inlineFirstPid);
137 $this->assertEquals($expectedInlineStructure, $this->fixture->inlineStructure);
138 $this->assertEquals($expectedInlineNames, $this->fixture->inlineNames);
139 }
140
141 /**
142 * @return array
143 */
144 public function structureStringIsParsedDataProvider() {
145 return array(
146 'simple 1-level table structure' => array(
147 'data-pageId-childTable',
148 array(
149 'unstable' => array(
150 'table' => 'childTable',
151 ),
152 ),
153 array()
154 ),
155 'simple 1-level table-uid structure' => array(
156 'data-pageId-childTable-childUid',
157 array(
158 'unstable' => array(
159 'table' => 'childTable',
160 'uid' => 'childUid',
161 ),
162 ),
163 array()
164 ),
165 'simple 1-level table-uid-field structure' => array(
166 'data-pageId-childTable-childUid-childField',
167 array(
168 'unstable' => array(
169 'table' => 'childTable',
170 'uid' => 'childUid',
171 'field' => 'childField',
172 ),
173 ),
174 array(),
175 ),
176 'simple 2-level table structure' => array(
177 'data-pageId-parentTable-parentUid-parentField-childTable',
178 array(
179 'stable' => array(
180 array(
181 'table' => 'parentTable',
182 'uid' => 'parentUid',
183 'field' => 'parentField',
184 ),
185 ),
186 'unstable' => array(
187 'table' => 'childTable',
188 ),
189 ),
190 array(
191 'form' => '[parentTable][parentUid][parentField]',
192 'object' => 'data-pageId-parentTable-parentUid-parentField',
193 ),
194 ),
195 'simple 2-level table-uid structure' => array(
196 'data-pageId-parentTable-parentUid-parentField-childTable-childUid',
197 array(
198 'stable' => array(
199 array(
200 'table' => 'parentTable',
201 'uid' => 'parentUid',
202 'field' => 'parentField',
203 ),
204 ),
205 'unstable' => array(
206 'table' => 'childTable',
207 'uid' => 'childUid',
208 ),
209 ),
210 array(
211 'form' => '[parentTable][parentUid][parentField]',
212 'object' => 'data-pageId-parentTable-parentUid-parentField',
213 ),
214 ),
215 'simple 2-level table-uid-field structure' => array(
216 'data-pageId-parentTable-parentUid-parentField-childTable-childUid-childField',
217 array(
218 'stable' => array(
219 array(
220 'table' => 'parentTable',
221 'uid' => 'parentUid',
222 'field' => 'parentField',
223 ),
224 ),
225 'unstable' => array(
226 'table' => 'childTable',
227 'uid' => 'childUid',
228 'field' => 'childField',
229 ),
230 ),
231 array(
232 'form' => '[parentTable][parentUid][parentField]',
233 'object' => 'data-pageId-parentTable-parentUid-parentField',
234 ),
235 ),
236 'simple 3-level table structure' => array(
237 'data-pageId-grandParentTable-grandParentUid-grandParentField-parentTable-parentUid-parentField-childTable',
238 array(
239 'stable' => array(
240 array(
241 'table' => 'grandParentTable',
242 'uid' => 'grandParentUid',
243 'field' => 'grandParentField',
244 ),
245 array(
246 'table' => 'parentTable',
247 'uid' => 'parentUid',
248 'field' => 'parentField',
249 ),
250 ),
251 'unstable' => array(
252 'table' => 'childTable',
253 ),
254 ),
255 array(
256 'form' => '[parentTable][parentUid][parentField]',
257 'object' => 'data-pageId-grandParentTable-grandParentUid-grandParentField-parentTable-parentUid-parentField',
258 ),
259 ),
260 'simple 3-level table-uid structure' => array(
261 'data-pageId-grandParentTable-grandParentUid-grandParentField-parentTable-parentUid-parentField-childTable-childUid',
262 array(
263 'stable' => array(
264 array(
265 'table' => 'grandParentTable',
266 'uid' => 'grandParentUid',
267 'field' => 'grandParentField',
268 ),
269 array(
270 'table' => 'parentTable',
271 'uid' => 'parentUid',
272 'field' => 'parentField',
273 ),
274 ),
275 'unstable' => array(
276 'table' => 'childTable',
277 'uid' => 'childUid',
278 ),
279 ),
280 array(
281 'form' => '[parentTable][parentUid][parentField]',
282 'object' => 'data-pageId-grandParentTable-grandParentUid-grandParentField-parentTable-parentUid-parentField',
283 ),
284 ),
285 'simple 3-level table-uid-field structure' => array(
286 'data-pageId-grandParentTable-grandParentUid-grandParentField-parentTable-parentUid-parentField-childTable-childUid-childField',
287 array(
288 'stable' => array(
289 array(
290 'table' => 'grandParentTable',
291 'uid' => 'grandParentUid',
292 'field' => 'grandParentField',
293 ),
294 array(
295 'table' => 'parentTable',
296 'uid' => 'parentUid',
297 'field' => 'parentField',
298 ),
299 ),
300 'unstable' => array(
301 'table' => 'childTable',
302 'uid' => 'childUid',
303 'field' => 'childField',
304 ),
305 ),
306 array(
307 'form' => '[parentTable][parentUid][parentField]',
308 'object' => 'data-pageId-grandParentTable-grandParentUid-grandParentField-parentTable-parentUid-parentField',
309 ),
310 ),
311 'flexform 3-level table-uid structure' => array(
312 'data-pageId-grandParentTable-grandParentUid-grandParentField---data---sDEF---lDEF---grandParentFlexForm---vDEF-parentTable-parentUid-parentField-childTable-childUid',
313 array(
314 'stable' => array(
315 array(
316 'table' => 'grandParentTable',
317 'uid' => 'grandParentUid',
318 'field' => 'grandParentField',
319 'flexform' => array(
320 'data', 'sDEF', 'lDEF', 'grandParentFlexForm', 'vDEF',
321 ),
322 ),
323 array(
324 'table' => 'parentTable',
325 'uid' => 'parentUid',
326 'field' => 'parentField',
327 ),
328 ),
329 'unstable' => array(
330 'table' => 'childTable',
331 'uid' => 'childUid',
332 ),
333 ),
334 array(
335 'form' => '[parentTable][parentUid][parentField]',
336 'object' => 'data-pageId-grandParentTable-grandParentUid-grandParentField---data---sDEF---lDEF---grandParentFlexForm---vDEF-parentTable-parentUid-parentField',
337 ),
338 ),
339 );
340 }
341 }
342 ?>