4e1ec6250b919b6db654a7695d5d4e533bbad400
[Packages/TYPO3.CMS.git] / tests / t3lib / class.t3lib_extmgmTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2011 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 * Testcase for class t3lib_extMgm
27 *
28 * @author Oliver Hader <oliver@typo3.org>
29 * @author Oliver Klee <typo3-coding@oliverklee.de>
30 *
31 * @package TYPO3
32 * @subpackage t3lib
33 */
34 class t3lib_extmgmTest extends tx_phpunit_testcase {
35
36 /**
37 * Enable backup of global and system variables
38 *
39 * @var boolean
40 */
41 protected $backupGlobals = TRUE;
42
43 /**
44 * Exclude TYPO3_DB from backup/ restore of $GLOBALS
45 * because resource types cannot be handled during serializing
46 *
47 * @var array
48 */
49 protected $backupGlobalsBlacklist = array('TYPO3_DB');
50
51 /**
52 * phpunit still needs some globals that are
53 * reconstructed before $backupGlobals is handled. Those
54 * important globals are handled in tearDown() directly.
55 *
56 * @var array
57 */
58 protected $globals = array();
59
60 public function setUp() {
61 $this->globals = array(
62 'TYPO3_LOADED_EXT' => serialize($GLOBALS['TYPO3_LOADED_EXT']),
63 );
64 }
65
66 public function tearDown() {
67 t3lib_extMgm::clearExtensionKeyMap();
68
69 foreach ($this->globals as $key => $value) {
70 $GLOBALS[$key] = unserialize($value);
71 }
72 }
73
74 ///////////////////////////////
75 // Tests concerning extPath
76 ///////////////////////////////
77
78 /**
79 * @test
80 * @expectedException BadFunctionCallException
81 */
82 public function extPathThrowsExceptionIfExtensionIsNotLoaded() {
83 $GLOBALS['TYPO3_LOADED_EXT']['foo'] = array();
84 t3lib_extMgm::extPath('bar');
85 }
86
87 /**
88 * @test
89 */
90 public function extPathAppendsScriptNameToPath() {
91 $GLOBALS['TYPO3_LOADED_EXT']['foo']['siteRelPath'] = 'foo/';
92 $this->assertSame(PATH_site . 'foo/bar.txt', t3lib_extMgm::extPath('foo', 'bar.txt'));
93 }
94
95 /**
96 * @test
97 * @expectedException BadFunctionCallException
98 */
99 public function extPathThrowsExceptionIfExtensionIsNotLoadedAndTypo3LoadedExtensionsIsEmpty() {
100 unset($GLOBALS['TYPO3_LOADED_EXT']);
101 $GLOBALS['TYPO3_CONF_VARS']['EXT']['requiredExt'] = '';
102 $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList'] = '';
103 t3lib_extMgm::extPath('bar');
104 }
105
106 /**
107 * @test
108 */
109 public function extPathSearchesForPathOfExtensionInRequiredExtensionList() {
110 $this->setExpectedException('Exception', '', 1294430951);
111
112 unset($GLOBALS['TYPO3_LOADED_EXT']);
113 $GLOBALS['TYPO3_CONF_VARS']['EXT']['requiredExt'] = 'foo';
114 $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList'] = '';
115 t3lib_extMgm::extPath('foo');
116 }
117
118 /**
119 * @test
120 */
121 public function extPathSearchesForPathOfExtensionInExtList() {
122 $this->setExpectedException('Exception', '', 1294430951);
123
124 unset($GLOBALS['TYPO3_LOADED_EXT']);
125 $GLOBALS['TYPO3_CONF_VARS']['EXT']['requiredExt'] = '';
126 $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList'] = 'foo';
127 t3lib_extMgm::extPath('foo');
128 }
129
130 //////////////////////
131 // Utility functions
132 //////////////////////
133
134 /**
135 * Generates a basic TCA for a given table.
136 *
137 * @param string $table name of the table, must not be empty
138 * @return array generated TCA for the given table, will not be empty
139 */
140 private function generateTCAForTable($table) {
141 $tca = array();
142 $tca[$table] = array();
143 $tca[$table]['columns'] = array(
144 'fieldA' => array(),
145 'fieldC' => array(),
146 );
147 $tca[$table]['types'] = array(
148 'typeA' => array('showitem' => 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD'),
149 'typeB' => array('showitem' => 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD'),
150 'typeC' => array('showitem' => 'fieldC;;paletteD'),
151 );
152 $tca[$table]['palettes'] = array(
153 'paletteA' => array('showitem' => 'fieldX, fieldY'),
154 'paletteB' => array('showitem' => 'fieldX, fieldY'),
155 'paletteC' => array('showitem' => 'fieldX, fieldY'),
156 'paletteD' => array('showitem' => 'fieldX, fieldY'),
157 );
158
159 return $tca;
160 }
161
162 /**
163 * Returns the fixtures path for this testcase relative to PATH_site.
164 *
165 * @return string the fixtures path for this testcase, will not be empty
166 */
167 private function determineFixturesPath() {
168 return t3lib_div::makeInstance('Tx_Phpunit_Service_TestFinder')
169 ->getRelativeCoreTestsPath() . 't3lib/fixtures/';
170 }
171
172
173 /////////////////////////////////////////////
174 // Tests concerning getExtensionKeyByPrefix
175 /////////////////////////////////////////////
176
177 /**
178 * @test
179 * @see t3lib_extMgm::getExtensionKeyByPrefix
180 */
181 public function getExtensionKeyByPrefixForLoadedExtensionWithUnderscoresReturnsExtensionKey() {
182 t3lib_extMgm::clearExtensionKeyMap();
183
184 $uniqueSuffix = uniqid('test');
185 $extensionKey = 'tt_news' . $uniqueSuffix;
186 $extensionPrefix = 'tx_ttnews' . $uniqueSuffix;
187
188 $GLOBALS['TYPO3_LOADED_EXT'][$extensionKey] = array();
189
190 $this->assertEquals(
191 $extensionKey,
192 t3lib_extMgm::getExtensionKeyByPrefix($extensionPrefix)
193 );
194 }
195
196 /**
197 * @test
198 * @see t3lib_extMgm::getExtensionKeyByPrefix
199 */
200 public function getExtensionKeyByPrefixForLoadedExtensionWithoutUnderscoresReturnsExtensionKey() {
201 t3lib_extMgm::clearExtensionKeyMap();
202
203 $uniqueSuffix = uniqid('test');
204 $extensionKey = 'kickstarter' . $uniqueSuffix;
205 $extensionPrefix = 'tx_kickstarter' . $uniqueSuffix;
206
207 $GLOBALS['TYPO3_LOADED_EXT'][$extensionKey] = array();
208
209 $this->assertEquals(
210 $extensionKey,
211 t3lib_extMgm::getExtensionKeyByPrefix($extensionPrefix)
212 );
213 }
214
215 /**
216 * @test
217 * @see t3lib_extMgm::getExtensionKeyByPrefix
218 */
219 public function getExtensionKeyByPrefixForNotLoadedExtensionReturnsFalse(){
220 t3lib_extMgm::clearExtensionKeyMap();
221
222 $uniqueSuffix = uniqid('test');
223 $extensionKey = 'unloadedextension' . $uniqueSuffix;
224 $extensionPrefix = 'tx_unloadedextension' . $uniqueSuffix;
225
226 $this->assertFalse(
227 t3lib_extMgm::getExtensionKeyByPrefix($extensionPrefix)
228 );
229 }
230
231
232 //////////////////////////////////////
233 // Tests concerning addToAllTCAtypes
234 //////////////////////////////////////
235
236 /**
237 * Tests whether fields can be add to all TCA types and duplicate fields are considered.
238 * @test
239 * @see t3lib_extMgm::addToAllTCAtypes()
240 */
241 public function canAddFieldsToAllTCATypesBeforeExistingOnes() {
242 $table = uniqid('tx_coretest_table');
243 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
244
245 t3lib_extMgm::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'before:fieldD');
246
247 // Checking typeA:
248 $this->assertEquals(
249 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD',
250 $GLOBALS['TCA'][$table]['types']['typeA']['showitem']
251 );
252 // Checking typeB:
253 $this->assertEquals(
254 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD',
255 $GLOBALS['TCA'][$table]['types']['typeB']['showitem']
256 );
257 }
258
259 /**
260 * Tests whether fields can be add to all TCA types and duplicate fields are considered.
261 * @test
262 * @see t3lib_extMgm::addToAllTCAtypes()
263 */
264 public function canAddFieldsToAllTCATypesAfterExistingOnes() {
265 $table = uniqid('tx_coretest_table');
266 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
267
268 t3lib_extMgm::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'after:fieldC');
269
270 // Checking typeA:
271 $this->assertEquals(
272 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD',
273 $GLOBALS['TCA'][$table]['types']['typeA']['showitem']
274 );
275 // Checking typeB:
276 $this->assertEquals(
277 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD',
278 $GLOBALS['TCA'][$table]['types']['typeB']['showitem']
279 );
280 }
281
282 /**
283 * Tests whether fields can be add to a TCA type before existing ones
284 * @test
285 * @see t3lib_extMgm::addToAllTCAtypes()
286 */
287 public function canAddFieldsToTCATypeBeforeExistingOnes() {
288 $table = uniqid('tx_coretest_table');
289 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
290
291 t3lib_extMgm::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', 'typeA', 'before:fieldD');
292
293 // Checking typeA:
294 $this->assertEquals(
295 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD',
296 $GLOBALS['TCA'][$table]['types']['typeA']['showitem']
297 );
298 // Checking typeB:
299 $this->assertEquals(
300 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD',
301 $GLOBALS['TCA'][$table]['types']['typeB']['showitem']
302 );
303 }
304
305 /**
306 * Tests whether fields can be add to a TCA type after existing ones
307 * @test
308 * @see t3lib_extMgm::addToAllTCAtypes()
309 */
310 public function canAddFieldsToTCATypeAfterExistingOnes() {
311 $table = uniqid('tx_coretest_table');
312 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
313
314 t3lib_extMgm::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', 'typeA', 'after:fieldC');
315
316 // Checking typeA:
317 $this->assertEquals(
318 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD',
319 $GLOBALS['TCA'][$table]['types']['typeA']['showitem']
320 );
321 // Checking typeB:
322 $this->assertEquals(
323 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD',
324 $GLOBALS['TCA'][$table]['types']['typeB']['showitem']
325 );
326 }
327
328 /**
329 * Test wheter replacing other TCA fields works as promissed
330 * @test
331 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
332 */
333 public function canAddFieldsToTCATypeAndReplaceExistingOnes() {
334 $table = uniqid('tx_coretest_table');
335 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
336
337 $typesBefore = $GLOBALS['TCA'][$table]['types'];
338
339 t3lib_extMgm::addToAllTCAtypes($table, 'fieldZ', '', 'replace:fieldX');
340
341 $this->assertEquals(
342 $typesBefore,
343 $GLOBALS['TCA'][$table]['types'],
344 'It\'s wrong that the "types" array changes here - the replaced field is only on palettes'
345 );
346
347 // unchanged because the palette is not used
348 $this->assertEquals(
349 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']
350 );
351 // unchanged because the palette is not used
352 $this->assertEquals(
353 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']
354 );
355
356 $this->assertEquals(
357 'fieldZ, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']
358 );
359
360 $this->assertEquals(
361 'fieldZ, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']
362 );
363 }
364
365
366
367 ///////////////////////////////////////////////////
368 // Tests concerning addFieldsToAllPalettesOfField
369 ///////////////////////////////////////////////////
370
371 /**
372 * Tests whether fields can be added to a palette before existing elements.
373 * @test
374 * @see t3lib_extMgm::addFieldsToPalette()
375 */
376 public function canAddFieldsToPaletteBeforeExistingOnes() {
377 $table = uniqid('tx_coretest_table');
378 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
379
380 t3lib_extMgm::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'before:fieldY');
381
382 $this->assertEquals(
383 'fieldX, newA, newB, fieldY',
384 $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']
385 );
386 }
387
388 /**
389 * Tests whether fields can be added to a palette after existing elements.
390 * @test
391 * @see t3lib_extMgm::addFieldsToPalette()
392 */
393 public function canAddFieldsToPaletteAfterExistingOnes() {
394 $table = uniqid('tx_coretest_table');
395 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
396
397 t3lib_extMgm::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'after:fieldX');
398
399 $this->assertEquals(
400 'fieldX, newA, newB, fieldY',
401 $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']
402 );
403 }
404
405 /**
406 * Tests whether fields can be added to a palette after a not existing elements.
407 * @test
408 * @see t3lib_extMgm::addFieldsToPalette()
409 */
410 public function canAddFieldsToPaletteAfterNotExistingOnes() {
411 $table = uniqid('tx_coretest_table');
412 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
413
414 t3lib_extMgm::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'after:' . uniqid('notExisting'));
415
416 $this->assertEquals(
417 'fieldX, fieldY, newA, newB',
418 $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']
419 );
420 }
421
422 /**
423 * Tests whether fields can be added to all palettes of a regular field before existing ones.
424 * @test
425 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
426 */
427 public function canAddFieldsToAllPalettesOfFieldBeforeExistingOnes() {
428 $table = uniqid('tx_coretest_table');
429 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
430
431 t3lib_extMgm::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'before:fieldY');
432
433 $this->assertEquals(
434 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']
435 );
436 $this->assertEquals(
437 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']
438 );
439 $this->assertEquals(
440 'fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']
441 );
442 $this->assertEquals(
443 'fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']
444 );
445 }
446
447 /**
448 * Tests whether fields can be added to all palettes of a regular field after existing ones.
449 * @test
450 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
451 */
452 public function canAddFieldsToAllPalettesOfFieldAfterExistingOnes() {
453 $table = uniqid('tx_coretest_table');
454 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
455
456 t3lib_extMgm::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'after:fieldX');
457
458 $this->assertEquals(
459 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']
460 );
461 $this->assertEquals(
462 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']
463 );
464 $this->assertEquals(
465 'fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']
466 );
467 $this->assertEquals(
468 'fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']
469 );
470 }
471
472 /**
473 * Tests whether fields can be added to all palettes of a regular field after a not existing field.
474 * @test
475 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
476 */
477 public function canAddFieldsToAllPalettesOfFieldAfterNotExistingOnes() {
478 $table = uniqid('tx_coretest_table');
479 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
480
481 t3lib_extMgm::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'after:' . uniqid('notExisting'));
482
483 $this->assertEquals(
484 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']
485 );
486 $this->assertEquals(
487 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']
488 );
489 $this->assertEquals(
490 'fieldX, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']
491 );
492 $this->assertEquals(
493 'fieldX, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']
494 );
495 }
496
497 /**
498 * Tests whether fields are added to a new palette that did not exist before.
499 * @test
500 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
501 */
502 public function canAddFieldsToAllPalettesOfFieldWithoutPaletteExistingBefore() {
503 $table = uniqid('tx_coretest_table');
504 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
505
506 t3lib_extMgm::addFieldsToAllPalettesOfField($table, 'fieldA', 'newA, newA, newB, fieldX');
507
508 $this->assertEquals(
509 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']
510 );
511 $this->assertEquals(
512 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']
513 );
514 $this->assertEquals(
515 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']
516 );
517 $this->assertEquals(
518 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']
519 );
520 $this->assertEquals(
521 'newA, newB, fieldX', $GLOBALS['TCA'][$table]['palettes']['generatedFor-fieldA']['showitem']
522 );
523 }
524
525
526 /////////////////////////////////////////
527 // Tests concerning addTcaSelectItem
528 /////////////////////////////////////////
529
530 /**
531 * @test
532 * @expectedException InvalidArgumentException
533 */
534 public function addTcaSelectItemThrowsExceptionIfTableIsNotOfTypeString() {
535 t3lib_extMgm::addTcaSelectItem(array(), 'foo', array());
536 }
537
538 /**
539 * @test
540 * @expectedException InvalidArgumentException
541 */
542 public function addTcaSelectItemThrowsExceptionIfFieldIsNotOfTypeString() {
543 t3lib_extMgm::addTcaSelectItem('foo', array(), array());
544 }
545
546 /**
547 * @test
548 * @expectedException InvalidArgumentException
549 */
550 public function addTcaSelectItemThrowsExceptionIfRelativeToFieldIsNotOfTypeString() {
551 t3lib_extMgm::addTcaSelectItem('foo', 'bar', array(), array());
552 }
553
554 /**
555 * @test
556 * @expectedException InvalidArgumentException
557 */
558 public function addTcaSelectItemThrowsExceptionIfRelativePositionIsNotOfTypeString() {
559 t3lib_extMgm::addTcaSelectItem('foo', 'bar', array(), 'foo', array());
560 }
561
562 /**
563 * @test
564 * @expectedException InvalidArgumentException
565 */
566 public function addTcaSelectItemThrowsExceptionIfRelativePositionIsNotOneOfValidKeywords() {
567 t3lib_extMgm::addTcaSelectItem('foo', 'bar', array(), 'foo', 'not allowed keyword');
568 }
569
570 /**
571 * @test
572 * @expectedException RuntimeException
573 */
574 public function addTcaSelectItemThrowsExceptionIfFieldIsNotFoundInTca() {
575 $GLOBALS['TCA'] = array();
576 t3lib_extMgm::addTcaSelectItem('foo', 'bar', array());
577 }
578
579 /**
580 * Data provider for addTcaSelectItemInsertsItemAtSpecifiedPosition
581 */
582 public function addTcaSelectItemDataProvider() {
583 // Every array splits into:
584 // - relativeToField
585 // - relativePosition
586 // - expectedResultArray
587 return array(
588 'add at end of array' => array(
589 '',
590 '',
591 array(
592 0 => array('firstElement'),
593 1 => array('matchMe'),
594 2 => array('thirdElement'),
595 3 => array('insertedElement'),
596 ),
597 ),
598 'replace element' => array(
599 'matchMe',
600 'replace',
601 array(
602 0 => array('firstElement'),
603 1 => array('insertedElement'),
604 2 => array('thirdElement'),
605 ),
606 ),
607 'add element after' => array(
608 'matchMe',
609 'after',
610 array(
611 0 => array('firstElement'),
612 1 => array('matchMe'),
613 2 => array('insertedElement'),
614 3 => array('thirdElement'),
615 ),
616 ),
617 'add element before' => array(
618 'matchMe',
619 'before',
620 array(
621 0 => array('firstElement'),
622 1 => array('insertedElement'),
623 2 => array('matchMe'),
624 3 => array('thirdElement'),
625 ),
626 ),
627 'add at end if relative position was not found' => array(
628 'notExistingItem',
629 'after',
630 array(
631 0 => array('firstElement'),
632 1 => array('matchMe'),
633 2 => array('thirdElement'),
634 3 => array('insertedElement'),
635 ),
636 ),
637 );
638 }
639
640 /**
641 * @test
642 * @dataProvider addTcaSelectItemDataProvider
643 */
644 public function addTcaSelectItemInsertsItemAtSpecifiedPosition($relativeToField, $relativePosition, $expectedResultArray) {
645 $GLOBALS['TCA'] = array(
646 'testTable' => array(
647 'columns' => array(
648 'testField' => array(
649 'config' => array(
650 'items' => array(
651 '0' => array('firstElement'),
652 '1' => array('matchMe'),
653 2 => array('thirdElement'),
654 ),
655 ),
656 ),
657 ),
658 ),
659 );
660 t3lib_extMgm::addTcaSelectItem('testTable', 'testField', array('insertedElement'), $relativeToField, $relativePosition);
661 $this->assertEquals($expectedResultArray, $GLOBALS['TCA']['testTable']['columns']['testField']['config']['items']);
662 }
663
664
665 /////////////////////////////////////////
666 // Tests concerning getExtensionVersion
667 /////////////////////////////////////////
668
669 /**
670 * Data provider for negative getExtensionVersion() tests.
671 *
672 * @return array
673 */
674 public function getExtensionVersionFaultyDataProvider() {
675 return array(
676 array(''),
677 array(0),
678 array(new stdClass()),
679 array(TRUE),
680 );
681 }
682
683 /**
684 * @test
685 * @expectedException InvalidArgumentException
686 * @dataProvider getExtensionVersionFaultyDataProvider
687 */
688 public function getExtensionVersionForFaultyExtensionKeyThrowsException($key) {
689 t3lib_extMgm::getExtensionVersion($key);
690 }
691
692 /**
693 * @test
694 */
695 public function getExtensionVersionForNotLoadedExtensionReturnsEmptyString() {
696 t3lib_extMgm::clearExtensionKeyMap();
697
698 $uniqueSuffix = uniqid('test');
699 $extensionKey = 'unloadedextension' . $uniqueSuffix;
700
701 $this->assertEquals(
702 '',
703 t3lib_extMgm::getExtensionVersion($extensionKey)
704 );
705 }
706
707 /**
708 * @test
709 */
710 public function getExtensionVersionForLoadedExtensionReturnsExtensionVersion() {
711 t3lib_extMgm::clearExtensionKeyMap();
712
713 $uniqueSuffix = uniqid('test');
714 $extensionKey = 'unloadedextension' . $uniqueSuffix;
715
716 $GLOBALS['TYPO3_LOADED_EXT'][$extensionKey] = array(
717 'siteRelPath' => $this->determineFixturesPath(),
718 );
719 $this->assertEquals(
720 '1.2.3',
721 t3lib_extMgm::getExtensionVersion($extensionKey)
722 );
723 }
724
725 /**
726 * @test
727 */
728 public function getEnabledExtensionListConsidersRequiredExtensions() {
729 $testrequiRedExtension = uniqid('test');
730 $GLOBALS['TYPO3_CONF_VARS']['EXT']['requiredExt'] = $testrequiRedExtension;
731
732 $extensions = explode(',', t3lib_extMgm::getEnabledExtensionList());
733 $this->assertTrue(in_array($testrequiRedExtension, $extensions));
734 }
735
736 /**
737 * @test
738 */
739 public function getEnabledExtensionListConsidersRequiredAndIgnoredExtensions() {
740 $testRequiredExtension = uniqid('test');
741 $testIgnoredExtension = uniqid('test');
742 $GLOBALS['TYPO3_CONF_VARS']['EXT']['requiredExt'] = $testRequiredExtension . ',' . $testIgnoredExtension;
743 $GLOBALS['TYPO3_CONF_VARS']['EXT']['ignoredExt'] = $testIgnoredExtension;
744
745 $extensions = explode(',', t3lib_extMgm::getEnabledExtensionList());
746 $this->assertTrue(in_array($testRequiredExtension, $extensions));
747 $this->assertFalse(in_array($testIgnoredExtension, $extensions));
748 }
749 }
750 ?>