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