23 use TYPO3\CMS\Core\Package\PackageManager;
28 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
33 class ExtensionManagementUtilityTest
extends UnitTestCase
38 protected $resetSingletonInstances =
true;
43 protected $backUpPackageManager;
48 protected function setUp()
56 protected function tearDown()
70 protected function createMockPackageManagerWithMockPackage($packageKey, $packageMethods = [
'getPackagePath',
'getPackageKey'])
73 GeneralUtility::mkdir_deep($packagePath);
74 $this->testFilesToDelete[] = $packagePath;
75 $package = $this->getMockBuilder(Package::class)
76 ->disableOriginalConstructor()
77 ->setMethods($packageMethods)
79 $packageManager = $this->getMockBuilder(PackageManager::class)
80 ->setMethods([
'isPackageActive',
'getPackage',
'getActivePackages'])
81 ->disableOriginalConstructor()
83 $package->expects($this->any())
84 ->method(
'getPackagePath')
85 ->will($this->returnValue($packagePath));
86 $package->expects($this->any())
87 ->method(
'getPackageKey')
88 ->will($this->returnValue($packageKey));
89 $packageManager->expects($this->any())
90 ->method(
'isPackageActive')
91 ->will($this->returnValueMap([
95 $packageManager->expects($this->any())
96 ->method(
'getPackage')
97 ->with($this->equalTo($packageKey))
98 ->will($this->returnValue($package));
99 $packageManager->expects($this->any())
100 ->method(
'getActivePackages')
101 ->will($this->returnValue([$packageKey => $package]));
102 return $packageManager;
111 public function isLoadedReturnsFalseIfExtensionIsNotLoaded()
122 public function extPathThrowsExceptionIfExtensionIsNotLoaded()
124 $this->expectException(\BadFunctionCallException::class);
125 $this->expectExceptionCode(1365429656);
127 $packageName = $this->getUniqueId(
'foo');
129 $packageManager = $this->getMockBuilder(PackageManager::class)
130 ->setMethods([
'isPackageActive'])
131 ->disableOriginalConstructor()
133 $packageManager->expects($this->once())
134 ->method(
'isPackageActive')
135 ->with($this->equalTo($packageName))
136 ->will($this->returnValue(
false));
144 public function extPathAppendsScriptNameToPath()
146 $package = $this->getMockBuilder(Package::class)
147 ->disableOriginalConstructor()
148 ->setMethods([
'getPackagePath'])
151 $packageManager = $this->getMockBuilder(PackageManager::class)
152 ->setMethods([
'isPackageActive',
'getPackage'])
153 ->disableOriginalConstructor()
155 $package->expects($this->once())
156 ->method(
'getPackagePath')
158 $packageManager->expects($this->once())
159 ->method(
'isPackageActive')
160 ->with($this->equalTo(
'foo'))
161 ->will($this->returnValue(
true));
162 $packageManager->expects($this->once())
163 ->method(
'getPackage')
165 ->will($this->returnValue($package));
179 private function generateTCAForTable($table)
183 $tca[$table][
'columns'] = [
187 $tca[$table][
'types'] = [
188 'typeA' => [
'showitem' =>
'fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, fieldD, fieldD1'],
189 'typeB' => [
'showitem' =>
'fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, fieldD, fieldD1'],
190 'typeC' => [
'showitem' =>
'fieldC;;paletteD']
192 $tca[$table][
'palettes'] = [
193 'paletteA' => [
'showitem' =>
'fieldX, fieldX1, fieldY'],
194 'paletteB' => [
'showitem' =>
'fieldX, fieldX1, fieldY'],
195 'paletteC' => [
'showitem' =>
'fieldX, fieldX1, fieldY'],
196 'paletteD' => [
'showitem' =>
'fieldX, fieldX1, fieldY']
206 public function extensionKeyDataProvider()
209 'Without underscores' => [
213 'With underscores' => [
214 'this_is_a_test_extension',
215 'tx_thisisatestextension'
217 'With user prefix and without underscores' => [
221 'With user prefix and with underscores' => [
234 public function getClassNamePrefixForExtensionKey($extensionName, $expectedPrefix)
248 public function canAddFieldsToAllTCATypesBeforeExistingOnes()
250 $table = $this->getUniqueId(
'tx_coretest_table');
251 $GLOBALS[
'TCA'] = $this->generateTCAForTable($table);
254 $this->assertEquals(
'fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, newA, newB, fieldD, fieldD1',
$GLOBALS[
'TCA'][$table][
'types'][
'typeA'][
'showitem']);
256 $this->assertEquals(
'fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, newA, newB, fieldD, fieldD1',
$GLOBALS[
'TCA'][$table][
'types'][
'typeB'][
'showitem']);
265 public function canAddFieldsToAllTCATypesAfterExistingOnes()
267 $table = $this->getUniqueId(
'tx_coretest_table');
268 $GLOBALS[
'TCA'] = $this->generateTCAForTable($table);
271 $this->assertEquals(
'fieldA, fieldB, fieldC;labelC, newA, newB, --palette--;;paletteC, fieldC1, fieldD, fieldD1',
$GLOBALS[
'TCA'][$table][
'types'][
'typeA'][
'showitem']);
273 $this->assertEquals(
'fieldA, fieldB, fieldC;labelC, newA, newB, --palette--;;paletteC, fieldC1, fieldD, fieldD1',
$GLOBALS[
'TCA'][$table][
'types'][
'typeB'][
'showitem']);
282 public function canAddFieldsToAllTCATypesRespectsPalettes()
284 $table = $this->getUniqueId(
'tx_coretest_table');
285 $GLOBALS[
'TCA'] = $this->generateTCAForTable($table);
286 $GLOBALS[
'TCA'][$table][
'types'][
'typeD'] = [
'showitem' =>
'fieldY, --palette--;;standard, fieldZ'];
289 $this->assertEquals(
'fieldY, --palette--;;standard, newA, newB, fieldA, fieldZ',
$GLOBALS[
'TCA'][$table][
'types'][
'typeD'][
'showitem']);
298 public function canAddFieldsToAllTCATypesRespectsPositionFieldInPalette()
300 $table = $this->getUniqueId(
'tx_coretest_table');
301 $GLOBALS[
'TCA'] = $this->generateTCAForTable($table);
304 $this->assertEquals(
'fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, newA, newB, fieldC1, fieldD, fieldD1',
$GLOBALS[
'TCA'][$table][
'types'][
'typeA'][
'showitem']);
313 public function canAddFieldsToTCATypeBeforeExistingOnes()
315 $table = $this->getUniqueId(
'tx_coretest_table');
316 $GLOBALS[
'TCA'] = $this->generateTCAForTable($table);
319 $this->assertEquals(
'fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, newA, newB, fieldD, fieldD1',
$GLOBALS[
'TCA'][$table][
'types'][
'typeA'][
'showitem']);
321 $this->assertEquals(
'fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, fieldD, fieldD1',
$GLOBALS[
'TCA'][$table][
'types'][
'typeB'][
'showitem']);
330 public function canAddFieldsToTCATypeAfterExistingOnes()
332 $table = $this->getUniqueId(
'tx_coretest_table');
333 $GLOBALS[
'TCA'] = $this->generateTCAForTable($table);
336 $this->assertEquals(
'fieldA, fieldB, fieldC;labelC, newA, newB, --palette--;;paletteC, fieldC1, fieldD, fieldD1',
$GLOBALS[
'TCA'][$table][
'types'][
'typeA'][
'showitem']);
338 $this->assertEquals(
'fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, fieldD, fieldD1',
$GLOBALS[
'TCA'][$table][
'types'][
'typeB'][
'showitem']);
344 public function canAddFieldWithPartOfAlreadyExistingFieldname()
346 $table = $this->getUniqueId(
'tx_coretest_table');
347 $GLOBALS[
'TCA'] = $this->generateTCAForTable($table);
350 $this->assertEquals(
'fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, fieldD, fieldD1, field',
$GLOBALS[
'TCA'][$table][
'types'][
'typeA'][
'showitem']);
359 public function canAddFieldsToTCATypeAndReplaceExistingOnes()
361 $table = $this->getUniqueId(
'tx_coretest_table');
362 $GLOBALS[
'TCA'] = $this->generateTCAForTable($table);
363 $typesBefore =
$GLOBALS[
'TCA'][$table][
'types'];
365 $this->assertEquals($typesBefore,
$GLOBALS[
'TCA'][$table][
'types'],
'It\'s wrong that the "types" array changes here - the replaced field is only on palettes');
367 $this->assertEquals(
'fieldX, fieldX1, fieldY',
$GLOBALS[
'TCA'][$table][
'palettes'][
'paletteA'][
'showitem']);
368 $this->assertEquals(
'fieldX, fieldX1, fieldY',
$GLOBALS[
'TCA'][$table][
'palettes'][
'paletteB'][
'showitem']);
370 $this->assertEquals(
'fieldZ, fieldX1, fieldY',
$GLOBALS[
'TCA'][$table][
'palettes'][
'paletteC'][
'showitem']);
371 $this->assertEquals(
'fieldZ, fieldX1, fieldY',
$GLOBALS[
'TCA'][$table][
'palettes'][
'paletteD'][
'showitem']);
377 public function addToAllTCAtypesReplacesExistingOnes()
379 $table = $this->getUniqueId(
'tx_coretest_table');
380 $GLOBALS[
'TCA'] = $this->generateTCAForTable($table);
381 $typesBefore =
$GLOBALS[
'TCA'][$table][
'types'];
383 $this->assertEquals($typesBefore,
$GLOBALS[
'TCA'][$table][
'types'],
'It\'s wrong that the "types" array changes here - the replaced field is only on palettes');
385 $this->assertEquals(
'fieldX, fieldX1, fieldY',
$GLOBALS[
'TCA'][$table][
'palettes'][
'paletteA'][
'showitem']);
386 $this->assertEquals(
'fieldX, fieldX1, fieldY',
$GLOBALS[
'TCA'][$table][
'palettes'][
'paletteB'][
'showitem']);
388 $this->assertEquals(
'fieldX, --palette--;;foo, fieldX1, fieldY',
$GLOBALS[
'TCA'][$table][
'palettes'][
'paletteC'][
'showitem']);
389 $this->assertEquals(
'fieldX, --palette--;;foo, fieldX1, fieldY',
$GLOBALS[
'TCA'][$table][
'palettes'][
'paletteD'][
'showitem']);
398 public function canAddFieldsToPaletteBeforeExistingOnes()
400 $table = $this->getUniqueId(
'tx_coretest_table');
401 $GLOBALS[
'TCA'] = $this->generateTCAForTable($table);
403 $this->assertEquals(
'fieldX, fieldX1, newA, newB, fieldY',
$GLOBALS[
'TCA'][$table][
'palettes'][
'paletteA'][
'showitem']);
412 public function canAddFieldsToPaletteAfterExistingOnes()
414 $table = $this->getUniqueId(
'tx_coretest_table');
415 $GLOBALS[
'TCA'] = $this->generateTCAForTable($table);
417 $this->assertEquals(
'fieldX, newA, newB, fieldX1, fieldY',
$GLOBALS[
'TCA'][$table][
'palettes'][
'paletteA'][
'showitem']);
426 public function canAddFieldsToPaletteAfterNotExistingOnes()
428 $table = $this->getUniqueId(
'tx_coretest_table');
429 $GLOBALS[
'TCA'] = $this->generateTCAForTable($table);
431 $this->assertEquals(
'fieldX, fieldX1, fieldY, newA, newB',
$GLOBALS[
'TCA'][$table][
'palettes'][
'paletteA'][
'showitem']);
437 public function removeDuplicatesForInsertionRemovesDuplicatesDataProvider()
441 'field_b, field_d, field_c',
442 'field_a, field_b, field_c',
445 'with linebreaks' => [
446 'field_b, --linebreak--, field_d, --linebreak--, field_c',
447 'field_a, field_b, field_c',
448 '--linebreak--, field_d, --linebreak--'
450 'with linebreaks in list and insertion list' => [
451 'field_b, --linebreak--, field_d, --linebreak--, field_c',
452 'field_a, field_b, --linebreak--, field_c',
453 '--linebreak--, field_d, --linebreak--'
465 public function removeDuplicatesForInsertionRemovesDuplicates($insertionList, $list, $expected)
468 $this->assertSame($expected, $result);
478 public function addFieldsToAllPalettesOfFieldDoesNotAddAnythingIfFieldIsNotRegisteredInColumns()
484 'showitem' =>
'fieldA;labelA, --palette--;;paletteA',
489 'showitem' =>
'fieldX, fieldY',
500 $this->assertEquals($expected,
$GLOBALS[
'TCA']);
506 public function addFieldsToAllPalettesOfFieldAddsFieldsToPaletteAndSuppressesDuplicates()
515 'showitem' =>
'fieldA;labelA, --palette--;;paletteA',
520 'showitem' =>
'fieldX, fieldY',
532 'showitem' =>
'fieldA;labelA, --palette--;;paletteA',
537 'showitem' =>
'fieldX, fieldY, dupeA',
547 $this->assertEquals($expected,
$GLOBALS[
'TCA']);
553 public function addFieldsToAllPalettesOfFieldDoesNotAddAFieldThatIsPartOfPaletteAlready()
562 'showitem' =>
'fieldA;labelA, --palette--;;paletteA',
567 'showitem' =>
'existingA',
579 'showitem' =>
'fieldA;labelA, --palette--;;paletteA',
584 'showitem' =>
'existingA',
594 $this->assertEquals($expected,
$GLOBALS[
'TCA']);
600 public function addFieldsToAllPalettesOfFieldAddsFieldsToMultiplePalettes()
609 'showitem' =>
'fieldA, --palette--;;palette1',
612 'showitem' =>
'fieldA;aLabel, --palette--;;palette2',
617 'showitem' =>
'fieldX',
620 'showitem' =>
'fieldY',
632 'showitem' =>
'fieldA, --palette--;;palette1',
635 'showitem' =>
'fieldA;aLabel, --palette--;;palette2',
640 'showitem' =>
'fieldX, newA',
643 'showitem' =>
'fieldY, newA',
653 $this->assertEquals($expected,
$GLOBALS[
'TCA']);
659 public function addFieldsToAllPalettesOfFieldAddsMultipleFields()
668 'showitem' =>
'fieldA, --palette--;;palette1',
673 'showitem' =>
'fieldX',
685 'showitem' =>
'fieldA, --palette--;;palette1',
690 'showitem' =>
'fieldX, newA, newB',
700 $this->assertEquals($expected,
$GLOBALS[
'TCA']);
706 public function addFieldsToAllPalettesOfFieldAddsBeforeExistingIfRequested()
715 'showitem' =>
'fieldA;labelA, --palette--;;paletteA',
720 'showitem' =>
'existingA, existingB',
732 'showitem' =>
'fieldA;labelA, --palette--;;paletteA',
737 'showitem' =>
'existingA, newA, existingB',
748 $this->assertEquals($expected,
$GLOBALS[
'TCA']);
754 public function addFieldsToAllPalettesOfFieldAddsFieldsAtEndIfBeforeRequestedDoesNotExist()
763 'showitem' =>
'fieldA;labelA, --palette--;;paletteA',
768 'showitem' =>
'fieldX, fieldY',
780 'showitem' =>
'fieldA;labelA, --palette--;;paletteA',
785 'showitem' =>
'fieldX, fieldY, newA, newB',
796 $this->assertEquals($expected,
$GLOBALS[
'TCA']);
802 public function addFieldsToAllPalettesOfFieldAddsAfterExistingIfRequested()
811 'showitem' =>
'fieldA;labelA, --palette--;;paletteA',
816 'showitem' =>
'existingA, existingB',
828 'showitem' =>
'fieldA;labelA, --palette--;;paletteA',
833 'showitem' =>
'existingA, newA, existingB',
844 $this->assertEquals($expected,
$GLOBALS[
'TCA']);
850 public function addFieldsToAllPalettesOfFieldAddsFieldsAtEndIfAfterRequestedDoesNotExist()
859 'showitem' =>
'fieldA;labelA, --palette--;;paletteA',
864 'showitem' =>
'existingA, existingB',
876 'showitem' =>
'fieldA;labelA, --palette--;;paletteA',
881 'showitem' =>
'existingA, existingB, newA, newB',
892 $this->assertEquals($expected,
$GLOBALS[
'TCA']);
898 public function addFieldsToAllPalettesOfFieldAddsNewPaletteIfFieldHasNoPaletteYet()
907 'showitem' =>
'fieldA',
919 'showitem' =>
'fieldA, --palette--;;generatedFor-fieldA',
923 'generatedFor-fieldA' => [
924 'showitem' =>
'newA',
934 $this->assertEquals($expected,
$GLOBALS[
'TCA']);
940 public function addFieldsToAllPalettesOfFieldAddsNewPaletteIfFieldHasNoPaletteYetAndKeepsExistingLabel()
949 'showitem' =>
'fieldA;labelA',
961 'showitem' =>
'fieldA;labelA, --palette--;;generatedFor-fieldA',
965 'generatedFor-fieldA' => [
966 'showitem' =>
'newA',
976 $this->assertEquals($expected,
$GLOBALS[
'TCA']);
987 public function executePositionedStringInsertionTrimsCorrectCharactersDataProvider()
990 'normal characters' => [
998 'newlines with carriage return' => [
1010 'multiple commas with trailing spaces' => [
1023 public function executePositionedStringInsertionTrimsCorrectCharacters($string, $expectedResult)
1025 $extensionManagementUtility = $this->getAccessibleMock(ExtensionManagementUtility::class, [
'dummy']);
1026 $string = $extensionManagementUtility->_call(
'executePositionedStringInsertion', $string,
'');
1027 $this->assertEquals($expectedResult, $string);
1036 public function addTcaSelectItemThrowsExceptionIfTableIsNotOfTypeString()
1038 $this->expectException(\InvalidArgumentException::class);
1039 $this->expectExceptionCode(1303236963);
1047 public function addTcaSelectItemThrowsExceptionIfFieldIsNotOfTypeString()
1049 $this->expectException(\InvalidArgumentException::class);
1050 $this->expectExceptionCode(1303236964);
1058 public function addTcaSelectItemThrowsExceptionIfRelativeToFieldIsNotOfTypeString()
1060 $this->expectException(\InvalidArgumentException::class);
1061 $this->expectExceptionCode(1303236965);
1069 public function addTcaSelectItemThrowsExceptionIfRelativePositionIsNotOfTypeString()
1071 $this->expectException(\InvalidArgumentException::class);
1072 $this->expectExceptionCode(1303236966);
1080 public function addTcaSelectItemThrowsExceptionIfRelativePositionIsNotOneOfValidKeywords()
1082 $this->expectException(\InvalidArgumentException::class);
1083 $this->expectExceptionCode(1303236967);
1091 public function addTcaSelectItemThrowsExceptionIfFieldIsNotFoundInTca()
1093 $this->expectException(\RuntimeException::class);
1094 $this->expectExceptionCode(1303237468);
1103 public function addTcaSelectItemDataProvider()
1110 'add at end of array' => [
1114 0 => [
'firstElement'],
1116 2 => [
'thirdElement'],
1117 3 => [
'insertedElement']
1120 'replace element' => [
1124 0 => [
'firstElement'],
1125 1 => [
'insertedElement'],
1126 2 => [
'thirdElement']
1129 'add element after' => [
1133 0 => [
'firstElement'],
1135 2 => [
'insertedElement'],
1136 3 => [
'thirdElement']
1139 'add element before' => [
1143 0 => [
'firstElement'],
1144 1 => [
'insertedElement'],
1146 3 => [
'thirdElement']
1149 'add at end if relative position was not found' => [
1153 0 => [
'firstElement'],
1155 2 => [
'thirdElement'],
1156 3 => [
'insertedElement']
1169 public function addTcaSelectItemInsertsItemAtSpecifiedPosition($relativeToField, $relativePosition, $expectedResultArray)
1177 '0' => [
'firstElement'],
1179 2 => [
'thirdElement']
1187 $this->assertEquals($expectedResultArray,
$GLOBALS[
'TCA'][
'testTable'][
'columns'][
'testField'][
'config'][
'items']);
1196 public function loadExtLocalconfDoesNotReadFromCacheIfCachingIsDenied()
1199 $mockCacheManager = $this->getMockBuilder(CacheManager::class)
1200 ->setMethods([
'getCache'])
1202 $mockCacheManager->expects($this->never())->method(
'getCache');
1204 $packageManager = $this->createMockPackageManagerWithMockPackage($this->getUniqueId());
1212 public function loadExtLocalconfRequiresCacheFileIfExistsAndCachingIsAllowed()
1214 $mockCache = $this->getMockBuilder(PhpFrontend::class)
1215 ->setMethods([
'getIdentifier',
'set',
'get',
'getByTag',
'has',
'remove',
'flush',
'flushByTag',
'require'])
1216 ->disableOriginalConstructor()
1220 $mockCacheManager = $this->getMockBuilder(CacheManager::class)
1221 ->setMethods([
'getCache'])
1223 $mockCacheManager->expects($this->any())->method(
'getCache')->will($this->returnValue($mockCache));
1225 $mockCache->expects($this->any())->method(
'has')->will($this->returnValue(
true));
1226 $mockCache->expects($this->once())->method(
'require');
1236 public function loadSingleExtLocalconfFilesRequiresExtLocalconfFileRegisteredInGlobalTypo3LoadedExt()
1238 $this->expectException(\RuntimeException::class);
1239 $this->expectExceptionCode(1340559079);
1241 $extensionName = $this->getUniqueId(
'foo');
1242 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
1243 $extLocalconfLocation = $packageManager->getPackage($extensionName)->getPackagePath() .
'ext_localconf.php';
1244 file_put_contents($extLocalconfLocation,
"<?php\n\nthrow new RuntimeException('', 1340559079);\n\n?>");
1257 public function addModulePositionTestsDataProvider()
1260 'can add new main module if none exists' => [
1265 'can add new sub module if no position specified' => [
1268 'some,modules,newModule'
1270 'can add new sub module to top of module' => [
1273 'newModule,some,modules'
1275 'can add new sub module if bottom of module' => [
1278 'some,modules,newModule'
1280 'can add new sub module before specified sub module' => [
1283 'some,newModule,modules'
1285 'can add new sub module after specified sub module' => [
1288 'some,newModule,modules'
1290 'can add new sub module at the bottom if specified sub module to add before does not exist' => [
1292 'some,otherModules',
1293 'some,otherModules,newModule'
1295 'can add new sub module at the bottom if specified sub module to add after does not exist' => [
1297 'someOther,modules',
1298 'someOther,modules,newModule'
1310 public function addModuleCanAddModule($position, $existing, $expected)
1312 $mainModule =
'foobar';
1313 $subModule =
'newModule';
1315 $GLOBALS[
'TBE_MODULES'][$mainModule] = $existing;
1320 $this->assertTrue(isset(
$GLOBALS[
'TBE_MODULES'][$mainModule]));
1321 $this->assertEquals($expected,
$GLOBALS[
'TBE_MODULES'][$mainModule]);
1330 public function createExtLocalconfCacheEntryWritesCacheEntryWithContentOfLoadedExtensionExtLocalconf()
1332 $extensionName = $this->getUniqueId(
'foo');
1333 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
1334 $extLocalconfLocation = $packageManager->getPackage($extensionName)->getPackagePath() .
'ext_localconf.php';
1335 $uniqueStringInLocalconf = $this->getUniqueId(
'foo');
1336 file_put_contents($extLocalconfLocation,
"<?php\n\n" . $uniqueStringInLocalconf .
"\n\n?>");
1338 $mockCache = $this->getMockBuilder(PhpFrontend::class)
1339 ->setMethods([
'getIdentifier',
'set',
'get',
'getByTag',
'has',
'remove',
'flush',
'flushByTag',
'require'])
1340 ->disableOriginalConstructor()
1343 $mockCache->expects($this->once())->method(
'set')->with($this->anything(), $this->stringContains($uniqueStringInLocalconf), $this->anything());
1350 public function createExtLocalconfCacheEntryWritesCacheEntryWithExtensionContentOnlyIfExtLocalconfExists()
1352 $extensionName = $this->getUniqueId(
'foo');
1353 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
1355 $mockCache = $this->getMockBuilder(PhpFrontend::class)
1356 ->setMethods([
'getIdentifier',
'set',
'get',
'getByTag',
'has',
'remove',
'flush',
'flushByTag',
'require'])
1357 ->disableOriginalConstructor()
1360 $mockCache->expects($this->once())
1362 ->with($this->anything(), $this->logicalNot($this->stringContains($extensionName)), $this->anything());
1369 public function createExtLocalconfCacheEntryWritesCacheEntryWithNoTags()
1371 $mockCache = $this->getMockBuilder(PhpFrontend::class)
1372 ->setMethods([
'getIdentifier',
'set',
'get',
'getByTag',
'has',
'remove',
'flush',
'flushByTag',
'require'])
1373 ->disableOriginalConstructor()
1375 $mockCache->expects($this->once())->method(
'set')->with($this->anything(), $this->anything(), $this->equalTo([]));
1376 $packageManager = $this->createMockPackageManagerWithMockPackage($this->getUniqueId());
1387 public function getExtLocalconfCacheIdentifierCreatesSha1WithFourtyCharactersAndPrefix()
1389 $prefix =
'ext_localconf_';
1391 $this->assertStringStartsWith($prefix, $identifier);
1392 $sha1 = str_replace($prefix,
'', $identifier);
1393 $this->assertEquals(40, strlen($sha1));
1403 public function loadBaseTcaDoesNotReadFromCacheIfCachingIsDenied()
1406 $mockCacheManager = $this->getMockBuilder(CacheManager::class)
1407 ->setMethods([
'getCache'])
1409 $mockCacheManager->expects($this->never())->method(
'getCache');
1417 public function loadBaseTcaRequiresCacheFileIfExistsAndCachingIsAllowed()
1419 $mockCache = $this->getMockBuilder(PhpFrontend::class)
1420 ->setMethods([
'getIdentifier',
'set',
'get',
'getByTag',
'has',
'remove',
'flush',
'flushByTag',
'require'])
1421 ->disableOriginalConstructor()
1424 $mockCache->expects($this->once())->method(
'require')->willReturn([
'tca' => [],
'categoryRegistry' => \serialize(
CategoryRegistry::getInstance())]);
1431 public function loadBaseTcaCreatesCacheFileWithContentOfAnExtensionsConfigurationTcaPhpFile()
1433 $extensionName = $this->getUniqueId(
'test_baseTca_');
1434 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
1435 $packagePath = $packageManager->getPackage($extensionName)->getPackagePath();
1436 GeneralUtility::mkdir($packagePath);
1437 GeneralUtility::mkdir($packagePath .
'Configuration/');
1438 GeneralUtility::mkdir($packagePath .
'Configuration/TCA/');
1440 $uniqueTableName = $this->getUniqueId(
'table_name_');
1441 $uniqueStringInTableConfiguration = $this->getUniqueId(
'table_configuration_');
1442 $tableConfiguration =
'<?php return array(\'foo\' => \'' . $uniqueStringInTableConfiguration .
'\'); ?>
';
1443 file_put_contents($packagePath . 'Configuration/TCA/
' . $uniqueTableName . '.php
', $tableConfiguration);
1444 $mockCache = $this->getMockBuilder(PhpFrontend::class)
1445 ->setMethods(['getIdentifier
', 'set', 'get', 'getByTag
', 'has
', 'remove', 'flush
', 'flushByTag
', 'require
'])
1446 ->disableOriginalConstructor()
1450 $mockCacheManager = $this->getMockBuilder(CacheManager::class)
1451 ->setMethods(['getCache
'])
1453 $mockCacheManager->expects($this->any())->method('getCache
')->will($this->returnValue($mockCache));
1454 ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1455 $mockCache->expects($this->once())->method('require
')->will($this->returnValue(false));
1456 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInTableConfiguration), $this->anything());
1458 $mockSignalSlotDispatcher = $this->createMock(SignalSlotDispatcher::class);
1459 $mockSignalSlotDispatcher->expects($this->once())->method('dispatch
')->with($this->anything(), $this->anything(), $this->isType('array
'))->will($this->returnArgument(2));
1460 ExtensionManagementUtilityAccessibleProxy::setSignalSlotDispatcher($mockSignalSlotDispatcher);
1462 ExtensionManagementUtility::loadBaseTca(true);
1468 public function loadBaseTcaWritesCacheEntryWithNoTags()
1470 $mockCache = $this->getMockBuilder(PhpFrontend::class)
1471 ->setMethods(['getIdentifier
', 'set', 'get', 'getByTag
', 'has
', 'remove', 'flush
', 'flushByTag
', 'require
'])
1472 ->disableOriginalConstructor()
1476 $mockCacheManager = $this->getMockBuilder(CacheManager::class)
1477 ->setMethods(['getCache
'])
1479 $mockCacheManager->expects($this->any())->method('getCache
')->will($this->returnValue($mockCache));
1480 ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1481 $mockCache->expects($this->once())->method('require
')->will($this->returnValue(false));
1482 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo([]));
1483 ExtensionManagementUtilityAccessibleProxy::loadBaseTca();
1487 // Tests concerning getBaseTcaCacheIdentifier
1493 public function getBaseTcaCacheIdentifierCreatesSha1WithFourtyCharactersAndPrefix()
1495 $prefix = 'tca_base_
';
1496 $identifier = ExtensionManagementUtilityAccessibleProxy::getBaseTcaCacheIdentifier();
1497 $this->assertStringStartsWith($prefix, $identifier);
1498 $sha1 = str_replace($prefix, '', $identifier);
1499 $this->assertEquals(40, strlen($sha1));
1503 // Tests concerning loadExtTables
1508 public function loadExtTablesDoesNotReadFromCacheIfCachingIsDenied()
1511 $mockCacheManager = $this->getMockBuilder(CacheManager::class)
1512 ->setMethods(['getCache
'])
1514 $mockCacheManager->expects($this->never())->method('getCache
');
1515 ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1516 $packageManager = $this->createMockPackageManagerWithMockPackage($this->getUniqueId());
1517 ExtensionManagementUtility::setPackageManager($packageManager);
1518 ExtensionManagementUtility::loadExtLocalconf(false);
1524 public function loadExtTablesRequiresCacheFileIfExistsAndCachingIsAllowed()
1526 $mockCache = $this->getMockBuilder(PhpFrontend::class)
1527 ->setMethods(['getIdentifier
', 'set', 'get', 'getByTag
', 'has
', 'remove', 'flush
', 'flushByTag
', 'require
'])
1528 ->disableOriginalConstructor()
1532 $mockCacheManager = $this->getMockBuilder(CacheManager::class)
1533 ->setMethods(['getCache
'])
1535 $mockCacheManager->expects($this->any())->method('getCache
')->will($this->returnValue($mockCache));
1536 ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1537 $mockCache->expects($this->any())->method('has
')->will($this->returnValue(true));
1538 $mockCache->expects($this->once())->method('require
');
1539 // Reset the internal cache access tracking variable of extMgm
1540 // This method is only in the ProxyClass!
1541 ExtensionManagementUtilityAccessibleProxy::resetExtTablesWasReadFromCacheOnceBoolean();
1542 ExtensionManagementUtility::loadExtTables(true);
1546 // Tests concerning createExtTablesCacheEntry
1551 public function createExtTablesCacheEntryWritesCacheEntryWithContentOfLoadedExtensionExtTables()
1553 $extensionName = $this->getUniqueId('foo
');
1554 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
1555 $extensionPath = $packageManager->getPackage($extensionName)->getPackagePath();
1556 $extTablesLocation = $extensionPath . 'ext_tables.php
';
1557 $uniqueStringInTables = $this->getUniqueId('foo
');
1558 file_put_contents($extTablesLocation, "<?php\n\n$uniqueStringInTables\n\n?>");
1559 ExtensionManagementUtility::setPackageManager($packageManager);
1560 $mockCache = $this->getMockBuilder(PhpFrontend::class)
1561 ->setMethods(['getIdentifier
', 'set', 'get', 'getByTag
', 'has
', 'remove', 'flush
', 'flushByTag
', 'require
'])
1562 ->disableOriginalConstructor()
1566 $mockCacheManager = $this->getMockBuilder(CacheManager::class)
1567 ->setMethods(['getCache
'])
1569 $mockCacheManager->expects($this->any())->method('getCache
')->will($this->returnValue($mockCache));
1570 ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1571 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInTables), $this->anything());
1572 ExtensionManagementUtilityAccessibleProxy::createExtTablesCacheEntry();
1578 public function createExtTablesCacheEntryWritesCacheEntryWithExtensionContentOnlyIfExtTablesExists()
1580 $extensionName = $this->getUniqueId('foo
');
1581 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
1582 ExtensionManagementUtility::setPackageManager($packageManager);
1583 $mockCache = $this->getMockBuilder(PhpFrontend::class)
1584 ->setMethods(['getIdentifier
', 'set', 'get', 'getByTag
', 'has
', 'remove', 'flush
', 'flushByTag
', 'require
'])
1585 ->disableOriginalConstructor()
1589 $mockCacheManager = $this->getMockBuilder(CacheManager::class)
1590 ->setMethods(['getCache
'])
1592 $mockCacheManager->expects($this->any())->method('getCache
')->will($this->returnValue($mockCache));
1593 ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1594 $mockCache->expects($this->once())
1596 ->with($this->anything(), $this->logicalNot($this->stringContains($extensionName)), $this->anything());
1597 ExtensionManagementUtilityAccessibleProxy::createExtTablesCacheEntry();
1603 public function createExtTablesCacheEntryWritesCacheEntryWithNoTags()
1605 $mockCache = $this->getMockBuilder(PhpFrontend::class)
1606 ->setMethods(['getIdentifier
', 'set', 'get', 'getByTag
', 'has
', 'remove', 'flush
', 'flushByTag
', 'require
'])
1607 ->disableOriginalConstructor()
1611 $mockCacheManager = $this->getMockBuilder(CacheManager::class)
1612 ->setMethods(['getCache
'])
1614 $mockCacheManager->expects($this->any())->method('getCache
')->will($this->returnValue($mockCache));
1615 ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1616 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo([]));
1617 $packageManager = $this->createMockPackageManagerWithMockPackage($this->getUniqueId());
1618 ExtensionManagementUtility::setPackageManager($packageManager);
1619 ExtensionManagementUtilityAccessibleProxy::createExtTablesCacheEntry();
1623 // Tests concerning getExtTablesCacheIdentifier
1628 public function getExtTablesCacheIdentifierCreatesSha1WithFourtyCharactersAndPrefix()
1630 $prefix = 'ext_tables_
';
1631 $identifier = ExtensionManagementUtilityAccessibleProxy::getExtTablesCacheIdentifier();
1632 $this->assertStringStartsWith($prefix, $identifier);
1633 $sha1 = str_replace($prefix, '', $identifier);
1634 $this->assertEquals(40, strlen($sha1));
1638 // Tests concerning getExtensionVersion
1645 public function getExtensionVersionFaultyDataProvider()
1661 public function getExtensionVersionForFaultyExtensionKeyThrowsException($key)
1663 $this->expectException(\InvalidArgumentException::class);
1664 $this->expectExceptionCode(1294586096);
1666 ExtensionManagementUtility::getExtensionVersion($key);
1672 public function getExtensionVersionForNotLoadedExtensionReturnsEmptyString()
1674 ExtensionManagementUtility::clearExtensionKeyMap();
1675 $uniqueSuffix = $this->getUniqueId('test
');
1676 $extensionKey = 'unloadedextension
' . $uniqueSuffix;
1677 $this->assertEquals('', ExtensionManagementUtility::getExtensionVersion($extensionKey));
1683 public function getExtensionVersionForLoadedExtensionReturnsExtensionVersion()
1685 ExtensionManagementUtility::clearExtensionKeyMap();
1686 $uniqueSuffix = $this->getUniqueId('test
');
1687 $extensionKey = 'unloadedextension
' . $uniqueSuffix;
1688 $packageMetaData = $this->getMockBuilder(MetaData::class)
1689 ->setMethods(['getVersion
'])
1690 ->setConstructorArgs([$extensionKey])
1692 $packageMetaData->expects($this->any())->method('getVersion
')->will($this->returnValue('1.2.3
'));
1693 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionKey, ['getPackagePath
', 'getPackageKey
', 'getPackageMetaData
']);
1695 $package = $packageManager->getPackage($extensionKey);
1696 $package->expects($this->any())
1697 ->method('getPackageMetaData
')
1698 ->will($this->returnValue($packageMetaData));
1699 ExtensionManagementUtility::setPackageManager($packageManager);
1700 $this->assertEquals('1.2.3
', ExtensionManagementUtility::getExtensionVersion($extensionKey));
1704 // Tests concerning loadExtension
1709 public function loadExtensionThrowsExceptionIfExtensionIsLoaded()
1711 $this->expectException(\RuntimeException::class);
1712 $this->expectExceptionCode(1342345486);
1714 $extensionKey = $this->getUniqueId('test
');
1715 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionKey);
1716 ExtensionManagementUtility::setPackageManager($packageManager);
1717 ExtensionManagementUtility::loadExtension($extensionKey);
1721 // Tests concerning unloadExtension
1726 public function unloadExtensionThrowsExceptionIfExtensionIsNotLoaded()
1728 $this->expectException(\RuntimeException::class);
1729 $this->expectExceptionCode(1342345487);
1731 $packageName = $this->getUniqueId('foo
');
1733 $packageManager = $this->getMockBuilder(PackageManager::class)
1734 ->setMethods(['isPackageActive
'])
1735 ->disableOriginalConstructor()
1737 $packageManager->expects($this->once())
1738 ->method('isPackageActive
')
1739 ->with($this->equalTo($packageName))
1740 ->will($this->returnValue(false));
1741 ExtensionManagementUtility::setPackageManager($packageManager);
1742 ExtensionManagementUtility::unloadExtension($packageName);
1748 public function unloadExtensionCallsPackageManagerToDeactivatePackage()
1750 $packageName = $this->getUniqueId('foo
');
1752 $packageManager = $this->getMockBuilder(PackageManager::class)
1753 ->setMethods(['isPackageActive
', 'deactivatePackage
'])
1754 ->disableOriginalConstructor()
1756 $packageManager->expects($this->any())
1757 ->method('isPackageActive
')
1758 ->will($this->returnValue(true));
1759 $packageManager->expects($this->once())
1760 ->method('deactivatePackage
')
1761 ->with($packageName);
1762 ExtensionManagementUtility::setPackageManager($packageManager);
1763 ExtensionManagementUtility::unloadExtension($packageName);
1767 // Tests concerning makeCategorizable
1772 public function doesMakeCategorizableCallsTheCategoryRegistryWithDefaultFieldName()
1774 $extensionKey = $this->getUniqueId('extension
');
1775 $tableName = $this->getUniqueId('table
');
1778 $registryMock = $this->getMockBuilder(CategoryRegistry::class)->getMock();
1779 $registryMock->expects($this->once())->method('add
')->with($extensionKey, $tableName, 'categories
', []);
1780 GeneralUtility::setSingletonInstance(CategoryRegistry::class, $registryMock);
1781 ExtensionManagementUtility::makeCategorizable($extensionKey, $tableName);
1787 public function doesMakeCategorizableCallsTheCategoryRegistryWithFieldName()
1789 $extensionKey = $this->getUniqueId('extension
');
1790 $tableName = $this->getUniqueId('table
');
1791 $fieldName = $this->getUniqueId('field
');
1794 $registryMock = $this->getMockBuilder(CategoryRegistry::class)->getMock();
1795 $registryMock->expects($this->once())->method('add
')->with($extensionKey, $tableName, $fieldName, []);
1796 GeneralUtility::setSingletonInstance(CategoryRegistry::class, $registryMock);
1797 ExtensionManagementUtility::makeCategorizable($extensionKey, $tableName, $fieldName);
1801 // Tests concerning addPlugin
1807 public function addPluginSetsTcaCorrectlyForGivenExtKeyAsParameter()
1809 $extKey = 'indexed_search
';
1814 'EXT:
' . $extKey . '/Resources/Public/Icons/Extension.png
'
1817 $GLOBALS['TCA
']['tt_content
']['columns
']['list_type
']['config
']['items
'] = [];
1818 ExtensionManagementUtility::addPlugin(['label
', $extKey], 'list_type
', $extKey);
1819 $this->assertEquals($expectedTCA, $GLOBALS['TCA
']['tt_content
']['columns
']['list_type
']['config
']['items
']);
1825 public function addPluginThrowsExceptionForMissingExtkey()
1827 $this->expectException(\InvalidArgumentException::class);
1828 $this->expectExceptionCode(1404068038);
1830 ExtensionManagementUtility::addPlugin('test
');