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