2 namespace TYPO3\CMS\Core\Tests\Unit\Utility
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility
;
18 use TYPO3\CMS\Core\Utility\GeneralUtility
;
21 * Testcase for ExtensionManagementUtility
23 * @author Oliver Hader <oliver@typo3.org>
24 * @author Oliver Klee <typo3-coding@oliverklee.de>
26 class ExtensionManagementUtilityTest
extends \TYPO3\CMS\Core\Tests\UnitTestCase
{
29 * @var array A backup of registered singleton instances
31 protected $singletonInstances = array();
34 * @var \TYPO3\CMS\Core\Package\PackageManager
36 protected $backUpPackageManager;
38 public function setUp() {
39 $this->singletonInstances
= GeneralUtility
::getSingletonInstances();
40 $this->createAccessibleProxyClass();
41 $this->backUpPackageManager
= ExtensionManagementUtilityAccessibleProxy
::getPackageManager();
42 $this->singletonInstances
= GeneralUtility
::getSingletonInstances();
45 public function tearDown() {
46 ExtensionManagementUtility
::clearExtensionKeyMap();
47 ExtensionManagementUtilityAccessibleProxy
::setPackageManager($this->backUpPackageManager
);
48 ExtensionManagementUtilityAccessibleProxy
::setCacheManager(NULL);
49 $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\
LoadedExtensionsArray($this->backUpPackageManager
);
50 GeneralUtility
::resetSingletonInstances($this->singletonInstances
);
55 * Create a subclass with protected methods made public
58 * @TODO: Move this to a fixture file
60 protected function createAccessibleProxyClass() {
61 $className = 'ExtensionManagementUtilityAccessibleProxy';
62 if (!class_exists(__NAMESPACE__
. '\\' . $className, FALSE)) {
64 'namespace ' . __NAMESPACE__
. ';' .
65 'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\Utility\\ExtensionManagementUtility {' .
66 ' static public function setCacheManager(\TYPO3\CMS\Core\Cache\CacheManager $cacheManager = NULL) {' .
67 ' static::$cacheManager = $cacheManager;' .
69 ' public static function getPackageManager() {' .
70 ' return static::$packageManager;' .
72 ' public static function createTypo3LoadedExtensionInformationArray() {' .
73 ' return parent::createTypo3LoadedExtensionInformationArray();' .
75 ' public static function getTypo3LoadedExtensionInformationCacheIdentifier() {' .
76 ' return parent::getTypo3LoadedExtensionInformationCacheIdentifier();' .
78 ' public static function getExtLocalconfCacheIdentifier() {' .
79 ' return parent::getExtLocalconfCacheIdentifier();' .
81 ' public static function loadSingleExtLocalconfFiles() {' .
82 ' return parent::loadSingleExtLocalconfFiles();' .
84 ' public static function getBaseTcaCacheIdentifier() {' .
85 ' return parent::getBaseTcaCacheIdentifier();' .
87 ' public static function resetExtTablesWasReadFromCacheOnceBoolean() {' .
88 ' self::$extTablesWasReadFromCacheOnce = FALSE;' .
90 ' public static function createExtLocalconfCacheEntry() {' .
91 ' return parent::createExtLocalconfCacheEntry();' .
93 ' public static function createExtTablesCacheEntry() {' .
94 ' return parent::createExtTablesCacheEntry();' .
96 ' public static function getExtTablesCacheIdentifier() {' .
97 ' return parent::getExtTablesCacheIdentifier();' .
99 ' public static function buildBaseTcaFromSingleFiles() {' .
100 ' $GLOBALS[\'TCA\'] = array();' .
102 ' public static function emitTcaIsBeingBuiltSignal(array $tca) {' .
110 * @param string $packageKey
111 * @param array $packageMethods
114 protected function createMockPackageManagerWithMockPackage($packageKey, $packageMethods = array('getPackagePath', 'getPackageKey')) {
115 $packagePath = PATH_site
. 'typo3temp/' . $packageKey . '/';
116 GeneralUtility
::mkdir_deep($packagePath);
117 $this->testFilesToDelete
[] = $packagePath;
118 $package = $this->getMockBuilder(\TYPO3\CMS\Core\Package\Package
::class)
119 ->disableOriginalConstructor()
120 ->setMethods($packageMethods)
122 $packageManager = $this->getMock(
123 \TYPO3\CMS\Core\Package\PackageManager
::class,
124 array('isPackageActive', 'getPackage', 'getActivePackages')
126 $package->expects($this->any())
127 ->method('getPackagePath')
128 ->will($this->returnValue($packagePath));
129 $package->expects($this->any())
130 ->method('getPackageKey')
131 ->will($this->returnValue($packageKey));
132 $packageManager->expects($this->any())
133 ->method('isPackageActive')
134 ->will($this->returnValueMap(array(
136 array($packageKey, TRUE)
138 $packageManager->expects($this->any())
139 ->method('getPackage')
140 ->with($this->equalTo($packageKey))
141 ->will($this->returnValue($package));
142 $packageManager->expects($this->any())
143 ->method('getActivePackages')
144 ->will($this->returnValue(array($packageKey => $package)));
145 return $packageManager;
148 ///////////////////////////////
149 // Tests concerning isLoaded
150 ///////////////////////////////
154 public function isLoadedReturnsTrueIfExtensionIsLoaded() {
155 $this->assertTrue(ExtensionManagementUtility
::isLoaded('cms'));
161 public function isLoadedReturnsFalseIfExtensionIsNotLoadedAndExitIsDisabled() {
162 $this->assertFalse(ExtensionManagementUtility
::isLoaded(uniqid('foobar'), FALSE));
167 * @expectedException \BadFunctionCallException
169 public function isLoadedThrowsExceptionIfExtensionIsNotLoaded() {
170 $this->assertFalse(ExtensionManagementUtility
::isLoaded(uniqid('foobar'), TRUE));
173 ///////////////////////////////
174 // Tests concerning extPath
175 ///////////////////////////////
178 * @expectedException \BadFunctionCallException
180 public function extPathThrowsExceptionIfExtensionIsNotLoaded() {
181 $packageName = uniqid('foo');
182 $packageManager = $this->getMock(\TYPO3\CMS\Core\Package\PackageManager
::class, array('isPackageActive'));
183 $packageManager->expects($this->once())
184 ->method('isPackageActive')
185 ->with($this->equalTo($packageName))
186 ->will($this->returnValue(FALSE));
187 ExtensionManagementUtility
::setPackageManager($packageManager);
188 ExtensionManagementUtility
::extPath($packageName);
194 public function extPathAppendsScriptNameToPath() {
195 $package = $this->getMockBuilder(\TYPO3\CMS\Core\Package\Package
::class)
196 ->disableOriginalConstructor()
197 ->setMethods(array('getPackagePath'))
199 $packageManager = $this->getMock(\TYPO3\CMS\Core\Package\PackageManager
::class, array('isPackageActive', 'getPackage'));
200 $package->expects($this->once())
201 ->method('getPackagePath')
202 ->will($this->returnValue(PATH_site
. 'foo/'));
203 $packageManager->expects($this->once())
204 ->method('isPackageActive')
205 ->with($this->equalTo('foo'))
206 ->will($this->returnValue(TRUE));
207 $packageManager->expects($this->once())
208 ->method('getPackage')
210 ->will($this->returnValue($package));
211 ExtensionManagementUtility
::setPackageManager($packageManager);
212 $this->assertSame(PATH_site
. 'foo/bar.txt', ExtensionManagementUtility
::extPath('foo', 'bar.txt'));
215 //////////////////////
217 //////////////////////
219 * Generates a basic TCA for a given table.
221 * @param string $table name of the table, must not be empty
222 * @return array generated TCA for the given table, will not be empty
224 private function generateTCAForTable($table) {
226 $tca[$table] = array();
227 $tca[$table]['columns'] = array(
231 $tca[$table]['types'] = array(
232 'typeA' => array('showitem' => 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldC1, fieldD, fieldD1'),
233 'typeB' => array('showitem' => 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldC1, fieldD, fieldD1'),
234 'typeC' => array('showitem' => 'fieldC;;paletteD')
236 $tca[$table]['palettes'] = array(
237 'paletteA' => array('showitem' => 'fieldX, fieldX1, fieldY'),
238 'paletteB' => array('showitem' => 'fieldX, fieldX1, fieldY'),
239 'paletteC' => array('showitem' => 'fieldX, fieldX1, fieldY'),
240 'paletteD' => array('showitem' => 'fieldX, fieldX1, fieldY')
246 * Data provider for getClassNamePrefixForExtensionKey.
250 public function extensionKeyDataProvider() {
252 'Without underscores' => array(
256 'With underscores' => array(
257 'this_is_a_test_extension',
258 'tx_thisisatestextension'
260 'With user prefix and without underscores' => array(
264 'With user prefix and with underscores' => array(
273 * @param string $extensionName
274 * @param string $expectedPrefix
275 * @dataProvider extensionKeyDataProvider
277 public function getClassNamePrefixForExtensionKey($extensionName, $expectedPrefix) {
278 $this->assertSame($expectedPrefix, ExtensionManagementUtility
::getCN($extensionName));
281 /////////////////////////////////////////////
282 // Tests concerning getExtensionKeyByPrefix
283 /////////////////////////////////////////////
286 * @see ExtensionManagementUtility::getExtensionKeyByPrefix
288 public function getExtensionKeyByPrefixForLoadedExtensionWithUnderscoresReturnsExtensionKey() {
289 ExtensionManagementUtility
::clearExtensionKeyMap();
290 $uniqueSuffix = uniqid('test');
291 $extensionKey = 'tt_news' . $uniqueSuffix;
292 $extensionPrefix = 'tx_ttnews' . $uniqueSuffix;
293 $package = $this->getMockBuilder(\TYPO3\CMS\Core\Package\Package
::class)
294 ->disableOriginalConstructor()
295 ->setMethods(array('getPackageKey'))
297 $package->expects($this->exactly(2))
298 ->method('getPackageKey')
299 ->will($this->returnValue($extensionKey));
300 $packageManager = $this->getMock(\TYPO3\CMS\Core\Package\PackageManager
::class, array('getActivePackages'));
301 $packageManager->expects($this->once())
302 ->method('getActivePackages')
303 ->will($this->returnValue(array($extensionKey => $package)));
304 ExtensionManagementUtility
::setPackageManager($packageManager);
305 $this->assertEquals($extensionKey, ExtensionManagementUtility
::getExtensionKeyByPrefix($extensionPrefix));
310 * @see ExtensionManagementUtility::getExtensionKeyByPrefix
312 public function getExtensionKeyByPrefixForLoadedExtensionWithoutUnderscoresReturnsExtensionKey() {
313 ExtensionManagementUtility
::clearExtensionKeyMap();
314 $uniqueSuffix = uniqid('test');
315 $extensionKey = 'kickstarter' . $uniqueSuffix;
316 $extensionPrefix = 'tx_kickstarter' . $uniqueSuffix;
317 $package = $this->getMockBuilder(\TYPO3\CMS\Core\Package\Package
::class)
318 ->disableOriginalConstructor()
319 ->setMethods(array('getPackageKey'))
321 $package->expects($this->exactly(2))
322 ->method('getPackageKey')
323 ->will($this->returnValue($extensionKey));
324 $packageManager = $this->getMock(\TYPO3\CMS\Core\Package\PackageManager
::class, array('getActivePackages'));
325 $packageManager->expects($this->once())
326 ->method('getActivePackages')
327 ->will($this->returnValue(array($extensionKey => $package)));
328 ExtensionManagementUtility
::setPackageManager($packageManager);
329 $this->assertEquals($extensionKey, ExtensionManagementUtility
::getExtensionKeyByPrefix($extensionPrefix));
334 * @see ExtensionManagementUtility::getExtensionKeyByPrefix
336 public function getExtensionKeyByPrefixForNotLoadedExtensionReturnsFalse() {
337 ExtensionManagementUtility
::clearExtensionKeyMap();
338 $uniqueSuffix = uniqid('test');
339 $extensionKey = 'unloadedextension' . $uniqueSuffix;
340 $extensionPrefix = 'tx_unloadedextension' . $uniqueSuffix;
341 $this->assertFalse(ExtensionManagementUtility
::getExtensionKeyByPrefix($extensionPrefix));
344 //////////////////////////////////////
345 // Tests concerning addToAllTCAtypes
346 //////////////////////////////////////
348 * Tests whether fields can be add to all TCA types and duplicate fields are considered.
351 * @see ExtensionManagementUtility::addToAllTCAtypes()
353 public function canAddFieldsToAllTCATypesBeforeExistingOnes() {
354 $table = uniqid('tx_coretest_table');
355 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
356 ExtensionManagementUtility
::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'before:fieldD');
358 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldC1, newA, newB, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
360 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldC1, newA, newB, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
364 * Tests whether fields can be add to all TCA types and duplicate fields are considered.
367 * @see ExtensionManagementUtility::addToAllTCAtypes()
369 public function canAddFieldsToAllTCATypesAfterExistingOnes() {
370 $table = uniqid('tx_coretest_table');
371 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
372 ExtensionManagementUtility
::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'after:fieldC');
374 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
376 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
380 * Tests whether fields can be add to a TCA type before existing ones
383 * @see ExtensionManagementUtility::addToAllTCAtypes()
385 public function canAddFieldsToTCATypeBeforeExistingOnes() {
386 $table = uniqid('tx_coretest_table');
387 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
388 ExtensionManagementUtility
::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', 'typeA', 'before:fieldD');
390 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldC1, newA, newB, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
392 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
396 * Tests whether fields can be add to a TCA type after existing ones
399 * @see ExtensionManagementUtility::addToAllTCAtypes()
401 public function canAddFieldsToTCATypeAfterExistingOnes() {
402 $table = uniqid('tx_coretest_table');
403 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
404 ExtensionManagementUtility
::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', 'typeA', 'after:fieldC');
406 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
408 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
412 * Test wheter replacing other TCA fields works as promissed
415 * @see ExtensionManagementUtility::addFieldsToAllPalettesOfField()
417 public function canAddFieldsToTCATypeAndReplaceExistingOnes() {
418 $table = uniqid('tx_coretest_table');
419 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
420 $typesBefore = $GLOBALS['TCA'][$table]['types'];
421 ExtensionManagementUtility
::addToAllTCAtypes($table, 'fieldZ', '', 'replace:fieldX');
422 $this->assertEquals($typesBefore, $GLOBALS['TCA'][$table]['types'], 'It\'s wrong that the "types" array changes here - the replaced field is only on palettes');
423 // unchanged because the palette is not used
424 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
425 // unchanged because the palette is not used
426 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
427 $this->assertEquals('fieldZ, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
428 $this->assertEquals('fieldZ, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
431 ///////////////////////////////////////////////////
432 // Tests concerning addFieldsToAllPalettesOfField
433 ///////////////////////////////////////////////////
435 * Tests whether fields can be added to a palette before existing elements.
438 * @see ExtensionManagementUtility::addFieldsToPalette()
440 public function canAddFieldsToPaletteBeforeExistingOnes() {
441 $table = uniqid('tx_coretest_table');
442 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
443 ExtensionManagementUtility
::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'before:fieldY');
444 $this->assertEquals('fieldX, fieldX1, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
448 * Tests whether fields can be added to a palette after existing elements.
451 * @see ExtensionManagementUtility::addFieldsToPalette()
453 public function canAddFieldsToPaletteAfterExistingOnes() {
454 $table = uniqid('tx_coretest_table');
455 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
456 ExtensionManagementUtility
::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'after:fieldX');
457 $this->assertEquals('fieldX, newA, newB, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
461 * Tests whether fields can be added to a palette after a not existing elements.
464 * @see ExtensionManagementUtility::addFieldsToPalette()
466 public function canAddFieldsToPaletteAfterNotExistingOnes() {
467 $table = uniqid('tx_coretest_table');
468 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
469 ExtensionManagementUtility
::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'after:' . uniqid('notExisting'));
470 $this->assertEquals('fieldX, fieldX1, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
474 * Tests whether fields can be added to all palettes of a regular field before existing ones.
477 * @see ExtensionManagementUtility::addFieldsToAllPalettesOfField()
479 public function canAddFieldsToAllPalettesOfFieldBeforeExistingOnes() {
480 $table = uniqid('tx_coretest_table');
481 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
482 ExtensionManagementUtility
::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'before:fieldY');
483 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
484 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
485 $this->assertEquals('fieldX, fieldX1, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
486 $this->assertEquals('fieldX, fieldX1, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
490 * Tests whether fields can be added to all palettes of a regular field after existing ones.
493 * @see ExtensionManagementUtility::addFieldsToAllPalettesOfField()
495 public function canAddFieldsToAllPalettesOfFieldAfterExistingOnes() {
496 $table = uniqid('tx_coretest_table');
497 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
498 ExtensionManagementUtility
::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'after:fieldX');
499 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
500 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
501 $this->assertEquals('fieldX, newA, newB, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
502 $this->assertEquals('fieldX, newA, newB, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
506 * Tests whether fields can be added to all palettes of a regular field after a not existing field.
509 * @see ExtensionManagementUtility::addFieldsToAllPalettesOfField()
511 public function canAddFieldsToAllPalettesOfFieldAfterNotExistingOnes() {
512 $table = uniqid('tx_coretest_table');
513 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
514 ExtensionManagementUtility
::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'after:' . uniqid('notExisting'));
515 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
516 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
517 $this->assertEquals('fieldX, fieldX1, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
518 $this->assertEquals('fieldX, fieldX1, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
522 * Tests whether fields are added to a new palette that did not exist before.
525 * @see ExtensionManagementUtility::addFieldsToAllPalettesOfField()
527 public function canAddFieldsToAllPalettesOfFieldWithoutPaletteExistingBefore() {
528 $table = uniqid('tx_coretest_table');
529 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
530 ExtensionManagementUtility
::addFieldsToAllPalettesOfField($table, 'fieldA', 'newA, newA, newB, fieldX');
531 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
532 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
533 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
534 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
535 $this->assertEquals('newA, newB, fieldX', $GLOBALS['TCA'][$table]['palettes']['generatedFor-fieldA']['showitem']);
539 * Data provider for executePositionedStringInsertionTrimsCorrectCharacters
542 public function executePositionedStringInsertionTrimsCorrectCharactersDataProvider() {
544 'normal characters' => array(
552 'newlines with carriage return' => array(
564 'multiple commas with trailing spaces' => array(
573 * @dataProvider executePositionedStringInsertionTrimsCorrectCharactersDataProvider
575 public function executePositionedStringInsertionTrimsCorrectCharacters($string, $expectedResult) {
576 $extensionManagementUtility = $this->getAccessibleMock(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility
::class, array('dummy'));
577 $string = $extensionManagementUtility->_call('executePositionedStringInsertion', $string, '');
578 $this->assertEquals($expectedResult, $string);
581 /////////////////////////////////////////
582 // Tests concerning addTcaSelectItem
583 /////////////////////////////////////////
586 * @expectedException \InvalidArgumentException
588 public function addTcaSelectItemThrowsExceptionIfTableIsNotOfTypeString() {
589 ExtensionManagementUtility
::addTcaSelectItem(array(), 'foo', array());
594 * @expectedException \InvalidArgumentException
596 public function addTcaSelectItemThrowsExceptionIfFieldIsNotOfTypeString() {
597 ExtensionManagementUtility
::addTcaSelectItem('foo', array(), array());
602 * @expectedException \InvalidArgumentException
604 public function addTcaSelectItemThrowsExceptionIfRelativeToFieldIsNotOfTypeString() {
605 ExtensionManagementUtility
::addTcaSelectItem('foo', 'bar', array(), array());
610 * @expectedException \InvalidArgumentException
612 public function addTcaSelectItemThrowsExceptionIfRelativePositionIsNotOfTypeString() {
613 ExtensionManagementUtility
::addTcaSelectItem('foo', 'bar', array(), 'foo', array());
618 * @expectedException \InvalidArgumentException
620 public function addTcaSelectItemThrowsExceptionIfRelativePositionIsNotOneOfValidKeywords() {
621 ExtensionManagementUtility
::addTcaSelectItem('foo', 'bar', array(), 'foo', 'not allowed keyword');
626 * @expectedException \RuntimeException
628 public function addTcaSelectItemThrowsExceptionIfFieldIsNotFoundInTca() {
629 $GLOBALS['TCA'] = array();
630 ExtensionManagementUtility
::addTcaSelectItem('foo', 'bar', array());
634 * Data provider for addTcaSelectItemInsertsItemAtSpecifiedPosition
636 public function addTcaSelectItemDataProvider() {
637 // Every array splits into:
639 // - relativePosition
640 // - expectedResultArray
642 'add at end of array' => array(
646 0 => array('firstElement'),
647 1 => array('matchMe'),
648 2 => array('thirdElement'),
649 3 => array('insertedElement')
652 'replace element' => array(
656 0 => array('firstElement'),
657 1 => array('insertedElement'),
658 2 => array('thirdElement')
661 'add element after' => array(
665 0 => array('firstElement'),
666 1 => array('matchMe'),
667 2 => array('insertedElement'),
668 3 => array('thirdElement')
671 'add element before' => array(
675 0 => array('firstElement'),
676 1 => array('insertedElement'),
677 2 => array('matchMe'),
678 3 => array('thirdElement')
681 'add at end if relative position was not found' => array(
685 0 => array('firstElement'),
686 1 => array('matchMe'),
687 2 => array('thirdElement'),
688 3 => array('insertedElement')
696 * @dataProvider addTcaSelectItemDataProvider
698 public function addTcaSelectItemInsertsItemAtSpecifiedPosition($relativeToField, $relativePosition, $expectedResultArray) {
699 $GLOBALS['TCA'] = array(
700 'testTable' => array(
702 'testField' => array(
705 '0' => array('firstElement'),
706 '1' => array('matchMe'),
707 2 => array('thirdElement')
714 ExtensionManagementUtility
::addTcaSelectItem('testTable', 'testField', array('insertedElement'), $relativeToField, $relativePosition);
715 $this->assertEquals($expectedResultArray, $GLOBALS['TCA']['testTable']['columns']['testField']['config']['items']);
718 /////////////////////////////////////////
719 // Tests concerning loadExtLocalconf
720 /////////////////////////////////////////
724 public function loadExtLocalconfDoesNotReadFromCacheIfCachingIsDenied() {
725 $mockCacheManager = $this->getMock(\TYPO3\CMS\Core\Cache\CacheManager
::class, array('getCache'));
726 $mockCacheManager->expects($this->never())->method('getCache');
727 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
728 $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\
LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage(uniqid()));
729 ExtensionManagementUtility
::loadExtLocalconf(FALSE);
735 public function loadExtLocalconfRequiresCacheFileIfExistsAndCachingIsAllowed() {
736 $mockCache = $this->getMock(
737 \TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend
::class,
738 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
743 $mockCacheManager = $this->getMock(\TYPO3\CMS\Core\Cache\CacheManager
::class, array('getCache'));
744 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
745 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
746 $mockCache->expects($this->any())->method('has')->will($this->returnValue(TRUE));
747 $mockCache->expects($this->once())->method('requireOnce');
748 ExtensionManagementUtility
::loadExtLocalconf(TRUE);
751 /////////////////////////////////////////
752 // Tests concerning loadSingleExtLocalconfFiles
753 /////////////////////////////////////////
756 * @expectedException \RuntimeException
758 public function loadSingleExtLocalconfFilesRequiresExtLocalconfFileRegisteredInGlobalTypo3LoadedExt() {
759 $extensionName = uniqid('foo');
760 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
761 $extLocalconfLocation = $packageManager->getPackage($extensionName)->getPackagePath() . 'ext_localconf.php';
762 file_put_contents($extLocalconfLocation, "<?php\n\nthrow new RuntimeException('', 1340559079);\n\n?>");
763 $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\
LoadedExtensionsArray($packageManager);
764 ExtensionManagementUtilityAccessibleProxy
::loadSingleExtLocalconfFiles();
768 /////////////////////////////////////////
769 // Tests concerning addModule
770 /////////////////////////////////////////
773 * Data provider for addModule tests
776 public function addModulePositionTestsDataProvider() {
778 'can add new main module if none exists' => array(
783 'can add new sub module if no position specified' => array(
786 'some,modules,newModule'
788 'can add new sub module to top of module' => array(
791 'newModule,some,modules'
793 'can add new sub module if bottom of module' => array(
796 'some,modules,newModule'
798 'can add new sub module before specified sub module' => array(
801 'some,newModule,modules'
803 'can add new sub module after specified sub module' => array(
806 'some,newModule,modules'
808 'can add new sub module at the bottom if specified sub module to add before does not exist' => array(
811 'some,otherModules,newModule'
813 'can add new sub module at the bottom if specified sub module to add after does not exist' => array(
816 'someOther,modules,newModule'
823 * @dataProvider addModulePositionTestsDataProvider
825 public function addModuleCanAddModule($position, $existing, $expected) {
826 $mainModule = 'foobar';
827 $subModule = 'newModule';
829 $GLOBALS['TBE_MODULES'][$mainModule] = $existing;
832 ExtensionManagementUtility
::addModule($mainModule, $subModule, $position);
834 $this->assertTrue(isset($GLOBALS['TBE_MODULES'][$mainModule]));
835 $this->assertEquals($expected, $GLOBALS['TBE_MODULES'][$mainModule]);
838 /////////////////////////////////////////
839 // Tests concerning createExtLocalconfCacheEntry
840 /////////////////////////////////////////
844 public function createExtLocalconfCacheEntryWritesCacheEntryWithContentOfLoadedExtensionExtLocalconf() {
845 $extensionName = uniqid('foo');
846 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
847 $extLocalconfLocation = $packageManager->getPackage($extensionName)->getPackagePath() . 'ext_localconf.php';
848 $uniqueStringInLocalconf = uniqid('foo');
849 file_put_contents($extLocalconfLocation, "<?php\n\n" . $uniqueStringInLocalconf . "\n\n?>");
850 $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\
LoadedExtensionsArray($packageManager);
851 $mockCache = $this->getMock(
852 \TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend
::class,
853 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
858 $mockCacheManager = $this->getMock(\TYPO3\CMS\Core\Cache\CacheManager
::class, array('getCache'));
859 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
860 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
861 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInLocalconf), $this->anything());
862 ExtensionManagementUtilityAccessibleProxy
::createExtLocalconfCacheEntry();
868 public function createExtLocalconfCacheEntryWritesCacheEntryWithExtensionContentOnlyIfExtLocalconfExists() {
869 $extensionName = uniqid('foo');
870 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
871 $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\
LoadedExtensionsArray($packageManager);
872 $mockCache = $this->getMock(
873 \TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend
::class,
874 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
879 $mockCacheManager = $this->getMock(\TYPO3\CMS\Core\Cache\CacheManager
::class, array('getCache'));
880 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
881 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
882 $mockCache->expects($this->once())
884 ->with($this->anything(), $this->logicalNot($this->stringContains($extensionName)), $this->anything());
885 ExtensionManagementUtilityAccessibleProxy
::createExtLocalconfCacheEntry();
891 public function createExtLocalconfCacheEntryWritesCacheEntryWithNoTags() {
892 $mockCache = $this->getMock(
893 \TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend
::class,
894 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
899 $mockCacheManager = $this->getMock(\TYPO3\CMS\Core\Cache\CacheManager
::class, array('getCache'));
900 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
901 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
902 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo(array()));
903 $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\
LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage(uniqid()));
904 ExtensionManagementUtilityAccessibleProxy
::createExtLocalconfCacheEntry();
907 /////////////////////////////////////////
908 // Tests concerning getExtLocalconfCacheIdentifier
909 /////////////////////////////////////////
913 public function getExtLocalconfCacheIdentifierCreatesSha1WithFourtyCharactersAndPrefix() {
914 $prefix = 'ext_localconf_';
915 $identifier = ExtensionManagementUtilityAccessibleProxy
::getExtLocalconfCacheIdentifier();
916 $this->assertStringStartsWith($prefix, $identifier);
917 $sha1 = str_replace($prefix, '', $identifier);
918 $this->assertEquals(40, strlen($sha1));
921 /////////////////////////////////////////
922 // Tests concerning loadBaseTca
923 /////////////////////////////////////////
928 public function loadBaseTcaDoesNotReadFromCacheIfCachingIsDenied() {
929 $mockCacheManager = $this->getMock(\TYPO3\CMS\Core\Cache\CacheManager
::class, array('getCache'));
930 $mockCacheManager->expects($this->never())->method('getCache');
931 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
932 ExtensionManagementUtilityAccessibleProxy
::loadBaseTca(FALSE);
938 public function loadBaseTcaRequiresCacheFileIfExistsAndCachingIsAllowed() {
939 $mockCache = $this->getMock(
940 \TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend
::class,
941 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
946 $mockCacheManager = $this->getMock(\TYPO3\CMS\Core\Cache\CacheManager
::class, array('getCache'));
947 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
948 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
949 $mockCache->expects($this->any())->method('has')->will($this->returnValue(TRUE));
950 $mockCache->expects($this->once())->method('get');
951 ExtensionManagementUtilityAccessibleProxy
::loadBaseTca(TRUE);
957 public function loadBaseTcaCreatesCacheFileWithContentOfAnExtensionsConfigurationTcaPhpFile() {
958 $extensionName = uniqid('test_baseTca_');
959 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
960 $packagePath = $packageManager->getPackage($extensionName)->getPackagePath();
961 GeneralUtility
::mkdir($packagePath);
962 GeneralUtility
::mkdir($packagePath . 'Configuration/');
963 GeneralUtility
::mkdir($packagePath . 'Configuration/TCA/');
964 $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\
LoadedExtensionsArray($packageManager);
965 ExtensionManagementUtility
::setPackageManager($packageManager);
966 $uniqueTableName = uniqid('table_name_');
967 $uniqueStringInTableConfiguration = uniqid('table_configuration_');
968 $tableConfiguration = '<?php return array(\'foo\' => \'' . $uniqueStringInTableConfiguration . '\'); ?>';
969 file_put_contents($packagePath . 'Configuration/TCA/' . $uniqueTableName . '.php', $tableConfiguration);
970 $mockCache = $this->getMock(
971 \TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend
::class,
972 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
977 $mockCacheManager = $this->getMock(\TYPO3\CMS\Core\Cache\CacheManager
::class, array('getCache'));
978 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
979 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
980 $mockCache->expects($this->once())->method('has')->will($this->returnValue(FALSE));
981 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInTableConfiguration), $this->anything());
982 ExtensionManagementUtility
::loadBaseTca(TRUE);
988 public function loadBaseTcaWritesCacheEntryWithNoTags() {
989 $mockCache = $this->getMock(
990 \TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend
::class,
991 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
996 $mockCacheManager = $this->getMock(\TYPO3\CMS\Core\Cache\CacheManager
::class, array('getCache'));
997 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
998 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
999 $mockCache->expects($this->once())->method('has')->will($this->returnValue(FALSE));
1000 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo(array()));
1001 ExtensionManagementUtilityAccessibleProxy
::loadBaseTca();
1004 /////////////////////////////////////////
1005 // Tests concerning getBaseTcaCacheIdentifier
1006 /////////////////////////////////////////
1011 public function getBaseTcaCacheIdentifierCreatesSha1WithFourtyCharactersAndPrefix() {
1012 $prefix = 'tca_base_';
1013 $identifier = ExtensionManagementUtilityAccessibleProxy
::getBaseTcaCacheIdentifier();
1014 $this->assertStringStartsWith($prefix, $identifier);
1015 $sha1 = str_replace($prefix, '', $identifier);
1016 $this->assertEquals(40, strlen($sha1));
1019 /////////////////////////////////////////
1020 // Tests concerning loadExtTables
1021 /////////////////////////////////////////
1025 public function loadExtTablesDoesNotReadFromCacheIfCachingIsDenied() {
1026 $mockCacheManager = $this->getMock(\TYPO3\CMS\Core\Cache\CacheManager
::class, array('getCache'));
1027 $mockCacheManager->expects($this->never())->method('getCache');
1028 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1029 $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\
LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage(uniqid()));
1030 ExtensionManagementUtility
::loadExtLocalconf(FALSE);
1036 public function loadExtTablesRequiresCacheFileIfExistsAndCachingIsAllowed() {
1037 $mockCache = $this->getMock(
1038 \TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend
::class,
1039 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1044 $mockCacheManager = $this->getMock(\TYPO3\CMS\Core\Cache\CacheManager
::class, array('getCache'));
1045 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1046 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1047 $mockCache->expects($this->any())->method('has')->will($this->returnValue(TRUE));
1048 $mockCache->expects($this->once())->method('requireOnce');
1049 // Reset the internal cache access tracking variable of extMgm
1050 // This method is only in the ProxyClass!
1051 ExtensionManagementUtilityAccessibleProxy
::resetExtTablesWasReadFromCacheOnceBoolean();
1052 ExtensionManagementUtility
::loadExtTables(TRUE);
1055 /////////////////////////////////////////
1056 // Tests concerning createExtTablesCacheEntry
1057 /////////////////////////////////////////
1061 public function createExtTablesCacheEntryWritesCacheEntryWithContentOfLoadedExtensionExtTables() {
1062 $extensionName = uniqid('foo');
1063 $extTablesLocation = PATH_site
. 'typo3temp/' . uniqid('test_ext_tables') . '.php';
1064 $this->testFilesToDelete
[] = $extTablesLocation;
1065 $uniqueStringInTables = uniqid('foo');
1066 file_put_contents($extTablesLocation, "<?php\n\n$uniqueStringInTables\n\n?>");
1067 $GLOBALS['TYPO3_LOADED_EXT'] = array(
1068 $extensionName => array(
1069 'ext_tables.php' => $extTablesLocation
1072 $mockCache = $this->getMock(
1073 \TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend
::class,
1074 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1079 $mockCacheManager = $this->getMock(\TYPO3\CMS\Core\Cache\CacheManager
::class, array('getCache'));
1080 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1081 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1082 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInTables), $this->anything());
1083 ExtensionManagementUtilityAccessibleProxy
::createExtTablesCacheEntry();
1089 public function createExtTablesCacheEntryWritesCacheEntryWithExtensionContentOnlyIfExtTablesExists() {
1090 $extensionName = uniqid('foo');
1091 $GLOBALS['TYPO3_LOADED_EXT'] = array(
1092 $extensionName => array(),
1094 $mockCache = $this->getMock(
1095 \TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend
::class,
1096 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1101 $mockCacheManager = $this->getMock(\TYPO3\CMS\Core\Cache\CacheManager
::class, array('getCache'));
1102 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1103 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1104 $mockCache->expects($this->once())
1106 ->with($this->anything(), $this->logicalNot($this->stringContains($extensionName)), $this->anything());
1107 ExtensionManagementUtilityAccessibleProxy
::createExtTablesCacheEntry();
1113 public function createExtTablesCacheEntryWritesCacheEntryWithNoTags() {
1114 $mockCache = $this->getMock(
1115 \TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend
::class,
1116 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1121 $mockCacheManager = $this->getMock(\TYPO3\CMS\Core\Cache\CacheManager
::class, array('getCache'));
1122 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1123 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1124 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo(array()));
1125 $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\
LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage(uniqid()));
1126 ExtensionManagementUtilityAccessibleProxy
::createExtTablesCacheEntry();
1129 /////////////////////////////////////////
1130 // Tests concerning getExtTablesCacheIdentifier
1131 /////////////////////////////////////////
1135 public function getExtTablesCacheIdentifierCreatesSha1WithFourtyCharactersAndPrefix() {
1136 $prefix = 'ext_tables_';
1137 $identifier = ExtensionManagementUtilityAccessibleProxy
::getExtTablesCacheIdentifier();
1138 $this->assertStringStartsWith($prefix, $identifier);
1139 $sha1 = str_replace($prefix, '', $identifier);
1140 $this->assertEquals(40, strlen($sha1));
1143 /////////////////////////////////////////
1144 // Tests concerning removeCacheFiles
1145 /////////////////////////////////////////
1149 public function removeCacheFilesFlushesSystemCaches() {
1150 $mockCacheManager = $this->getMock(\TYPO3\CMS\Core\Cache\CacheManager
::class, array('flushCachesInGroup'));
1151 $mockCacheManager->expects($this->once())->method('flushCachesInGroup')->with('system');
1152 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1153 ExtensionManagementUtility
::removeCacheFiles();
1156 /////////////////////////////////////////
1157 // Tests concerning loadNewTcaColumnsConfigFiles
1158 /////////////////////////////////////////
1162 * @expectedException \RuntimeException
1164 public function loadNewTcaColumnsConfigFilesIncludesDefinedDynamicConfigFileIfNoColumnsExist() {
1165 $GLOBALS['TCA'] = array(
1168 'dynamicConfigFile' => __DIR__
. '/Fixtures/RuntimeException.php'
1172 ExtensionManagementUtility
::loadNewTcaColumnsConfigFiles();
1178 public function loadNewTcaColumnsConfigFilesDoesNotIncludeFileIfColumnsExist() {
1179 $GLOBALS['TCA'] = array(
1182 'dynamicConfigFile' => __DIR__
. '/Fixtures/RuntimeException.php'
1189 ExtensionManagementUtility
::loadNewTcaColumnsConfigFiles();
1192 /////////////////////////////////////////
1193 // Tests concerning getExtensionVersion
1194 /////////////////////////////////////////
1196 * Data provider for negative getExtensionVersion() tests.
1200 public function getExtensionVersionFaultyDataProvider() {
1204 array(new \
stdClass()),
1211 * @expectedException \InvalidArgumentException
1212 * @dataProvider getExtensionVersionFaultyDataProvider
1214 public function getExtensionVersionForFaultyExtensionKeyThrowsException($key) {
1215 ExtensionManagementUtility
::getExtensionVersion($key);
1221 public function getExtensionVersionForNotLoadedExtensionReturnsEmptyString() {
1222 ExtensionManagementUtility
::clearExtensionKeyMap();
1223 $uniqueSuffix = uniqid('test');
1224 $extensionKey = 'unloadedextension' . $uniqueSuffix;
1225 $this->assertEquals('', ExtensionManagementUtility
::getExtensionVersion($extensionKey));
1231 public function getExtensionVersionForLoadedExtensionReturnsExtensionVersion() {
1232 ExtensionManagementUtility
::clearExtensionKeyMap();
1233 $className = uniqid('ExtensionManagementUtility');
1235 'namespace ' . __NAMESPACE__
. ';' .
1236 'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\Utility\\ExtensionManagementUtility {' .
1237 ' public static function isLoaded() {' .
1242 $className = __NAMESPACE__
. '\\' . $className;
1243 ExtensionManagementUtility
::clearExtensionKeyMap();
1244 $uniqueSuffix = uniqid('test');
1245 $extensionKey = 'unloadedextension' . $uniqueSuffix;
1246 $packageMetaData = $this->getMock(\TYPO3\Flow\Package\MetaData
::class, array('getVersion'), array($extensionKey));
1247 $packageMetaData->expects($this->any())->method('getVersion')->will($this->returnValue('1.2.3'));
1248 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionKey, array('getPackagePath', 'getPackageKey', 'getPackageMetaData'));
1249 /** @var \PHPUnit_Framework_MockObject_MockObject $package */
1250 $package = $packageManager->getPackage($extensionKey);
1251 $package->expects($this->any())
1252 ->method('getPackageMetaData')
1253 ->will($this->returnValue($packageMetaData));
1254 ExtensionManagementUtility
::setPackageManager($packageManager);
1255 $this->assertEquals('1.2.3', ExtensionManagementUtility
::getExtensionVersion($extensionKey));
1258 /////////////////////////////////////////
1259 // Tests concerning loadExtension
1260 /////////////////////////////////////////
1263 * @expectedException \RuntimeException
1265 public function loadExtensionThrowsExceptionIfExtensionIsLoaded() {
1266 $extensionKey = uniqid('test');
1267 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionKey);
1268 ExtensionManagementUtility
::setPackageManager($packageManager);
1269 ExtensionManagementUtility
::loadExtension($extensionKey);
1272 /////////////////////////////////////////
1273 // Tests concerning unloadExtension
1274 /////////////////////////////////////////
1277 * @expectedException \RuntimeException
1279 public function unloadExtensionThrowsExceptionIfExtensionIsNotLoaded() {
1280 $packageName = uniqid('foo');
1281 $packageManager = $this->getMock(\TYPO3\CMS\Core\Package\PackageManager
::class, array('isPackageActive'));
1282 $packageManager->expects($this->once())
1283 ->method('isPackageActive')
1284 ->with($this->equalTo($packageName))
1285 ->will($this->returnValue(FALSE));
1286 ExtensionManagementUtility
::setPackageManager($packageManager);
1287 ExtensionManagementUtility
::unloadExtension($packageName);
1293 public function unloadExtensionCallsPackageManagerToDeactivatePackage() {
1294 $packageName = uniqid('foo');
1295 $packageManager = $this->getMock(
1296 \TYPO3\CMS\Core\Package\PackageManager
::class,
1297 array('isPackageActive', 'deactivatePackage')
1299 $packageManager->expects($this->any())
1300 ->method('isPackageActive')
1301 ->will($this->returnValue(TRUE));
1302 $packageManager->expects($this->once())
1303 ->method('deactivatePackage')
1304 ->with($packageName);
1305 ExtensionManagementUtility
::setPackageManager($packageManager);
1306 ExtensionManagementUtility
::unloadExtension($packageName);
1309 /////////////////////////////////////////
1310 // Tests concerning makeCategorizable
1311 /////////////////////////////////////////
1315 public function doesMakeCategorizableCallsTheCategoryRegistryWithDefaultFieldName() {
1316 $extensionKey = uniqid('extension');
1317 $tableName = uniqid('table');
1319 $registryMock = $this->getMock(\TYPO3\CMS\Core\Category\CategoryRegistry
::class);
1320 $registryMock->expects($this->once())->method('add')->with($extensionKey, $tableName, 'categories', array());
1321 GeneralUtility
::setSingletonInstance(\TYPO3\CMS\Core\Category\CategoryRegistry
::class, $registryMock);
1322 ExtensionManagementUtility
::makeCategorizable($extensionKey, $tableName);
1328 public function doesMakeCategorizableCallsTheCategoryRegistryWithFieldName() {
1329 $extensionKey = uniqid('extension');
1330 $tableName = uniqid('table');
1331 $fieldName = uniqid('field');
1333 $registryMock = $this->getMock(\TYPO3\CMS\Core\Category\CategoryRegistry
::class);
1334 $registryMock->expects($this->once())->method('add')->with($extensionKey, $tableName, $fieldName, array());
1335 GeneralUtility
::setSingletonInstance(\TYPO3\CMS\Core\Category\CategoryRegistry
::class, $registryMock);
1336 ExtensionManagementUtility
::makeCategorizable($extensionKey, $tableName, $fieldName);
1339 ///////////////////////////////
1340 // Tests concerning addPlugin
1341 ///////////////////////////////
1346 public function addPluginSetsTcaCorrectlyForGivenExtkeyAsParameter() {
1347 $extKey = 'indexed_search';
1348 $GLOBALS['TYPO3_LOADED_EXT'] = array();
1349 $GLOBALS['TYPO3_LOADED_EXT'][$extKey]['ext_icon'] = 'foo.gif';
1350 $expectedTCA = array(
1354 'sysext/' . $extKey . '/foo.gif'
1357 $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'] = array();
1358 ExtensionManagementUtility
::addPlugin(array('label', $extKey), 'list_type', $extKey);
1359 $this->assertEquals($expectedTCA, $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items']);
1365 public function addPluginSetsTcaCorrectlyForGivenExtkeyAsGlobal() {
1366 $extKey = 'indexed_search';
1367 $GLOBALS['TYPO3_LOADED_EXT'] = array();
1368 $GLOBALS['TYPO3_LOADED_EXT'][$extKey]['ext_icon'] = 'foo.gif';
1369 $GLOBALS['_EXTKEY'] = $extKey;
1370 $expectedTCA = array(
1374 'sysext/' . $extKey . '/foo.gif'
1377 $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'] = array();
1378 ExtensionManagementUtility
::addPlugin(array('label', $extKey));
1379 $this->assertEquals($expectedTCA, $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items']);
1384 * @expectedException \RuntimeException
1386 public function addPluginThrowsExceptionForMissingExtkey() {
1387 ExtensionManagementUtility
::addPlugin('test');