Fixed bug #11224: Special menu directory only renders 1st level if special.value...
[Packages/TYPO3.CMS.git] / tests / t3lib / t3lib_extmgm_testcase.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Oliver Hader <oliver@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25
26 /**
27 * Testcase for class t3lib_extMgm
28 *
29 * @author Oliver Hader <oliver@typo3.org>
30 * @package TYPO3
31 * @subpackage t3lib
32 */
33 class t3lib_extmgm_testcase extends tx_phpunit_testcase {
34 /**
35 * Contains backup of defined GLOBALS
36 * @var array
37 */
38 protected $globals = array();
39
40 public function setUp() {
41 $this->globals = array(
42 'TYPO3_LOADED_EXT' => serialize($GLOBALS['TYPO3_LOADED_EXT']),
43 );
44 }
45
46 /**
47 * @test
48 * @see t3lib_extMgm::getExtensionKeyByPrefix
49 */
50 public function checkGetExtensionKeyByPrefix() {
51 $uniqueSuffix = uniqid('test');
52 $GLOBALS['TYPO3_LOADED_EXT']['tt_news' . $uniqueSuffix] = array();
53 $GLOBALS['TYPO3_LOADED_EXT']['kickstarter' . $uniqueSuffix] = array();
54
55 $this->assertEquals(
56 'tt_news' . $uniqueSuffix,
57 t3lib_extMgm::getExtensionKeyByPrefix('tx_ttnews' . $uniqueSuffix)
58 );
59 $this->assertEquals(
60 'kickstarter' . $uniqueSuffix,
61 t3lib_extMgm::getExtensionKeyByPrefix('tx_kickstarter' . $uniqueSuffix)
62 );
63 $this->assertFalse(
64 t3lib_extMgm::getExtensionKeyByPrefix('tx_unloadedextension' . $uniqueSuffix)
65 );
66 }
67
68 /**
69 * Tests whether fields can be add to all TCA types and duplicate fields are considered.
70 * @test
71 * @see t3lib_extMgm::addToAllTCAtypes()
72 */
73 public function canAddFieldsToAllTCATypesBeforeExistingOnes() {
74 $table = uniqid('tx_coretest_table');
75 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
76
77 t3lib_extMgm::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'before:fieldD');
78
79 // Checking typeA:
80 $this->assertEquals(
81 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD',
82 $GLOBALS['TCA'][$table]['types']['typeA']['showitem']
83 );
84 // Checking typeB:
85 $this->assertEquals(
86 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD',
87 $GLOBALS['TCA'][$table]['types']['typeB']['showitem']
88 );
89 }
90
91 /**
92 * Tests whether fields can be add to all TCA types and duplicate fields are considered.
93 * @test
94 * @see t3lib_extMgm::addToAllTCAtypes()
95 */
96 public function canAddFieldsToAllTCATypesAfterExistingOnes() {
97 $table = uniqid('tx_coretest_table');
98 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
99
100 t3lib_extMgm::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'after:fieldC');
101
102 // Checking typeA:
103 $this->assertEquals(
104 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD',
105 $GLOBALS['TCA'][$table]['types']['typeA']['showitem']
106 );
107 // Checking typeB:
108 $this->assertEquals(
109 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD',
110 $GLOBALS['TCA'][$table]['types']['typeB']['showitem']
111 );
112 }
113
114 /**
115 * Tests whether fields can be add to a TCA type before existing ones
116 * @test
117 * @see t3lib_extMgm::addToAllTCAtypes()
118 */
119 public function canAddFieldsToTCATypeBeforeExistingOnes() {
120 $table = uniqid('tx_coretest_table');
121 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
122
123 t3lib_extMgm::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', 'typeA', 'before:fieldD');
124
125 // Checking typeA:
126 $this->assertEquals(
127 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD',
128 $GLOBALS['TCA'][$table]['types']['typeA']['showitem']
129 );
130 // Checking typeB:
131 $this->assertEquals(
132 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD',
133 $GLOBALS['TCA'][$table]['types']['typeB']['showitem']
134 );
135 }
136
137 /**
138 * Tests whether fields can be add to a TCA type after existing ones
139 * @test
140 * @see t3lib_extMgm::addToAllTCAtypes()
141 */
142 public function canAddFieldsToTCATypeAfterExistingOnes() {
143 $table = uniqid('tx_coretest_table');
144 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
145
146 t3lib_extMgm::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', 'typeA', 'after:fieldC');
147
148 // Checking typeA:
149 $this->assertEquals(
150 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD',
151 $GLOBALS['TCA'][$table]['types']['typeA']['showitem']
152 );
153 // Checking typeB:
154 $this->assertEquals(
155 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD',
156 $GLOBALS['TCA'][$table]['types']['typeB']['showitem']
157 );
158 }
159
160 /**
161 * Tests whether fields can be added to a palette before existing elements.
162 * @test
163 * @see t3lib_extMgm::addFieldsToPalette()
164 */
165 public function canAddFieldsToPaletteBeforeExistingOnes() {
166 $table = uniqid('tx_coretest_table');
167 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
168
169 t3lib_extMgm::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'before:fieldY');
170
171 $this->assertEquals(
172 'fieldX, newA, newB, fieldY',
173 $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']
174 );
175 }
176
177 /**
178 * Tests whether fields can be added to a palette after existing elements.
179 * @test
180 * @see t3lib_extMgm::addFieldsToPalette()
181 */
182 public function canAddFieldsToPaletteAfterExistingOnes() {
183 $table = uniqid('tx_coretest_table');
184 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
185
186 t3lib_extMgm::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'after:fieldX');
187
188 $this->assertEquals(
189 'fieldX, newA, newB, fieldY',
190 $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']
191 );
192 }
193
194 /**
195 * Tests whether fields can be added to a palette after a not existing elements.
196 * @test
197 * @see t3lib_extMgm::addFieldsToPalette()
198 */
199 public function canAddFieldsToPaletteAfterNotExistingOnes() {
200 $table = uniqid('tx_coretest_table');
201 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
202
203 t3lib_extMgm::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'after:' . uniqid('notExisting'));
204
205 $this->assertEquals(
206 'fieldX, fieldY, newA, newB',
207 $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']
208 );
209 }
210
211 /**
212 * Tests whether fields can be added to all palettes of a regular field before existing ones.
213 * @test
214 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
215 */
216 public function canAddFieldsToAllPalettesOfFieldBeforeExistingOnes() {
217 $table = uniqid('tx_coretest_table');
218 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
219
220 t3lib_extMgm::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'before:fieldY');
221
222 $this->assertEquals(
223 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']
224 );
225 $this->assertEquals(
226 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']
227 );
228 $this->assertEquals(
229 'fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']
230 );
231 $this->assertEquals(
232 'fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']
233 );
234 }
235
236 /**
237 * Tests whether fields can be added to all palettes of a regular field after existing ones.
238 * @test
239 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
240 */
241 public function canAddFieldsToAllPalettesOfFieldAfterExistingOnes() {
242 $table = uniqid('tx_coretest_table');
243 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
244
245 t3lib_extMgm::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'after:fieldX');
246
247 $this->assertEquals(
248 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']
249 );
250 $this->assertEquals(
251 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']
252 );
253 $this->assertEquals(
254 'fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']
255 );
256 $this->assertEquals(
257 'fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']
258 );
259 }
260
261 /**
262 * Tests whether fields can be added to all palettes of a regular field after a not existing field.
263 * @test
264 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
265 */
266 public function canAddFieldsToAllPalettesOfFieldAfterNotExistingOnes() {
267 $table = uniqid('tx_coretest_table');
268 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
269
270 t3lib_extMgm::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'after:' . uniqid('notExisting'));
271
272 $this->assertEquals(
273 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']
274 );
275 $this->assertEquals(
276 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']
277 );
278 $this->assertEquals(
279 'fieldX, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']
280 );
281 $this->assertEquals(
282 'fieldX, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']
283 );
284 }
285
286 /**
287 * Tests whether fields are added to a new palette that did not exist before.
288 * @test
289 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
290 */
291 public function canAddFieldsToAllPalettesOfFieldWithoutPaletteExistingBefore() {
292 $table = uniqid('tx_coretest_table');
293 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
294
295 t3lib_extMgm::addFieldsToAllPalettesOfField($table, 'fieldA', 'newA, newA, newB, fieldX');
296
297 $this->assertEquals(
298 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']
299 );
300 $this->assertEquals(
301 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']
302 );
303 $this->assertEquals(
304 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']
305 );
306 $this->assertEquals(
307 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']
308 );
309 $this->assertEquals(
310 'newA, newB, fieldX', $GLOBALS['TCA'][$table]['palettes']['generatedFor-fieldA']['showitem']
311 );
312 }
313
314 public function tearDown() {
315 foreach ($this->globals as $key => $value) {
316 $GLOBALS[$key] = unserialize($value);
317 }
318 }
319
320 /**
321 * Generates a basic TCA for a given table.
322 *
323 * @param string $table: Name of the table
324 * @return array Generated TCA for the given table
325 */
326 private function generateTCAForTable($table) {
327 $tca = array();
328 $tca[$table] = array();
329 $tca[$table]['columns'] = array(
330 'fieldA' => array(),
331 'fieldC' => array(),
332 );
333 $tca[$table]['types'] = array(
334 'typeA' => array('showitem' => 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD'),
335 'typeB' => array('showitem' => 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD'),
336 'typeC' => array('showitem' => 'fieldC;;paletteD'),
337 );
338 $tca[$table]['palettes'] = array(
339 'paletteA' => array('showitem' => 'fieldX, fieldY'),
340 'paletteB' => array('showitem' => 'fieldX, fieldY'),
341 'paletteC' => array('showitem' => 'fieldX, fieldY'),
342 'paletteD' => array('showitem' => 'fieldX, fieldY'),
343 );
344
345 return $tca;
346 }
347 }
348
349 ?>