[TASK] Use single quotes instead of double quotes
[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 a TCA type before existing ones
342 *
343 * @test
344 * @see ExtensionManagementUtility::addToAllTCAtypes()
345 */
346 public function canAddFieldsToTCATypeBeforeExistingOnes()
347 {
348 $table = $this->getUniqueId('tx_coretest_table');
349 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
350 ExtensionManagementUtility::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', 'typeA', 'before:fieldD');
351 // Checking typeA:
352 $this->assertEquals('fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, newA, newB, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
353 // Checking typeB:
354 $this->assertEquals('fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
355 }
356
357 /**
358 * Tests whether fields can be add to a TCA type after existing ones
359 *
360 * @test
361 * @see ExtensionManagementUtility::addToAllTCAtypes()
362 */
363 public function canAddFieldsToTCATypeAfterExistingOnes()
364 {
365 $table = $this->getUniqueId('tx_coretest_table');
366 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
367 ExtensionManagementUtility::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', 'typeA', 'after:fieldC');
368 // Checking typeA:
369 $this->assertEquals('fieldA, fieldB, fieldC;labelC, newA, newB, --palette--;;paletteC, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
370 // Checking typeB:
371 $this->assertEquals('fieldA, fieldB, fieldC;labelC, --palette--;;paletteC, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
372 }
373
374 /**
375 * Test wheter replacing other TCA fields works as promissed
376 *
377 * @test
378 * @see ExtensionManagementUtility::addFieldsToAllPalettesOfField()
379 */
380 public function canAddFieldsToTCATypeAndReplaceExistingOnes()
381 {
382 $table = $this->getUniqueId('tx_coretest_table');
383 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
384 $typesBefore = $GLOBALS['TCA'][$table]['types'];
385 ExtensionManagementUtility::addToAllTCAtypes($table, 'fieldZ', '', 'replace:fieldX');
386 $this->assertEquals($typesBefore, $GLOBALS['TCA'][$table]['types'], 'It\'s wrong that the "types" array changes here - the replaced field is only on palettes');
387 // unchanged because the palette is not used
388 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
389 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
390 // changed
391 $this->assertEquals('fieldZ, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
392 $this->assertEquals('fieldZ, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
393 }
394
395 /**
396 * @test
397 */
398 public function addToAllTCAtypesReplacesExistingOnes()
399 {
400 $table = $this->getUniqueId('tx_coretest_table');
401 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
402 $typesBefore = $GLOBALS['TCA'][$table]['types'];
403 ExtensionManagementUtility::addToAllTCAtypes($table, 'fieldX, --palette--;;foo', '', 'replace:fieldX');
404 $this->assertEquals($typesBefore, $GLOBALS['TCA'][$table]['types'], 'It\'s wrong that the "types" array changes here - the replaced field is only on palettes');
405 // unchanged because the palette is not used
406 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
407 $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
408 // changed
409 $this->assertEquals('fieldX, --palette--;;foo, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
410 $this->assertEquals('fieldX, --palette--;;foo, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
411 }
412
413 /**
414 * Tests whether fields can be added to a palette before existing elements.
415 *
416 * @test
417 * @see ExtensionManagementUtility::addFieldsToPalette()
418 */
419 public function canAddFieldsToPaletteBeforeExistingOnes()
420 {
421 $table = $this->getUniqueId('tx_coretest_table');
422 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
423 ExtensionManagementUtility::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'before:fieldY');
424 $this->assertEquals('fieldX, fieldX1, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
425 }
426
427 /**
428 * Tests whether fields can be added to a palette after existing elements.
429 *
430 * @test
431 * @see ExtensionManagementUtility::addFieldsToPalette()
432 */
433 public function canAddFieldsToPaletteAfterExistingOnes()
434 {
435 $table = $this->getUniqueId('tx_coretest_table');
436 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
437 ExtensionManagementUtility::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'after:fieldX');
438 $this->assertEquals('fieldX, newA, newB, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
439 }
440
441 /**
442 * Tests whether fields can be added to a palette after a not existing elements.
443 *
444 * @test
445 * @see ExtensionManagementUtility::addFieldsToPalette()
446 */
447 public function canAddFieldsToPaletteAfterNotExistingOnes()
448 {
449 $table = $this->getUniqueId('tx_coretest_table');
450 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
451 ExtensionManagementUtility::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'after:' . $this->getUniqueId('notExisting'));
452 $this->assertEquals('fieldX, fieldX1, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
453 }
454
455 /**
456 * @return array
457 */
458 public function removeDuplicatesForInsertionRemovesDuplicatesDataProvider()
459 {
460 return array(
461 'Simple' => array(
462 'field_b, field_d, field_c',
463 'field_a, field_b, field_c',
464 'field_d'
465 ),
466 'with linebreaks' => array(
467 'field_b, --linebreak--, field_d, --linebreak--, field_c',
468 'field_a, field_b, field_c',
469 '--linebreak--, field_d, --linebreak--'
470 ),
471 'with linebreaks in list and insertion list' => array(
472 'field_b, --linebreak--, field_d, --linebreak--, field_c',
473 'field_a, field_b, --linebreak--, field_c',
474 '--linebreak--, field_d, --linebreak--'
475 ),
476 );
477 }
478
479 /**
480 * @test
481 * @dataProvider removeDuplicatesForInsertionRemovesDuplicatesDataProvider
482 * @param $insertionList
483 * @param $list
484 * @param $expected
485 */
486 public function removeDuplicatesForInsertionRemovesDuplicates($insertionList, $list, $expected)
487 {
488 $result = ExtensionManagementUtilityAccessibleProxy::removeDuplicatesForInsertion($insertionList, $list);
489 $this->assertSame($expected, $result);
490 }
491
492
493 ///////////////////////////////////////////////////
494 // Tests concerning addFieldsToAllPalettesOfField
495 ///////////////////////////////////////////////////
496
497 /**
498 * @test
499 */
500 public function addFieldsToAllPalettesOfFieldDoesNotAddAnythingIfFieldIsNotRegisteredInColumns()
501 {
502 $GLOBALS['TCA'] = array(
503 'aTable' => array(
504 'types' => array(
505 'typeA' => array(
506 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
507 ),
508 ),
509 'palettes' => array(
510 'paletteA' => array(
511 'showitem' => 'fieldX, fieldY',
512 ),
513 ),
514 ),
515 );
516 $expected = $GLOBALS['TCA'];
517 ExtensionManagementUtility::addFieldsToAllPalettesOfField(
518 'aTable',
519 'fieldA',
520 'newA'
521 );
522 $this->assertEquals($expected, $GLOBALS['TCA']);
523 }
524
525 /**
526 * @test
527 */
528 public function addFieldsToAllPalettesOfFieldAddsFieldsToPaletteAndSuppressesDuplicates()
529 {
530 $GLOBALS['TCA'] = array(
531 'aTable' => array(
532 'columns' => array(
533 'fieldA' => array(),
534 ),
535 'types' => array(
536 'typeA' => array(
537 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
538 ),
539 ),
540 'palettes' => array(
541 'paletteA' => array(
542 'showitem' => 'fieldX, fieldY',
543 ),
544 ),
545 ),
546 );
547 $expected = array(
548 'aTable' => array(
549 'columns' => array(
550 'fieldA' => array(),
551 ),
552 'types' => array(
553 'typeA' => array(
554 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
555 ),
556 ),
557 'palettes' => array(
558 'paletteA' => array(
559 'showitem' => 'fieldX, fieldY, dupeA',
560 ),
561 ),
562 ),
563 );
564 ExtensionManagementUtility::addFieldsToAllPalettesOfField(
565 'aTable',
566 'fieldA',
567 'dupeA, dupeA' // Duplicate
568 );
569 $this->assertEquals($expected, $GLOBALS['TCA']);
570 }
571
572 /**
573 * @test
574 */
575 public function addFieldsToAllPalettesOfFieldDoesNotAddAFieldThatIsPartOfPaletteAlready()
576 {
577 $GLOBALS['TCA'] = 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' => 'existingA',
590 ),
591 ),
592 ),
593 );
594 $expected = array(
595 'aTable' => array(
596 'columns' => array(
597 'fieldA' => array(),
598 ),
599 'types' => array(
600 'typeA' => array(
601 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
602 ),
603 ),
604 'palettes' => array(
605 'paletteA' => array(
606 'showitem' => 'existingA',
607 ),
608 ),
609 ),
610 );
611 ExtensionManagementUtility::addFieldsToAllPalettesOfField(
612 'aTable',
613 'fieldA',
614 'existingA'
615 );
616 $this->assertEquals($expected, $GLOBALS['TCA']);
617 }
618
619 /**
620 * @test
621 */
622 public function addFieldsToAllPalettesOfFieldAddsFieldsToMultiplePalettes()
623 {
624 $GLOBALS['TCA'] = array(
625 'aTable' => array(
626 'columns' => array(
627 'fieldA' => array(),
628 ),
629 'types' => array(
630 'typeA' => array(
631 'showitem' => 'fieldA, --palette--;;palette1',
632 ),
633 'typeB' => array(
634 'showitem' => 'fieldA;aLabel, --palette--;;palette2',
635 ),
636 ),
637 'palettes' => array(
638 'palette1' => array(
639 'showitem' => 'fieldX',
640 ),
641 'palette2' => array(
642 'showitem' => 'fieldY',
643 ),
644 ),
645 ),
646 );
647 $expected = array(
648 'aTable' => array(
649 'columns' => array(
650 'fieldA' => array(),
651 ),
652 'types' => array(
653 'typeA' => array(
654 'showitem' => 'fieldA, --palette--;;palette1',
655 ),
656 'typeB' => array(
657 'showitem' => 'fieldA;aLabel, --palette--;;palette2',
658 ),
659 ),
660 'palettes' => array(
661 'palette1' => array(
662 'showitem' => 'fieldX, newA',
663 ),
664 'palette2' => array(
665 'showitem' => 'fieldY, newA',
666 ),
667 ),
668 ),
669 );
670 ExtensionManagementUtility::addFieldsToAllPalettesOfField(
671 'aTable',
672 'fieldA',
673 'newA'
674 );
675 $this->assertEquals($expected, $GLOBALS['TCA']);
676 }
677
678 /**
679 * @test
680 */
681 public function addFieldsToAllPalettesOfFieldAddsMultipleFields()
682 {
683 $GLOBALS['TCA'] = array(
684 'aTable' => array(
685 'columns' => array(
686 'fieldA' => array(),
687 ),
688 'types' => array(
689 'typeA' => array(
690 'showitem' => 'fieldA, --palette--;;palette1',
691 ),
692 ),
693 'palettes' => array(
694 'palette1' => array(
695 'showitem' => 'fieldX',
696 ),
697 ),
698 ),
699 );
700 $expected = array(
701 'aTable' => array(
702 'columns' => array(
703 'fieldA' => array(),
704 ),
705 'types' => array(
706 'typeA' => array(
707 'showitem' => 'fieldA, --palette--;;palette1',
708 ),
709 ),
710 'palettes' => array(
711 'palette1' => array(
712 'showitem' => 'fieldX, newA, newB',
713 ),
714 ),
715 ),
716 );
717 ExtensionManagementUtility::addFieldsToAllPalettesOfField(
718 'aTable',
719 'fieldA',
720 'newA, newB'
721 );
722 $this->assertEquals($expected, $GLOBALS['TCA']);
723 }
724
725 /**
726 * @test
727 */
728 public function addFieldsToAllPalettesOfFieldAddsBeforeExistingIfRequested()
729 {
730 $GLOBALS['TCA'] = array(
731 'aTable' => array(
732 'columns' => array(
733 'fieldA' => array(),
734 ),
735 'types' => array(
736 'typeA' => array(
737 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
738 ),
739 ),
740 'palettes' => array(
741 'paletteA' => array(
742 'showitem' => 'existingA, existingB',
743 ),
744 ),
745 ),
746 );
747 $expected = array(
748 'aTable' => array(
749 'columns' => array(
750 'fieldA' => array(),
751 ),
752 'types' => array(
753 'typeA' => array(
754 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
755 ),
756 ),
757 'palettes' => array(
758 'paletteA' => array(
759 'showitem' => 'existingA, newA, existingB',
760 ),
761 ),
762 ),
763 );
764 ExtensionManagementUtility::addFieldsToAllPalettesOfField(
765 'aTable',
766 'fieldA',
767 'newA',
768 'before:existingB'
769 );
770 $this->assertEquals($expected, $GLOBALS['TCA']);
771 }
772
773 /**
774 * @test
775 */
776 public function addFieldsToAllPalettesOfFieldAddsFieldsAtEndIfBeforeRequestedDoesNotExist()
777 {
778 $GLOBALS['TCA'] = array(
779 'aTable' => array(
780 'columns' => array(
781 'fieldA' => array(),
782 ),
783 'types' => array(
784 'typeA' => array(
785 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
786 ),
787 ),
788 'palettes' => array(
789 'paletteA' => array(
790 'showitem' => 'fieldX, fieldY',
791 ),
792 ),
793 ),
794 );
795 $expected = array(
796 'aTable' => array(
797 'columns' => array(
798 'fieldA' => array(),
799 ),
800 'types' => array(
801 'typeA' => array(
802 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
803 ),
804 ),
805 'palettes' => array(
806 'paletteA' => array(
807 'showitem' => 'fieldX, fieldY, newA, newB',
808 ),
809 ),
810 ),
811 );
812 ExtensionManagementUtility::addFieldsToAllPalettesOfField(
813 'aTable',
814 'fieldA',
815 'newA, newB',
816 'before:notExisting'
817 );
818 $this->assertEquals($expected, $GLOBALS['TCA']);
819 }
820
821 /**
822 * @test
823 */
824 public function addFieldsToAllPalettesOfFieldAddsAfterExistingIfRequested()
825 {
826 $GLOBALS['TCA'] = array(
827 'aTable' => array(
828 'columns' => array(
829 'fieldA' => array(),
830 ),
831 'types' => array(
832 'typeA' => array(
833 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
834 ),
835 ),
836 'palettes' => array(
837 'paletteA' => array(
838 'showitem' => 'existingA, existingB',
839 ),
840 ),
841 ),
842 );
843 $expected = array(
844 'aTable' => array(
845 'columns' => array(
846 'fieldA' => array(),
847 ),
848 'types' => array(
849 'typeA' => array(
850 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
851 ),
852 ),
853 'palettes' => array(
854 'paletteA' => array(
855 'showitem' => 'existingA, newA, existingB',
856 ),
857 ),
858 ),
859 );
860 ExtensionManagementUtility::addFieldsToAllPalettesOfField(
861 'aTable',
862 'fieldA',
863 'newA',
864 'after:existingA'
865 );
866 $this->assertEquals($expected, $GLOBALS['TCA']);
867 }
868
869 /**
870 * @test
871 */
872 public function addFieldsToAllPalettesOfFieldAddsFieldsAtEndIfAfterRequestedDoesNotExist()
873 {
874 $GLOBALS['TCA'] = array(
875 'aTable' => array(
876 'columns' => array(
877 'fieldA' => array(),
878 ),
879 'types' => array(
880 'typeA' => array(
881 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
882 ),
883 ),
884 'palettes' => array(
885 'paletteA' => array(
886 'showitem' => 'existingA, existingB',
887 ),
888 ),
889 ),
890 );
891 $expected = array(
892 'aTable' => array(
893 'columns' => array(
894 'fieldA' => array(),
895 ),
896 'types' => array(
897 'typeA' => array(
898 'showitem' => 'fieldA;labelA, --palette--;;paletteA',
899 ),
900 ),
901 'palettes' => array(
902 'paletteA' => array(
903 'showitem' => 'existingA, existingB, newA, newB',
904 ),
905 ),
906 ),
907 );
908 ExtensionManagementUtility::addFieldsToAllPalettesOfField(
909 'aTable',
910 'fieldA',
911 'newA, newB',
912 'after:notExistingA'
913 );
914 $this->assertEquals($expected, $GLOBALS['TCA']);
915 }
916
917 /**
918 * @test
919 */
920 public function addFieldsToAllPalettesOfFieldAddsNewPaletteIfFieldHasNoPaletteYet()
921 {
922 $GLOBALS['TCA'] = array(
923 'aTable' => array(
924 'columns' => array(
925 'fieldA' => array(),
926 ),
927 'types' => array(
928 'typeA' => array(
929 'showitem' => 'fieldA',
930 ),
931 ),
932 ),
933 );
934 $expected = array(
935 'aTable' => array(
936 'columns' => array(
937 'fieldA' => array(),
938 ),
939 'types' => array(
940 'typeA' => array(
941 'showitem' => 'fieldA, --palette--;;generatedFor-fieldA',
942 ),
943 ),
944 'palettes' => array(
945 'generatedFor-fieldA' => array(
946 'showitem' => 'newA',
947 ),
948 ),
949 ),
950 );
951 ExtensionManagementUtility::addFieldsToAllPalettesOfField(
952 'aTable',
953 'fieldA',
954 'newA'
955 );
956 $this->assertEquals($expected, $GLOBALS['TCA']);
957 }
958
959 /**
960 * @test
961 */
962 public function addFieldsToAllPalettesOfFieldAddsNewPaletteIfFieldHasNoPaletteYetAndKeepsExistingLabel()
963 {
964 $GLOBALS['TCA'] = array(
965 'aTable' => array(
966 'columns' => array(
967 'fieldA' => array(),
968 ),
969 'types' => array(
970 'typeA' => array(
971 'showitem' => 'fieldA;labelA',
972 ),
973 ),
974 ),
975 );
976 $expected = array(
977 'aTable' => array(
978 'columns' => array(
979 'fieldA' => array(),
980 ),
981 'types' => array(
982 'typeA' => array(
983 'showitem' => 'fieldA;labelA, --palette--;;generatedFor-fieldA',
984 ),
985 ),
986 'palettes' => array(
987 'generatedFor-fieldA' => array(
988 'showitem' => 'newA',
989 ),
990 ),
991 ),
992 );
993 ExtensionManagementUtility::addFieldsToAllPalettesOfField(
994 'aTable',
995 'fieldA',
996 'newA'
997 );
998 $this->assertEquals($expected, $GLOBALS['TCA']);
999 }
1000
1001
1002 ///////////////////////////////////////////////////
1003 // Tests concerning executePositionedStringInsertion
1004 ///////////////////////////////////////////////////
1005
1006 /**
1007 * Data provider for executePositionedStringInsertionTrimsCorrectCharacters
1008 * @return array
1009 */
1010 public function executePositionedStringInsertionTrimsCorrectCharactersDataProvider()
1011 {
1012 return array(
1013 'normal characters' => array(
1014 'tr0',
1015 'tr0',
1016 ),
1017 'newlines' => array(
1018 "test\n",
1019 'test',
1020 ),
1021 'newlines with carriage return' => array(
1022 "test\r\n",
1023 'test',
1024 ),
1025 'tabs' => array(
1026 "test\t",
1027 'test',
1028 ),
1029 'commas' => array(
1030 'test,',
1031 'test',
1032 ),
1033 'multiple commas with trailing spaces' => array(
1034 "test,,\t, \r\n",
1035 'test',
1036 ),
1037 );
1038 }
1039
1040 /**
1041 * @test
1042 * @dataProvider executePositionedStringInsertionTrimsCorrectCharactersDataProvider
1043 * @param $string
1044 * @param $expectedResult
1045 */
1046 public function executePositionedStringInsertionTrimsCorrectCharacters($string, $expectedResult)
1047 {
1048 $extensionManagementUtility = $this->getAccessibleMock(ExtensionManagementUtility::class, array('dummy'));
1049 $string = $extensionManagementUtility->_call('executePositionedStringInsertion', $string, '');
1050 $this->assertEquals($expectedResult, $string);
1051 }
1052
1053
1054 /////////////////////////////////////////
1055 // Tests concerning addTcaSelectItem
1056 /////////////////////////////////////////
1057 /**
1058 * @test
1059 * @expectedException \InvalidArgumentException
1060 */
1061 public function addTcaSelectItemThrowsExceptionIfTableIsNotOfTypeString()
1062 {
1063 ExtensionManagementUtility::addTcaSelectItem(array(), 'foo', array());
1064 }
1065
1066 /**
1067 * @test
1068 * @expectedException \InvalidArgumentException
1069 */
1070 public function addTcaSelectItemThrowsExceptionIfFieldIsNotOfTypeString()
1071 {
1072 ExtensionManagementUtility::addTcaSelectItem('foo', array(), array());
1073 }
1074
1075 /**
1076 * @test
1077 * @expectedException \InvalidArgumentException
1078 */
1079 public function addTcaSelectItemThrowsExceptionIfRelativeToFieldIsNotOfTypeString()
1080 {
1081 ExtensionManagementUtility::addTcaSelectItem('foo', 'bar', array(), array());
1082 }
1083
1084 /**
1085 * @test
1086 * @expectedException \InvalidArgumentException
1087 */
1088 public function addTcaSelectItemThrowsExceptionIfRelativePositionIsNotOfTypeString()
1089 {
1090 ExtensionManagementUtility::addTcaSelectItem('foo', 'bar', array(), 'foo', array());
1091 }
1092
1093 /**
1094 * @test
1095 * @expectedException \InvalidArgumentException
1096 */
1097 public function addTcaSelectItemThrowsExceptionIfRelativePositionIsNotOneOfValidKeywords()
1098 {
1099 ExtensionManagementUtility::addTcaSelectItem('foo', 'bar', array(), 'foo', 'not allowed keyword');
1100 }
1101
1102 /**
1103 * @test
1104 * @expectedException \RuntimeException
1105 */
1106 public function addTcaSelectItemThrowsExceptionIfFieldIsNotFoundInTca()
1107 {
1108 $GLOBALS['TCA'] = array();
1109 ExtensionManagementUtility::addTcaSelectItem('foo', 'bar', array());
1110 }
1111
1112 /**
1113 * Data provider for addTcaSelectItemInsertsItemAtSpecifiedPosition
1114 */
1115 public function addTcaSelectItemDataProvider()
1116 {
1117 // Every array splits into:
1118 // - relativeToField
1119 // - relativePosition
1120 // - expectedResultArray
1121 return array(
1122 'add at end of array' => array(
1123 '',
1124 '',
1125 array(
1126 0 => array('firstElement'),
1127 1 => array('matchMe'),
1128 2 => array('thirdElement'),
1129 3 => array('insertedElement')
1130 )
1131 ),
1132 'replace element' => array(
1133 'matchMe',
1134 'replace',
1135 array(
1136 0 => array('firstElement'),
1137 1 => array('insertedElement'),
1138 2 => array('thirdElement')
1139 )
1140 ),
1141 'add element after' => array(
1142 'matchMe',
1143 'after',
1144 array(
1145 0 => array('firstElement'),
1146 1 => array('matchMe'),
1147 2 => array('insertedElement'),
1148 3 => array('thirdElement')
1149 )
1150 ),
1151 'add element before' => array(
1152 'matchMe',
1153 'before',
1154 array(
1155 0 => array('firstElement'),
1156 1 => array('insertedElement'),
1157 2 => array('matchMe'),
1158 3 => array('thirdElement')
1159 )
1160 ),
1161 'add at end if relative position was not found' => array(
1162 'notExistingItem',
1163 'after',
1164 array(
1165 0 => array('firstElement'),
1166 1 => array('matchMe'),
1167 2 => array('thirdElement'),
1168 3 => array('insertedElement')
1169 )
1170 )
1171 );
1172 }
1173
1174 /**
1175 * @test
1176 * @dataProvider addTcaSelectItemDataProvider
1177 * @param $relativeToField
1178 * @param $relativePosition
1179 * @param $expectedResultArray
1180 */
1181 public function addTcaSelectItemInsertsItemAtSpecifiedPosition($relativeToField, $relativePosition, $expectedResultArray)
1182 {
1183 $GLOBALS['TCA'] = array(
1184 'testTable' => array(
1185 'columns' => array(
1186 'testField' => array(
1187 'config' => array(
1188 'items' => array(
1189 '0' => array('firstElement'),
1190 '1' => array('matchMe'),
1191 2 => array('thirdElement')
1192 )
1193 )
1194 )
1195 )
1196 )
1197 );
1198 ExtensionManagementUtility::addTcaSelectItem('testTable', 'testField', array('insertedElement'), $relativeToField, $relativePosition);
1199 $this->assertEquals($expectedResultArray, $GLOBALS['TCA']['testTable']['columns']['testField']['config']['items']);
1200 }
1201
1202 /////////////////////////////////////////
1203 // Tests concerning loadExtLocalconf
1204 /////////////////////////////////////////
1205 /**
1206 * @test
1207 */
1208 public function loadExtLocalconfDoesNotReadFromCacheIfCachingIsDenied()
1209 {
1210 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1211 $mockCacheManager = $this->getMock(CacheManager::class, array('getCache'));
1212 $mockCacheManager->expects($this->never())->method('getCache');
1213 ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1214 $GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage($this->getUniqueId()));
1215 ExtensionManagementUtility::loadExtLocalconf(false);
1216 }
1217
1218 /**
1219 * @test
1220 */
1221 public function loadExtLocalconfRequiresCacheFileIfExistsAndCachingIsAllowed()
1222 {
1223 $mockCache = $this->getMock(
1224 AbstractFrontend::class,
1225 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1226 array(),
1227 '',
1228 false
1229 );
1230 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1231 $mockCacheManager = $this->getMock(CacheManager::class, array('getCache'));
1232 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1233 ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1234 $mockCache->expects($this->any())->method('has')->will($this->returnValue(true));
1235 $mockCache->expects($this->once())->method('requireOnce');
1236 ExtensionManagementUtility::loadExtLocalconf(true);
1237 }
1238
1239 /////////////////////////////////////////
1240 // Tests concerning loadSingleExtLocalconfFiles
1241 /////////////////////////////////////////
1242 /**
1243 * @test
1244 * @expectedException \RuntimeException
1245 */
1246 public function loadSingleExtLocalconfFilesRequiresExtLocalconfFileRegisteredInGlobalTypo3LoadedExt()
1247 {
1248 $extensionName = $this->getUniqueId('foo');
1249 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
1250 $extLocalconfLocation = $packageManager->getPackage($extensionName)->getPackagePath() . 'ext_localconf.php';
1251 file_put_contents($extLocalconfLocation, "<?php\n\nthrow new RuntimeException('', 1340559079);\n\n?>");
1252 $GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($packageManager);
1253 ExtensionManagementUtilityAccessibleProxy::loadSingleExtLocalconfFiles();
1254 }
1255
1256
1257 /////////////////////////////////////////
1258 // Tests concerning addModule
1259 /////////////////////////////////////////
1260
1261 /**
1262 * Data provider for addModule tests
1263 * @return array
1264 */
1265 public function addModulePositionTestsDataProvider()
1266 {
1267 return array(
1268 'can add new main module if none exists' => array(
1269 'top',
1270 '',
1271 'newModule'
1272 ),
1273 'can add new sub module if no position specified' => array(
1274 '',
1275 'some,modules',
1276 'some,modules,newModule'
1277 ),
1278 'can add new sub module to top of module' => array(
1279 'top',
1280 'some,modules',
1281 'newModule,some,modules'
1282 ),
1283 'can add new sub module if bottom of module' => array(
1284 'bottom',
1285 'some,modules',
1286 'some,modules,newModule'
1287 ),
1288 'can add new sub module before specified sub module' => array(
1289 'before:modules',
1290 'some,modules',
1291 'some,newModule,modules'
1292 ),
1293 'can add new sub module after specified sub module' => array(
1294 'after:some',
1295 'some,modules',
1296 'some,newModule,modules'
1297 ),
1298 'can add new sub module at the bottom if specified sub module to add before does not exist' => array(
1299 'before:modules',
1300 'some,otherModules',
1301 'some,otherModules,newModule'
1302 ),
1303 'can add new sub module at the bottom if specified sub module to add after does not exist' => array(
1304 'after:some',
1305 'someOther,modules',
1306 'someOther,modules,newModule'
1307 ),
1308 );
1309 }
1310
1311 /**
1312 * @test
1313 * @dataProvider addModulePositionTestsDataProvider
1314 * @param $position
1315 * @param $existing
1316 * @param $expected
1317 */
1318 public function addModuleCanAddModule($position, $existing, $expected)
1319 {
1320 $mainModule = 'foobar';
1321 $subModule = 'newModule';
1322 if ($existing) {
1323 $GLOBALS['TBE_MODULES'][$mainModule] = $existing;
1324 }
1325
1326 ExtensionManagementUtility::addModule($mainModule, $subModule, $position);
1327
1328 $this->assertTrue(isset($GLOBALS['TBE_MODULES'][$mainModule]));
1329 $this->assertEquals($expected, $GLOBALS['TBE_MODULES'][$mainModule]);
1330 }
1331
1332 /////////////////////////////////////////
1333 // Tests concerning createExtLocalconfCacheEntry
1334 /////////////////////////////////////////
1335 /**
1336 * @test
1337 */
1338 public function createExtLocalconfCacheEntryWritesCacheEntryWithContentOfLoadedExtensionExtLocalconf()
1339 {
1340 $extensionName = $this->getUniqueId('foo');
1341 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
1342 $extLocalconfLocation = $packageManager->getPackage($extensionName)->getPackagePath() . 'ext_localconf.php';
1343 $uniqueStringInLocalconf = $this->getUniqueId('foo');
1344 file_put_contents($extLocalconfLocation, "<?php\n\n" . $uniqueStringInLocalconf . "\n\n?>");
1345 $GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($packageManager);
1346 $mockCache = $this->getMock(
1347 AbstractFrontend::class,
1348 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1349 array(),
1350 '',
1351 false
1352 );
1353 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1354 $mockCacheManager = $this->getMock(CacheManager::class, array('getCache'));
1355 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1356 ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1357 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInLocalconf), $this->anything());
1358 ExtensionManagementUtilityAccessibleProxy::createExtLocalconfCacheEntry();
1359 }
1360
1361 /**
1362 * @test
1363 */
1364 public function createExtLocalconfCacheEntryWritesCacheEntryWithExtensionContentOnlyIfExtLocalconfExists()
1365 {
1366 $extensionName = $this->getUniqueId('foo');
1367 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
1368 $GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($packageManager);
1369 $mockCache = $this->getMock(
1370 AbstractFrontend::class,
1371 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1372 array(),
1373 '',
1374 false
1375 );
1376 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1377 $mockCacheManager = $this->getMock(CacheManager::class, array('getCache'));
1378 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1379 ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1380 $mockCache->expects($this->once())
1381 ->method('set')
1382 ->with($this->anything(), $this->logicalNot($this->stringContains($extensionName)), $this->anything());
1383 ExtensionManagementUtilityAccessibleProxy::createExtLocalconfCacheEntry();
1384 }
1385
1386 /**
1387 * @test
1388 */
1389 public function createExtLocalconfCacheEntryWritesCacheEntryWithNoTags()
1390 {
1391 $mockCache = $this->getMock(
1392 AbstractFrontend::class,
1393 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1394 array(),
1395 '',
1396 false
1397 );
1398 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1399 $mockCacheManager = $this->getMock(CacheManager::class, array('getCache'));
1400 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1401 ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1402 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo(array()));
1403 $GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage($this->getUniqueId()));
1404 ExtensionManagementUtilityAccessibleProxy::createExtLocalconfCacheEntry();
1405 }
1406
1407 /////////////////////////////////////////
1408 // Tests concerning getExtLocalconfCacheIdentifier
1409 /////////////////////////////////////////
1410 /**
1411 * @test
1412 */
1413 public function getExtLocalconfCacheIdentifierCreatesSha1WithFourtyCharactersAndPrefix()
1414 {
1415 $prefix = 'ext_localconf_';
1416 $identifier = ExtensionManagementUtilityAccessibleProxy::getExtLocalconfCacheIdentifier();
1417 $this->assertStringStartsWith($prefix, $identifier);
1418 $sha1 = str_replace($prefix, '', $identifier);
1419 $this->assertEquals(40, strlen($sha1));
1420 }
1421
1422 /////////////////////////////////////////
1423 // Tests concerning loadBaseTca
1424 /////////////////////////////////////////
1425
1426 /**
1427 * @test
1428 */
1429 public function loadBaseTcaDoesNotReadFromCacheIfCachingIsDenied()
1430 {
1431 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1432 $mockCacheManager = $this->getMock(CacheManager::class, array('getCache'));
1433 $mockCacheManager->expects($this->never())->method('getCache');
1434 ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1435 ExtensionManagementUtilityAccessibleProxy::loadBaseTca(false);
1436 }
1437
1438 /**
1439 * @test
1440 */
1441 public function loadBaseTcaRequiresCacheFileIfExistsAndCachingIsAllowed()
1442 {
1443 $mockCache = $this->getMock(
1444 AbstractFrontend::class,
1445 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1446 array(),
1447 '',
1448 false
1449 );
1450 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1451 $mockCacheManager = $this->getMock(CacheManager::class, array('getCache'));
1452 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1453 ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1454 $mockCache->expects($this->any())->method('has')->will($this->returnValue(true));
1455 $mockCache->expects($this->once())->method('get')->willReturn('<?php ' . serialize(array('tca' => array(), 'categoryRegistry' => CategoryRegistry::getInstance())) . '?>');
1456 ExtensionManagementUtilityAccessibleProxy::loadBaseTca(true);
1457 }
1458
1459 /**
1460 * @test
1461 */
1462 public function loadBaseTcaCreatesCacheFileWithContentOfAnExtensionsConfigurationTcaPhpFile()
1463 {
1464 $extensionName = $this->getUniqueId('test_baseTca_');
1465 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
1466 $packagePath = $packageManager->getPackage($extensionName)->getPackagePath();
1467 GeneralUtility::mkdir($packagePath);
1468 GeneralUtility::mkdir($packagePath . 'Configuration/');
1469 GeneralUtility::mkdir($packagePath . 'Configuration/TCA/');
1470 $GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($packageManager);
1471 ExtensionManagementUtility::setPackageManager($packageManager);
1472 $uniqueTableName = $this->getUniqueId('table_name_');
1473 $uniqueStringInTableConfiguration = $this->getUniqueId('table_configuration_');
1474 $tableConfiguration = '<?php return array(\'foo\' => \'' . $uniqueStringInTableConfiguration . '\'); ?>';
1475 file_put_contents($packagePath . 'Configuration/TCA/' . $uniqueTableName . '.php', $tableConfiguration);
1476 $mockCache = $this->getMock(
1477 AbstractFrontend::class,
1478 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1479 array(),
1480 '',
1481 false
1482 );
1483 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1484 $mockCacheManager = $this->getMock(CacheManager::class, array('getCache'));
1485 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1486 ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1487 $mockCache->expects($this->once())->method('has')->will($this->returnValue(false));
1488 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInTableConfiguration), $this->anything());
1489 ExtensionManagementUtility::loadBaseTca(true);
1490 }
1491
1492 /**
1493 * @test
1494 */
1495 public function loadBaseTcaWritesCacheEntryWithNoTags()
1496 {
1497 $mockCache = $this->getMock(
1498 AbstractFrontend::class,
1499 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1500 array(),
1501 '',
1502 false
1503 );
1504 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1505 $mockCacheManager = $this->getMock(CacheManager::class, array('getCache'));
1506 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1507 ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1508 $mockCache->expects($this->once())->method('has')->will($this->returnValue(false));
1509 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo(array()));
1510 ExtensionManagementUtilityAccessibleProxy::loadBaseTca();
1511 }
1512
1513 /////////////////////////////////////////
1514 // Tests concerning getBaseTcaCacheIdentifier
1515 /////////////////////////////////////////
1516
1517 /**
1518 * @test
1519 */
1520 public function getBaseTcaCacheIdentifierCreatesSha1WithFourtyCharactersAndPrefix()
1521 {
1522 $prefix = 'tca_base_';
1523 $identifier = ExtensionManagementUtilityAccessibleProxy::getBaseTcaCacheIdentifier();
1524 $this->assertStringStartsWith($prefix, $identifier);
1525 $sha1 = str_replace($prefix, '', $identifier);
1526 $this->assertEquals(40, strlen($sha1));
1527 }
1528
1529 /////////////////////////////////////////
1530 // Tests concerning loadExtTables
1531 /////////////////////////////////////////
1532 /**
1533 * @test
1534 */
1535 public function loadExtTablesDoesNotReadFromCacheIfCachingIsDenied()
1536 {
1537 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1538 $mockCacheManager = $this->getMock(CacheManager::class, array('getCache'));
1539 $mockCacheManager->expects($this->never())->method('getCache');
1540 ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1541 $GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage($this->getUniqueId()));
1542 ExtensionManagementUtility::loadExtLocalconf(false);
1543 }
1544
1545 /**
1546 * @test
1547 */
1548 public function loadExtTablesRequiresCacheFileIfExistsAndCachingIsAllowed()
1549 {
1550 $mockCache = $this->getMock(
1551 AbstractFrontend::class,
1552 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1553 array(),
1554 '',
1555 false
1556 );
1557 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1558 $mockCacheManager = $this->getMock(CacheManager::class, array('getCache'));
1559 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1560 ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1561 $mockCache->expects($this->any())->method('has')->will($this->returnValue(true));
1562 $mockCache->expects($this->once())->method('requireOnce');
1563 // Reset the internal cache access tracking variable of extMgm
1564 // This method is only in the ProxyClass!
1565 ExtensionManagementUtilityAccessibleProxy::resetExtTablesWasReadFromCacheOnceBoolean();
1566 ExtensionManagementUtility::loadExtTables(true);
1567 }
1568
1569 /////////////////////////////////////////
1570 // Tests concerning createExtTablesCacheEntry
1571 /////////////////////////////////////////
1572 /**
1573 * @test
1574 */
1575 public function createExtTablesCacheEntryWritesCacheEntryWithContentOfLoadedExtensionExtTables()
1576 {
1577 $extensionName = $this->getUniqueId('foo');
1578 $extTablesLocation = PATH_site . 'typo3temp/' . $this->getUniqueId('test_ext_tables') . '.php';
1579 $this->testFilesToDelete[] = $extTablesLocation;
1580 $uniqueStringInTables = $this->getUniqueId('foo');
1581 file_put_contents($extTablesLocation, "<?php\n\n$uniqueStringInTables\n\n?>");
1582 $GLOBALS['TYPO3_LOADED_EXT'] = array(
1583 $extensionName => array(
1584 'ext_tables.php' => $extTablesLocation
1585 )
1586 );
1587 $mockCache = $this->getMock(
1588 AbstractFrontend::class,
1589 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1590 array(),
1591 '',
1592 false
1593 );
1594 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1595 $mockCacheManager = $this->getMock(CacheManager::class, array('getCache'));
1596 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1597 ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1598 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInTables), $this->anything());
1599 ExtensionManagementUtilityAccessibleProxy::createExtTablesCacheEntry();
1600 }
1601
1602 /**
1603 * @test
1604 */
1605 public function createExtTablesCacheEntryWritesCacheEntryWithExtensionContentOnlyIfExtTablesExists()
1606 {
1607 $extensionName = $this->getUniqueId('foo');
1608 $GLOBALS['TYPO3_LOADED_EXT'] = array(
1609 $extensionName => array(),
1610 );
1611 $mockCache = $this->getMock(
1612 AbstractFrontend::class,
1613 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1614 array(),
1615 '',
1616 false
1617 );
1618 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1619 $mockCacheManager = $this->getMock(CacheManager::class, array('getCache'));
1620 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1621 ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1622 $mockCache->expects($this->once())
1623 ->method('set')
1624 ->with($this->anything(), $this->logicalNot($this->stringContains($extensionName)), $this->anything());
1625 ExtensionManagementUtilityAccessibleProxy::createExtTablesCacheEntry();
1626 }
1627
1628 /**
1629 * @test
1630 */
1631 public function createExtTablesCacheEntryWritesCacheEntryWithNoTags()
1632 {
1633 $mockCache = $this->getMock(
1634 AbstractFrontend::class,
1635 array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1636 array(),
1637 '',
1638 false
1639 );
1640 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1641 $mockCacheManager = $this->getMock(CacheManager::class, array('getCache'));
1642 $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1643 ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1644 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo(array()));
1645 $GLOBALS['TYPO3_LOADED_EXT'] = new LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage($this->getUniqueId()));
1646 ExtensionManagementUtilityAccessibleProxy::createExtTablesCacheEntry();
1647 }
1648
1649 /////////////////////////////////////////
1650 // Tests concerning getExtTablesCacheIdentifier
1651 /////////////////////////////////////////
1652 /**
1653 * @test
1654 */
1655 public function getExtTablesCacheIdentifierCreatesSha1WithFourtyCharactersAndPrefix()
1656 {
1657 $prefix = 'ext_tables_';
1658 $identifier = ExtensionManagementUtilityAccessibleProxy::getExtTablesCacheIdentifier();
1659 $this->assertStringStartsWith($prefix, $identifier);
1660 $sha1 = str_replace($prefix, '', $identifier);
1661 $this->assertEquals(40, strlen($sha1));
1662 }
1663
1664 /////////////////////////////////////////
1665 // Tests concerning removeCacheFiles
1666 /////////////////////////////////////////
1667 /**
1668 * @test
1669 */
1670 public function removeCacheFilesFlushesSystemCaches()
1671 {
1672 /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */
1673 $mockCacheManager = $this->getMock(CacheManager::class, array('flushCachesInGroup'));
1674 $mockCacheManager->expects($this->once())->method('flushCachesInGroup')->with('system');
1675 ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1676 ExtensionManagementUtility::removeCacheFiles();
1677 }
1678
1679 /////////////////////////////////////////
1680 // Tests concerning loadNewTcaColumnsConfigFiles
1681 /////////////////////////////////////////
1682
1683 /**
1684 * @test
1685 * @expectedException \RuntimeException
1686 */
1687 public function loadNewTcaColumnsConfigFilesIncludesDefinedDynamicConfigFileIfNoColumnsExist()
1688 {
1689 $GLOBALS['TCA'] = array(
1690 'test' => array(
1691 'ctrl' => array(
1692 'dynamicConfigFile' => __DIR__ . '/Fixtures/RuntimeException.php'
1693 ),
1694 ),
1695 );
1696 ExtensionManagementUtility::loadNewTcaColumnsConfigFiles();
1697 }
1698
1699 /**
1700 * @test
1701 */
1702 public function loadNewTcaColumnsConfigFilesDoesNotIncludeFileIfColumnsExist()
1703 {
1704 $GLOBALS['TCA'] = array(
1705 'test' => array(
1706 'ctrl' => array(
1707 'dynamicConfigFile' => __DIR__ . '/Fixtures/RuntimeException.php'
1708 ),
1709 'columns' => array(
1710 'foo' => 'bar',
1711 ),
1712 ),
1713 );
1714 ExtensionManagementUtility::loadNewTcaColumnsConfigFiles();
1715 }
1716
1717 /////////////////////////////////////////
1718 // Tests concerning getExtensionVersion
1719 /////////////////////////////////////////
1720 /**
1721 * Data provider for negative getExtensionVersion() tests.
1722 *
1723 * @return array
1724 */
1725 public function getExtensionVersionFaultyDataProvider()
1726 {
1727 return array(
1728 array(''),
1729 array(0),
1730 array(new \stdClass()),
1731 array(true)
1732 );
1733 }
1734
1735 /**
1736 * @test
1737 * @expectedException \InvalidArgumentException
1738 * @dataProvider getExtensionVersionFaultyDataProvider
1739 * @param $key
1740 * @throws \TYPO3\CMS\Core\Package\Exception
1741 */
1742 public function getExtensionVersionForFaultyExtensionKeyThrowsException($key)
1743 {
1744 ExtensionManagementUtility::getExtensionVersion($key);
1745 }
1746
1747 /**
1748 * @test
1749 */
1750 public function getExtensionVersionForNotLoadedExtensionReturnsEmptyString()
1751 {
1752 ExtensionManagementUtility::clearExtensionKeyMap();
1753 $uniqueSuffix = $this->getUniqueId('test');
1754 $extensionKey = 'unloadedextension' . $uniqueSuffix;
1755 $this->assertEquals('', ExtensionManagementUtility::getExtensionVersion($extensionKey));
1756 }
1757
1758 /**
1759 * @test
1760 */
1761 public function getExtensionVersionForLoadedExtensionReturnsExtensionVersion()
1762 {
1763 ExtensionManagementUtility::clearExtensionKeyMap();
1764 $uniqueSuffix = $this->getUniqueId('test');
1765 $extensionKey = 'unloadedextension' . $uniqueSuffix;
1766 $packageMetaData = $this->getMock(MetaData::class, array('getVersion'), array($extensionKey));
1767 $packageMetaData->expects($this->any())->method('getVersion')->will($this->returnValue('1.2.3'));
1768 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionKey, array('getPackagePath', 'getPackageKey', 'getPackageMetaData'));
1769 /** @var \PHPUnit_Framework_MockObject_MockObject $package */
1770 $package = $packageManager->getPackage($extensionKey);
1771 $package->expects($this->any())
1772 ->method('getPackageMetaData')
1773 ->will($this->returnValue($packageMetaData));
1774 ExtensionManagementUtility::setPackageManager($packageManager);
1775 $this->assertEquals('1.2.3', ExtensionManagementUtility::getExtensionVersion($extensionKey));
1776 }
1777
1778 /////////////////////////////////////////
1779 // Tests concerning loadExtension
1780 /////////////////////////////////////////
1781 /**
1782 * @test
1783 * @expectedException \RuntimeException
1784 */
1785 public function loadExtensionThrowsExceptionIfExtensionIsLoaded()
1786 {
1787 $extensionKey = $this->getUniqueId('test');
1788 $packageManager = $this->createMockPackageManagerWithMockPackage($extensionKey);
1789 ExtensionManagementUtility::setPackageManager($packageManager);
1790 ExtensionManagementUtility::loadExtension($extensionKey);
1791 }
1792
1793 /////////////////////////////////////////
1794 // Tests concerning unloadExtension
1795 /////////////////////////////////////////
1796 /**
1797 * @test
1798 * @expectedException \RuntimeException
1799 */
1800 public function unloadExtensionThrowsExceptionIfExtensionIsNotLoaded()
1801 {
1802 $packageName = $this->getUniqueId('foo');
1803 /** @var PackageManager|\PHPUnit_Framework_MockObject_MockObject $packageManager */
1804 $packageManager = $this->getMock(PackageManager::class, array('isPackageActive'));
1805 $packageManager->expects($this->once())
1806 ->method('isPackageActive')
1807 ->with($this->equalTo($packageName))
1808 ->will($this->returnValue(false));
1809 ExtensionManagementUtility::setPackageManager($packageManager);
1810 ExtensionManagementUtility::unloadExtension($packageName);
1811 }
1812
1813 /**
1814 * @test
1815 */
1816 public function unloadExtensionCallsPackageManagerToDeactivatePackage()
1817 {
1818 $packageName = $this->getUniqueId('foo');
1819 /** @var PackageManager|\PHPUnit_Framework_MockObject_MockObject $packageManager */
1820 $packageManager = $this->getMock(
1821 PackageManager::class,
1822 array('isPackageActive', 'deactivatePackage')
1823 );
1824 $packageManager->expects($this->any())
1825 ->method('isPackageActive')
1826 ->will($this->returnValue(true));
1827 $packageManager->expects($this->once())
1828 ->method('deactivatePackage')
1829 ->with($packageName);
1830 ExtensionManagementUtility::setPackageManager($packageManager);
1831 ExtensionManagementUtility::unloadExtension($packageName);
1832 }
1833
1834 /////////////////////////////////////////
1835 // Tests concerning makeCategorizable
1836 /////////////////////////////////////////
1837 /**
1838 * @test
1839 */
1840 public function doesMakeCategorizableCallsTheCategoryRegistryWithDefaultFieldName()
1841 {
1842 $extensionKey = $this->getUniqueId('extension');
1843 $tableName = $this->getUniqueId('table');
1844
1845 /** @var CategoryRegistry|\PHPUnit_Framework_MockObject_MockObject $registryMock */
1846 $registryMock = $this->getMock(CategoryRegistry::class);
1847 $registryMock->expects($this->once())->method('add')->with($extensionKey, $tableName, 'categories', array());
1848 GeneralUtility::setSingletonInstance(CategoryRegistry::class, $registryMock);
1849 ExtensionManagementUtility::makeCategorizable($extensionKey, $tableName);
1850 }
1851
1852 /**
1853 * @test
1854 */
1855 public function doesMakeCategorizableCallsTheCategoryRegistryWithFieldName()
1856 {
1857 $extensionKey = $this->getUniqueId('extension');
1858 $tableName = $this->getUniqueId('table');
1859 $fieldName = $this->getUniqueId('field');
1860
1861 /** @var CategoryRegistry|\PHPUnit_Framework_MockObject_MockObject $registryMock */
1862 $registryMock = $this->getMock(CategoryRegistry::class);
1863 $registryMock->expects($this->once())->method('add')->with($extensionKey, $tableName, $fieldName, array());
1864 GeneralUtility::setSingletonInstance(CategoryRegistry::class, $registryMock);
1865 ExtensionManagementUtility::makeCategorizable($extensionKey, $tableName, $fieldName);
1866 }
1867
1868 ///////////////////////////////
1869 // Tests concerning addPlugin
1870 ///////////////////////////////
1871
1872 /**
1873 * @test
1874 */
1875 public function addPluginSetsTcaCorrectlyForGivenExtKeyAsParameter()
1876 {
1877 $extKey = 'indexed_search';
1878 $GLOBALS['TYPO3_LOADED_EXT'] = array();
1879 $GLOBALS['TYPO3_LOADED_EXT'][$extKey]['ext_icon'] = 'foo.gif';
1880 $expectedTCA = array(
1881 array(
1882 'label',
1883 $extKey,
1884 'EXT:' . $extKey . '/foo.gif'
1885 )
1886 );
1887 $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'] = array();
1888 ExtensionManagementUtility::addPlugin(array('label', $extKey), 'list_type', $extKey);
1889 $this->assertEquals($expectedTCA, $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items']);
1890 }
1891
1892 /**
1893 * @test
1894 */
1895 public function addPluginSetsTcaCorrectlyForGivenExtKeyAsGlobal()
1896 {
1897 $extKey = 'indexed_search';
1898 $GLOBALS['TYPO3_LOADED_EXT'] = array();
1899 $GLOBALS['TYPO3_LOADED_EXT'][$extKey]['ext_icon'] = 'foo.gif';
1900 $GLOBALS['_EXTKEY'] = $extKey;
1901 $expectedTCA = array(
1902 array(
1903 'label',
1904 $extKey,
1905 'EXT:' . $extKey . '/foo.gif'
1906 )
1907 );
1908 $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'] = array();
1909 ExtensionManagementUtility::addPlugin(array('label', $extKey));
1910 $this->assertEquals($expectedTCA, $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items']);
1911 }
1912
1913 /**
1914 * @test
1915 * @expectedException \RuntimeException
1916 */
1917 public function addPluginThrowsExceptionForMissingExtkey()
1918 {
1919 ExtensionManagementUtility::addPlugin('test');
1920 }
1921 }