InlineStackProcessorTest.php 7.83 KB
Newer Older
1
<?php
Christian Kuhn's avatar
Christian Kuhn committed
2
namespace TYPO3\CMS\Backend\Tests\Unit\Form;
3

4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
8
9
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
10
 *
11
12
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
15
 * The TYPO3 project - inspiring people to share!
 */
16

17
use TYPO3\CMS\Core\Tests\UnitTestCase;
Christian Kuhn's avatar
Christian Kuhn committed
18
use TYPO3\CMS\Backend\Form\InlineStackProcessor;
19

20
/**
21
 * Test case
22
 */
Christian Kuhn's avatar
Christian Kuhn committed
23
class InlineStackProcessorTest extends UnitTestCase {
24

25
26
27
	/**
	 * @return array
	 */
28
29
30
31
32
33
34
35
36
	public function structureStringIsParsedDataProvider() {
		return array(
			'simple 1-level table structure' => array(
				'data-pageId-childTable',
				array(
					'unstable' => array(
						'table' => 'childTable',
					),
				),
37
				array()
38
39
40
41
42
43
44
45
46
			),
			'simple 1-level table-uid structure' => array(
				'data-pageId-childTable-childUid',
				array(
					'unstable' => array(
						'table' => 'childTable',
						'uid' => 'childUid',
					),
				),
47
				array()
48
49
50
51
52
53
54
55
56
57
			),
			'simple 1-level table-uid-field structure' => array(
				'data-pageId-childTable-childUid-childField',
				array(
					'unstable' => array(
						'table' => 'childTable',
						'uid' => 'childUid',
						'field' => 'childField',
					),
				),
58
				array(),
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
			),
			'simple 2-level table structure' => array(
				'data-pageId-parentTable-parentUid-parentField-childTable',
				array(
					'stable' => array(
						array(
							'table' => 'parentTable',
							'uid' => 'parentUid',
							'field' => 'parentField',
						),
					),
					'unstable' => array(
						'table' => 'childTable',
					),
				),
74
				array(
75
					'form' => 'data[parentTable][parentUid][parentField]',
76
77
					'object' => 'data-pageId-parentTable-parentUid-parentField',
				),
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
			),
			'simple 2-level table-uid structure' => array(
				'data-pageId-parentTable-parentUid-parentField-childTable-childUid',
				array(
					'stable' => array(
						array(
							'table' => 'parentTable',
							'uid' => 'parentUid',
							'field' => 'parentField',
						),
					),
					'unstable' => array(
						'table' => 'childTable',
						'uid' => 'childUid',
					),
				),
94
				array(
95
					'form' => 'data[parentTable][parentUid][parentField]',
96
97
					'object' => 'data-pageId-parentTable-parentUid-parentField',
				),
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
			),
			'simple 2-level table-uid-field structure' => array(
				'data-pageId-parentTable-parentUid-parentField-childTable-childUid-childField',
				array(
					'stable' => array(
						array(
							'table' => 'parentTable',
							'uid' => 'parentUid',
							'field' => 'parentField',
						),
					),
					'unstable' => array(
						'table' => 'childTable',
						'uid' => 'childUid',
						'field' => 'childField',
					),
				),
115
				array(
116
					'form' => 'data[parentTable][parentUid][parentField]',
117
118
					'object' => 'data-pageId-parentTable-parentUid-parentField',
				),
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
			),
			'simple 3-level table structure' => array(
				'data-pageId-grandParentTable-grandParentUid-grandParentField-parentTable-parentUid-parentField-childTable',
				array(
					'stable' => array(
						array(
							'table' => 'grandParentTable',
							'uid' => 'grandParentUid',
							'field' => 'grandParentField',
						),
						array(
							'table' => 'parentTable',
							'uid' => 'parentUid',
							'field' => 'parentField',
						),
					),
					'unstable' => array(
						'table' => 'childTable',
					),
				),
139
				array(
140
					'form' => 'data[parentTable][parentUid][parentField]',
141
142
					'object' => 'data-pageId-grandParentTable-grandParentUid-grandParentField-parentTable-parentUid-parentField',
				),
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
			),
			'simple 3-level table-uid structure' => array(
				'data-pageId-grandParentTable-grandParentUid-grandParentField-parentTable-parentUid-parentField-childTable-childUid',
				array(
					'stable' => array(
						array(
							'table' => 'grandParentTable',
							'uid' => 'grandParentUid',
							'field' => 'grandParentField',
						),
						array(
							'table' => 'parentTable',
							'uid' => 'parentUid',
							'field' => 'parentField',
						),
					),
					'unstable' => array(
						'table' => 'childTable',
						'uid' => 'childUid',
					),
				),
164
				array(
165
					'form' => 'data[parentTable][parentUid][parentField]',
166
167
					'object' => 'data-pageId-grandParentTable-grandParentUid-grandParentField-parentTable-parentUid-parentField',
				),
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
			),
			'simple 3-level table-uid-field structure' => array(
				'data-pageId-grandParentTable-grandParentUid-grandParentField-parentTable-parentUid-parentField-childTable-childUid-childField',
				array(
					'stable' => array(
						array(
							'table' => 'grandParentTable',
							'uid' => 'grandParentUid',
							'field' => 'grandParentField',
						),
						array(
							'table' => 'parentTable',
							'uid' => 'parentUid',
							'field' => 'parentField',
						),
					),
					'unstable' => array(
						'table' => 'childTable',
						'uid' => 'childUid',
						'field' => 'childField',
					),
				),
190
				array(
191
					'form' => 'data[parentTable][parentUid][parentField]',
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
					'object' => 'data-pageId-grandParentTable-grandParentUid-grandParentField-parentTable-parentUid-parentField',
				),
			),
			'flexform 3-level table-uid structure' => array(
				'data-pageId-grandParentTable-grandParentUid-grandParentField---data---sDEF---lDEF---grandParentFlexForm---vDEF-parentTable-parentUid-parentField-childTable-childUid',
				array(
					'stable' => array(
						array(
							'table' => 'grandParentTable',
							'uid' => 'grandParentUid',
							'field' => 'grandParentField',
							'flexform' => array(
								'data', 'sDEF', 'lDEF', 'grandParentFlexForm', 'vDEF',
							),
						),
						array(
							'table' => 'parentTable',
							'uid' => 'parentUid',
							'field' => 'parentField',
						),
					),
					'unstable' => array(
						'table' => 'childTable',
						'uid' => 'childUid',
					),
				),
				array(
219
					'form' => 'data[parentTable][parentUid][parentField]',
220
221
					'object' => 'data-pageId-grandParentTable-grandParentUid-grandParentField---data---sDEF---lDEF---grandParentFlexForm---vDEF-parentTable-parentUid-parentField',
				),
222
223
224
			),
		);
	}
225

226
	/**
Christian Kuhn's avatar
Christian Kuhn committed
227
	 * @dataProvider structureStringIsParsedDataProvider
228
229
	 * @test
	 */
Christian Kuhn's avatar
Christian Kuhn committed
230
231
232
233
234
235
	public function initializeByParsingDomObjectIdStringParsesStructureString($string, array $expectedInlineStructure, array $_) {
		/** @var InlineStackProcessor|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $subject */
		$subject = $this->getAccessibleMock(InlineStackProcessor::class, array('dummy'));
		$subject->initializeByParsingDomObjectIdString($string, FALSE);
		$structure = $subject->_get('inlineStructure');
		$this->assertEquals($expectedInlineStructure, $structure);
236
237
238
	}

