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\Cache\CacheManager
;
18 use TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend
;
19 use TYPO3\CMS\Core\Category\CategoryRegistry
;
20 use TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray
;
21 use TYPO3\CMS\Core\Package\MetaData
;
22 use TYPO3\CMS\Core\Package\Package
;
23 use TYPO3\CMS\Core\Package\PackageManager
;
24 use TYPO3\CMS\Core\Tests\Unit\Utility\AccessibleProxies\ExtensionManagementUtilityAccessibleProxy
;
25 use TYPO3\CMS\Core\Tests\UnitTestCase
;
26 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility
;
27 use TYPO3\CMS\Core\Utility\GeneralUtility
;
32 class ExtensionManagementUtilityTest
extends UnitTestCase
35 * @var array A backup of registered singleton instances
37 protected $singletonInstances = array();
40 * @var \TYPO3\CMS\Core\Package\PackageManager
42 protected $backUpPackageManager;
44 protected function setUp()
46 $this->singletonInstances
= GeneralUtility
::getSingletonInstances();
47 $this->backUpPackageManager
= ExtensionManagementUtilityAccessibleProxy
::getPackageManager();
48 $this->singletonInstances
= GeneralUtility
::getSingletonInstances();
51 protected function tearDown()
53 ExtensionManagementUtility
::clearExtensionKeyMap();
54 ExtensionManagementUtilityAccessibleProxy
::setPackageManager($this->backUpPackageManager
);
55 ExtensionManagementUtilityAccessibleProxy
::setCacheManager(null
);
56 $GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($this->backUpPackageManager
);
57 GeneralUtility
::resetSingletonInstances($this->singletonInstances
);
62 * @param string $packageKey
63 * @param array $packageMethods
64 * @return PackageManager|\PHPUnit_Framework_MockObject_MockObject
66 protected function createMockPackageManagerWithMockPackage($packageKey, $packageMethods = array('getPackagePath', 'getPackageKey'))
68 $packagePath = PATH_site
. 'typo3temp/' . $packageKey . '/';
69 GeneralUtility
::mkdir_deep($packagePath);
70 $this->testFilesToDelete
[] = $packagePath;
71 $package = $this->getMockBuilder(Package
::class)
72 ->disableOriginalConstructor()
73 ->setMethods($packageMethods)
75 $packageManager = $this->getMock(
76 PackageManager
::class,
77 array('isPackageActive', 'getPackage', 'getActivePackages')
79 $package->expects($this->any())
80 ->method('getPackagePath')
81 ->will($this->returnValue($packagePath));
82 $package->expects($this->any())
83 ->method('getPackageKey')
84 ->will($this->returnValue($packageKey));
85 $packageManager->expects($this->any())
86 ->method('isPackageActive')
87 ->will($this->returnValueMap(array(
89 array($packageKey, true
)
91 $packageManager->expects($this->any())
92 ->method('getPackage')
93 ->with($this->equalTo($packageKey))
94 ->will($this->returnValue($package));
95 $packageManager->expects($this->any())
96 ->method('getActivePackages')
97 ->will($this->returnValue(array($packageKey => $package)));
98 return $packageManager;
101 ///////////////////////////////
102 // Tests concerning isLoaded
103 ///////////////////////////////
107 public function isLoadedReturnsFalseIfExtensionIsNotLoadedAndExitIsDisabled()
109 $this->assertFalse(ExtensionManagementUtility
::isLoaded($this->getUniqueId('foobar'), false
));
114 * @expectedException \BadFunctionCallException
116 public function isLoadedThrowsExceptionIfExtensionIsNotLoaded()
118 $this->assertFalse(ExtensionManagementUtility
::isLoaded($this->getUniqueId('foobar'), true
));
121 ///////////////////////////////
122 // Tests concerning extPath
123 ///////////////////////////////
126 * @expectedException \BadFunctionCallException
128 public function extPathThrowsExceptionIfExtensionIsNotLoaded()
130 $packageName = $this->getUniqueId('foo');
131 /** @var PackageManager|\PHPUnit_Framework_MockObject_MockObject $packageManager */
132 $packageManager = $this->getMock(PackageManager
::class, array('isPackageActive'));
133 $packageManager->expects($this->once())
134 ->method('isPackageActive')
135 ->with($this->equalTo($packageName))
136 ->will($this->returnValue(false
));
137 ExtensionManagementUtility
::setPackageManager($packageManager);
138 ExtensionManagementUtility
::extPath($packageName);
144 public function extPathAppendsScriptNameToPath()
146 $package = $this->getMockBuilder(Package
::class)
147 ->disableOriginalConstructor()
148 ->setMethods(array('getPackagePath'))
150 /** @var PackageManager|\PHPUnit_Framework_MockObject_MockObject $packageManager */
151 $packageManager = $this->getMock(PackageManager
::class, array('isPackageActive', 'getPackage'));
152 $package->expects($this->once())
153 ->method('getPackagePath')
154 ->will($this->returnValue(PATH_site
. 'foo/'));
155 $packageManager->expects($this->once())
156 ->method('isPackageActive')
157 ->with($this->equalTo('foo'))
158 ->will($this->returnValue(true
));
159 $packageManager->expects($this->once())
160 ->method('getPackage')
162 ->will($this->returnValue($package));
163 ExtensionManagementUtility
::setPackageManager($packageManager);
164 $this->assertSame(PATH_site
. 'foo/bar.txt', ExtensionManagementUtility
::extPath('foo', 'bar.txt'));
167 //////////////////////
169 //////////////////////
171 * Generates a basic TCA for a given table.
173 * @param string $table name of the table, must not be empty
174 * @return array generated TCA for the given table, will not be empty
176 private function generateTCAForTable($table)
179 $tca[$table] = array();
180 $tca[$table]['columns'] = array(
184 $tca[$table]['types'] = array(
185 'typeA' => array('showitem' => 'fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, fieldD, fieldD1'),
186 'typeB' => array('showitem' => 'fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, fieldD, fieldD1'),
187 'typeC' => array('showitem' => 'fieldC;;paletteD')
189 $tca[$table]['palettes'] = array(
190 'paletteA' => array('showitem' => 'fieldX, fieldX1, fieldY'),
191 'paletteB' => array('showitem' => 'fieldX, fieldX1, fieldY'),
192 'paletteC' => array('showitem' => 'fieldX, fieldX1, fieldY'),
193 'paletteD' => array('showitem' => 'fieldX, fieldX1, fieldY')
199 * Data provider for getClassNamePrefixForExtensionKey.
203 public function extensionKeyDataProvider()
206 'Without underscores' => array(
210 'With underscores' => array(
211 'this_is_a_test_extension',
212 'tx_thisisatestextension'
214 'With user prefix and without underscores' => array(
218 'With user prefix and with underscores' => array(
227 * @param string $extensionName
228 * @param string $expectedPrefix
229 * @dataProvider extensionKeyDataProvider
231 public function getClassNamePrefixForExtensionKey($extensionName, $expectedPrefix)
233 $this->assertSame($expectedPrefix, ExtensionManagementUtility
::getCN($extensionName));
236 /////////////////////////////////////////////
237 // Tests concerning getExtensionKeyByPrefix
238 /////////////////////////////////////////////
241 * @see ExtensionManagementUtility::getExtensionKeyByPrefix
243 public function getExtensionKeyByPrefixForLoadedExtensionWithUnderscoresReturnsExtensionKey()
245 ExtensionManagementUtility
::clearExtensionKeyMap();
246 $uniqueSuffix = $this->getUniqueId('test');
247 $extensionKey = 'tt_news' . $uniqueSuffix;
248 $extensionPrefix = 'tx_ttnews' . $uniqueSuffix;
249 $package = $this->getMockBuilder(Package
::class)
250 ->disableOriginalConstructor()
251 ->setMethods(array('getPackageKey'))
253 $package->expects($this->exactly(2))
254 ->method('getPackageKey')
255 ->will($this->returnValue($extensionKey));
256 /** @var PackageManager|\PHPUnit_Framework_MockObject_MockObject $packageManager */
257 $packageManager = $this->getMock(PackageManager
::class, array('getActivePackages'));
258 $packageManager->expects($this->once())
259 ->method('getActivePackages')
260 ->will($this->returnValue(array($extensionKey => $package)));
261 ExtensionManagementUtility
::setPackageManager($packageManager);
262 $this->assertEquals($extensionKey, ExtensionManagementUtility
::getExtensionKeyByPrefix($extensionPrefix));
267 * @see ExtensionManagementUtility::getExtensionKeyByPrefix
269 public function getExtensionKeyByPrefixForLoadedExtensionWithoutUnderscoresReturnsExtensionKey()
271 ExtensionManagementUtility
::clearExtensionKeyMap();
272 $uniqueSuffix = $this->getUniqueId('test');
273 $extensionKey = 'kickstarter' . $uniqueSuffix;
274 $extensionPrefix = 'tx_kickstarter' . $uniqueSuffix;
275 $package = $this->getMockBuilder(Package
::class)
276 ->disableOriginalConstructor()
277 ->setMethods(array('getPackageKey'))
279 $package->expects($this->exactly(2))
280 ->method('getPackageKey')
281 ->will($this->returnValue($extensionKey));
282 /** @var PackageManager|\PHPUnit_Framework_MockObject_MockObject $packageManager */
283 $packageManager = $this->getMock(PackageManager
::class, array('getActivePackages'));
284 $packageManager->expects($this->once())
285 ->method('getActivePackages')
286 ->will($this->returnValue(array($extensionKey => $package)));
287 ExtensionManagementUtility
::setPackageManager($packageManager);
288 $this->assertEquals($extensionKey, ExtensionManagementUtility
::getExtensionKeyByPrefix($extensionPrefix));
293 * @see ExtensionManagementUtility::getExtensionKeyByPrefix
295 public function getExtensionKeyByPrefixForNotLoadedExtensionReturnsFalse()
297 ExtensionManagementUtility
::clearExtensionKeyMap();
298 $uniqueSuffix = $this->getUniqueId('test');
299 $extensionPrefix = 'tx_unloadedextension' . $uniqueSuffix;
300 $this->assertFalse(ExtensionManagementUtility
::getExtensionKeyByPrefix($extensionPrefix));
303 //////////////////////////////////////
304 // Tests concerning addToAllTCAtypes
305 //////////////////////////////////////
307 * Tests whether fields can be add to all TCA types and duplicate fields are considered.
310 * @see ExtensionManagementUtility::addToAllTCAtypes()
312 public function canAddFieldsToAllTCATypesBeforeExistingOnes()
314 $table = $this->getUniqueId('tx_coretest_table');
315 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
316 ExtensionManagementUtility
::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'before:fieldD');
318 $this->assertEquals('fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, newA, newB, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
320 $this->assertEquals('fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, newA, newB, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
324 * Tests whether fields can be add to all TCA types and duplicate fields are considered.
327 * @see ExtensionManagementUtility::addToAllTCAtypes()
329 public function canAddFieldsToAllTCATypesAfterExistingOnes()
331 $table = $this->getUniqueId('tx_coretest_table');
332 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
333 ExtensionManagementUtility
::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'after:fieldC');
335 $this->assertEquals('fieldA, fieldB, fieldC;labelC, newA, newB, --palette--;;paletteC, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
337 $this->assertEquals('fieldA, fieldB, fieldC;labelC, newA, newB, --palette--;;paletteC, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
341 * Tests whether fields can be add to all TCA types and duplicate fields are considered.
344 * @see ExtensionManagementUtility::addToAllTCAtypes()
346 public function canAddFieldsToAllTCATypesRespectsPalettes()
348 $table = $this->getUniqueId('tx_coretest_table');
349 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
350 $GLOBALS['TCA'][$table]['types']['typeD'] = ['showitem' => 'fieldY, --palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.palettes.standard;standard, fieldZ'];
351 ExtensionManagementUtility
::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'after:--palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.palettes.standard;standard');
353 $this->assertEquals('fieldY, --palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages.palettes.standard;standard, newA, newB, fieldA, fieldZ', $GLOBALS['TCA'][$table]['types']['typeD']['showitem']);
357 * Tests whether fields can be add to all TCA types and fields in pallets are respected.
360 * @see ExtensionManagementUtility::addToAllTCAtypes()
362 public function canAddFieldsToAllTCATypesRespectsPositionFieldInPalette()
364 $table = $this->getUniqueId('tx_coretest_table');
365 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
366 ExtensionManagementUtility
::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'after:fieldX1');
368 $this->assertEquals('fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, newA, newB, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
372 * Tests whether fields can be add to a TCA type before existing ones
375 * @see ExtensionManagementUtility::addToAllTCAtypes()
377 public function canAddFieldsToTCATypeBeforeExistingOnes()
379 $table = $this->getUniqueId('tx_coretest_table');
380 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
381 ExtensionManagementUtility
::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', 'typeA', 'before:fieldD');
383 $this->assertEquals('fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, newA, newB, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
385 $this->assertEquals('fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
389 * Tests whether fields can be add to a TCA type after existing ones
392 * @see ExtensionManagementUtility::addToAllTCAtypes()
394 public function canAddFieldsToTCATypeAfterExistingOnes()
396 $table = $this->getUniqueId('tx_coretest_table');
397 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
398 ExtensionManagementUtility
::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', 'typeA', 'after:fieldC');
400 $this->assertEquals('fieldA, fieldB, fieldC;labelC, newA, newB, --palette--;;paletteC, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
402 $this->assertEquals('fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
406 * Test wheter replacing other TCA fields works as promissed
409 * @see ExtensionManagementUtility::addFieldsToAllPalettesOfField()
411 public function canAddFieldsToTCATypeAndReplaceExistingOnes()
413 $table = $this->getUniqueId('tx_coretest_table');
414 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
415 $typesBefore = $GLOBALS['TCA'][$table]['types'];
416 ExtensionManagementUtility
::addToAllTCAtypes($table, 'fieldZ', '', 'replace:fieldX');
417 $this->assertEquals($typesBefore, $GLOBALS['TCA'][$table]['types'], 'It\'s wrong that the "types" array changes here - the replaced field is only on palettes');
418 // unchanged because the palette is not used
419 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
420 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
422 $this->assertEquals('fieldZ, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
423 $this->assertEquals('fieldZ, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
429 public function addToAllTCAtypesReplacesExistingOnes()
431 $table = $this->getUniqueId('tx_coretest_table');
432 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
433 $typesBefore = $GLOBALS['TCA'][$table]['types'];
434 ExtensionManagementUtility
::addToAllTCAtypes($table, 'fieldX, --palette--;;foo', '', 'replace:fieldX');
435 $this->assertEquals($typesBefore, $GLOBALS['TCA'][$table]['types'], 'It\'s wrong that the "types" array changes here - the replaced field is only on palettes');
436 // unchanged because the palette is not used
437 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
438 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
440 $this->assertEquals('fieldX, --palette--;;foo, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
441 $this->assertEquals('fieldX, --palette--;;foo, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
445 * Tests whether fields can be added to a palette before existing elements.
448 * @see ExtensionManagementUtility::addFieldsToPalette()
450 public function canAddFieldsToPaletteBeforeExistingOnes()
452 $table = $this->getUniqueId('tx_coretest_table');
453 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
454 ExtensionManagementUtility
::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'before:fieldY');
455 $this->assertEquals('fieldX, fieldX1, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
459 * Tests whether fields can be added to a palette after existing elements.
462 * @see ExtensionManagementUtility::addFieldsToPalette()
464 public function canAddFieldsToPaletteAfterExistingOnes()
466 $table = $this->getUniqueId('tx_coretest_table');
467 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
468 ExtensionManagementUtility
::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'after:fieldX');
469 $this->assertEquals('fieldX, newA, newB, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
473 * Tests whether fields can be added to a palette after a not existing elements.
476 * @see ExtensionManagementUtility::addFieldsToPalette()
478 public function canAddFieldsToPaletteAfterNotExistingOnes()
480 $table = $this->getUniqueId('tx_coretest_table');
481 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
482 ExtensionManagementUtility
::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'after:' . $this->getUniqueId('notExisting'));
483 $this->assertEquals('fieldX, fieldX1, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
489 public function removeDuplicatesForInsertionRemovesDuplicatesDataProvider()
493 'field_b, field_d, field_c',
494 'field_a, field_b, field_c',
497 'with linebreaks' => array(
498 'field_b, --linebreak--, field_d, --linebreak--, field_c',
499 'field_a, field_b, field_c',
500 '--linebreak--, field_d, --linebreak--'
502 'with linebreaks in list and insertion list' => array(
503 'field_b, --linebreak--, field_d, --linebreak--, field_c',
504 'field_a, field_b, --linebreak--, field_c',
505 '--linebreak--, field_d, --linebreak--'
512 * @dataProvider removeDuplicatesForInsertionRemovesDuplicatesDataProvider
513 * @param $insertionList
517 public function removeDuplicatesForInsertionRemovesDuplicates($insertionList, $list, $expected)
519 $result = ExtensionManagementUtilityAccessibleProxy
::removeDuplicatesForInsertion($insertionList, $list);
520 $this->assertSame($expected, $result);
523 ///////////////////////////////////////////////////
524 // Tests concerning addFieldsToAllPalettesOfField
525 ///////////////////////////////////////////////////
530 public function addFieldsToAllPalettesOfFieldDoesNotAddAnythingIfFieldIsNotRegisteredInColumns()
532 $GLOBALS['TCA'] = array(
536 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
541 'showitem' => 'fieldX, fieldY',
546 $expected = $GLOBALS['TCA'];
547 ExtensionManagementUtility
::addFieldsToAllPalettesOfField(
552 $this->assertEquals($expected, $GLOBALS['TCA']);
558 public function addFieldsToAllPalettesOfFieldAddsFieldsToPaletteAndSuppressesDuplicates()
560 $GLOBALS['TCA'] = array(
567 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
572 'showitem' => 'fieldX, fieldY',
584 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
589 'showitem' => 'fieldX, fieldY, dupeA',
594 ExtensionManagementUtility
::addFieldsToAllPalettesOfField(
597 'dupeA, dupeA' // Duplicate
599 $this->assertEquals($expected, $GLOBALS['TCA']);
605 public function addFieldsToAllPalettesOfFieldDoesNotAddAFieldThatIsPartOfPaletteAlready()
607 $GLOBALS['TCA'] = array(
614 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
619 'showitem' => 'existingA',
631 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
636 'showitem' => 'existingA',
641 ExtensionManagementUtility
::addFieldsToAllPalettesOfField(
646 $this->assertEquals($expected, $GLOBALS['TCA']);
652 public function addFieldsToAllPalettesOfFieldAddsFieldsToMultiplePalettes()
654 $GLOBALS['TCA'] = array(
661 'showitem' => 'fieldA, --palette--;;palette1',
664 'showitem' => 'fieldA;aLabel, --palette--;;palette2',
669 'showitem' => 'fieldX',
672 'showitem' => 'fieldY',
684 'showitem' => 'fieldA, --palette--;;palette1',
687 'showitem' => 'fieldA;aLabel, --palette--;;palette2',
692 'showitem' => 'fieldX, newA',
695 'showitem' => 'fieldY, newA',
700 ExtensionManagementUtility
::addFieldsToAllPalettesOfField(
705 $this->assertEquals($expected, $GLOBALS['TCA']);
711 public function addFieldsToAllPalettesOfFieldAddsMultipleFields()
713 $GLOBALS['TCA'] = array(
720 'showitem' => 'fieldA, --palette--;;palette1',
725 'showitem' => 'fieldX',
737 'showitem' => 'fieldA, --palette--;;palette1',
742 'showitem' => 'fieldX, newA, newB',
747 ExtensionManagementUtility
::addFieldsToAllPalettesOfField(
752 $this->assertEquals($expected, $GLOBALS['TCA']);
758 public function addFieldsToAllPalettesOfFieldAddsBeforeExistingIfRequested()
760 $GLOBALS['TCA'] = array(
767 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
772 'showitem' => 'existingA, existingB',
784 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
789 'showitem' => 'existingA, newA, existingB',
794 ExtensionManagementUtility
::addFieldsToAllPalettesOfField(
800 $this->assertEquals($expected, $GLOBALS['TCA']);
806 public function addFieldsToAllPalettesOfFieldAddsFieldsAtEndIfBeforeRequestedDoesNotExist()
808 $GLOBALS['TCA'] = array(
815 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
820 'showitem' => 'fieldX, fieldY',
832 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
837 'showitem' => 'fieldX, fieldY, newA, newB',
842 ExtensionManagementUtility
::addFieldsToAllPalettesOfField(
848 $this->assertEquals($expected, $GLOBALS['TCA']);
854 public function addFieldsToAllPalettesOfFieldAddsAfterExistingIfRequested()
856 $GLOBALS['TCA'] = array(
863 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
868 'showitem' => 'existingA, existingB',
880 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
885 'showitem' => 'existingA, newA, existingB',
890 ExtensionManagementUtility
::addFieldsToAllPalettesOfField(
896 $this->assertEquals($expected, $GLOBALS['TCA']);
902 public function addFieldsToAllPalettesOfFieldAddsFieldsAtEndIfAfterRequestedDoesNotExist()
904 $GLOBALS['TCA'] = array(
911 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
916 'showitem' => 'existingA, existingB',
928 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
933 'showitem' => 'existingA, existingB, newA, newB',
938 ExtensionManagementUtility
::addFieldsToAllPalettesOfField(
944 $this->assertEquals($expected, $GLOBALS['TCA']);
950 public function addFieldsToAllPalettesOfFieldAddsNewPaletteIfFieldHasNoPaletteYet()
952 $GLOBALS['TCA'] = array(
959 'showitem' => 'fieldA',
971 'showitem' => 'fieldA, --palette--;;generatedFor-fieldA',
975 'generatedFor-fieldA' => array(
976 'showitem' => 'newA',
981 ExtensionManagementUtility
::addFieldsToAllPalettesOfField(
986 $this->assertEquals($expected, $GLOBALS['TCA']);
992 public function addFieldsToAllPalettesOfFieldAddsNewPaletteIfFieldHasNoPaletteYetAndKeepsExistingLabel()
994 $GLOBALS['TCA'] = array(
1001 'showitem' => 'fieldA;labelA',
1009 'fieldA' => array(),
1013 'showitem' => 'fieldA;labelA, --palette--;;generatedFor-fieldA',
1016 'palettes' => array(
1017 'generatedFor-fieldA' => array(
1018 'showitem' => 'newA',
1023 ExtensionManagementUtility
::addFieldsToAllPalettesOfField(
1028 $this->assertEquals($expected, $GLOBALS['TCA']);
1031 ///////////////////////////////////////////////////
1032 // Tests concerning executePositionedStringInsertion
1033 ///////////////////////////////////////////////////
1036 * Data provider for executePositionedStringInsertionTrimsCorrectCharacters
1039 public function executePositionedStringInsertionTrimsCorrectCharactersDataProvider()
1042 'normal characters' => array(
1046 'newlines' => array(
1050 'newlines with carriage return' => array(
1062 'multiple commas with trailing spaces' => array(
1071 * @dataProvider executePositionedStringInsertionTrimsCorrectCharactersDataProvider
1073 * @param $expectedResult
1075 public function executePositionedStringInsertionTrimsCorrectCharacters($string, $expectedResult)
1077 $extensionManagementUtility = $this->getAccessibleMock(ExtensionManagementUtility
::class, array('dummy'));
1078 $string = $extensionManagementUtility->_call('executePositionedStringInsertion', $string, '');
1079 $this->assertEquals($expectedResult, $string);
1082 /////////////////////////////////////////
1083 // Tests concerning addTcaSelectItem
1084 /////////////////////////////////////////
1087 * @expectedException \InvalidArgumentException
1089 public function addTcaSelectItemThrowsExceptionIfTableIsNotOfTypeString()
1091 ExtensionManagementUtility
::addTcaSelectItem(array(), 'foo', array());
1096 * @expectedException \InvalidArgumentException
1098 public function addTcaSelectItemThrowsExceptionIfFieldIsNotOfTypeString()
1100 ExtensionManagementUtility
::addTcaSelectItem('foo', array(), array());
1105 * @expectedException \InvalidArgumentException
1107 public function addTcaSelectItemThrowsExceptionIfRelativeToFieldIsNotOfTypeString()
1109 ExtensionManagementUtility
::addTcaSelectItem('foo', 'bar', array(), array());
1114 * @expectedException \InvalidArgumentException
1116 public function addTcaSelectItemThrowsExceptionIfRelativePositionIsNotOfTypeString()
1118 ExtensionManagementUtility
::addTcaSelectItem('foo', 'bar', array(), 'foo', array());
1123 * @expectedException \InvalidArgumentException
1125 public function addTcaSelectItemThrowsExceptionIfRelativePositionIsNotOneOfValidKeywords()
1127 ExtensionManagementUtility
::addTcaSelectItem('foo', 'bar', array(), 'foo', 'not allowed keyword');
1132 * @expectedException \RuntimeException
1134 public function addTcaSelectItemThrowsExceptionIfFieldIsNotFoundInTca()
1136 $GLOBALS['TCA'] = array();
1137 ExtensionManagementUtility
::addTcaSelectItem('foo', 'bar', array());
1141 * Data provider for addTcaSelectItemInsertsItemAtSpecifiedPosition
1143 public function addTcaSelectItemDataProvider()
1145 // Every array splits into:
1146 // - relativeToField
1147 // - relativePosition
1148 // - expectedResultArray
1150 'add at end of array' => array(
1154 0 => array('firstElement'),
1155 1 => array('matchMe'),
1156 2 => array('thirdElement'),
1157 3 => array('insertedElement')
1160 'replace element' => array(
1164 0 => array('firstElement'),
1165 1 => array('insertedElement'),
1166 2 => array('thirdElement')
1169 'add element after' => array(
1173 0 => array('firstElement'),
1174 1 => array('matchMe'),
1175 2 => array('insertedElement'),
1176 3 => array('thirdElement')
1179 'add element before' => array(
1183 0 => array('firstElement'),
1184 1 => array('insertedElement'),
1185 2 => array('matchMe'),
1186 3 => array('thirdElement')
1189 'add at end if relative position was not found' => array(
1193 0 => array('firstElement'),
1194 1 => array('matchMe'),
1195 2 => array('thirdElement'),
1196 3 => array('insertedElement')
1204 * @dataProvider addTcaSelectItemDataProvider
1205 * @param $relativeToField
1206 * @param $relativePosition
1207 * @param $expectedResultArray
1209 public function addTcaSelectItemInsertsItemAtSpecifiedPosition($relativeToField, $relativePosition, $expectedResultArray)
1211 $GLOBALS['TCA'] = array(
1212 'testTable' => array(
1214 'testField' => array(
1217 '0' => array('firstElement'),
1218 '1' => array('matchMe'),
1219 2 => array('thirdElement')
1226 ExtensionManagementUtility
::addTcaSelectItem('testTable', 'testField', array('insertedElement'), $relativeToField, $relativePosition);
1227 $this->assertEquals($expectedResultArray, $GLOBALS['TCA']['testTable']['columns']['testField']['config']['items']);
1230 /////////////////////////////////////////
1231 // Tests concerning loadExtLocalconf
1232 /////////////////////////////////////////
1236 public function loadExtLocalconfDoesNotReadFromCacheIfCachingIsDenied()
1238 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1239 $mockCacheManager = $this->getMock(CacheManager
::class, array('getCache'));
1240 $mockCacheManager->expects($this->never())->method('getCache');
1241 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1242 $GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage($this->getUniqueId()));
1243 ExtensionManagementUtility
::loadExtLocalconf(false
);
1249 public function loadExtLocalconfRequiresCacheFileIfExistsAndCachingIsAllowed()
1251 $mockCache = $this->getMock(
1252 AbstractFrontend
::class,
1253 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1258 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1259 $mockCacheManager = $this->getMock(CacheManager
::class, array('getCache'));
1260 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1261 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1262 $mockCache->expects($this->any())->method('has')->will($this->returnValue(true
));
1263 $mockCache->expects($this->once())->method('requireOnce');
1264 ExtensionManagementUtility
::loadExtLocalconf(true
);
1267 /////////////////////////////////////////
1268 // Tests concerning loadSingleExtLocalconfFiles
1269 /////////////////////////////////////////
1272 * @expectedException \RuntimeException
1274 public function loadSingleExtLocalconfFilesRequiresExtLocalconfFileRegisteredInGlobalTypo3LoadedExt()
1276 $extensionName = $this->getUniqueId('foo');
1277 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
1278 $extLocalconfLocation = $packageManager->getPackage($extensionName)->getPackagePath() . 'ext_localconf.php';
1279 file_put_contents($extLocalconfLocation, "<?php\n\nthrow new RuntimeException('', 1340559079);\n\n?>");
1280 $GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($packageManager);
1281 ExtensionManagementUtilityAccessibleProxy
::loadSingleExtLocalconfFiles();
1284 /////////////////////////////////////////
1285 // Tests concerning addModule
1286 /////////////////////////////////////////
1289 * Data provider for addModule tests
1292 public function addModulePositionTestsDataProvider()
1295 'can add new main module if none exists' => array(
1300 'can add new sub module if no position specified' => array(
1303 'some,modules,newModule'
1305 'can add new sub module to top of module' => array(
1308 'newModule,some,modules'
1310 'can add new sub module if bottom of module' => array(
1313 'some,modules,newModule'
1315 'can add new sub module before specified sub module' => array(
1318 'some,newModule,modules'
1320 'can add new sub module after specified sub module' => array(
1323 'some,newModule,modules'
1325 'can add new sub module at the bottom if specified sub module to add before does not exist' => array(
1327 'some,otherModules',
1328 'some,otherModules,newModule'
1330 'can add new sub module at the bottom if specified sub module to add after does not exist' => array(
1332 'someOther,modules',
1333 'someOther,modules,newModule'
1340 * @dataProvider addModulePositionTestsDataProvider
1345 public function addModuleCanAddModule($position, $existing, $expected)
1347 $mainModule = 'foobar';
1348 $subModule = 'newModule';
1350 $GLOBALS['TBE_MODULES'][$mainModule] = $existing;
1353 ExtensionManagementUtility
::addModule($mainModule, $subModule, $position);
1355 $this->assertTrue(isset($GLOBALS['TBE_MODULES'][$mainModule]));
1356 $this->assertEquals($expected, $GLOBALS['TBE_MODULES'][$mainModule]);
1359 /////////////////////////////////////////
1360 // Tests concerning createExtLocalconfCacheEntry
1361 /////////////////////////////////////////
1365 public function createExtLocalconfCacheEntryWritesCacheEntryWithContentOfLoadedExtensionExtLocalconf()
1367 $extensionName = $this->getUniqueId('foo');
1368 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
1369 $extLocalconfLocation = $packageManager->getPackage($extensionName)->getPackagePath() . 'ext_localconf.php';
1370 $uniqueStringInLocalconf = $this->getUniqueId('foo');
1371 file_put_contents($extLocalconfLocation, "<?php\n\n" . $uniqueStringInLocalconf . "\n\n?>");
1372 $GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($packageManager);
1373 $mockCache = $this->getMock(
1374 AbstractFrontend
::class,
1375 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1380 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1381 $mockCacheManager = $this->getMock(CacheManager
::class, array('getCache'));
1382 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1383 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1384 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInLocalconf), $this->anything());
1385 ExtensionManagementUtilityAccessibleProxy
::createExtLocalconfCacheEntry();
1391 public function createExtLocalconfCacheEntryWritesCacheEntryWithExtensionContentOnlyIfExtLocalconfExists()
1393 $extensionName = $this->getUniqueId('foo');
1394 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
1395 $GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($packageManager);
1396 $mockCache = $this->getMock(
1397 AbstractFrontend
::class,
1398 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1403 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1404 $mockCacheManager = $this->getMock(CacheManager
::class, array('getCache'));
1405 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1406 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1407 $mockCache->expects($this->once())
1409 ->with($this->anything(), $this->logicalNot($this->stringContains($extensionName)), $this->anything());
1410 ExtensionManagementUtilityAccessibleProxy
::createExtLocalconfCacheEntry();
1416 public function createExtLocalconfCacheEntryWritesCacheEntryWithNoTags()
1418 $mockCache = $this->getMock(
1419 AbstractFrontend
::class,
1420 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1425 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1426 $mockCacheManager = $this->getMock(CacheManager
::class, array('getCache'));
1427 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1428 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1429 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo(array()));
1430 $GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage($this->getUniqueId()));
1431 ExtensionManagementUtilityAccessibleProxy
::createExtLocalconfCacheEntry();
1434 /////////////////////////////////////////
1435 // Tests concerning getExtLocalconfCacheIdentifier
1436 /////////////////////////////////////////
1440 public function getExtLocalconfCacheIdentifierCreatesSha1WithFourtyCharactersAndPrefix()
1442 $prefix = 'ext_localconf_';
1443 $identifier = ExtensionManagementUtilityAccessibleProxy
::getExtLocalconfCacheIdentifier();
1444 $this->assertStringStartsWith($prefix, $identifier);
1445 $sha1 = str_replace($prefix, '', $identifier);
1446 $this->assertEquals(40, strlen($sha1));
1449 /////////////////////////////////////////
1450 // Tests concerning loadBaseTca
1451 /////////////////////////////////////////
1456 public function loadBaseTcaDoesNotReadFromCacheIfCachingIsDenied()
1458 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1459 $mockCacheManager = $this->getMock(CacheManager
::class, array('getCache'));
1460 $mockCacheManager->expects($this->never())->method('getCache');
1461 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1462 ExtensionManagementUtilityAccessibleProxy
::loadBaseTca(false
);
1468 public function loadBaseTcaRequiresCacheFileIfExistsAndCachingIsAllowed()
1470 $mockCache = $this->getMock(
1471 AbstractFrontend
::class,
1472 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1477 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1478 $mockCacheManager = $this->getMock(CacheManager
::class, array('getCache'));
1479 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1480 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1481 $mockCache->expects($this->any())->method('has')->will($this->returnValue(true
));
1482 $mockCache->expects($this->once())->method('get')->willReturn('<?php ' . serialize(array('tca' => array(), 'categoryRegistry' => CategoryRegistry
::getInstance())) . '?>');
1483 ExtensionManagementUtilityAccessibleProxy
::loadBaseTca(true
);
1489 public function loadBaseTcaCreatesCacheFileWithContentOfAnExtensionsConfigurationTcaPhpFile()
1491 $extensionName = $this->getUniqueId('test_baseTca_');
1492 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
1493 $packagePath = $packageManager->getPackage($extensionName)->getPackagePath();
1494 GeneralUtility
::mkdir($packagePath);
1495 GeneralUtility
::mkdir($packagePath . 'Configuration/');
1496 GeneralUtility
::mkdir($packagePath . 'Configuration/TCA/');
1497 $GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($packageManager);
1498 ExtensionManagementUtility
::setPackageManager($packageManager);
1499 $uniqueTableName = $this->getUniqueId('table_name_');
1500 $uniqueStringInTableConfiguration = $this->getUniqueId('table_configuration_');
1501 $tableConfiguration = '<?php return array(\'foo\' => \'' . $uniqueStringInTableConfiguration . '\'); ?>';
1502 file_put_contents($packagePath . 'Configuration/TCA/' . $uniqueTableName . '.php', $tableConfiguration);
1503 $mockCache = $this->getMock(
1504 AbstractFrontend
::class,
1505 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1510 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1511 $mockCacheManager = $this->getMock(CacheManager
::class, array('getCache'));
1512 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1513 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1514 $mockCache->expects($this->once())->method('has')->will($this->returnValue(false
));
1515 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInTableConfiguration), $this->anything());
1516 ExtensionManagementUtility
::loadBaseTca(true
);
1522 public function loadBaseTcaWritesCacheEntryWithNoTags()
1524 $mockCache = $this->getMock(
1525 AbstractFrontend
::class,
1526 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1531 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1532 $mockCacheManager = $this->getMock(CacheManager
::class, array('getCache'));
1533 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1534 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1535 $mockCache->expects($this->once())->method('has')->will($this->returnValue(false
));
1536 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo(array()));
1537 ExtensionManagementUtilityAccessibleProxy
::loadBaseTca();
1540 /////////////////////////////////////////
1541 // Tests concerning getBaseTcaCacheIdentifier
1542 /////////////////////////////////////////
1547 public function getBaseTcaCacheIdentifierCreatesSha1WithFourtyCharactersAndPrefix()
1549 $prefix = 'tca_base_';
1550 $identifier = ExtensionManagementUtilityAccessibleProxy
::getBaseTcaCacheIdentifier();
1551 $this->assertStringStartsWith($prefix, $identifier);
1552 $sha1 = str_replace($prefix, '', $identifier);
1553 $this->assertEquals(40, strlen($sha1));
1556 /////////////////////////////////////////
1557 // Tests concerning loadExtTables
1558 /////////////////////////////////////////
1562 public function loadExtTablesDoesNotReadFromCacheIfCachingIsDenied()
1564 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1565 $mockCacheManager = $this->getMock(CacheManager
::class, array('getCache'));
1566 $mockCacheManager->expects($this->never())->method('getCache');
1567 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1568 $GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage($this->getUniqueId()));
1569 ExtensionManagementUtility
::loadExtLocalconf(false
);
1575 public function loadExtTablesRequiresCacheFileIfExistsAndCachingIsAllowed()
1577 $mockCache = $this->getMock(
1578 AbstractFrontend
::class,
1579 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1584 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1585 $mockCacheManager = $this->getMock(CacheManager
::class, array('getCache'));
1586 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1587 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1588 $mockCache->expects($this->any())->method('has')->will($this->returnValue(true
));
1589 $mockCache->expects($this->once())->method('requireOnce');
1590 // Reset the internal cache access tracking variable of extMgm
1591 // This method is only in the ProxyClass!
1592 ExtensionManagementUtilityAccessibleProxy
::resetExtTablesWasReadFromCacheOnceBoolean();
1593 ExtensionManagementUtility
::loadExtTables(true
);
1596 /////////////////////////////////////////
1597 // Tests concerning createExtTablesCacheEntry
1598 /////////////////////////////////////////
1602 public function createExtTablesCacheEntryWritesCacheEntryWithContentOfLoadedExtensionExtTables()
1604 $extensionName = $this->getUniqueId('foo');
1605 $extTablesLocation = PATH_site
. 'typo3temp/' . $this->getUniqueId('test_ext_tables') . '.php';
1606 $this->testFilesToDelete
[] = $extTablesLocation;
1607 $uniqueStringInTables = $this->getUniqueId('foo');
1608 file_put_contents($extTablesLocation, "<?php\n\n$uniqueStringInTables\n\n?>");
1609 $GLOBALS['TYPO3_LOADED_EXT'] = array(
1610 $extensionName => array(
1611 'ext_tables.php' => $extTablesLocation
1614 $mockCache = $this->getMock(
1615 AbstractFrontend
::class,
1616 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1621 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1622 $mockCacheManager = $this->getMock(CacheManager
::class, array('getCache'));
1623 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1624 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1625 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInTables), $this->anything());
1626 ExtensionManagementUtilityAccessibleProxy
::createExtTablesCacheEntry();
1632 public function createExtTablesCacheEntryWritesCacheEntryWithExtensionContentOnlyIfExtTablesExists()
1634 $extensionName = $this->getUniqueId('foo');
1635 $GLOBALS['TYPO3_LOADED_EXT'] = array(
1636 $extensionName => array(),
1638 $mockCache = $this->getMock(
1639 AbstractFrontend
::class,
1640 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1645 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1646 $mockCacheManager = $this->getMock(CacheManager
::class, array('getCache'));
1647 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1648 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1649 $mockCache->expects($this->once())
1651 ->with($this->anything(), $this->logicalNot($this->stringContains($extensionName)), $this->anything());
1652 ExtensionManagementUtilityAccessibleProxy
::createExtTablesCacheEntry();
1658 public function createExtTablesCacheEntryWritesCacheEntryWithNoTags()
1660 $mockCache = $this->getMock(
1661 AbstractFrontend
::class,
1662 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1667 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1668 $mockCacheManager = $this->getMock(CacheManager
::class, array('getCache'));
1669 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1670 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1671 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo(array()));
1672 $GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage($this->getUniqueId()));
1673 ExtensionManagementUtilityAccessibleProxy
::createExtTablesCacheEntry();
1676 /////////////////////////////////////////
1677 // Tests concerning getExtTablesCacheIdentifier
1678 /////////////////////////////////////////
1682 public function getExtTablesCacheIdentifierCreatesSha1WithFourtyCharactersAndPrefix()
1684 $prefix = 'ext_tables_';
1685 $identifier = ExtensionManagementUtilityAccessibleProxy
::getExtTablesCacheIdentifier();
1686 $this->assertStringStartsWith($prefix, $identifier);
1687 $sha1 = str_replace($prefix, '', $identifier);
1688 $this->assertEquals(40, strlen($sha1));
1691 /////////////////////////////////////////
1692 // Tests concerning removeCacheFiles
1693 /////////////////////////////////////////
1697 public function removeCacheFilesFlushesSystemCaches()
1699 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1700 $mockCacheManager = $this->getMock(CacheManager
::class, array('flushCachesInGroup'));
1701 $mockCacheManager->expects($this->once())->method('flushCachesInGroup')->with('system');
1702 ExtensionManagementUtilityAccessibleProxy
::setCacheManager($mockCacheManager);
1703 ExtensionManagementUtility
::removeCacheFiles();
1706 /////////////////////////////////////////
1707 // Tests concerning loadNewTcaColumnsConfigFiles
1708 /////////////////////////////////////////
1712 * @expectedException \RuntimeException
1714 public function loadNewTcaColumnsConfigFilesIncludesDefinedDynamicConfigFileIfNoColumnsExist()
1716 $GLOBALS['TCA'] = array(
1719 'dynamicConfigFile' => __DIR__
. '/Fixtures/RuntimeException.php'
1723 ExtensionManagementUtility
::loadNewTcaColumnsConfigFiles();
1729 public function loadNewTcaColumnsConfigFilesDoesNotIncludeFileIfColumnsExist()
1731 $GLOBALS['TCA'] = array(
1734 'dynamicConfigFile' => __DIR__
. '/Fixtures/RuntimeException.php'
1741 ExtensionManagementUtility
::loadNewTcaColumnsConfigFiles();
1744 /////////////////////////////////////////
1745 // Tests concerning getExtensionVersion
1746 /////////////////////////////////////////
1748 * Data provider for negative getExtensionVersion() tests.
1752 public function getExtensionVersionFaultyDataProvider()
1757 array(new \
stdClass()),
1764 * @expectedException \InvalidArgumentException
1765 * @dataProvider getExtensionVersionFaultyDataProvider
1767 * @throws \TYPO3\CMS\Core\Package\Exception
1769 public function getExtensionVersionForFaultyExtensionKeyThrowsException($key)
1771 ExtensionManagementUtility
::getExtensionVersion($key);
1777 public function getExtensionVersionForNotLoadedExtensionReturnsEmptyString()
1779 ExtensionManagementUtility
::clearExtensionKeyMap();
1780 $uniqueSuffix = $this->getUniqueId('test');
1781 $extensionKey = 'unloadedextension' . $uniqueSuffix;
1782 $this->assertEquals('', ExtensionManagementUtility
::getExtensionVersion($extensionKey));
1788 public function getExtensionVersionForLoadedExtensionReturnsExtensionVersion()
1790 ExtensionManagementUtility
::clearExtensionKeyMap();
1791 $uniqueSuffix = $this->getUniqueId('test');
1792 $extensionKey = 'unloadedextension' . $uniqueSuffix;
1793 $packageMetaData = $this->getMock(MetaData
::class, array('getVersion'), array($extensionKey));
1794 $packageMetaData->expects($this->any())->method('getVersion')->will($this->returnValue('1.2.3'));
1795 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionKey, array('getPackagePath', 'getPackageKey', 'getPackageMetaData'));
1796 /** @var \PHPUnit_Framework_MockObject_MockObject $package */
1797 $package = $packageManager->getPackage($extensionKey);
1798 $package->expects($this->any())
1799 ->method('getPackageMetaData')
1800 ->will($this->returnValue($packageMetaData));
1801 ExtensionManagementUtility
::setPackageManager($packageManager);
1802 $this->assertEquals('1.2.3', ExtensionManagementUtility
::getExtensionVersion($extensionKey));
1805 /////////////////////////////////////////
1806 // Tests concerning loadExtension
1807 /////////////////////////////////////////
1810 * @expectedException \RuntimeException
1812 public function loadExtensionThrowsExceptionIfExtensionIsLoaded()
1814 $extensionKey = $this->getUniqueId('test');
1815 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionKey);
1816 ExtensionManagementUtility
::setPackageManager($packageManager);
1817 ExtensionManagementUtility
::loadExtension($extensionKey);
1820 /////////////////////////////////////////
1821 // Tests concerning unloadExtension
1822 /////////////////////////////////////////
1825 * @expectedException \RuntimeException
1827 public function unloadExtensionThrowsExceptionIfExtensionIsNotLoaded()
1829 $packageName = $this->getUniqueId('foo');
1830 /** @var PackageManager|\PHPUnit_Framework_MockObject_MockObject $packageManager */
1831 $packageManager = $this->getMock(PackageManager
::class, array('isPackageActive'));
1832 $packageManager->expects($this->once())
1833 ->method('isPackageActive')
1834 ->with($this->equalTo($packageName))
1835 ->will($this->returnValue(false
));
1836 ExtensionManagementUtility
::setPackageManager($packageManager);
1837 ExtensionManagementUtility
::unloadExtension($packageName);
1843 public function unloadExtensionCallsPackageManagerToDeactivatePackage()
1845 $packageName = $this->getUniqueId('foo');
1846 /** @var PackageManager|\PHPUnit_Framework_MockObject_MockObject $packageManager */
1847 $packageManager = $this->getMock(
1848 PackageManager
::class,
1849 array('isPackageActive', 'deactivatePackage')
1851 $packageManager->expects($this->any())
1852 ->method('isPackageActive')
1853 ->will($this->returnValue(true
));
1854 $packageManager->expects($this->once())
1855 ->method('deactivatePackage')
1856 ->with($packageName);
1857 ExtensionManagementUtility
::setPackageManager($packageManager);
1858 ExtensionManagementUtility
::unloadExtension($packageName);
1861 /////////////////////////////////////////
1862 // Tests concerning makeCategorizable
1863 /////////////////////////////////////////
1867 public function doesMakeCategorizableCallsTheCategoryRegistryWithDefaultFieldName()
1869 $extensionKey = $this->getUniqueId('extension');
1870 $tableName = $this->getUniqueId('table');
1872 /** @var CategoryRegistry|\PHPUnit_Framework_MockObject_MockObject $registryMock */
1873 $registryMock = $this->getMock(CategoryRegistry
::class);
1874 $registryMock->expects($this->once())->method('add')->with($extensionKey, $tableName, 'categories', array());
1875 GeneralUtility
::setSingletonInstance(CategoryRegistry
::class, $registryMock);
1876 ExtensionManagementUtility
::makeCategorizable($extensionKey, $tableName);
1882 public function doesMakeCategorizableCallsTheCategoryRegistryWithFieldName()
1884 $extensionKey = $this->getUniqueId('extension');
1885 $tableName = $this->getUniqueId('table');
1886 $fieldName = $this->getUniqueId('field');
1888 /** @var CategoryRegistry|\PHPUnit_Framework_MockObject_MockObject $registryMock */
1889 $registryMock = $this->getMock(CategoryRegistry
::class);
1890 $registryMock->expects($this->once())->method('add')->with($extensionKey, $tableName, $fieldName, array());
1891 GeneralUtility
::setSingletonInstance(CategoryRegistry
::class, $registryMock);
1892 ExtensionManagementUtility
::makeCategorizable($extensionKey, $tableName, $fieldName);
1895 ///////////////////////////////
1896 // Tests concerning addPlugin
1897 ///////////////////////////////
1902 public function addPluginSetsTcaCorrectlyForGivenExtKeyAsParameter()
1904 $extKey = 'indexed_search';
1905 $GLOBALS['TYPO3_LOADED_EXT'] = array();
1906 $GLOBALS['TYPO3_LOADED_EXT'][$extKey]['ext_icon'] = 'foo.gif';
1907 $expectedTCA = array(
1911 'EXT:' . $extKey . '/foo.gif'
1914 $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'] = array();
1915 ExtensionManagementUtility
::addPlugin(array('label', $extKey), 'list_type', $extKey);
1916 $this->assertEquals($expectedTCA, $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items']);
1922 public function addPluginSetsTcaCorrectlyForGivenExtKeyAsGlobal()
1924 $extKey = 'indexed_search';
1925 $GLOBALS['TYPO3_LOADED_EXT'] = array();
1926 $GLOBALS['TYPO3_LOADED_EXT'][$extKey]['ext_icon'] = 'foo.gif';
1927 $GLOBALS['_EXTKEY'] = $extKey;
1928 $expectedTCA = array(
1932 'EXT:' . $extKey . '/foo.gif'
1935 $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'] = array();
1936 ExtensionManagementUtility
::addPlugin(array('label', $extKey));
1937 $this->assertEquals($expectedTCA, $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items']);
1942 * @expectedException \RuntimeException
1944 public function addPluginThrowsExceptionForMissingExtkey()
1946 ExtensionManagementUtility
::addPlugin('test');