2 namespace TYPO3\CMS\Core\Tests\Unit\Utility
;
4 /***************************************************************
7 * (c) 2009-2013 Oliver Hader <oliver@typo3.org>
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
27 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility
;
28 use TYPO3\CMS\Core\Utility\GeneralUtility
;
31 * Testcase for ExtensionManagementUtility
33 * @author Oliver Hader <oliver@typo3.org>
34 * @author Oliver Klee <typo3-coding@oliverklee.de>
36 class ExtensionManagementUtilityTest
extends \TYPO3\CMS\Core\Tests\UnitTestCase
{
39 * @var array A backup of registered singleton instances
41 protected $singletonInstances = array();
44 * Absolute path to files that must be removed
45 * after a test - handled in tearDown
47 * @TODO : Check if the tests can use vfs:// instead
49 protected $testFilesToDelete = array();
52 * @var \TYPO3\CMS\Core\Package\PackageManager
54 protected $backUpPackageManager;
56 public function setUp() {
57 $this->singletonInstances
= \TYPO3\CMS\Core\Utility\GeneralUtility
::getSingletonInstances();
58 $this->createAccessibleProxyClass();
59 $this->testFilesToDelete
= array();
60 $this->backUpPackageManager
= ExtensionManagementUtilityAccessibleProxy
::getPackageManager();
61 $this->singletonInstances
= \TYPO3\CMS\Core\Utility\GeneralUtility
::getSingletonInstances();
64 public function tearDown() {
65 ExtensionManagementUtility
::clearExtensionKeyMap();
66 foreach ($this->testFilesToDelete
as $absoluteFileName) {
67 \TYPO3\CMS\Core\Utility\GeneralUtility
::unlink_tempfile($absoluteFileName);
69 if (file_exists(PATH_site
. 'typo3temp/test_ext/')) {
70 \TYPO3\CMS\Core\Utility\GeneralUtility
::rmdir(PATH_site
. 'typo3temp/test_ext/', TRUE);
72 ExtensionManagementUtilityAccessibleProxy
::setPackageManager($this->backUpPackageManager
);
73 ExtensionManagementUtilityAccessibleProxy
::setCacheManager(NULL);
74 $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\
LoadedExtensionsArray($this->backUpPackageManager
);
75 \TYPO3\CMS\Core\Utility\GeneralUtility
::resetSingletonInstances($this->singletonInstances
);
80 * Create a subclass with protected methods made public
83 * @TODO: Move this to a fixture file
85 protected function createAccessibleProxyClass() {
86 $className = 'ExtensionManagementUtilityAccessibleProxy';
87 if (!class_exists(__NAMESPACE__
. '\\' . $className, FALSE)) {
89 'namespace ' . __NAMESPACE__
. ';' .
90 'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\Utility\\ExtensionManagementUtility {' .
91 ' static public function setCacheManager(\TYPO3\CMS\Core\Cache\CacheManager $cacheManager = NULL) {'.
92 ' static::$cacheManager = $cacheManager;'.
94 ' public static function getPackageManager() {' .
95 ' return static::$packageManager;' .
97 ' public static function createTypo3LoadedExtensionInformationArray() {' .
98 ' return parent::createTypo3LoadedExtensionInformationArray();' .
100 ' public static function getTypo3LoadedExtensionInformationCacheIdentifier() {' .
101 ' return parent::getTypo3LoadedExtensionInformationCacheIdentifier();' .
103 ' public static function getExtLocalconfCacheIdentifier() {' .
104 ' return parent::getExtLocalconfCacheIdentifier();' .
106 ' public static function loadSingleExtLocalconfFiles() {' .
107 ' return parent::loadSingleExtLocalconfFiles();' .
109 ' public static function getBaseTcaCacheIdentifier() {' .
110 ' return parent::getBaseTcaCacheIdentifier();' .
112 ' public static function resetExtTablesWasReadFromCacheOnceBoolean() {' .
113 ' self::$extTablesWasReadFromCacheOnce = FALSE;' .
115 ' public static function createExtLocalconfCacheEntry() {' .
116 ' return parent::createExtLocalconfCacheEntry();' .
118 ' public static function createExtTablesCacheEntry() {' .
119 ' return parent::createExtTablesCacheEntry();' .
121 ' public static function getExtTablesCacheIdentifier() {' .
122 ' return parent::getExtTablesCacheIdentifier();' .
124 ' public static function buildBaseTcaFromSingleFiles() {' .
125 ' $GLOBALS[\'TCA\'] = array();' .
127 ' public static function emitTcaIsBeingBuiltSignal(array $tca) {' .
135 * @param string $packageKey
136 * @param array $packageMethods
139 protected function createMockPackageManagerWithMockPackage($packageKey, $packageMethods = array('getPackagePath', 'getPackageKey')) {
140 $packagePath = PATH_site
. 'typo3temp/test_ext/' . $packageKey . '/';
141 \TYPO3\CMS\Core\Utility\GeneralUtility
::mkdir_deep($packagePath);
142 $package = $this->getMockBuilder('TYPO3\\CMS\\Core\\Package\\Package')
143 ->disableOriginalConstructor()
144 ->setMethods($packageMethods)
146 $packageManager = $this->getMock(
147 'TYPO3\\CMS\\Core\\Package\\PackageManager',
148 array('isPackageActive', 'getPackage', 'getActivePackages')
150 $package->expects($this->any())
151 ->method('getPackagePath')
152 ->will($this->returnValue($packagePath));
153 $package->expects($this->any())
154 ->method('getPackageKey')
155 ->will($this->returnValue($packageKey));
156 $packageManager->expects($this->any())
157 ->method('isPackageActive')
158 ->will($this->returnValueMap(array(
160 array($packageKey, TRUE)
162 $packageManager->expects($this->any())
163 ->method('getPackage')
164 ->with($this->equalTo($packageKey))
165 ->will($this->returnValue($package));
166 $packageManager->expects($this->any())
167 ->method('getActivePackages')
168 ->will($this->returnValue(array($packageKey => $package)));
169 return $packageManager;
172 ///////////////////////////////
173 // Tests concerning isLoaded
174 ///////////////////////////////
178 public function isLoadedReturnsTrueIfExtensionIsLoaded() {
179 $this->assertTrue(ExtensionManagementUtility
::isLoaded('cms'));
185 public function isLoadedReturnsFalseIfExtensionIsNotLoadedAndExitIsDisabled() {
186 $this->assertFalse(ExtensionManagementUtility
::isLoaded(uniqid('foobar'), FALSE));
191 * @expectedException \BadFunctionCallException
193 public function isLoadedThrowsExceptionIfExtensionIsNotLoaded() {
194 $this->assertFalse(ExtensionManagementUtility
::isLoaded(uniqid('foobar'), TRUE));
197 ///////////////////////////////
198 // Tests concerning extPath
199 ///////////////////////////////
202 * @expectedException \BadFunctionCallException
204 public function extPathThrowsExceptionIfExtensionIsNotLoaded() {
205 $packageName = uniqid('foo');
206 $packageManager = $this->getMock('TYPO3\\CMS\\Core\\Package\\PackageManager', array('isPackageActive'));
207 $packageManager->expects($this->once())
208 ->method('isPackageActive')
209 ->with($this->equalTo($packageName))
210 ->will($this->returnValue(FALSE));
211 ExtensionManagementUtility
::setPackageManager($packageManager);
212 ExtensionManagementUtility
::extPath($packageName);
218 public function extPathAppendsScriptNameToPath() {
219 $package = $this->getMockBuilder('TYPO3\\CMS\\Core\\Package\\Package')
220 ->disableOriginalConstructor()
221 ->setMethods(array('getPackagePath'))
223 $packageManager = $this->getMock('TYPO3\\CMS\\Core\\Package\\PackageManager', array('isPackageActive', 'getPackage'));
224 $package->expects($this->once())
225 ->method('getPackagePath')
226 ->will($this->returnValue(PATH_site
. 'foo/'));
227 $packageManager->expects($this->once())
228 ->method('isPackageActive')
229 ->with($this->equalTo('foo'))
230 ->will($this->returnValue(TRUE));
231 $packageManager->expects($this->once())
232 ->method('getPackage')
234 ->will($this->returnValue($package));
235 ExtensionManagementUtility
::setPackageManager($packageManager);
236 $this->assertSame(PATH_site
. 'foo/bar.txt', ExtensionManagementUtility
::extPath('foo', 'bar.txt'));
239 //////////////////////
241 //////////////////////
243 * Generates a basic TCA for a given table.
245 * @param string $table name of the table, must not be empty
246 * @return array generated TCA for the given table, will not be empty
248 private function generateTCAForTable($table) {
250 $tca[$table] = array();
251 $tca[$table]['columns'] = array(
255 $tca[$table]['types'] = array(
256 'typeA' => array('showitem' => 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldC1, fieldD, fieldD1'),
257 'typeB' => array('showitem' => 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldC1, fieldD, fieldD1'),
258 'typeC' => array('showitem' => 'fieldC;;paletteD')
260 $tca[$table]['palettes'] = array(
261 'paletteA' => array('showitem' => 'fieldX, fieldX1, fieldY'),
262 'paletteB' => array('showitem' => 'fieldX, fieldX1, fieldY'),
263 'paletteC' => array('showitem' => 'fieldX, fieldX1, fieldY'),
264 'paletteD' => array('showitem' => 'fieldX, fieldX1, fieldY')
270 * Data provider for getClassNamePrefixForExtensionKey.
274 public function extensionKeyDataProvider() {
276 'Without underscores' => array(
280 'With underscores' => array(
281 'this_is_a_test_extension',
282 'tx_thisisatestextension'
284 'With user prefix and without underscores' => array(
288 'With user prefix and with underscores' => array(
297 * @param string $extensionName
298 * @param string $expectedPrefix
299 * @dataProvider extensionKeyDataProvider
301 public function getClassNamePrefixForExtensionKey($extensionName, $expectedPrefix) {
302 $this->assertSame($expectedPrefix, ExtensionManagementUtility
::getCN($extensionName));
305 /////////////////////////////////////////////
306 // Tests concerning getExtensionKeyByPrefix
307 /////////////////////////////////////////////
310 * @see ExtensionManagementUtility::getExtensionKeyByPrefix
312 public function getExtensionKeyByPrefixForLoadedExtensionWithUnderscoresReturnsExtensionKey() {
313 ExtensionManagementUtility
::clearExtensionKeyMap();
314 $uniqueSuffix = uniqid('test');
315 $extensionKey = 'tt_news' . $uniqueSuffix;
316 $extensionPrefix = 'tx_ttnews' . $uniqueSuffix;
317 $package = $this->getMockBuilder('TYPO3\\CMS\\Core\\Package\\Package')
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', 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 getExtensionKeyByPrefixForLoadedExtensionWithoutUnderscoresReturnsExtensionKey() {
337 ExtensionManagementUtility
::clearExtensionKeyMap();
338 $uniqueSuffix = uniqid('test');
339 $extensionKey = 'kickstarter' . $uniqueSuffix;
340 $extensionPrefix = 'tx_kickstarter' . $uniqueSuffix;
341 $package = $this->getMockBuilder('TYPO3\\CMS\\Core\\Package\\Package')
342 ->disableOriginalConstructor()
343 ->setMethods(array('getPackageKey'))
345 $package->expects($this->exactly(2))
346 ->method('getPackageKey')
347 ->will($this->returnValue($extensionKey));
348 $packageManager = $this->getMock('TYPO3\\CMS\\Core\\Package\\PackageManager', array('getActivePackages'));
349 $packageManager->expects($this->once())
350 ->method('getActivePackages')
351 ->will($this->returnValue(array($extensionKey => $package)));
352 ExtensionManagementUtility
::setPackageManager($packageManager);
353 $this->assertEquals($extensionKey, ExtensionManagementUtility
::getExtensionKeyByPrefix($extensionPrefix));
358 * @see ExtensionManagementUtility::getExtensionKeyByPrefix
360 public function getExtensionKeyByPrefixForNotLoadedExtensionReturnsFalse() {
361 ExtensionManagementUtility
::clearExtensionKeyMap();
362 $uniqueSuffix = uniqid('test');
363 $extensionKey = 'unloadedextension' . $uniqueSuffix;
364 $extensionPrefix = 'tx_unloadedextension' . $uniqueSuffix;
365 $this->assertFalse(ExtensionManagementUtility
::getExtensionKeyByPrefix($extensionPrefix));
368 //////////////////////////////////////
369 // Tests concerning addToAllTCAtypes
370 //////////////////////////////////////
372 * Tests whether fields can be add to all TCA types and duplicate fields are considered.
375 * @see ExtensionManagementUtility::addToAllTCAtypes()
377 public function canAddFieldsToAllTCATypesBeforeExistingOnes() {
378 $table = uniqid('tx_coretest_table');
379 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
380 ExtensionManagementUtility
::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'before:fieldD');
382 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldC1, newA, newB, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
384 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldC1, newA, newB, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
388 * Tests whether fields can be add to all TCA types and duplicate fields are considered.
391 * @see ExtensionManagementUtility::addToAllTCAtypes()
393 public function canAddFieldsToAllTCATypesAfterExistingOnes() {
394 $table = uniqid('tx_coretest_table');
395 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
396 ExtensionManagementUtility
::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'after:fieldC');
398 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
400 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
404 * Tests whether fields can be add to a TCA type before existing ones
407 * @see ExtensionManagementUtility::addToAllTCAtypes()
409 public function canAddFieldsToTCATypeBeforeExistingOnes() {
410 $table = uniqid('tx_coretest_table');
411 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
412 ExtensionManagementUtility
::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', 'typeA', 'before:fieldD');
414 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldC1, newA, newB, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
416 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
420 * Tests whether fields can be add to a TCA type after existing ones
423 * @see ExtensionManagementUtility::addToAllTCAtypes()
425 public function canAddFieldsToTCATypeAfterExistingOnes() {
426 $table = uniqid('tx_coretest_table');
427 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
428 ExtensionManagementUtility
::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', 'typeA', 'after:fieldC');
430 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
432 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
436 * Test wheter replacing other TCA fields works as promissed
439 * @see ExtensionManagementUtility::addFieldsToAllPalettesOfField()
441 public function canAddFieldsToTCATypeAndReplaceExistingOnes() {
442 $table = uniqid('tx_coretest_table');
443 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
444 $typesBefore = $GLOBALS['TCA'][$table]['types'];
445 ExtensionManagementUtility
::addToAllTCAtypes($table, 'fieldZ', '', 'replace:fieldX');
446 $this->assertEquals($typesBefore, $GLOBALS['TCA'][$table]['types'], 'It\'s wrong that the "types" array changes here - the replaced field is only on palettes');
447 // unchanged because the palette is not used
448 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
449 // unchanged because the palette is not used
450 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
451 $this->assertEquals('fieldZ, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
452 $this->assertEquals('fieldZ, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
455 ///////////////////////////////////////////////////
456 // Tests concerning addFieldsToAllPalettesOfField
457 ///////////////////////////////////////////////////
459 * Tests whether fields can be added to a palette before existing elements.
462 * @see ExtensionManagementUtility::addFieldsToPalette()
464 public function canAddFieldsToPaletteBeforeExistingOnes() {
465 $table = uniqid('tx_coretest_table');
466 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
467 ExtensionManagementUtility
::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'before:fieldY');
468 $this->assertEquals('fieldX, fieldX1, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
472 * Tests whether fields can be added to a palette after existing elements.
475 * @see ExtensionManagementUtility::addFieldsToPalette()
477 public function canAddFieldsToPaletteAfterExistingOnes() {
478 $table = uniqid('tx_coretest_table');
479 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
480 ExtensionManagementUtility
::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'after:fieldX');
481 $this->assertEquals('fieldX, newA, newB, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
485 * Tests whether fields can be added to a palette after a not existing elements.
488 * @see ExtensionManagementUtility::addFieldsToPalette()
490 public function canAddFieldsToPaletteAfterNotExistingOnes() {
491 $table = uniqid('tx_coretest_table');
492 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
493 ExtensionManagementUtility
::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'after:' . uniqid('notExisting'));
494 $this->assertEquals('fieldX, fieldX1, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
498 * Tests whether fields can be added to all palettes of a regular field before existing ones.
501 * @see ExtensionManagementUtility::addFieldsToAllPalettesOfField()
503 public function canAddFieldsToAllPalettesOfFieldBeforeExistingOnes() {
504 $table = uniqid('tx_coretest_table');
505 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
506 ExtensionManagementUtility
::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'before:fieldY');
507 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
508 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
509 $this->assertEquals('fieldX, fieldX1, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
510 $this->assertEquals('fieldX, fieldX1, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
514 * Tests whether fields can be added to all palettes of a regular field after existing ones.
517 * @see ExtensionManagementUtility::addFieldsToAllPalettesOfField()
519 public function canAddFieldsToAllPalettesOfFieldAfterExistingOnes() {
520 $table = uniqid('tx_coretest_table');
521 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
522 ExtensionManagementUtility
::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'after:fieldX');
523 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
524 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
525 $this->assertEquals('fieldX, newA, newB, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
526 $this->assertEquals('fieldX, newA, newB, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
530 * Tests whether fields can be added to all palettes of a regular field after a not existing field.
533 * @see ExtensionManagementUtility::addFieldsToAllPalettesOfField()
535 public function canAddFieldsToAllPalettesOfFieldAfterNotExistingOnes() {
536 $table = uniqid('tx_coretest_table');
537 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
538 ExtensionManagementUtility
::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'after:' . uniqid('notExisting'));
539 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
540 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
541 $this->assertEquals('fieldX, fieldX1, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
542 $this->assertEquals('fieldX, fieldX1, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
546 * Tests whether fields are added to a new palette that did not exist before.
549 * @see ExtensionManagementUtility::addFieldsToAllPalettesOfField()
551 public function canAddFieldsToAllPalettesOfFieldWithoutPaletteExistingBefore() {
552 $table = uniqid('tx_coretest_table');
553 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
554 ExtensionManagementUtility
::addFieldsToAllPalettesOfField($table, 'fieldA', 'newA, newA, newB, fieldX');
555 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
556 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
557 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
558 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
559 $this->assertEquals('newA, newB, fieldX', $GLOBALS['TCA'][$table]['palettes']['generatedFor-fieldA']['showitem']);
563 * Data provider for executePositionedStringInsertionTrimsCorrectCharacters
566 public function executePositionedStringInsertionTrimsCorrectCharactersDataProvider() {
568 'normal characters' => array(
576 'newlines with carriage return' => array(
588 'multiple commas with trailing spaces' => array(
597 * @dataProvider executePositionedStringInsertionTrimsCorrectCharactersDataProvider
599 public function executePositionedStringInsertionTrimsCorrectCharacters($string, $expectedResult) {
600 $extensionManagementUtility = $this->getAccessibleMock('\\TYPO3\\CMS\\Core\\Utility\\ExtensionManagementUtility', array('dummy'));
601 $string = $extensionManagementUtility->_call('executePositionedStringInsertion', $string, '');
602 $this->assertEquals($expectedResult, $string);
605 /////////////////////////////////////////
606 // Tests concerning addTcaSelectItem
607 /////////////////////////////////////////
610 * @expectedException \InvalidArgumentException
612 public function addTcaSelectItemThrowsExceptionIfTableIsNotOfTypeString() {
613 ExtensionManagementUtility
::addTcaSelectItem(array(), 'foo', array());
618 * @expectedException \InvalidArgumentException
620 public function addTcaSelectItemThrowsExceptionIfFieldIsNotOfTypeString() {
621 ExtensionManagementUtility
::addTcaSelectItem('foo', array(), array());
626 * @expectedException \InvalidArgumentException
628 public function addTcaSelectItemThrowsExceptionIfRelativeToFieldIsNotOfTypeString() {
629 ExtensionManagementUtility
::addTcaSelectItem('foo', 'bar', array(), array());
634 * @expectedException \InvalidArgumentException
636 public function addTcaSelectItemThrowsExceptionIfRelativePositionIsNotOfTypeString() {
637 ExtensionManagementUtility
::addTcaSelectItem('foo', 'bar', array(), 'foo', array());
642 * @expectedException \InvalidArgumentException
644 public function addTcaSelectItemThrowsExceptionIfRelativePositionIsNotOneOfValidKeywords() {
645 ExtensionManagementUtility
::addTcaSelectItem('foo', 'bar', array(), 'foo', 'not allowed keyword');
650 * @expectedException \RuntimeException
652 public function addTcaSelectItemThrowsExceptionIfFieldIsNotFoundInTca() {
653 $GLOBALS['TCA'] = array();
654 ExtensionManagementUtility
::addTcaSelectItem('foo', 'bar', array());
658 * Data provider for addTcaSelectItemInsertsItemAtSpecifiedPosition
660 public function addTcaSelectItemDataProvider() {
661 // Every array splits into:
663 // - relativePosition
664 // - expectedResultArray
666 'add at end of array' => array(
670 0 => array('firstElement'),
671 1 => array('matchMe'),
672 2 => array('thirdElement'),
673 3 => array('insertedElement')
676 'replace element' => array(
680 0 => array('firstElement'),
681 1 => array('insertedElement'),
682 2 => array('thirdElement')
685 'add element after' => array(
689 0 => array('firstElement'),
690 1 => array('matchMe'),
691 2 => array('insertedElement'),
692 3 => array('thirdElement')
695 'add element before' => array(
699 0 => array('firstElement'),
700 1 => array('insertedElement'),
701 2 => array('matchMe'),
702 3 => array('thirdElement')
705 'add at end if relative position was not found' => array(
709 0 => array('firstElement'),
710 1 => array('matchMe'),
711 2 => array('thirdElement'),
712 3 => array('insertedElement')
720 * @dataProvider addTcaSelectItemDataProvider
722 public function addTcaSelectItemInsertsItemAtSpecifiedPosition($relativeToField, $relativePosition, $expectedResultArray) {
723 $GLOBALS['TCA'] = array(
724 'testTable' => array(
726 'testField' => array(
729 '0' => array('firstElement'),
730 '1' => array('matchMe'),
731 2 => array('thirdElement')
738 ExtensionManagementUtility
::addTcaSelectItem('testTable', 'testField', array('insertedElement'), $relativeToField, $relativePosition);
739 $this->assertEquals($expectedResultArray, $GLOBALS['TCA']['testTable']['columns']['testField']['config']['items']);
742 /////////////////////////////////////////
743 // Tests concerning loadExtLocalconf
744 /////////////////////////////////////////
748 public function loadExtLocalconfDoesNotReadFromCacheIfCachingIsDenied() {
749 $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
750 $mockCacheManager->expects($this->never())->method('getCache');
751 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
752 $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\
LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage(uniqid()));
753 ExtensionManagementUtility
::loadExtLocalconf(FALSE);
759 public function loadExtLocalconfRequiresCacheFileIfExistsAndCachingIsAllowed() {
760 $mockCache = $this->getMock(
761 'TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend',
762 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
767 $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
768 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
769 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
770 $mockCache->expects($this->any())->method('has')->will($this->returnValue(TRUE));
771 $mockCache->expects($this->once())->method('requireOnce');
772 ExtensionManagementUtility
::loadExtLocalconf(TRUE);
775 /////////////////////////////////////////
776 // Tests concerning loadSingleExtLocalconfFiles
777 /////////////////////////////////////////
780 * @expectedException \RuntimeException
782 public function loadSingleExtLocalconfFilesRequiresExtLocalconfFileRegisteredInGlobalTypo3LoadedExt() {
783 $extensionName = uniqid('foo');
784 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
785 $extLocalconfLocation = $packageManager->getPackage($extensionName)->getPackagePath() . 'ext_localconf.php';
786 file_put_contents($extLocalconfLocation, "<?php\n\nthrow new RuntimeException('', 1340559079);\n\n?>");
787 $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\
LoadedExtensionsArray($packageManager);
788 ExtensionManagementUtilityAccessibleProxy
::loadSingleExtLocalconfFiles();
792 /////////////////////////////////////////
793 // Tests concerning addModule
794 /////////////////////////////////////////
797 * Data provider for addModule tests
800 public function addModulePositionTestsDataProvider() {
802 'can add new main module if none exists' => array(
807 'can add new sub module if no position specified' => array(
810 'some,modules,newModule'
812 'can add new sub module to top of module' => array(
815 'newModule,some,modules'
817 'can add new sub module if bottom of module' => array(
820 'some,modules,newModule'
822 'can add new sub module before specified sub module' => array(
825 'some,newModule,modules'
827 'can add new sub module after specified sub module' => array(
830 'some,newModule,modules'
832 'can add new sub module at the bottom if specified sub module to add before does not exist' => array(
835 'some,otherModules,newModule'
837 'can add new sub module at the bottom if specified sub module to add after does not exist' => array(
840 'someOther,modules,newModule'
847 * @dataProvider addModulePositionTestsDataProvider
849 public function addModuleCanAddModule($position, $existing, $expected) {
850 $mainModule = 'foobar';
851 $subModule = 'newModule';
853 $GLOBALS['TBE_MODULES'][$mainModule] = $existing;
856 ExtensionManagementUtility
::addModule($mainModule, $subModule, $position);
858 $this->assertTrue(isset($GLOBALS['TBE_MODULES'][$mainModule]));
859 $this->assertEquals($expected, $GLOBALS['TBE_MODULES'][$mainModule]);
862 /////////////////////////////////////////
863 // Tests concerning createExtLocalconfCacheEntry
864 /////////////////////////////////////////
868 public function createExtLocalconfCacheEntryWritesCacheEntryWithContentOfLoadedExtensionExtLocalconf() {
869 $extensionName = uniqid('foo');
870 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
871 $extLocalconfLocation = $packageManager->getPackage($extensionName)->getPackagePath() . 'ext_localconf.php';
872 $this->testFilesToDelete
[] = $extLocalconfLocation;
873 $uniqueStringInLocalconf = uniqid('foo');
874 file_put_contents($extLocalconfLocation, "<?php\n\n" . $uniqueStringInLocalconf . "\n\n?>");
875 $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\
LoadedExtensionsArray($packageManager);
876 $mockCache = $this->getMock(
877 'TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend',
878 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
883 $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
884 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
885 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
886 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInLocalconf), $this->anything());
887 ExtensionManagementUtilityAccessibleProxy
::createExtLocalconfCacheEntry();
893 public function createExtLocalconfCacheEntryWritesCacheEntryWithExtensionContentOnlyIfExtLocalconfExists() {
894 $extensionName = uniqid('foo');
895 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
896 $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\
LoadedExtensionsArray($packageManager);
897 $mockCache = $this->getMock(
898 'TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend',
899 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
904 $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
905 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
906 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
907 $mockCache->expects($this->once())
909 ->with($this->anything(), $this->logicalNot($this->stringContains($extensionName)), $this->anything());
910 ExtensionManagementUtilityAccessibleProxy
::createExtLocalconfCacheEntry();
916 public function createExtLocalconfCacheEntryWritesCacheEntryWithNoTags() {
917 $mockCache = $this->getMock(
918 'TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend',
919 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
924 $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
925 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
926 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
927 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo(array()));
928 $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\
LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage(uniqid()));
929 ExtensionManagementUtilityAccessibleProxy
::createExtLocalconfCacheEntry();
932 /////////////////////////////////////////
933 // Tests concerning getExtLocalconfCacheIdentifier
934 /////////////////////////////////////////
938 public function getExtLocalconfCacheIdentifierCreatesSha1WithFourtyCharactersAndPrefix() {
939 $prefix = 'ext_localconf_';
940 $identifier = ExtensionManagementUtilityAccessibleProxy
::getExtLocalconfCacheIdentifier();
941 $this->assertStringStartsWith($prefix, $identifier);
942 $sha1 = str_replace($prefix, '', $identifier);
943 $this->assertEquals(40, strlen($sha1));
946 /////////////////////////////////////////
947 // Tests concerning loadBaseTca
948 /////////////////////////////////////////
953 public function loadBaseTcaDoesNotReadFromCacheIfCachingIsDenied() {
954 $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
955 $mockCacheManager->expects($this->never())->method('getCache');
956 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
957 ExtensionManagementUtilityAccessibleProxy
::loadBaseTca(FALSE);
963 public function loadBaseTcaRequiresCacheFileIfExistsAndCachingIsAllowed() {
964 $mockCache = $this->getMock(
965 'TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend',
966 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
971 $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
972 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
973 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
974 $mockCache->expects($this->any())->method('has')->will($this->returnValue(TRUE));
975 $mockCache->expects($this->once())->method('get');
976 ExtensionManagementUtilityAccessibleProxy
::loadBaseTca(TRUE);
982 public function loadBaseTcaCreatesCacheFileWithContentOfAnExtensionsConfigurationTcaPhpFile() {
983 $extensionName = uniqid('test_baseTca_');
984 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
985 $packagePath = $packageManager->getPackage($extensionName)->getPackagePath();
986 \TYPO3\CMS\Core\Utility\GeneralUtility
::mkdir($packagePath);
987 \TYPO3\CMS\Core\Utility\GeneralUtility
::mkdir($packagePath . 'Configuration/');
988 \TYPO3\CMS\Core\Utility\GeneralUtility
::mkdir($packagePath . 'Configuration/TCA/');
989 $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\
LoadedExtensionsArray($packageManager);
990 ExtensionManagementUtility
::setPackageManager($packageManager);
991 $uniqueTableName = uniqid('table_name_');
992 $uniqueStringInTableConfiguration = uniqid('table_configuration_');
993 $tableConfiguration = '<?php return array(\'foo\' => \'' . $uniqueStringInTableConfiguration . '\'); ?>';
994 file_put_contents($packagePath . 'Configuration/TCA/' . $uniqueTableName . '.php', $tableConfiguration);
995 $mockCache = $this->getMock(
996 'TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend',
997 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1002 $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
1003 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1004 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1005 $mockCache->expects($this->once())->method('has')->will($this->returnValue(FALSE));
1006 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInTableConfiguration), $this->anything());
1007 ExtensionManagementUtility
::loadBaseTca(TRUE);
1013 public function loadBaseTcaWritesCacheEntryWithNoTags() {
1014 $mockCache = $this->getMock(
1015 'TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend',
1016 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1021 $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
1022 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1023 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1024 $mockCache->expects($this->once())->method('has')->will($this->returnValue(FALSE));
1025 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo(array()));
1026 ExtensionManagementUtilityAccessibleProxy
::loadBaseTca();
1029 /////////////////////////////////////////
1030 // Tests concerning getBaseTcaCacheIdentifier
1031 /////////////////////////////////////////
1036 public function getBaseTcaCacheIdentifierCreatesSha1WithFourtyCharactersAndPrefix() {
1037 $prefix = 'tca_base_';
1038 $identifier = ExtensionManagementUtilityAccessibleProxy
::getBaseTcaCacheIdentifier();
1039 $this->assertStringStartsWith($prefix, $identifier);
1040 $sha1 = str_replace($prefix, '', $identifier);
1041 $this->assertEquals(40, strlen($sha1));
1044 /////////////////////////////////////////
1045 // Tests concerning loadExtTables
1046 /////////////////////////////////////////
1050 public function loadExtTablesDoesNotReadFromCacheIfCachingIsDenied() {
1051 $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
1052 $mockCacheManager->expects($this->never())->method('getCache');
1053 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1054 $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\
LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage(uniqid()));
1055 ExtensionManagementUtility
::loadExtLocalconf(FALSE);
1061 public function loadExtTablesRequiresCacheFileIfExistsAndCachingIsAllowed() {
1062 $mockCache = $this->getMock(
1063 'TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend',
1064 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1069 $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
1070 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1071 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1072 $mockCache->expects($this->any())->method('has')->will($this->returnValue(TRUE));
1073 $mockCache->expects($this->once())->method('requireOnce');
1074 // Reset the internal cache access tracking variable of extMgm
1075 // This method is only in the ProxyClass!
1076 ExtensionManagementUtilityAccessibleProxy
::resetExtTablesWasReadFromCacheOnceBoolean();
1077 ExtensionManagementUtility
::loadExtTables(TRUE);
1080 /////////////////////////////////////////
1081 // Tests concerning createExtTablesCacheEntry
1082 /////////////////////////////////////////
1086 public function createExtTablesCacheEntryWritesCacheEntryWithContentOfLoadedExtensionExtTables() {
1087 $extensionName = uniqid('foo');
1088 $extTablesLocation = PATH_site
. 'typo3temp/' . uniqid('test_ext_tables') . '.php';
1089 $this->testFilesToDelete
[] = $extTablesLocation;
1090 $uniqueStringInTables = uniqid('foo');
1091 file_put_contents($extTablesLocation, "<?php\n\n$uniqueStringInTables\n\n?>");
1092 $GLOBALS['TYPO3_LOADED_EXT'] = array(
1093 $extensionName => array(
1094 'ext_tables.php' => $extTablesLocation
1097 $mockCache = $this->getMock(
1098 'TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend',
1099 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1104 $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
1105 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1106 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1107 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInTables), $this->anything());
1108 ExtensionManagementUtilityAccessibleProxy
::createExtTablesCacheEntry();
1114 public function createExtTablesCacheEntryWritesCacheEntryWithExtensionContentOnlyIfExtTablesExists() {
1115 $extensionName = uniqid('foo');
1116 $GLOBALS['TYPO3_LOADED_EXT'] = array(
1117 $extensionName => array(),
1119 $mockCache = $this->getMock(
1120 'TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend',
1121 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1126 $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
1127 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1128 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1129 $mockCache->expects($this->once())
1131 ->with($this->anything(), $this->logicalNot($this->stringContains($extensionName)), $this->anything());
1132 ExtensionManagementUtilityAccessibleProxy
::createExtTablesCacheEntry();
1138 public function createExtTablesCacheEntryWritesCacheEntryWithNoTags() {
1139 $mockCache = $this->getMock(
1140 'TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend',
1141 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1146 $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
1147 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1148 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1149 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo(array()));
1150 $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\
LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage(uniqid()));
1151 ExtensionManagementUtilityAccessibleProxy
::createExtTablesCacheEntry();
1154 /////////////////////////////////////////
1155 // Tests concerning getExtTablesCacheIdentifier
1156 /////////////////////////////////////////
1160 public function getExtTablesCacheIdentifierCreatesSha1WithFourtyCharactersAndPrefix() {
1161 $prefix = 'ext_tables_';
1162 $identifier = ExtensionManagementUtilityAccessibleProxy
::getExtTablesCacheIdentifier();
1163 $this->assertStringStartsWith($prefix, $identifier);
1164 $sha1 = str_replace($prefix, '', $identifier);
1165 $this->assertEquals(40, strlen($sha1));
1168 /////////////////////////////////////////
1169 // Tests concerning removeCacheFiles
1170 /////////////////////////////////////////
1174 public function removeCacheFilesFlushesSystemCaches() {
1175 $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('flushCachesInGroup'));
1176 $mockCacheManager->expects($this->once())->method('flushCachesInGroup')->with('system');
1177 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1178 ExtensionManagementUtility
::removeCacheFiles();
1181 /////////////////////////////////////////
1182 // Tests concerning loadNewTcaColumnsConfigFiles
1183 /////////////////////////////////////////
1187 * @expectedException \RuntimeException
1189 public function loadNewTcaColumnsConfigFilesIncludesDefinedDynamicConfigFileIfNoColumnsExist() {
1190 $GLOBALS['TCA'] = array(
1193 'dynamicConfigFile' => __DIR__
. '/Fixtures/RuntimeException.php'
1197 ExtensionManagementUtility
::loadNewTcaColumnsConfigFiles();
1203 public function loadNewTcaColumnsConfigFilesDoesNotIncludeFileIfColumnsExist() {
1204 $GLOBALS['TCA'] = array(
1207 'dynamicConfigFile' => __DIR__
. '/Fixtures/RuntimeException.php'
1214 ExtensionManagementUtility
::loadNewTcaColumnsConfigFiles();
1217 /////////////////////////////////////////
1218 // Tests concerning getExtensionVersion
1219 /////////////////////////////////////////
1221 * Data provider for negative getExtensionVersion() tests.
1225 public function getExtensionVersionFaultyDataProvider() {
1229 array(new \
stdClass()),
1236 * @expectedException \InvalidArgumentException
1237 * @dataProvider getExtensionVersionFaultyDataProvider
1239 public function getExtensionVersionForFaultyExtensionKeyThrowsException($key) {
1240 ExtensionManagementUtility
::getExtensionVersion($key);
1246 public function getExtensionVersionForNotLoadedExtensionReturnsEmptyString() {
1247 ExtensionManagementUtility
::clearExtensionKeyMap();
1248 $uniqueSuffix = uniqid('test');
1249 $extensionKey = 'unloadedextension' . $uniqueSuffix;
1250 $this->assertEquals('', ExtensionManagementUtility
::getExtensionVersion($extensionKey));
1256 public function getExtensionVersionForLoadedExtensionReturnsExtensionVersion() {
1257 ExtensionManagementUtility
::clearExtensionKeyMap();
1258 $className = uniqid('ExtensionManagementUtility');
1260 'namespace ' . __NAMESPACE__
.';' .
1261 'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\Utility\\ExtensionManagementUtility {' .
1262 ' public static function isLoaded() {' .
1267 $className = __NAMESPACE__
. '\\' . $className;
1268 ExtensionManagementUtility
::clearExtensionKeyMap();
1269 $uniqueSuffix = uniqid('test');
1270 $extensionKey = 'unloadedextension' . $uniqueSuffix;
1271 $packageMetaData = $this->getMock('TYPO3\\Flow\\Package\\MetaData', array('getVersion'), array($extensionKey));
1272 $packageMetaData->expects($this->any())->method('getVersion')->will($this->returnValue('1.2.3'));
1273 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionKey, array('getPackagePath', 'getPackageKey', 'getPackageMetaData'));
1274 /** @var \PHPUnit_Framework_MockObject_MockObject $package */
1275 $package = $packageManager->getPackage($extensionKey);
1276 $package->expects($this->any())
1277 ->method('getPackageMetaData')
1278 ->will($this->returnValue($packageMetaData));
1279 ExtensionManagementUtility
::setPackageManager($packageManager);
1280 $this->assertEquals('1.2.3', ExtensionManagementUtility
::getExtensionVersion($extensionKey));
1283 /////////////////////////////////////////
1284 // Tests concerning loadExtension
1285 /////////////////////////////////////////
1288 * @expectedException \RuntimeException
1290 public function loadExtensionThrowsExceptionIfExtensionIsLoaded() {
1291 $extensionKey = uniqid('test');
1292 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionKey);
1293 ExtensionManagementUtility
::setPackageManager($packageManager);
1294 ExtensionManagementUtility
::loadExtension($extensionKey);
1297 /////////////////////////////////////////
1298 // Tests concerning unloadExtension
1299 /////////////////////////////////////////
1302 * @expectedException \RuntimeException
1304 public function unloadExtensionThrowsExceptionIfExtensionIsNotLoaded() {
1305 $packageName = uniqid('foo');
1306 $packageManager = $this->getMock('TYPO3\\CMS\\Core\\Package\\PackageManager', array('isPackageActive'));
1307 $packageManager->expects($this->once())
1308 ->method('isPackageActive')
1309 ->with($this->equalTo($packageName))
1310 ->will($this->returnValue(FALSE));
1311 ExtensionManagementUtility
::setPackageManager($packageManager);
1312 ExtensionManagementUtility
::unloadExtension($packageName);
1318 public function unloadExtensionCallsPackageManagerToDeactivatePackage() {
1319 $packageName = uniqid('foo');
1320 $packageManager = $this->getMock(
1321 'TYPO3\\CMS\\Core\\Package\\PackageManager',
1322 array('isPackageActive', 'deactivatePackage')
1324 $packageManager->expects($this->any())
1325 ->method('isPackageActive')
1326 ->will($this->returnValue(TRUE));
1327 $packageManager->expects($this->once())
1328 ->method('deactivatePackage')
1329 ->with($packageName);
1330 ExtensionManagementUtility
::setPackageManager($packageManager);
1331 ExtensionManagementUtility
::unloadExtension($packageName);
1334 /////////////////////////////////////////
1335 // Tests concerning makeCategorizable
1336 /////////////////////////////////////////
1340 public function doesMakeCategorizableCallsTheCategoryRegistryWithDefaultFieldName() {
1341 $extensionKey = uniqid('extension');
1342 $tableName = uniqid('table');
1343 $GLOBALS['TCA'][$tableName] = array(
1345 'columns' => array()
1347 $registryMock = $this->getMock('TYPO3\\CMS\\Core\\Category\\CategoryRegistry');
1348 $registryMock->expects($this->once())->method('add')->with($extensionKey, $tableName, 'categories', array());
1349 \TYPO3\CMS\Core\Utility\GeneralUtility
::setSingletonInstance('TYPO3\\CMS\\Core\\Category\\CategoryRegistry', $registryMock);
1350 ExtensionManagementUtility
::makeCategorizable($extensionKey, $tableName);
1356 public function doesMakeCategorizableCallsTheCategoryRegistryWithFieldName() {
1357 $extensionKey = uniqid('extension');
1358 $tableName = uniqid('table');
1359 $fieldName = uniqid('field');
1360 $GLOBALS['TCA'][$tableName] = array(
1362 'columns' => array()
1364 $registryMock = $this->getMock('TYPO3\\CMS\\Core\\Category\\CategoryRegistry');
1365 $registryMock->expects($this->once())->method('add')->with($extensionKey, $tableName, $fieldName, array());
1366 \TYPO3\CMS\Core\Utility\GeneralUtility
::setSingletonInstance('TYPO3\\CMS\\Core\\Category\\CategoryRegistry', $registryMock);
1367 ExtensionManagementUtility
::makeCategorizable($extensionKey, $tableName, $fieldName);