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