6f2c4cb373db9ec23e00ba43843c74fea03ad688
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Utility / ExtensionManagementUtilityTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Utility;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
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.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
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;
28
29 /**
30 * Test case
31 */
32 class ExtensionManagementUtilityTest extends UnitTestCase
33 {
34 /**
35 * @var array A backup of registered singleton instances
36 */
37 protected $singletonInstances = array();
38
39 /**
40 * @var \TYPO3\CMS\Core\Package\PackageManager
41 */
42 protected $backUpPackageManager;
43
44 protected function setUp()
45 {
46 $this->singletonInstances = GeneralUtility::getSingletonInstances();
47 $this->backUpPackageManager = ExtensionManagementUtilityAccessibleProxy::getPackageManager();
48 $this->singletonInstances = GeneralUtility::getSingletonInstances();
49 }
50
51 protected function tearDown()
52 {
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);
58 parent::tearDown();
59 }
60
61 /**
62 * @param string $packageKey
63 * @param array $packageMethods
64 * @return PackageManager|\PHPUnit_Framework_MockObject_MockObject
65 */
66 protected function createMockPackageManagerWithMockPackage($packageKey, $packageMethods = array('getPackagePath', 'getPackageKey'))
67 {
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)
74 ->getMock();
75 $packageManager = $this->getMock(
76 PackageManager::class,
77 array('isPackageActive', 'getPackage', 'getActivePackages')
78 );
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(
88 array(null, false),
89 array($packageKey, true)
90 )));
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;
99 }
100
101 ///////////////////////////////
102 // Tests concerning isLoaded
103 ///////////////////////////////
104 /**
105 * @test
106 */
107 public function isLoadedReturnsFalseIfExtensionIsNotLoadedAndExitIsDisabled()
108 {
109 $this->assertFalse(ExtensionManagementUtility::isLoaded($this->getUniqueId('foobar'), false));
110 }
111
112 /**
113 * @test
114 * @expectedException \BadFunctionCallException
115 */
116 public function isLoadedThrowsExceptionIfExtensionIsNotLoaded()
117 {
118 $this->assertFalse(ExtensionManagementUtility::isLoaded($this->getUniqueId('foobar'), true));
119 }
120
121 ///////////////////////////////
122 // Tests concerning extPath
123 ///////////////////////////////
124 /**
125 * @test
126 * @expectedException \BadFunctionCallException
127 */
128 public function extPathThrowsExceptionIfExtensionIsNotLoaded()
129 {
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);
139 }
140
141 /**
142 * @test
143 */
144 public function extPathAppendsScriptNameToPath()
145 {
146 $package = $this->getMockBuilder(Package::class)
147 ->disableOriginalConstructor()
148 ->setMethods(array('getPackagePath'))
149 ->getMock();
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')
161 ->with('foo')
162 ->will($this->returnValue($package));
163 ExtensionManagementUtility::setPackageManager($packageManager);
164 $this->assertSame(PATH_site . 'foo/bar.txt', ExtensionManagementUtility::extPath('foo', 'bar.txt'));
165 }
166
167 //////////////////////
168 // Utility functions
169 //////////////////////
170 /**
171 * Generates a basic TCA for a given table.
172 *
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
175 */
176 private function generateTCAForTable($table)
177 {
178 $tca = array();
179 $tca[$table] = array();
180 $tca[$table]['columns'] = array(
181 'fieldA' => array(),
182 'fieldC' => array()
183 );
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')
188 );
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')
194 );
195 return $tca;
196 }
197
198 /**
199 * Data provider for getClassNamePrefixForExtensionKey.
200 *
201 * @return array
202 */
203 public function extensionKeyDataProvider()
204 {
205 return array(
206 'Without underscores' => array(
207 'testkey',
208 'tx_testkey'
209 ),
210 'With underscores' => array(
211 'this_is_a_test_extension',
212 'tx_thisisatestextension'
213 ),
214 'With user prefix and without underscores' => array(
215 'user_testkey',
216 'user_testkey'
217 ),
218 'With user prefix and with underscores' => array(
219 'user_test_key',
220 'user_testkey'
221 ),
222 );
223 }
224
225 /**
226 * @test
227 * @param string $extensionName
228 * @param string $expectedPrefix
229 * @dataProvider extensionKeyDataProvider
230 */
231 public function getClassNamePrefixForExtensionKey($extensionName, $expectedPrefix)
232 {
233 $this->assertSame($expectedPrefix, ExtensionManagementUtility::getCN($extensionName));
234 }
235
236 /////////////////////////////////////////////
237 // Tests concerning getExtensionKeyByPrefix
238 /////////////////////////////////////////////
239 /**
240 * @test
241 * @see ExtensionManagementUtility::getExtensionKeyByPrefix
242 */
243 public function getExtensionKeyByPrefixForLoadedExtensionWithUnderscoresReturnsExtensionKey()
244 {
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'))
252 ->getMock();
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));
263 }
264
265 /**
266 * @test
267 * @see ExtensionManagementUtility::getExtensionKeyByPrefix
268 */
269 public function getExtensionKeyByPrefixForLoadedExtensionWithoutUnderscoresReturnsExtensionKey()
270 {
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'))
278 ->getMock();
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));
289 }
290
291 /**
292 * @test
293 * @see ExtensionManagementUtility::getExtensionKeyByPrefix
294 */
295 public function getExtensionKeyByPrefixForNotLoadedExtensionReturnsFalse()
296 {
297 ExtensionManagementUtility::clearExtensionKeyMap();
298 $uniqueSuffix = $this->getUniqueId('test');
299 $extensionPrefix = 'tx_unloadedextension' . $uniqueSuffix;
300 $this->assertFalse(ExtensionManagementUtility::getExtensionKeyByPrefix($extensionPrefix));
301 }
302
303 //////////////////////////////////////
304 // Tests concerning addToAllTCAtypes
305 //////////////////////////////////////
306 /**
307 * Tests whether fields can be add to all TCA types and duplicate fields are considered.
308 *
309 * @test
310 * @see ExtensionManagementUtility::addToAllTCAtypes()
311 */
312 public function canAddFieldsToAllTCATypesBeforeExistingOnes()
313 {
314 $table = $this->getUniqueId('tx_coretest_table');
315 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
316 ExtensionManagementUtility::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'before:fieldD');
317 // Checking typeA:
318 $this->assertEquals('fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, newA, newB, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
319 // Checking typeB:
320 $this->assertEquals('fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, newA, newB, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
321 }
322
323 /**
324 * Tests whether fields can be add to all TCA types and duplicate fields are considered.
325 *
326 * @test
327 * @see ExtensionManagementUtility::addToAllTCAtypes()
328 */
329 public function canAddFieldsToAllTCATypesAfterExistingOnes()
330 {
331 $table = $this->getUniqueId('tx_coretest_table');
332 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
333 ExtensionManagementUtility::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'after:fieldC');
334 // Checking typeA:
335 $this->assertEquals('fieldA, fieldB, fieldC;labelC, newA, newB, --palette--;;paletteC, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
336 // Checking typeB:
337 $this->assertEquals('fieldA, fieldB, fieldC;labelC, newA, newB, --palette--;;paletteC, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
338 }
339
340 /**
341 * Tests whether fields can be add to all TCA types and duplicate fields are considered.
342 *
343 * @test
344 * @see ExtensionManagementUtility::addToAllTCAtypes()
345 */
346 public function canAddFieldsToAllTCATypesRespectsPalettes()
347 {
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');
352 // Checking typeD:
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']);
354 }
355
356 /**
357 * Tests whether fields can be add to all TCA types and fields in pallets are respected.
358 *
359 * @test
360 * @see ExtensionManagementUtility::addToAllTCAtypes()
361 */
362 public function canAddFieldsToAllTCATypesRespectsPositionFieldInPalette()
363 {
364 $table = $this->getUniqueId('tx_coretest_table');
365 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
366 ExtensionManagementUtility::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'after:fieldX1');
367 // Checking typeA:
368 $this->assertEquals('fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, newA, newB, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
369 }
370
371 /**
372 * Tests whether fields can be add to a TCA type before existing ones
373 *
374 * @test
375 * @see ExtensionManagementUtility::addToAllTCAtypes()
376 */
377 public function canAddFieldsToTCATypeBeforeExistingOnes()
378 {
379 $table = $this->getUniqueId('tx_coretest_table');
380 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
381 ExtensionManagementUtility::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', 'typeA', 'before:fieldD');
382 // Checking typeA:
383 $this->assertEquals('fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, newA, newB, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
384 // Checking typeB:
385 $this->assertEquals('fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
386 }
387
388 /**
389 * Tests whether fields can be add to a TCA type after existing ones
390 *
391 * @test
392 * @see ExtensionManagementUtility::addToAllTCAtypes()
393 */
394 public function canAddFieldsToTCATypeAfterExistingOnes()
395 {
396 $table = $this->getUniqueId('tx_coretest_table');
397 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
398 ExtensionManagementUtility::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', 'typeA', 'after:fieldC');
399 // Checking typeA:
400 $this->assertEquals('fieldA, fieldB, fieldC;labelC, newA, newB, --palette--;;paletteC, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
401 // Checking typeB:
402 $this->assertEquals('fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
403 }
404
405 /**
406 * Test wheter replacing other TCA fields works as promissed
407 *
408 * @test
409 * @see ExtensionManagementUtility::addFieldsToAllPalettesOfField()
410 */
411 public function canAddFieldsToTCATypeAndReplaceExistingOnes()
412 {
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']);
421 // changed
422 $this->assertEquals('fieldZ, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
423 $this->assertEquals('fieldZ, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
424 }
425
426 /**
427 * @test
428 */
429 public function addToAllTCAtypesReplacesExistingOnes()
430 {
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']);
439 // changed
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']);
442 }
443
444 /**
445 * Tests whether fields can be added to a palette before existing elements.
446 *
447 * @test
448 * @see ExtensionManagementUtility::addFieldsToPalette()
449 */
450 public function canAddFieldsToPaletteBeforeExistingOnes()
451 {
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']);
456 }
457
458 /**
459 * Tests whether fields can be added to a palette after existing elements.
460 *
461 * @test
462 * @see ExtensionManagementUtility::addFieldsToPalette()
463 */
464 public function canAddFieldsToPaletteAfterExistingOnes()
465 {
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']);
470 }
471
472 /**
473 * Tests whether fields can be added to a palette after a not existing elements.
474 *
475 * @test
476 * @see ExtensionManagementUtility::addFieldsToPalette()
477 */
478 public function canAddFieldsToPaletteAfterNotExistingOnes()
479 {
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']);
484 }
485
486 /**
487 * @return array
488 */
489 public function removeDuplicatesForInsertionRemovesDuplicatesDataProvider()
490 {
491 return array(
492 'Simple' => array(
493 'field_b, field_d, field_c',
494 'field_a, field_b, field_c',
495 'field_d'
496 ),
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--'
501 ),
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--'
506 ),
507 );
508 }
509
510 /**
511 * @test
512 * @dataProvider removeDuplicatesForInsertionRemovesDuplicatesDataProvider
513 * @param $insertionList
514 * @param $list
515 * @param $expected
516 */
517 public function removeDuplicatesForInsertionRemovesDuplicates($insertionList, $list, $expected)
518 {
519 $result = ExtensionManagementUtilityAccessibleProxy::removeDuplicatesForInsertion($insertionList, $list);
520 $this->assertSame($expected, $result);
521 }
522
523 ///////////////////////////////////////////////////
524 // Tests concerning addFieldsToAllPalettesOfField
525 ///////////////////////////////////////////////////
526
527 /**
528 * @test
529 */
530 public function addFieldsToAllPalettesOfFieldDoesNotAddAnythingIfFieldIsNotRegisteredInColumns()
531 {
532 $GLOBALS['TCA'] = array(
533 'aTable' => array(
534 'types' => array(
535 'typeA' => array(
536 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
537 ),
538 ),
539 'palettes' => array(
540 'paletteA' => array(
541 'showitem' => 'fieldX, fieldY',
542 ),
543 ),
544 ),
545 );
546 $expected = $GLOBALS['TCA'];
547 ExtensionManagementUtility::addFieldsToAllPalettesOfField(
548 'aTable',
549 'fieldA',
550 'newA'
551 );
552 $this->assertEquals($expected, $GLOBALS['TCA']);
553 }
554
555 /**
556 * @test
557 */
558 public function addFieldsToAllPalettesOfFieldAddsFieldsToPaletteAndSuppressesDuplicates()
559 {
560 $GLOBALS['TCA'] = array(
561 'aTable' => array(
562 'columns' => array(
563 'fieldA' => array(),
564 ),
565 'types' => array(
566 'typeA' => array(
567 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
568 ),
569 ),
570 'palettes' => array(
571 'paletteA' => array(
572 'showitem' => 'fieldX, fieldY',
573 ),
574 ),
575 ),
576 );
577 $expected = array(
578 'aTable' => array(
579 'columns' => array(
580 'fieldA' => array(),
581 ),
582 'types' => array(
583 'typeA' => array(
584 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
585 ),
586 ),
587 'palettes' => array(
588 'paletteA' => array(
589 'showitem' => 'fieldX, fieldY, dupeA',
590 ),
591 ),
592 ),
593 );
594 ExtensionManagementUtility::addFieldsToAllPalettesOfField(
595 'aTable',
596 'fieldA',
597 'dupeA, dupeA' // Duplicate
598 );
599 $this->assertEquals($expected, $GLOBALS['TCA']);
600 }
601
602 /**
603 * @test
604 */
605 public function addFieldsToAllPalettesOfFieldDoesNotAddAFieldThatIsPartOfPaletteAlready()
606 {
607 $GLOBALS['TCA'] = array(
608 'aTable' => array(
609 'columns' => array(
610 'fieldA' => array(),
611 ),
612 'types' => array(
613 'typeA' => array(
614 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
615 ),
616 ),
617 'palettes' => array(
618 'paletteA' => array(
619 'showitem' => 'existingA',
620 ),
621 ),
622 ),
623 );
624 $expected = array(
625 'aTable' => array(
626 'columns' => array(
627 'fieldA' => array(),
628 ),
629 'types' => array(
630 'typeA' => array(
631 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
632 ),
633 ),
634 'palettes' => array(
635 'paletteA' => array(
636 'showitem' => 'existingA',
637 ),
638 ),
639 ),
640 );
641 ExtensionManagementUtility::addFieldsToAllPalettesOfField(
642 'aTable',
643 'fieldA',
644 'existingA'
645 );
646 $this->assertEquals($expected, $GLOBALS['TCA']);
647 }
648
649 /**
650 * @test
651 */
652 public function addFieldsToAllPalettesOfFieldAddsFieldsToMultiplePalettes()
653 {
654 $GLOBALS['TCA'] = array(
655 'aTable' => array(
656 'columns' => array(
657 'fieldA' => array(),
658 ),
659 'types' => array(
660 'typeA' => array(
661 'showitem' => 'fieldA, --palette--;;palette1',
662 ),
663 'typeB' => array(
664 'showitem' => 'fieldA;aLabel, --palette--;;palette2',
665 ),
666 ),
667 'palettes' => array(
668 'palette1' => array(
669 'showitem' => 'fieldX',
670 ),
671 'palette2' => array(
672 'showitem' => 'fieldY',
673 ),
674 ),
675 ),
676 );
677 $expected = array(
678 'aTable' => array(
679 'columns' => array(
680 'fieldA' => array(),
681 ),
682 'types' => array(
683 'typeA' => array(
684 'showitem' => 'fieldA, --palette--;;palette1',
685 ),
686 'typeB' => array(
687 'showitem' => 'fieldA;aLabel, --palette--;;palette2',
688 ),
689 ),
690 'palettes' => array(
691 'palette1' => array(
692 'showitem' => 'fieldX, newA',
693 ),
694 'palette2' => array(
695 'showitem' => 'fieldY, newA',
696 ),
697 ),
698 ),
699 );
700 ExtensionManagementUtility::addFieldsToAllPalettesOfField(
701 'aTable',
702 'fieldA',
703 'newA'
704 );
705 $this->assertEquals($expected, $GLOBALS['TCA']);
706 }
707
708 /**
709 * @test
710 */
711 public function addFieldsToAllPalettesOfFieldAddsMultipleFields()
712 {
713 $GLOBALS['TCA'] = array(
714 'aTable' => array(
715 'columns' => array(
716 'fieldA' => array(),
717 ),
718 'types' => array(
719 'typeA' => array(
720 'showitem' => 'fieldA, --palette--;;palette1',
721 ),
722 ),
723 'palettes' => array(
724 'palette1' => array(
725 'showitem' => 'fieldX',
726 ),
727 ),
728 ),
729 );
730 $expected = array(
731 'aTable' => array(
732 'columns' => array(
733 'fieldA' => array(),
734 ),
735 'types' => array(
736 'typeA' => array(
737 'showitem' => 'fieldA, --palette--;;palette1',
738 ),
739 ),
740 'palettes' => array(
741 'palette1' => array(
742 'showitem' => 'fieldX, newA, newB',
743 ),
744 ),
745 ),
746 );
747 ExtensionManagementUtility::addFieldsToAllPalettesOfField(
748 'aTable',
749 'fieldA',
750 'newA, newB'
751 );
752 $this->assertEquals($expected, $GLOBALS['TCA']);
753 }
754
755 /**
756 * @test
757 */
758 public function addFieldsToAllPalettesOfFieldAddsBeforeExistingIfRequested()
759 {
760 $GLOBALS['TCA'] = array(
761 'aTable' => array(
762 'columns' => array(
763 'fieldA' => array(),
764 ),
765 'types' => array(
766 'typeA' => array(
767 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
768 ),
769 ),
770 'palettes' => array(
771 'paletteA' => array(
772 'showitem' => 'existingA, existingB',
773 ),
774 ),
775 ),
776 );
777 $expected = array(
778 'aTable' => array(
779 'columns' => array(
780 'fieldA' => array(),
781 ),
782 'types' => array(
783 'typeA' => array(
784 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
785 ),
786 ),
787 'palettes' => array(
788 'paletteA' => array(
789 'showitem' => 'existingA, newA, existingB',
790 ),
791 ),
792 ),
793 );
794 ExtensionManagementUtility::addFieldsToAllPalettesOfField(
795 'aTable',
796 'fieldA',
797 'newA',
798 'before:existingB'
799 );
800 $this->assertEquals($expected, $GLOBALS['TCA']);
801 }
802
803 /**
804 * @test
805 */
806 public function addFieldsToAllPalettesOfFieldAddsFieldsAtEndIfBeforeRequestedDoesNotExist()
807 {
808 $GLOBALS['TCA'] = array(
809 'aTable' => array(
810 'columns' => array(
811 'fieldA' => array(),
812 ),
813 'types' => array(
814 'typeA' => array(
815 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
816 ),
817 ),
818 'palettes' => array(
819 'paletteA' => array(
820 'showitem' => 'fieldX, fieldY',
821 ),
822 ),
823 ),
824 );
825 $expected = array(
826 'aTable' => array(
827 'columns' => array(
828 'fieldA' => array(),
829 ),
830 'types' => array(
831 'typeA' => array(
832 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
833 ),
834 ),
835 'palettes' => array(
836 'paletteA' => array(
837 'showitem' => 'fieldX, fieldY, newA, newB',
838 ),
839 ),
840 ),
841 );
842 ExtensionManagementUtility::addFieldsToAllPalettesOfField(
843 'aTable',
844 'fieldA',
845 'newA, newB',
846 'before:notExisting'
847 );
848 $this->assertEquals($expected, $GLOBALS['TCA']);
849 }
850
851 /**
852 * @test
853 */
854 public function addFieldsToAllPalettesOfFieldAddsAfterExistingIfRequested()
855 {
856 $GLOBALS['TCA'] = array(
857 'aTable' => array(
858 'columns' => array(
859 'fieldA' => array(),
860 ),
861 'types' => array(
862 'typeA' => array(
863 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
864 ),
865 ),
866 'palettes' => array(
867 'paletteA' => array(
868 'showitem' => 'existingA, existingB',
869 ),
870 ),
871 ),
872 );
873 $expected = array(
874 'aTable' => array(
875 'columns' => array(
876 'fieldA' => array(),
877 ),
878 'types' => array(
879 'typeA' => array(
880 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
881 ),
882 ),
883 'palettes' => array(
884 'paletteA' => array(
885 'showitem' => 'existingA, newA, existingB',
886 ),
887 ),
888 ),
889 );
890 ExtensionManagementUtility::addFieldsToAllPalettesOfField(
891 'aTable',
892 'fieldA',
893 'newA',
894 'after:existingA'
895 );
896 $this->assertEquals($expected, $GLOBALS['TCA']);
897 }
898
899 /**
900 * @test
901 */
902 public function addFieldsToAllPalettesOfFieldAddsFieldsAtEndIfAfterRequestedDoesNotExist()
903 {
904 $GLOBALS['TCA'] = array(
905 'aTable' => array(
906 'columns' => array(
907 'fieldA' => array(),
908 ),
909 'types' => array(
910 'typeA' => array(
911 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
912 ),
913 ),
914 'palettes' => array(
915 'paletteA' => array(
916 'showitem' => 'existingA, existingB',
917 ),
918 ),
919 ),
920 );
921 $expected = array(
922 'aTable' => array(
923 'columns' => array(
924 'fieldA' => array(),
925 ),
926 'types' => array(
927 'typeA' => array(
928 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
929 ),
930 ),
931 'palettes' => array(
932 'paletteA' => array(
933 'showitem' => 'existingA, existingB, newA, newB',
934 ),
935 ),
936 ),
937 );
938 ExtensionManagementUtility::addFieldsToAllPalettesOfField(
939 'aTable',
940 'fieldA',
941 'newA, newB',
942 'after:notExistingA'
943 );
944 $this->assertEquals($expected, $GLOBALS['TCA']);
945 }
946
947 /**
948 * @test
949 */
950 public function addFieldsToAllPalettesOfFieldAddsNewPaletteIfFieldHasNoPaletteYet()
951 {
952 $GLOBALS['TCA'] = array(
953 'aTable' => array(
954 'columns' => array(
955 'fieldA' => array(),
956 ),
957 'types' => array(
958 'typeA' => array(
959 'showitem' => 'fieldA',
960 ),
961 ),
962 ),
963 );
964 $expected = array(
965 'aTable' => array(
966 'columns' => array(
967 'fieldA' => array(),
968 ),
969 'types' => array(
970 'typeA' => array(
971 'showitem' => 'fieldA, --palette--;;generatedFor-fieldA',
972 ),
973 ),
974 'palettes' => array(
975 'generatedFor-fieldA' => array(
976 'showitem' => 'newA',
977 ),
978 ),
979 ),
980 );
981 ExtensionManagementUtility::addFieldsToAllPalettesOfField(
982 'aTable',
983 'fieldA',
984 'newA'
985 );
986 $this->assertEquals($expected, $GLOBALS['TCA']);
987 }
988
989 /**
990 * @test
991 */
992 public function addFieldsToAllPalettesOfFieldAddsNewPaletteIfFieldHasNoPaletteYetAndKeepsExistingLabel()
993 {
994 $GLOBALS['TCA'] = array(
995 'aTable' => array(
996 'columns' => array(
997 'fieldA' => array(),
998 ),
999 'types' => array(
1000 'typeA' => array(
1001 'showitem' => 'fieldA;labelA',
1002 ),
1003 ),
1004 ),
1005 );
1006 $expected = array(
1007 'aTable' => array(
1008 'columns' => array(
1009 'fieldA' => array(),
1010 ),
1011 'types' => array(
1012 'typeA' => array(
1013 'showitem' => 'fieldA;labelA, --palette--;;generatedFor-fieldA',
1014 ),
1015 ),
1016 'palettes' => array(
1017 'generatedFor-fieldA' => array(
1018 'showitem' => 'newA',
1019 ),
1020 ),
1021 ),
1022 );
1023 ExtensionManagementUtility::addFieldsToAllPalettesOfField(
1024 'aTable',
1025 'fieldA',
1026 'newA'
1027 );
1028 $this->assertEquals($expected, $GLOBALS['TCA']);
1029 }
1030
1031 ///////////////////////////////////////////////////
1032 // Tests concerning executePositionedStringInsertion
1033 ///////////////////////////////////////////////////
1034
1035 /**
1036 * Data provider for executePositionedStringInsertionTrimsCorrectCharacters
1037 * @return array
1038 */
1039 public function executePositionedStringInsertionTrimsCorrectCharactersDataProvider()
1040 {
1041 return array(
1042 'normal characters' => array(
1043 'tr0',
1044 'tr0',
1045 ),
1046 'newlines' => array(
1047 "test\n",
1048 'test',
1049 ),
1050 'newlines with carriage return' => array(
1051 "test\r\n",
1052 'test',
1053 ),
1054 'tabs' => array(
1055 "test\t",
1056 'test',
1057 ),
1058 'commas' => array(
1059 'test,',
1060 'test',
1061 ),
1062 'multiple commas with trailing spaces' => array(
1063 "test,,\t, \r\n",
1064 'test',
1065 ),
1066 );
1067 }
1068
1069 /**
1070 * @test
1071 * @dataProvider executePositionedStringInsertionTrimsCorrectCharactersDataProvider
1072 * @param $string
1073 * @param $expectedResult
1074 */
1075 public function executePositionedStringInsertionTrimsCorrectCharacters($string, $expectedResult)
1076 {
1077 $extensionManagementUtility = $this->getAccessibleMock(ExtensionManagementUtility::class, array('dummy'));
1078 $string = $extensionManagementUtility->_call('executePositionedStringInsertion', $string, '');
1079 $this->assertEquals($expectedResult, $string);
1080 }
1081
1082 /////////////////////////////////////////
1083 // Tests concerning addTcaSelectItem
1084 /////////////////////////////////////////
1085 /**
1086 * @test
1087 * @expectedException \InvalidArgumentException
1088 */
1089 public function addTcaSelectItemThrowsExceptionIfTableIsNotOfTypeString()
1090 {
1091 ExtensionManagementUtility::addTcaSelectItem(array(), 'foo', array());
1092 }
1093
1094 /**
1095 * @test
1096 * @expectedException \InvalidArgumentException
1097 */
1098 public function addTcaSelectItemThrowsExceptionIfFieldIsNotOfTypeString()
1099 {
1100 ExtensionManagementUtility::addTcaSelectItem('foo', array(), array());
1101 }
1102
1103 /**
1104 * @test
1105 * @expectedException \InvalidArgumentException
1106 */
1107 public function addTcaSelectItemThrowsExceptionIfRelativeToFieldIsNotOfTypeString()
1108 {
1109 ExtensionManagementUtility::addTcaSelectItem('foo', 'bar', array(), array());
1110 }
1111
1112 /**
1113 * @test
1114 * @expectedException \InvalidArgumentException
1115 */
1116 public function addTcaSelectItemThrowsExceptionIfRelativePositionIsNotOfTypeString()
1117 {
1118 ExtensionManagementUtility::addTcaSelectItem('foo', 'bar', array(), 'foo', array());
1119 }
1120
1121 /**
1122 * @test
1123 * @expectedException \InvalidArgumentException
1124 */
1125 public function addTcaSelectItemThrowsExceptionIfRelativePositionIsNotOneOfValidKeywords()
1126 {
1127 ExtensionManagementUtility::addTcaSelectItem('foo', 'bar', array(), 'foo', 'not allowed keyword');
1128 }
1129
1130 /**
1131 * @test
1132 * @expectedException \RuntimeException
1133 */
1134 public function addTcaSelectItemThrowsExceptionIfFieldIsNotFoundInTca()
1135 {
1136 $GLOBALS['TCA'] = array();
1137 ExtensionManagementUtility::addTcaSelectItem('foo', 'bar', array());
1138 }
1139
1140 /**
1141 * Data provider for addTcaSelectItemInsertsItemAtSpecifiedPosition
1142 */
1143 public function addTcaSelectItemDataProvider()
1144 {
1145 // Every array splits into:
1146 // - relativeToField
1147 // - relativePosition
1148 // - expectedResultArray
1149 return array(
1150 'add at end of array' => array(
1151 '',
1152 '',
1153 array(
1154 0 => array('firstElement'),
1155 1 => array('matchMe'),
1156 2 => array('thirdElement'),
1157 3 => array('insertedElement')
1158 )
1159 ),
1160 'replace element' => array(
1161 'matchMe',
1162 'replace',
1163 array(
1164 0 => array('firstElement'),
1165 1 => array('insertedElement'),
1166 2 => array('thirdElement')
1167 )
1168 ),
1169 'add element after' => array(
1170 'matchMe',
1171 'after',
1172 array(
1173 0 => array('firstElement'),
1174 1 => array('matchMe'),
1175 2 => array('insertedElement'),
1176 3 => array('thirdElement')
1177 )
1178 ),
1179 'add element before' => array(
1180 'matchMe',
1181 'before',
1182 array(
1183 0 => array('firstElement'),
1184 1 => array('insertedElement'),
1185 2 => array('matchMe'),
1186 3 => array('thirdElement')
1187 )
1188 ),
1189 'add at end if relative position was not found' => array(
1190 'notExistingItem',
1191 'after',
1192 array(
1193 0 => array('firstElement'),
1194 1 => array('matchMe'),
1195 2 => array('thirdElement'),
1196 3 => array('insertedElement')
1197 )
1198 )
1199 );
1200 }
1201
1202 /**
1203 * @test
1204 * @dataProvider addTcaSelectItemDataProvider
1205 * @param $relativeToField
1206 * @param $relativePosition
1207 * @param $expectedResultArray
1208 */
1209 public function addTcaSelectItemInsertsItemAtSpecifiedPosition($relativeToField, $relativePosition, $expectedResultArray)
1210 {
1211 $GLOBALS['TCA'] = array(
1212 'testTable' => array(
1213 'columns' => array(
1214 'testField' => array(
1215 'config' => array(
1216 'items' => array(
1217 '0' => array('firstElement'),
1218 '1' => array('matchMe'),
1219 2 => array('thirdElement')
1220 )
1221 )
1222 )
1223 )
1224 )
1225 );
1226 ExtensionManagementUtility::addTcaSelectItem('testTable', 'testField', array('insertedElement'), $relativeToField, $relativePosition);
1227 $this->assertEquals($expectedResultArray, $GLOBALS['TCA']['testTable']['columns']['testField']['config']['items']);
1228 }
1229
1230 /////////////////////////////////////////
1231 // Tests concerning loadExtLocalconf
1232 /////////////////////////////////////////
1233 /**
1234 * @test
1235 */
1236 public function loadExtLocalconfDoesNotReadFromCacheIfCachingIsDenied()
1237 {
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);
1244 }
1245
1246 /**
1247 * @test
1248 */
1249 public function loadExtLocalconfRequiresCacheFileIfExistsAndCachingIsAllowed()
1250 {
1251 $mockCache = $this->getMock(
1252 AbstractFrontend::class,
1253 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1254 array(),
1255 '',
1256 false
1257 );
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);
1265 }
1266
1267 /////////////////////////////////////////
1268 // Tests concerning loadSingleExtLocalconfFiles
1269 /////////////////////////////////////////
1270 /**
1271 * @test
1272 * @expectedException \RuntimeException
1273 */
1274 public function loadSingleExtLocalconfFilesRequiresExtLocalconfFileRegisteredInGlobalTypo3LoadedExt()
1275 {
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();
1282 }
1283
1284 /////////////////////////////////////////
1285 // Tests concerning addModule
1286 /////////////////////////////////////////
1287
1288 /**
1289 * Data provider for addModule tests
1290 * @return array
1291 */
1292 public function addModulePositionTestsDataProvider()
1293 {
1294 return array(
1295 'can add new main module if none exists' => array(
1296 'top',
1297 '',
1298 'newModule'
1299 ),
1300 'can add new sub module if no position specified' => array(
1301 '',
1302 'some,modules',
1303 'some,modules,newModule'
1304 ),
1305 'can add new sub module to top of module' => array(
1306 'top',
1307 'some,modules',
1308 'newModule,some,modules'
1309 ),
1310 'can add new sub module if bottom of module' => array(
1311 'bottom',
1312 'some,modules',
1313 'some,modules,newModule'
1314 ),
1315 'can add new sub module before specified sub module' => array(
1316 'before:modules',
1317 'some,modules',
1318 'some,newModule,modules'
1319 ),
1320 'can add new sub module after specified sub module' => array(
1321 'after:some',
1322 'some,modules',
1323 'some,newModule,modules'
1324 ),
1325 'can add new sub module at the bottom if specified sub module to add before does not exist' => array(
1326 'before:modules',
1327 'some,otherModules',
1328 'some,otherModules,newModule'
1329 ),
1330 'can add new sub module at the bottom if specified sub module to add after does not exist' => array(
1331 'after:some',
1332 'someOther,modules',
1333 'someOther,modules,newModule'
1334 ),
1335 );
1336 }
1337
1338 /**
1339 * @test
1340 * @dataProvider addModulePositionTestsDataProvider
1341 * @param $position
1342 * @param $existing
1343 * @param $expected
1344 */
1345 public function addModuleCanAddModule($position, $existing, $expected)
1346 {
1347 $mainModule = 'foobar';
1348 $subModule = 'newModule';
1349 if ($existing) {
1350 $GLOBALS['TBE_MODULES'][$mainModule] = $existing;
1351 }
1352
1353 ExtensionManagementUtility::addModule($mainModule, $subModule, $position);
1354
1355 $this->assertTrue(isset($GLOBALS['TBE_MODULES'][$mainModule]));
1356 $this->assertEquals($expected, $GLOBALS['TBE_MODULES'][$mainModule]);
1357 }
1358
1359 /////////////////////////////////////////
1360 // Tests concerning createExtLocalconfCacheEntry
1361 /////////////////////////////////////////
1362 /**
1363 * @test
1364 */
1365 public function createExtLocalconfCacheEntryWritesCacheEntryWithContentOfLoadedExtensionExtLocalconf()
1366 {
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'),
1376 array(),
1377 '',
1378 false
1379 );
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();
1386 }
1387
1388 /**
1389 * @test
1390 */
1391 public function createExtLocalconfCacheEntryWritesCacheEntryWithExtensionContentOnlyIfExtLocalconfExists()
1392 {
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'),
1399 array(),
1400 '',
1401 false
1402 );
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())
1408 ->method('set')
1409 ->with($this->anything(), $this->logicalNot($this->stringContains($extensionName)), $this->anything());
1410 ExtensionManagementUtilityAccessibleProxy::createExtLocalconfCacheEntry();
1411 }
1412
1413 /**
1414 * @test
1415 */
1416 public function createExtLocalconfCacheEntryWritesCacheEntryWithNoTags()
1417 {
1418 $mockCache = $this->getMock(
1419 AbstractFrontend::class,
1420 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1421 array(),
1422 '',
1423 false
1424 );
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();
1432 }
1433
1434 /////////////////////////////////////////
1435 // Tests concerning getExtLocalconfCacheIdentifier
1436 /////////////////////////////////////////
1437 /**
1438 * @test
1439 */
1440 public function getExtLocalconfCacheIdentifierCreatesSha1WithFourtyCharactersAndPrefix()
1441 {
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));
1447 }
1448
1449 /////////////////////////////////////////
1450 // Tests concerning loadBaseTca
1451 /////////////////////////////////////////
1452
1453 /**
1454 * @test
1455 */
1456 public function loadBaseTcaDoesNotReadFromCacheIfCachingIsDenied()
1457 {
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);
1463 }
1464
1465 /**
1466 * @test
1467 */
1468 public function loadBaseTcaRequiresCacheFileIfExistsAndCachingIsAllowed()
1469 {
1470 $mockCache = $this->getMock(
1471 AbstractFrontend::class,
1472 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1473 array(),
1474 '',
1475 false
1476 );
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);
1484 }
1485
1486 /**
1487 * @test
1488 */
1489 public function loadBaseTcaCreatesCacheFileWithContentOfAnExtensionsConfigurationTcaPhpFile()
1490 {
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'),
1506 array(),
1507 '',
1508 false
1509 );
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);
1517 }
1518
1519 /**
1520 * @test
1521 */
1522 public function loadBaseTcaWritesCacheEntryWithNoTags()
1523 {
1524 $mockCache = $this->getMock(
1525 AbstractFrontend::class,
1526 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1527 array(),
1528 '',
1529 false
1530 );
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();
1538 }
1539
1540 /////////////////////////////////////////
1541 // Tests concerning getBaseTcaCacheIdentifier
1542 /////////////////////////////////////////
1543
1544 /**
1545 * @test
1546 */
1547 public function getBaseTcaCacheIdentifierCreatesSha1WithFourtyCharactersAndPrefix()
1548 {
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));
1554 }
1555
1556 /////////////////////////////////////////
1557 // Tests concerning loadExtTables
1558 /////////////////////////////////////////
1559 /**
1560 * @test
1561 */
1562 public function loadExtTablesDoesNotReadFromCacheIfCachingIsDenied()
1563 {
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);
1570 }
1571
1572 /**
1573 * @test
1574 */
1575 public function loadExtTablesRequiresCacheFileIfExistsAndCachingIsAllowed()
1576 {
1577 $mockCache = $this->getMock(
1578 AbstractFrontend::class,
1579 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1580 array(),
1581 '',
1582 false
1583 );
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);
1594 }
1595
1596 /////////////////////////////////////////
1597 // Tests concerning createExtTablesCacheEntry
1598 /////////////////////////////////////////
1599 /**
1600 * @test
1601 */
1602 public function createExtTablesCacheEntryWritesCacheEntryWithContentOfLoadedExtensionExtTables()
1603 {
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
1612 )
1613 );
1614 $mockCache = $this->getMock(
1615 AbstractFrontend::class,
1616 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1617 array(),
1618 '',
1619 false
1620 );
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();
1627 }
1628
1629 /**
1630 * @test
1631 */
1632 public function createExtTablesCacheEntryWritesCacheEntryWithExtensionContentOnlyIfExtTablesExists()
1633 {
1634 $extensionName = $this->getUniqueId('foo');
1635 $GLOBALS['TYPO3_LOADED_EXT'] = array(
1636 $extensionName => array(),
1637 );
1638 $mockCache = $this->getMock(
1639 AbstractFrontend::class,
1640 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1641 array(),
1642 '',
1643 false
1644 );
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())
1650 ->method('set')
1651 ->with($this->anything(), $this->logicalNot($this->stringContains($extensionName)), $this->anything());
1652 ExtensionManagementUtilityAccessibleProxy::createExtTablesCacheEntry();
1653 }
1654
1655 /**
1656 * @test
1657 */
1658 public function createExtTablesCacheEntryWritesCacheEntryWithNoTags()
1659 {
1660 $mockCache = $this->getMock(
1661 AbstractFrontend::class,
1662 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1663 array(),
1664 '',
1665 false
1666 );
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();
1674 }
1675
1676 /////////////////////////////////////////
1677 // Tests concerning getExtTablesCacheIdentifier
1678 /////////////////////////////////////////
1679 /**
1680 * @test
1681 */
1682 public function getExtTablesCacheIdentifierCreatesSha1WithFourtyCharactersAndPrefix()
1683 {
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));
1689 }
1690
1691 /////////////////////////////////////////
1692 // Tests concerning removeCacheFiles
1693 /////////////////////////////////////////
1694 /**
1695 * @test
1696 */
1697 public function removeCacheFilesFlushesSystemCaches()
1698 {
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();
1704 }
1705
1706 /////////////////////////////////////////
1707 // Tests concerning loadNewTcaColumnsConfigFiles
1708 /////////////////////////////////////////
1709
1710 /**
1711 * @test
1712 * @expectedException \RuntimeException
1713 */
1714 public function loadNewTcaColumnsConfigFilesIncludesDefinedDynamicConfigFileIfNoColumnsExist()
1715 {
1716 $GLOBALS['TCA'] = array(
1717 'test' => array(
1718 'ctrl' => array(
1719 'dynamicConfigFile' => __DIR__ . '/Fixtures/RuntimeException.php'
1720 ),
1721 ),
1722 );
1723 ExtensionManagementUtility::loadNewTcaColumnsConfigFiles();
1724 }
1725
1726 /**
1727 * @test
1728 */
1729 public function loadNewTcaColumnsConfigFilesDoesNotIncludeFileIfColumnsExist()
1730 {
1731 $GLOBALS['TCA'] = array(
1732 'test' => array(
1733 'ctrl' => array(
1734 'dynamicConfigFile' => __DIR__ . '/Fixtures/RuntimeException.php'
1735 ),
1736 'columns' => array(
1737 'foo' => 'bar',
1738 ),
1739 ),
1740 );
1741 ExtensionManagementUtility::loadNewTcaColumnsConfigFiles();
1742 }
1743
1744 /////////////////////////////////////////
1745 // Tests concerning getExtensionVersion
1746 /////////////////////////////////////////
1747 /**
1748 * Data provider for negative getExtensionVersion() tests.
1749 *
1750 * @return array
1751 */
1752 public function getExtensionVersionFaultyDataProvider()
1753 {
1754 return array(
1755 array(''),
1756 array(0),
1757 array(new \stdClass()),
1758 array(true)
1759 );
1760 }
1761
1762 /**
1763 * @test
1764 * @expectedException \InvalidArgumentException
1765 * @dataProvider getExtensionVersionFaultyDataProvider
1766 * @param $key
1767 * @throws \TYPO3\CMS\Core\Package\Exception
1768 */
1769 public function getExtensionVersionForFaultyExtensionKeyThrowsException($key)
1770 {
1771 ExtensionManagementUtility::getExtensionVersion($key);
1772 }
1773
1774 /**
1775 * @test
1776 */
1777 public function getExtensionVersionForNotLoadedExtensionReturnsEmptyString()
1778 {
1779 ExtensionManagementUtility::clearExtensionKeyMap();
1780 $uniqueSuffix = $this->getUniqueId('test');
1781 $extensionKey = 'unloadedextension' . $uniqueSuffix;
1782 $this->assertEquals('', ExtensionManagementUtility::getExtensionVersion($extensionKey));
1783 }
1784
1785 /**
1786 * @test
1787 */
1788 public function getExtensionVersionForLoadedExtensionReturnsExtensionVersion()
1789 {
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));
1803 }
1804
1805 /////////////////////////////////////////
1806 // Tests concerning loadExtension
1807 /////////////////////////////////////////
1808 /**
1809 * @test
1810 * @expectedException \RuntimeException
1811 */
1812 public function loadExtensionThrowsExceptionIfExtensionIsLoaded()
1813 {
1814 $extensionKey = $this->getUniqueId('test');
1815 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionKey);
1816 ExtensionManagementUtility::setPackageManager($packageManager);
1817 ExtensionManagementUtility::loadExtension($extensionKey);
1818 }
1819
1820 /////////////////////////////////////////
1821 // Tests concerning unloadExtension
1822 /////////////////////////////////////////
1823 /**
1824 * @test
1825 * @expectedException \RuntimeException
1826 */
1827 public function unloadExtensionThrowsExceptionIfExtensionIsNotLoaded()
1828 {
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);
1838 }
1839
1840 /**
1841 * @test
1842 */
1843 public function unloadExtensionCallsPackageManagerToDeactivatePackage()
1844 {
1845 $packageName = $this->getUniqueId('foo');
1846 /** @var PackageManager|\PHPUnit_Framework_MockObject_MockObject $packageManager */
1847 $packageManager = $this->getMock(
1848 PackageManager::class,
1849 array('isPackageActive', 'deactivatePackage')
1850 );
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);
1859 }
1860
1861 /////////////////////////////////////////
1862 // Tests concerning makeCategorizable
1863 /////////////////////////////////////////
1864 /**
1865 * @test
1866 */
1867 public function doesMakeCategorizableCallsTheCategoryRegistryWithDefaultFieldName()
1868 {
1869 $extensionKey = $this->getUniqueId('extension');
1870 $tableName = $this->getUniqueId('table');
1871
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);
1877 }
1878
1879 /**
1880 * @test
1881 */
1882 public function doesMakeCategorizableCallsTheCategoryRegistryWithFieldName()
1883 {
1884 $extensionKey = $this->getUniqueId('extension');
1885 $tableName = $this->getUniqueId('table');
1886 $fieldName = $this->getUniqueId('field');
1887
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);
1893 }
1894
1895 ///////////////////////////////
1896 // Tests concerning addPlugin
1897 ///////////////////////////////
1898
1899 /**
1900 * @test
1901 */
1902 public function addPluginSetsTcaCorrectlyForGivenExtKeyAsParameter()
1903 {
1904 $extKey = 'indexed_search';
1905 $GLOBALS['TYPO3_LOADED_EXT'] = array();
1906 $GLOBALS['TYPO3_LOADED_EXT'][$extKey]['ext_icon'] = 'foo.gif';
1907 $expectedTCA = array(
1908 array(
1909 'label',
1910 $extKey,
1911 'EXT:' . $extKey . '/foo.gif'
1912 )
1913 );
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']);
1917 }
1918
1919 /**
1920 * @test
1921 */
1922 public function addPluginSetsTcaCorrectlyForGivenExtKeyAsGlobal()
1923 {
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(
1929 array(
1930 'label',
1931 $extKey,
1932 'EXT:' . $extKey . '/foo.gif'
1933 )
1934 );
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']);
1938 }
1939
1940 /**
1941 * @test
1942 * @expectedException \RuntimeException
1943 */
1944 public function addPluginThrowsExceptionForMissingExtkey()
1945 {
1946 ExtensionManagementUtility::addPlugin('test');
1947 }
1948 }