TYPO3 CMS  TYPO3_6-2
ExtensionManagementUtilityTest.php
Go to the documentation of this file.
1 <?php
3 
19 
27 
31  protected $singletonInstances = array();
32 
39  protected $testFilesToDelete = array();
40 
45 
46  public function setUp() {
49  $this->testFilesToDelete = array();
50  $this->backUpPackageManager = ExtensionManagementUtilityAccessibleProxy::getPackageManager();
52  }
53 
54  public function tearDown() {
56  foreach ($this->testFilesToDelete as $absoluteFileName) {
58  }
59  if (file_exists(PATH_site . 'typo3temp/test_ext/')) {
60  \TYPO3\CMS\Core\Utility\GeneralUtility::rmdir(PATH_site . 'typo3temp/test_ext/', TRUE);
61  }
62  ExtensionManagementUtilityAccessibleProxy::setPackageManager($this->backUpPackageManager);
63  ExtensionManagementUtilityAccessibleProxy::setCacheManager(NULL);
64  $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray($this->backUpPackageManager);
66  parent::tearDown();
67  }
68 
75  protected function createAccessibleProxyClass() {
76  $className = 'ExtensionManagementUtilityAccessibleProxy';
77  if (!class_exists(__NAMESPACE__ . '\\' . $className, FALSE)) {
78  eval(
79  'namespace ' . __NAMESPACE__ . ';' .
80  'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\Utility\\ExtensionManagementUtility {' .
81  ' static public function setCacheManager(\TYPO3\CMS\Core\Cache\CacheManager $cacheManager = NULL) {'.
82  ' static::$cacheManager = $cacheManager;'.
83  ' }'.
84  ' public static function getPackageManager() {' .
85  ' return static::$packageManager;' .
86  ' }' .
87  ' public static function createTypo3LoadedExtensionInformationArray() {' .
88  ' return parent::createTypo3LoadedExtensionInformationArray();' .
89  ' }' .
90  ' public static function getTypo3LoadedExtensionInformationCacheIdentifier() {' .
91  ' return parent::getTypo3LoadedExtensionInformationCacheIdentifier();' .
92  ' }' .
93  ' public static function getExtLocalconfCacheIdentifier() {' .
94  ' return parent::getExtLocalconfCacheIdentifier();' .
95  ' }' .
96  ' public static function loadSingleExtLocalconfFiles() {' .
97  ' return parent::loadSingleExtLocalconfFiles();' .
98  ' }' .
99  ' public static function getBaseTcaCacheIdentifier() {' .
100  ' return parent::getBaseTcaCacheIdentifier();' .
101  ' }' .
102  ' public static function resetExtTablesWasReadFromCacheOnceBoolean() {' .
103  ' self::$extTablesWasReadFromCacheOnce = FALSE;' .
104  ' }' .
105  ' public static function createExtLocalconfCacheEntry() {' .
106  ' return parent::createExtLocalconfCacheEntry();' .
107  ' }' .
108  ' public static function createExtTablesCacheEntry() {' .
109  ' return parent::createExtTablesCacheEntry();' .
110  ' }' .
111  ' public static function getExtTablesCacheIdentifier() {' .
112  ' return parent::getExtTablesCacheIdentifier();' .
113  ' }' .
114  ' public static function buildBaseTcaFromSingleFiles() {' .
115  ' $GLOBALS[\'TCA\'] = array();' .
116  ' }' .
117  ' public static function emitTcaIsBeingBuiltSignal(array $tca) {' .
118  ' }' .
119  ' public static function removeDuplicatesForInsertion($insertionList, $list = \'\') {' .
120  ' return parent::removeDuplicatesForInsertion($insertionList, $list);' .
121  ' }' .
122  '}'
123  );
124  }
125  }
126 
132  protected function createMockPackageManagerWithMockPackage($packageKey, $packageMethods = array('getPackagePath', 'getPackageKey')) {
133  $packagePath = PATH_site . 'typo3temp/test_ext/' . $packageKey . '/';
135  $package = $this->getMockBuilder('TYPO3\\CMS\\Core\\Package\\Package')
136  ->disableOriginalConstructor()
137  ->setMethods($packageMethods)
138  ->getMock();
139  $packageManager = $this->getMock(
140  'TYPO3\\CMS\\Core\\Package\\PackageManager',
141  array('isPackageActive', 'getPackage', 'getActivePackages')
142  );
143  $package->expects($this->any())
144  ->method('getPackagePath')
145  ->will($this->returnValue($packagePath));
146  $package->expects($this->any())
147  ->method('getPackageKey')
148  ->will($this->returnValue($packageKey));
149  $packageManager->expects($this->any())
150  ->method('isPackageActive')
151  ->will($this->returnValueMap(array(
152  array(NULL, FALSE),
153  array($packageKey, TRUE)
154  )));
155  $packageManager->expects($this->any())
156  ->method('getPackage')
157  ->with($this->equalTo($packageKey))
158  ->will($this->returnValue($package));
159  $packageManager->expects($this->any())
160  ->method('getActivePackages')
161  ->will($this->returnValue(array($packageKey => $package)));
162  return $packageManager;
163  }
164 
166  // Tests concerning isLoaded
168 
172  $this->assertTrue(ExtensionManagementUtility::isLoaded('cms'));
173  }
174 
179  $this->assertFalse(ExtensionManagementUtility::isLoaded($this->getUniqueId('foobar'), FALSE));
180  }
181 
187  $this->assertFalse(ExtensionManagementUtility::isLoaded($this->getUniqueId('foobar'), TRUE));
188  }
189 
191  // Tests concerning extPath
193 
198  $packageName = $this->getUniqueId('foo');
199  $packageManager = $this->getMock('TYPO3\\CMS\\Core\\Package\\PackageManager', array('isPackageActive'));
200  $packageManager->expects($this->once())
201  ->method('isPackageActive')
202  ->with($this->equalTo($packageName))
203  ->will($this->returnValue(FALSE));
206  }
207 
211  public function extPathAppendsScriptNameToPath() {
212  $package = $this->getMockBuilder('TYPO3\\CMS\\Core\\Package\\Package')
213  ->disableOriginalConstructor()
214  ->setMethods(array('getPackagePath'))
215  ->getMock();
216  $packageManager = $this->getMock('TYPO3\\CMS\\Core\\Package\\PackageManager', array('isPackageActive', 'getPackage'));
217  $package->expects($this->once())
218  ->method('getPackagePath')
219  ->will($this->returnValue(PATH_site . 'foo/'));
220  $packageManager->expects($this->once())
221  ->method('isPackageActive')
222  ->with($this->equalTo('foo'))
223  ->will($this->returnValue(TRUE));
224  $packageManager->expects($this->once())
225  ->method('getPackage')
226  ->with('foo')
227  ->will($this->returnValue($package));
229  $this->assertSame(PATH_site . 'foo/bar.txt', ExtensionManagementUtility::extPath('foo', 'bar.txt'));
230  }
231 
233  // Utility functions
235 
241  private function generateTCAForTable($table) {
242  $tca = array();
243  $tca[$table] = array();
244  $tca[$table]['columns'] = array(
245  'fieldA' => array(),
246  'fieldC' => array()
247  );
248  $tca[$table]['types'] = array(
249  'typeA' => array('showitem' => 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldC1, fieldD, fieldD1'),
250  'typeB' => array('showitem' => 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldC1, fieldD, fieldD1'),
251  'typeC' => array('showitem' => 'fieldC;;paletteD')
252  );
253  $tca[$table]['palettes'] = array(
254  'paletteA' => array('showitem' => 'fieldX, fieldX1, fieldY'),
255  'paletteB' => array('showitem' => 'fieldX, fieldX1, fieldY'),
256  'paletteC' => array('showitem' => 'fieldX, fieldX1, fieldY'),
257  'paletteD' => array('showitem' => 'fieldX, fieldX1, fieldY')
258  );
259  return $tca;
260  }
261 
267  public function extensionKeyDataProvider() {
268  return array(
269  'Without underscores' => array(
270  'testkey',
271  'tx_testkey'
272  ),
273  'With underscores' => array(
274  'this_is_a_test_extension',
275  'tx_thisisatestextension'
276  ),
277  'With user prefix and without underscores' => array(
278  'user_testkey',
279  'user_testkey'
280  ),
281  'With user prefix and with underscores' => array(
282  'user_test_key',
283  'user_testkey'
284  ),
285  );
286  }
287 
294  public function getClassNamePrefixForExtensionKey($extensionName, $expectedPrefix) {
295  $this->assertSame($expectedPrefix, ExtensionManagementUtility::getCN($extensionName));
296  }
297 
299  // Tests concerning getExtensionKeyByPrefix
301 
307  $uniqueSuffix = $this->getUniqueId('test');
308  $extensionKey = 'tt_news' . $uniqueSuffix;
309  $extensionPrefix = 'tx_ttnews' . $uniqueSuffix;
310  $package = $this->getMockBuilder('TYPO3\\CMS\\Core\\Package\\Package')
311  ->disableOriginalConstructor()
312  ->setMethods(array('getPackageKey'))
313  ->getMock();
314  $package->expects($this->exactly(2))
315  ->method('getPackageKey')
316  ->will($this->returnValue($extensionKey));
317  $packageManager = $this->getMock('TYPO3\\CMS\\Core\\Package\\PackageManager', array('getActivePackages'));
318  $packageManager->expects($this->once())
319  ->method('getActivePackages')
320  ->will($this->returnValue(array($extensionKey => $package)));
322  $this->assertEquals($extensionKey, ExtensionManagementUtility::getExtensionKeyByPrefix($extensionPrefix));
323  }
324 
331  $uniqueSuffix = $this->getUniqueId('test');
332  $extensionKey = 'kickstarter' . $uniqueSuffix;
333  $extensionPrefix = 'tx_kickstarter' . $uniqueSuffix;
334  $package = $this->getMockBuilder('TYPO3\\CMS\\Core\\Package\\Package')
335  ->disableOriginalConstructor()
336  ->setMethods(array('getPackageKey'))
337  ->getMock();
338  $package->expects($this->exactly(2))
339  ->method('getPackageKey')
340  ->will($this->returnValue($extensionKey));
341  $packageManager = $this->getMock('TYPO3\\CMS\\Core\\Package\\PackageManager', array('getActivePackages'));
342  $packageManager->expects($this->once())
343  ->method('getActivePackages')
344  ->will($this->returnValue(array($extensionKey => $package)));
346  $this->assertEquals($extensionKey, ExtensionManagementUtility::getExtensionKeyByPrefix($extensionPrefix));
347  }
348 
355  $uniqueSuffix = $this->getUniqueId('test');
356  $extensionKey = 'unloadedextension' . $uniqueSuffix;
357  $extensionPrefix = 'tx_unloadedextension' . $uniqueSuffix;
358  $this->assertFalse(ExtensionManagementUtility::getExtensionKeyByPrefix($extensionPrefix));
359  }
360 
362  // Tests concerning addToAllTCAtypes
364 
371  $table = $this->getUniqueId('tx_coretest_table');
372  $GLOBALS['TCA'] = $this->generateTCAForTable($table);
373  ExtensionManagementUtility::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'before:fieldD');
374  // Checking typeA:
375  $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldC1, newA, newB, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
376  // Checking typeB:
377  $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldC1, newA, newB, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
378  }
379 
387  $table = $this->getUniqueId('tx_coretest_table');
388  $GLOBALS['TCA'] = $this->generateTCAForTable($table);
389  ExtensionManagementUtility::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'after:fieldC');
390  // Checking typeA:
391  $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
392  // Checking typeB:
393  $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
394  }
395 
403  $table = $this->getUniqueId('tx_coretest_table');
404  $GLOBALS['TCA'] = $this->generateTCAForTable($table);
405  ExtensionManagementUtility::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', 'typeA', 'before:fieldD');
406  // Checking typeA:
407  $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldC1, newA, newB, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
408  // Checking typeB:
409  $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
410  }
411 
419  $table = $this->getUniqueId('tx_coretest_table');
420  $GLOBALS['TCA'] = $this->generateTCAForTable($table);
421  ExtensionManagementUtility::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', 'typeA', 'after:fieldC');
422  // Checking typeA:
423  $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
424  // Checking typeB:
425  $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldC1, fieldD, fieldD1', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
426  }
427 
432  {
433  $table = $this->getUniqueId('tx_coretest_table');
434  $GLOBALS['TCA'] = $this->generateTCAForTable($table);
435  ExtensionManagementUtility::addToAllTCAtypes($table, 'field', 'typeA', 'after:fieldD1');
436 
437  $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldC1, fieldD, fieldD1, field', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
438  }
439 
447  $table = $this->getUniqueId('tx_coretest_table');
448  $GLOBALS['TCA'] = $this->generateTCAForTable($table);
449  $typesBefore = $GLOBALS['TCA'][$table]['types'];
450  ExtensionManagementUtility::addToAllTCAtypes($table, 'fieldZ', '', 'replace:fieldX');
451  $this->assertEquals($typesBefore, $GLOBALS['TCA'][$table]['types'], 'It\'s wrong that the "types" array changes here - the replaced field is only on palettes');
452  // unchanged because the palette is not used
453  $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
454  $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
455  // changed
456  $this->assertEquals('fieldZ, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
457  $this->assertEquals('fieldZ, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
458  }
459 
464  $table = $this->getUniqueId('tx_coretest_table');
465  $GLOBALS['TCA'] = $this->generateTCAForTable($table);
466  $typesBefore = $GLOBALS['TCA'][$table]['types'];
467  ExtensionManagementUtility::addToAllTCAtypes($table, 'fieldX;;foo;;', '', 'replace:fieldX');
468  $this->assertEquals($typesBefore, $GLOBALS['TCA'][$table]['types'], 'It\'s wrong that the "types" array changes here - the replaced field is only on palettes');
469  // unchanged because the palette is not used
470  $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
471  $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
472  // changed
473  $this->assertEquals('fieldX;;foo;;, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
474  $this->assertEquals('fieldX;;foo;;, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
475  }
476 
478  // Tests concerning addFieldsToAllPalettesOfField
480 
487  $table = $this->getUniqueId('tx_coretest_table');
488  $GLOBALS['TCA'] = $this->generateTCAForTable($table);
489  ExtensionManagementUtility::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'before:fieldY');
490  $this->assertEquals('fieldX, fieldX1, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
491  }
492 
500  $table = $this->getUniqueId('tx_coretest_table');
501  $GLOBALS['TCA'] = $this->generateTCAForTable($table);
502  ExtensionManagementUtility::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'after:fieldX');
503  $this->assertEquals('fieldX, newA, newB, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
504  }
505 
513  $table = $this->getUniqueId('tx_coretest_table');
514  $GLOBALS['TCA'] = $this->generateTCAForTable($table);
515  ExtensionManagementUtility::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'after:' . $this->getUniqueId('notExisting'));
516  $this->assertEquals('fieldX, fieldX1, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
517  }
518 
523  return array(
524  'Simple' => array(
525  'field_b, field_d, field_c',
526  'field_a, field_b, field_c',
527  'field_d'
528  ),
529  'with linebreaks' => array(
530  'field_b, --linebreak--, field_d, --linebreak--, field_c',
531  'field_a, field_b, field_c',
532  '--linebreak--, field_d, --linebreak--'
533  ),
534  'with linebreaks in list and insertion list' => array(
535  'field_b, --linebreak--, field_d, --linebreak--, field_c',
536  'field_a, field_b, --linebreak--, field_c',
537  '--linebreak--, field_d, --linebreak--'
538  ),
539  'with configuration in list' => array(
540  'field_b, field_d, field_c;;;4-4-4',
541  'field_a, field_b;;;;2-2-2, field_c;;;;3-3-3',
542  'field_d',
543  ),
544  'with configuration in list and insertion list' => array(
545  'field_b, field_d;;;3-3-3, field_c;;;4-4-4',
546  'field_a, field_b;;;;2-2-2, field_c;;;;3-3-3',
547  'field_d;;;3-3-3',
548  ),
549  );
550  }
551 
559  public function removeDuplicatesForInsertionRemovesDuplicates($insertionList, $list, $expected) {
560  $result = ExtensionManagementUtilityAccessibleProxy::removeDuplicatesForInsertion($insertionList, $list);
561  $this->assertSame($expected, $result);
562  }
563 
571  $table = $this->getUniqueId('tx_coretest_table');
572  $GLOBALS['TCA'] = $this->generateTCAForTable($table);
573  ExtensionManagementUtility::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'before:fieldY');
574  $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
575  $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
576  $this->assertEquals('fieldX, fieldX1, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
577  $this->assertEquals('fieldX, fieldX1, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
578  }
579 
587  $table = $this->getUniqueId('tx_coretest_table');
588  $GLOBALS['TCA'] = $this->generateTCAForTable($table);
589  ExtensionManagementUtility::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'after:fieldX');
590  $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
591  $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
592  $this->assertEquals('fieldX, newA, newB, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
593  $this->assertEquals('fieldX, newA, newB, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
594  }
595 
603  $table = $this->getUniqueId('tx_coretest_table');
604  $GLOBALS['TCA'] = $this->generateTCAForTable($table);
605  ExtensionManagementUtility::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'after:' . $this->getUniqueId('notExisting'));
606  $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
607  $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
608  $this->assertEquals('fieldX, fieldX1, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
609  $this->assertEquals('fieldX, fieldX1, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
610  }
611 
619  $table = $this->getUniqueId('tx_coretest_table');
620  $GLOBALS['TCA'] = $this->generateTCAForTable($table);
621  ExtensionManagementUtility::addFieldsToAllPalettesOfField($table, 'fieldA', 'newA, newA, newB, fieldX');
622  $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
623  $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
624  $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
625  $this->assertEquals('fieldX, fieldX1, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
626  $this->assertEquals('newA, newB, fieldX', $GLOBALS['TCA'][$table]['palettes']['generatedFor-fieldA']['showitem']);
627  }
628 
634  return array(
635  'normal characters' => array(
636  'tr0',
637  'tr0',
638  ),
639  'newlines' => array(
640  "test\n",
641  'test',
642  ),
643  'newlines with carriage return' => array(
644  "test\r\n",
645  'test',
646  ),
647  'tabs' => array(
648  "test\t",
649  'test',
650  ),
651  'commas' => array(
652  "test,",
653  'test',
654  ),
655  'multiple commas with trailing spaces' => array(
656  "test,,\t, \r\n",
657  'test',
658  ),
659  );
660  }
661 
666  public function executePositionedStringInsertionTrimsCorrectCharacters($string, $expectedResult) {
667  $extensionManagementUtility = $this->getAccessibleMock('\\TYPO3\\CMS\\Core\\Utility\\ExtensionManagementUtility', array('dummy'));
668  $string = $extensionManagementUtility->_call('executePositionedStringInsertion', $string, '');
669  $this->assertEquals($expectedResult, $string);
670  }
671 
673  // Tests concerning addTcaSelectItem
675 
680  ExtensionManagementUtility::addTcaSelectItem(array(), 'foo', array());
681  }
682 
688  ExtensionManagementUtility::addTcaSelectItem('foo', array(), array());
689  }
690 
696  ExtensionManagementUtility::addTcaSelectItem('foo', 'bar', array(), array());
697  }
698 
704  ExtensionManagementUtility::addTcaSelectItem('foo', 'bar', array(), 'foo', array());
705  }
706 
712  ExtensionManagementUtility::addTcaSelectItem('foo', 'bar', array(), 'foo', 'not allowed keyword');
713  }
714 
720  $GLOBALS['TCA'] = array();
721  ExtensionManagementUtility::addTcaSelectItem('foo', 'bar', array());
722  }
723 
727  public function addTcaSelectItemDataProvider() {
728  // Every array splits into:
729  // - relativeToField
730  // - relativePosition
731  // - expectedResultArray
732  return array(
733  'add at end of array' => array(
734  '',
735  '',
736  array(
737  0 => array('firstElement'),
738  1 => array('matchMe'),
739  2 => array('thirdElement'),
740  3 => array('insertedElement')
741  )
742  ),
743  'replace element' => array(
744  'matchMe',
745  'replace',
746  array(
747  0 => array('firstElement'),
748  1 => array('insertedElement'),
749  2 => array('thirdElement')
750  )
751  ),
752  'add element after' => array(
753  'matchMe',
754  'after',
755  array(
756  0 => array('firstElement'),
757  1 => array('matchMe'),
758  2 => array('insertedElement'),
759  3 => array('thirdElement')
760  )
761  ),
762  'add element before' => array(
763  'matchMe',
764  'before',
765  array(
766  0 => array('firstElement'),
767  1 => array('insertedElement'),
768  2 => array('matchMe'),
769  3 => array('thirdElement')
770  )
771  ),
772  'add at end if relative position was not found' => array(
773  'notExistingItem',
774  'after',
775  array(
776  0 => array('firstElement'),
777  1 => array('matchMe'),
778  2 => array('thirdElement'),
779  3 => array('insertedElement')
780  )
781  )
782  );
783  }
784 
789  public function addTcaSelectItemInsertsItemAtSpecifiedPosition($relativeToField, $relativePosition, $expectedResultArray) {
790  $GLOBALS['TCA'] = array(
791  'testTable' => array(
792  'columns' => array(
793  'testField' => array(
794  'config' => array(
795  'items' => array(
796  '0' => array('firstElement'),
797  '1' => array('matchMe'),
798  2 => array('thirdElement')
799  )
800  )
801  )
802  )
803  )
804  );
805  ExtensionManagementUtility::addTcaSelectItem('testTable', 'testField', array('insertedElement'), $relativeToField, $relativePosition);
806  $this->assertEquals($expectedResultArray, $GLOBALS['TCA']['testTable']['columns']['testField']['config']['items']);
807  }
808 
810  // Tests concerning loadExtLocalconf
812 
816  $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
817  $mockCacheManager->expects($this->never())->method('getCache');
818  ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
819  $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage($this->getUniqueId()));
820  ExtensionManagementUtility::loadExtLocalconf(FALSE);
821  }
822 
827  $mockCache = $this->getMock(
828  'TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend',
829  array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
830  array(),
831  '',
832  FALSE
833  );
834  $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
835  $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
836  ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
837  $mockCache->expects($this->any())->method('has')->will($this->returnValue(TRUE));
838  $mockCache->expects($this->once())->method('requireOnce');
839  ExtensionManagementUtility::loadExtLocalconf(TRUE);
840  }
841 
843  // Tests concerning loadSingleExtLocalconfFiles
845 
850  $extensionName = $this->getUniqueId('foo');
851  $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
852  $extLocalconfLocation = $packageManager->getPackage($extensionName)->getPackagePath() . 'ext_localconf.php';
853  file_put_contents($extLocalconfLocation, "<?php\n\nthrow new RuntimeException('', 1340559079);\n\n?>");
854  $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray($packageManager);
855  ExtensionManagementUtilityAccessibleProxy::loadSingleExtLocalconfFiles();
856  }
857 
858 
860  // Tests concerning addModule
862 
868  return array(
869  'can add new main module if none exists' => array(
870  'top',
871  '',
872  'newModule'
873  ),
874  'can add new sub module if no position specified' => array(
875  '',
876  'some,modules',
877  'some,modules,newModule'
878  ),
879  'can add new sub module to top of module' => array(
880  'top',
881  'some,modules',
882  'newModule,some,modules'
883  ),
884  'can add new sub module if bottom of module' => array(
885  'bottom',
886  'some,modules',
887  'some,modules,newModule'
888  ),
889  'can add new sub module before specified sub module' => array(
890  'before:modules',
891  'some,modules',
892  'some,newModule,modules'
893  ),
894  'can add new sub module after specified sub module' => array(
895  'after:some',
896  'some,modules',
897  'some,newModule,modules'
898  ),
899  'can add new sub module at the bottom if specified sub module to add before does not exist' => array(
900  'before:modules',
901  'some,otherModules',
902  'some,otherModules,newModule'
903  ),
904  'can add new sub module at the bottom if specified sub module to add after does not exist' => array(
905  'after:some',
906  'someOther,modules',
907  'someOther,modules,newModule'
908  ),
909  );
910  }
911 
916  public function addModuleCanAddModule($position, $existing, $expected) {
917  $mainModule = 'foobar';
918  $subModule = 'newModule';
919  if ($existing) {
920  $GLOBALS['TBE_MODULES'][$mainModule] = $existing;
921  }
922 
923  ExtensionManagementUtility::addModule($mainModule, $subModule, $position);
924 
925  $this->assertTrue(isset($GLOBALS['TBE_MODULES'][$mainModule]));
926  $this->assertEquals($expected, $GLOBALS['TBE_MODULES'][$mainModule]);
927  }
928 
930  // Tests concerning createExtLocalconfCacheEntry
932 
936  $extensionName = $this->getUniqueId('foo');
937  $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
938  $extLocalconfLocation = $packageManager->getPackage($extensionName)->getPackagePath() . 'ext_localconf.php';
939  $this->testFilesToDelete[] = $extLocalconfLocation;
940  $uniqueStringInLocalconf = $this->getUniqueId('foo');
941  file_put_contents($extLocalconfLocation, "<?php\n\n" . $uniqueStringInLocalconf . "\n\n?>");
942  $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray($packageManager);
943  $mockCache = $this->getMock(
944  'TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend',
945  array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
946  array(),
947  '',
948  FALSE
949  );
950  $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
951  $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
952  ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
953  $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInLocalconf), $this->anything());
954  ExtensionManagementUtilityAccessibleProxy::createExtLocalconfCacheEntry();
955  }
956 
961  $extensionName = $this->getUniqueId('foo');
962  $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
963  $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray($packageManager);
964  $mockCache = $this->getMock(
965  'TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend',
966  array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
967  array(),
968  '',
969  FALSE
970  );
971  $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
972  $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
973  ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
974  $mockCache->expects($this->once())
975  ->method('set')
976  ->with($this->anything(), $this->logicalNot($this->stringContains($extensionName)), $this->anything());
977  ExtensionManagementUtilityAccessibleProxy::createExtLocalconfCacheEntry();
978  }
979 
984  $mockCache = $this->getMock(
985  'TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend',
986  array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
987  array(),
988  '',
989  FALSE
990  );
991  $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
992  $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
993  ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
994  $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo(array()));
995  $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage($this->getUniqueId()));
996  ExtensionManagementUtilityAccessibleProxy::createExtLocalconfCacheEntry();
997  }
998 
1000  // Tests concerning getExtLocalconfCacheIdentifier
1002 
1006  $prefix = 'ext_localconf_';
1007  $identifier = ExtensionManagementUtilityAccessibleProxy::getExtLocalconfCacheIdentifier();
1008  $this->assertStringStartsWith($prefix, $identifier);
1009  $sha1 = str_replace($prefix, '', $identifier);
1010  $this->assertEquals(40, strlen($sha1));
1011  }
1012 
1014  // Tests concerning loadBaseTca
1016 
1021  $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
1022  $mockCacheManager->expects($this->never())->method('getCache');
1023  ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1024  ExtensionManagementUtilityAccessibleProxy::loadBaseTca(FALSE);
1025  }
1026 
1031  $mockCache = $this->getMock(
1032  'TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend',
1033  array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1034  array(),
1035  '',
1036  FALSE
1037  );
1038  $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
1039  $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1040  ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1041  $mockCache->expects($this->any())->method('has')->will($this->returnValue(TRUE));
1042  $mockCache->expects($this->once())->method('get')->willReturn('<?php ' . serialize(array('tca' => array(), 'categoryRegistry' => \TYPO3\CMS\Core\Category\CategoryRegistry::getInstance())) . '?>');
1043  ExtensionManagementUtilityAccessibleProxy::loadBaseTca(TRUE);
1044  }
1045 
1050  $extensionName = $this->getUniqueId('test_baseTca_');
1051  $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName);
1052  $packagePath = $packageManager->getPackage($extensionName)->getPackagePath();
1054  \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir($packagePath . 'Configuration/');
1055  \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir($packagePath . 'Configuration/TCA/');
1056  $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray($packageManager);
1058  $uniqueTableName = $this->getUniqueId('table_name_');
1059  $uniqueStringInTableConfiguration = $this->getUniqueId('table_configuration_');
1060  $tableConfiguration = '<?php return array(\'foo\' => \'' . $uniqueStringInTableConfiguration . '\'); ?>';
1061  file_put_contents($packagePath . 'Configuration/TCA/' . $uniqueTableName . '.php', $tableConfiguration);
1062  $mockCache = $this->getMock(
1063  'TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend',
1064  array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1065  array(),
1066  '',
1067  FALSE
1068  );
1069  $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
1070  $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1071  ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1072  $mockCache->expects($this->once())->method('has')->will($this->returnValue(FALSE));
1073  $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInTableConfiguration), $this->anything());
1074  ExtensionManagementUtility::loadBaseTca(TRUE);
1075  }
1076 
1080  public function loadBaseTcaWritesCacheEntryWithNoTags() {
1081  $mockCache = $this->getMock(
1082  'TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend',
1083  array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1084  array(),
1085  '',
1086  FALSE
1087  );
1088  $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
1089  $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1090  ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1091  $mockCache->expects($this->once())->method('has')->will($this->returnValue(FALSE));
1092  $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo(array()));
1093  ExtensionManagementUtilityAccessibleProxy::loadBaseTca();
1094  }
1095 
1097  // Tests concerning getBaseTcaCacheIdentifier
1099 
1103  public function getBaseTcaCacheIdentifierCreatesSha1WithFourtyCharactersAndPrefix() {
1104  $prefix = 'tca_base_';
1105  $identifier = ExtensionManagementUtilityAccessibleProxy::getBaseTcaCacheIdentifier();
1106  $this->assertStringStartsWith($prefix, $identifier);
1107  $sha1 = str_replace($prefix, '', $identifier);
1108  $this->assertEquals(40, strlen($sha1));
1109  }
1110 
1112  // Tests concerning loadExtTables
1114 
1117  public function loadExtTablesDoesNotReadFromCacheIfCachingIsDenied() {
1118  $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
1119  $mockCacheManager->expects($this->never())->method('getCache');
1120  ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1121  $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage($this->getUniqueId()));
1122  ExtensionManagementUtility::loadExtLocalconf(FALSE);
1123  }
1124 
1128  public function loadExtTablesRequiresCacheFileIfExistsAndCachingIsAllowed() {
1129  $mockCache = $this->getMock(
1130  'TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend',
1131  array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1132  array(),
1133  '',
1134  FALSE
1135  );
1136  $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
1137  $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1138  ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1139  $mockCache->expects($this->any())->method('has')->will($this->returnValue(TRUE));
1140  $mockCache->expects($this->once())->method('requireOnce');
1141  // Reset the internal cache access tracking variable of extMgm
1142  // This method is only in the ProxyClass!
1143  ExtensionManagementUtilityAccessibleProxy::resetExtTablesWasReadFromCacheOnceBoolean();
1144  ExtensionManagementUtility::loadExtTables(TRUE);
1145  }
1146 
1148  // Tests concerning createExtTablesCacheEntry
1150 
1153  public function createExtTablesCacheEntryWritesCacheEntryWithContentOfLoadedExtensionExtTables() {
1154  $extensionName = $this->getUniqueId('foo');
1155  $extTablesLocation = PATH_site . 'typo3temp/' . $this->getUniqueId('test_ext_tables') . '.php';
1156  $this->testFilesToDelete[] = $extTablesLocation;
1157  $uniqueStringInTables = $this->getUniqueId('foo');
1158  file_put_contents($extTablesLocation, "<?php\n\n$uniqueStringInTables\n\n?>");
1159  $GLOBALS['TYPO3_LOADED_EXT'] = array(
1160  $extensionName => array(
1161  'ext_tables.php' => $extTablesLocation
1162  )
1163  );
1164  $mockCache = $this->getMock(
1165  'TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend',
1166  array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1167  array(),
1168  '',
1169  FALSE
1170  );
1171  $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
1172  $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1173  ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1174  $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInTables), $this->anything());
1175  ExtensionManagementUtilityAccessibleProxy::createExtTablesCacheEntry();
1176  }
1177 
1181  public function createExtTablesCacheEntryWritesCacheEntryWithExtensionContentOnlyIfExtTablesExists() {
1182  $extensionName = $this->getUniqueId('foo');
1183  $GLOBALS['TYPO3_LOADED_EXT'] = array(
1184  $extensionName => array(),
1185  );
1186  $mockCache = $this->getMock(
1187  'TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend',
1188  array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1189  array(),
1190  '',
1191  FALSE
1192  );
1193  $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
1194  $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1195  ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1196  $mockCache->expects($this->once())
1197  ->method('set')
1198  ->with($this->anything(), $this->logicalNot($this->stringContains($extensionName)), $this->anything());
1199  ExtensionManagementUtilityAccessibleProxy::createExtTablesCacheEntry();
1200  }
1201 
1205  public function createExtTablesCacheEntryWritesCacheEntryWithNoTags() {
1206  $mockCache = $this->getMock(
1207  'TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend',
1208  array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
1209  array(),
1210  '',
1211  FALSE
1212  );
1213  $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
1214  $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
1215  ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1216  $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo(array()));
1217  $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray($this->createMockPackageManagerWithMockPackage($this->getUniqueId()));
1218  ExtensionManagementUtilityAccessibleProxy::createExtTablesCacheEntry();
1219  }
1220 
1222  // Tests concerning getExtTablesCacheIdentifier
1224 
1227  public function getExtTablesCacheIdentifierCreatesSha1WithFourtyCharactersAndPrefix() {
1228  $prefix = 'ext_tables_';
1229  $identifier = ExtensionManagementUtilityAccessibleProxy::getExtTablesCacheIdentifier();
1230  $this->assertStringStartsWith($prefix, $identifier);
1231  $sha1 = str_replace($prefix, '', $identifier);
1232  $this->assertEquals(40, strlen($sha1));
1233  }
1234 
1236  // Tests concerning removeCacheFiles
1238 
1241  public function removeCacheFilesFlushesSystemCaches() {
1242  $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('flushCachesInGroup'));
1243  $mockCacheManager->expects($this->once())->method('flushCachesInGroup')->with('system');
1244  ExtensionManagementUtilityAccessibleProxy::setCacheManager($mockCacheManager);
1245  ExtensionManagementUtility::removeCacheFiles();
1246  }
1247 
1249  // Tests concerning loadNewTcaColumnsConfigFiles
1251 
1256  public function loadNewTcaColumnsConfigFilesIncludesDefinedDynamicConfigFileIfNoColumnsExist() {
1257  $GLOBALS['TCA'] = array(
1258  'test' => array(
1259  'ctrl' => array(
1260  'dynamicConfigFile' => __DIR__ . '/Fixtures/RuntimeException.php'
1261  ),
1262  ),
1263  );
1264  ExtensionManagementUtility::loadNewTcaColumnsConfigFiles();
1265  }
1266 
1270  public function loadNewTcaColumnsConfigFilesDoesNotIncludeFileIfColumnsExist() {
1271  $GLOBALS['TCA'] = array(
1272  'test' => array(
1273  'ctrl' => array(
1274  'dynamicConfigFile' => __DIR__ . '/Fixtures/RuntimeException.php'
1275  ),
1276  'columns' => array(
1277  'foo' => 'bar',
1278  ),
1279  ),
1280  );
1281  ExtensionManagementUtility::loadNewTcaColumnsConfigFiles();
1282  }
1283 
1285  // Tests concerning getExtensionVersion
1287 
1292  public function getExtensionVersionFaultyDataProvider() {
1293  return array(
1294  array(''),
1295  array(0),
1296  array(new \stdClass()),
1297  array(TRUE)
1298  );
1299  }
1300 
1306  public function getExtensionVersionForFaultyExtensionKeyThrowsException($key) {
1307  ExtensionManagementUtility::getExtensionVersion($key);
1308  }
1309 
1313  public function getExtensionVersionForNotLoadedExtensionReturnsEmptyString() {
1314  ExtensionManagementUtility::clearExtensionKeyMap();
1315  $uniqueSuffix = $this->getUniqueId('test');
1316  $extensionKey = 'unloadedextension' . $uniqueSuffix;
1317  $this->assertEquals('', ExtensionManagementUtility::getExtensionVersion($extensionKey));
1318  }
1319 
1323  public function getExtensionVersionForLoadedExtensionReturnsExtensionVersion() {
1324  ExtensionManagementUtility::clearExtensionKeyMap();
1325  $className = $this->getUniqueId('ExtensionManagementUtility');
1326  eval(
1327  'namespace ' . __NAMESPACE__ .';' .
1328  'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\Utility\\ExtensionManagementUtility {' .
1329  ' public static function isLoaded() {' .
1330  ' return TRUE;' .
1331  ' }' .
1332  '}'
1333  );
1334  $className = __NAMESPACE__ . '\\' . $className;
1335  ExtensionManagementUtility::clearExtensionKeyMap();
1336  $uniqueSuffix = $this->getUniqueId('test');
1337  $extensionKey = 'unloadedextension' . $uniqueSuffix;
1338  $packageMetaData = $this->getMock('TYPO3\\Flow\\Package\\MetaData', array('getVersion'), array($extensionKey));
1339  $packageMetaData->expects($this->any())->method('getVersion')->will($this->returnValue('1.2.3'));
1340  $packageManager = $this->createMockPackageManagerWithMockPackage($extensionKey, array('getPackagePath', 'getPackageKey', 'getPackageMetaData'));
1342  $package = $packageManager->getPackage($extensionKey);
1343  $package->expects($this->any())
1344  ->method('getPackageMetaData')
1345  ->will($this->returnValue($packageMetaData));
1346  ExtensionManagementUtility::setPackageManager($packageManager);
1347  $this->assertEquals('1.2.3', ExtensionManagementUtility::getExtensionVersion($extensionKey));
1348  }
1349 
1351  // Tests concerning loadExtension
1353 
1357  public function loadExtensionThrowsExceptionIfExtensionIsLoaded() {
1358  $extensionKey = $this->getUniqueId('test');
1359  $packageManager = $this->createMockPackageManagerWithMockPackage($extensionKey);
1360  ExtensionManagementUtility::setPackageManager($packageManager);
1361  ExtensionManagementUtility::loadExtension($extensionKey);
1362  }
1363 
1365  // Tests concerning unloadExtension
1367 
1371  public function unloadExtensionThrowsExceptionIfExtensionIsNotLoaded() {
1372  $packageName = $this->getUniqueId('foo');
1373  $packageManager = $this->getMock('TYPO3\\CMS\\Core\\Package\\PackageManager', array('isPackageActive'));
1374  $packageManager->expects($this->once())
1375  ->method('isPackageActive')
1376  ->with($this->equalTo($packageName))
1377  ->will($this->returnValue(FALSE));
1378  ExtensionManagementUtility::setPackageManager($packageManager);
1379  ExtensionManagementUtility::unloadExtension($packageName);
1380  }
1381 
1385  public function unloadExtensionCallsPackageManagerToDeactivatePackage() {
1386  $packageName = $this->getUniqueId('foo');
1387  $packageManager = $this->getMock(
1388  'TYPO3\\CMS\\Core\\Package\\PackageManager',
1389  array('isPackageActive', 'deactivatePackage')
1390  );
1391  $packageManager->expects($this->any())
1392  ->method('isPackageActive')
1393  ->will($this->returnValue(TRUE));
1394  $packageManager->expects($this->once())
1395  ->method('deactivatePackage')
1396  ->with($packageName);
1397  ExtensionManagementUtility::setPackageManager($packageManager);
1398  ExtensionManagementUtility::unloadExtension($packageName);
1399  }
1400 
1402  // Tests concerning makeCategorizable
1404 
1407  public function doesMakeCategorizableCallsTheCategoryRegistryWithDefaultFieldName() {
1408  $extensionKey = $this->getUniqueId('extension');
1409  $tableName = $this->getUniqueId('table');
1410 
1411  $registryMock = $this->getMock('TYPO3\\CMS\\Core\\Category\\CategoryRegistry');
1412  $registryMock->expects($this->once())->method('add')->with($extensionKey, $tableName, 'categories', array());
1413  \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Category\\CategoryRegistry', $registryMock);
1414  ExtensionManagementUtility::makeCategorizable($extensionKey, $tableName);
1415  }
1416 
1420  public function doesMakeCategorizableCallsTheCategoryRegistryWithFieldName() {
1421  $extensionKey = $this->getUniqueId('extension');
1422  $tableName = $this->getUniqueId('table');
1423  $fieldName = $this->getUniqueId('field');
1424 
1425  $registryMock = $this->getMock('TYPO3\\CMS\\Core\\Category\\CategoryRegistry');
1426  $registryMock->expects($this->once())->method('add')->with($extensionKey, $tableName, $fieldName, array());
1427  \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Category\\CategoryRegistry', $registryMock);
1428  ExtensionManagementUtility::makeCategorizable($extensionKey, $tableName, $fieldName);
1429  }
1430 
1432  // Tests concerning addPlugin
1434 
1438  public function addPluginSetsTcaCorrectlyForGivenExtkeyAsParameter() {
1439  $extKey = 'indexed_search';
1440  $GLOBALS['TYPO3_LOADED_EXT'] = array();
1441  $GLOBALS['TYPO3_LOADED_EXT'][$extKey]['ext_icon'] = 'foo.gif';
1442  $expectedTCA = array(
1443  array(
1444  'label',
1445  $extKey,
1446  'sysext/' . $extKey . '/foo.gif'
1447  )
1448  );
1449  $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'] = array();
1450  ExtensionManagementUtility::addPlugin(array('label', $extKey), 'list_type', $extKey);
1451  $this->assertEquals($expectedTCA, $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items']);
1452  }
1453 
1457  public function addPluginSetsTcaCorrectlyForGivenExtkeyAsGlobal() {
1458  $extKey = 'indexed_search';
1459  $GLOBALS['TYPO3_LOADED_EXT'] = array();
1460  $GLOBALS['TYPO3_LOADED_EXT'][$extKey]['ext_icon'] = 'foo.gif';
1461  $GLOBALS['_EXTKEY'] = $extKey;
1462  $expectedTCA = array(
1463  array(
1464  'label',
1465  $extKey,
1466  'sysext/' . $extKey . '/foo.gif'
1467  )
1468  );
1469  $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items'] = array();
1470  ExtensionManagementUtility::addPlugin(array('label', $extKey));
1471  $this->assertEquals($expectedTCA, $GLOBALS['TCA']['tt_content']['columns']['list_type']['config']['items']);
1472  }
1473 
1478  public function addPluginThrowsExceptionForMissingExtkey() {
1479  ExtensionManagementUtility::addPlugin('test');
1480  }
1481 }
static addFieldsToAllPalettesOfField($table, $field, $addFields, $insertionPosition='')
static unlink_tempfile($uploadedTempFileName)
static mkdir_deep($directory, $deepDirectory='')
static setPackageManager(\TYPO3\CMS\Core\Package\PackageManager $packageManager)
static rmdir($path, $removeNonEmpty=FALSE)
createMockPackageManagerWithMockPackage($packageKey, $packageMethods=array('getPackagePath', 'getPackageKey'))
static resetSingletonInstances(array $newSingletonInstances)
static addToAllTCAtypes($table, $newFieldsString, $typeList='', $position='')
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.
static addTcaSelectItem($table, $field, array $item, $relativeToField='', $relativePosition='')
static addModule($main, $sub='', $position='', $path='', $moduleConfiguration=array())
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
addTcaSelectItemInsertsItemAtSpecifiedPosition($relativeToField, $relativePosition, $expectedResultArray)
static addFieldsToPalette($table, $palette, $addFields, $insertionPosition='')