	/**
Christian Kuhn's avatar
Christian Kuhn committed
239
	 * @dataProvider structureStringIsParsedDataProvider
240
241
	 * @test
	 */
Christian Kuhn's avatar
Christian Kuhn committed
242
243
244
245
	public function getCurrentStructureFormPrefixReturnsExceptedStringAfterInitializationByStructureString($string, array $_, array $expectedFormName) {
		/** @var InlineStackProcessor|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $subject */
		$subject = new InlineStackProcessor;
		$subject->initializeByParsingDomObjectIdString($string, FALSE);
246
		$this->assertEquals($expectedFormName['form'], $subject->getCurrentStructureFormPrefix());
247
248
249
	}

	/**
Christian Kuhn's avatar
Christian Kuhn committed
250
	 * @dataProvider structureStringIsParsedDataProvider
251
252
	 * @test
	 */
Christian Kuhn's avatar
Christian Kuhn committed
253
254
255
256
257
	public function getCurrentStructureDomObjectIdPrefixReturnsExceptedStringAfterInitializationByStructureString($string, array $_, array $expectedFormName) {
		/** @var InlineStackProcessor|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $subject */
		$subject = new InlineStackProcessor;
		$subject->initializeByParsingDomObjectIdString($string, FALSE);
		$this->assertEquals($expectedFormName['object'], $subject->getCurrentStructureDomObjectIdPrefix('pageId'));
258
	}
Christian Kuhn's avatar
Christian Kuhn committed
259

260
}