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