2 namespace TYPO3\CMS\Core\Tests\Unit\Extension
;
4 /***************************************************************
7 * (c) 2009-2011 Oliver Hader <oliver@typo3.org>
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
28 * Testcase for \TYPO3\CMS\Core\Extension\ExtensionManager
30 * @author Oliver Hader <oliver@typo3.org>
31 * @author Oliver Klee <typo3-coding@oliverklee.de>
35 class ExtensionManagerTest
extends \tx_phpunit_testcase
{
38 * @var array A backup of registered singleton instances
40 protected $singletonInstances = array();
43 * Enable backup of global and system variables
47 protected $backupGlobals = TRUE;
50 * Exclude TYPO3_DB from backup/ restore of $GLOBALS
51 * because resource types cannot be handled during serializing
55 protected $backupGlobalsBlacklist = array('TYPO3_DB');
58 * phpunit still needs some globals that are
59 * reconstructed before $backupGlobals is handled. Those
60 * important globals are handled in tearDown() directly.
64 protected $globals = array();
67 * Absolute path to files that must be removed
68 * after a test - handled in tearDown
70 * @TODO : Check if the tests can use vfs:// instead
72 protected $testFilesToDelete = array();
74 public function setUp() {
75 $this->createAccessibleProxyClass();
76 $this->globals
= array(
77 'TYPO3_LOADED_EXT' => serialize($GLOBALS['TYPO3_LOADED_EXT'])
79 $this->testFilesToDelete
= array();
80 $this->singletonInstances
= \TYPO3\CMS\Core\Utility\GeneralUtility
::getSingletonInstances();
83 public function tearDown() {
84 \TYPO3\CMS\Core\Extension\ExtensionManager
::clearExtensionKeyMap();
85 foreach ($this->globals
as $key => $value) {
86 $GLOBALS[$key] = unserialize($value);
88 foreach ($this->testFilesToDelete
as $absoluteFileName) {
89 \TYPO3\CMS\Core\Utility\GeneralUtility
::unlink_tempfile($absoluteFileName);
91 \TYPO3\CMS\Core\Utility\GeneralUtility
::resetSingletonInstances($this->singletonInstances
);
95 * Create a subclass with protected methods made public
99 protected function createAccessibleProxyClass() {
100 $namespace = 'TYPO3\\CMS\\Core\\Extension';
101 $className = 'ExtensionManagerAccessibleProxy';
102 if (!class_exists($namespace . '\\' . $className, FALSE)) {
103 eval((((((((((((((((((((((((((('namespace ' . $namespace . '; class ' . $className) . ' extends \\TYPO3\\CMS\\Core\\Extension\\ExtensionManager {') . ' public static function createTypo3LoadedExtensionInformationArray() {') . ' return parent::createTypo3LoadedExtensionInformationArray();') . ' }') . ' public static function getTypo3LoadedExtensionInformationCacheIdentifier() {') . ' return parent::getTypo3LoadedExtensionInformationCacheIdentifier();') . ' }') . ' public static function getExtLocalconfCacheIdentifier() {') . ' return parent::getExtLocalconfCacheIdentifier();') . ' }') . ' public static function loadSingleExtLocalconfFiles() {') . ' return parent::loadSingleExtLocalconfFiles();') . ' }') . ' public static function resetExtTablesWasReadFromCacheOnceBoolean() {') . ' self::$extTablesWasReadFromCacheOnce = FALSE;') . ' }') . ' public static function createExtLocalconfCacheEntry() {') . ' return parent::createExtLocalconfCacheEntry();') . ' }') . ' public static function createExtTablesCacheEntry() {') . ' return parent::createExtTablesCacheEntry();') . ' }') . ' public static function getExtTablesCacheIdentifier() {') . ' return parent::getExtTablesCacheIdentifier();') . ' }') . '}');
107 ///////////////////////////////
108 // Tests concerning isLoaded
109 ///////////////////////////////
113 public function isLoadedReturnsTrueIfExtensionIsLoaded() {
114 $this->assertTrue(\TYPO3\CMS\Core\Extension\ExtensionManager
::isLoaded('cms'));
120 public function isLoadedReturnsFalseIfExtensionIsNotLoadedAndExitIsDisabled() {
121 $this->assertFalse(\TYPO3\CMS\Core\Extension\ExtensionManager
::isLoaded(uniqid('foobar'), FALSE));
126 * @expectedException BadFunctionCallException
128 public function isLoadedThrowsExceptionIfExtensionIsNotLoaded() {
129 $this->assertFalse(\TYPO3\CMS\Core\Extension\ExtensionManager
::isLoaded(uniqid('foobar'), TRUE));
132 ///////////////////////////////
133 // Tests concerning extPath
134 ///////////////////////////////
137 * @expectedException BadFunctionCallException
139 public function extPathThrowsExceptionIfExtensionIsNotLoaded() {
140 $GLOBALS['TYPO3_LOADED_EXT']['foo'] = array();
141 \TYPO3\CMS\Core\Extension\ExtensionManager
::extPath('bar');
147 public function extPathAppendsScriptNameToPath() {
148 $GLOBALS['TYPO3_LOADED_EXT']['foo']['siteRelPath'] = 'foo/';
149 $this->assertSame(PATH_site
. 'foo/bar.txt', \TYPO3\CMS\Core\Extension\ExtensionManager
::extPath('foo', 'bar.txt'));
154 * @expectedException BadFunctionCallException
156 public function extPathThrowsExceptionIfExtensionIsNotLoadedAndTypo3LoadedExtensionsIsEmpty() {
157 unset($GLOBALS['TYPO3_LOADED_EXT']);
158 $GLOBALS['TYPO3_CONF_VARS']['EXT']['requiredExt'] = '';
159 $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList'] = '';
160 \TYPO3\CMS\Core\Extension\ExtensionManager
::extPath('bar');
166 public function extPathSearchesForPathOfExtensionInRequiredExtensionList() {
167 $this->setExpectedException('BadFunctionCallException', '', 1294430951);
168 unset($GLOBALS['TYPO3_LOADED_EXT']);
169 $GLOBALS['TYPO3_CONF_VARS']['EXT']['requiredExt'] = 'foo';
170 $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList'] = '';
171 \TYPO3\CMS\Core\Extension\ExtensionManager
::extPath('foo');
177 public function extPathSearchesForPathOfExtensionInExtList() {
178 $this->setExpectedException('BadFunctionCallException', '', 1294430951);
179 unset($GLOBALS['TYPO3_LOADED_EXT']);
180 $GLOBALS['TYPO3_CONF_VARS']['EXT']['requiredExt'] = '';
181 $GLOBALS['TYPO3_CONF_VARS']['EXT']['extListArray'] = array('foo');
182 \TYPO3\CMS\Core\Extension\ExtensionManager
::extPath('foo');
185 //////////////////////
187 //////////////////////
189 * Generates a basic TCA for a given table.
191 * @param string $table name of the table, must not be empty
192 * @return array generated TCA for the given table, will not be empty
194 private function generateTCAForTable($table) {
196 $tca[$table] = array();
197 $tca[$table]['columns'] = array(
201 $tca[$table]['types'] = array(
202 'typeA' => array('showitem' => 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD'),
203 'typeB' => array('showitem' => 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD'),
204 'typeC' => array('showitem' => 'fieldC;;paletteD')
206 $tca[$table]['palettes'] = array(
207 'paletteA' => array('showitem' => 'fieldX, fieldY'),
208 'paletteB' => array('showitem' => 'fieldX, fieldY'),
209 'paletteC' => array('showitem' => 'fieldX, fieldY'),
210 'paletteD' => array('showitem' => 'fieldX, fieldY')
216 * Returns the fixtures path for this testcase relative to PATH_site.
218 * @return string the fixtures path for this testcase, will not be empty
220 private function determineFixturesPath() {
221 return \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance('Tx_Phpunit_Service_TestFinder')->getRelativeCoreTestsPath() . 'Unit/t3lib/fixtures/';
224 /////////////////////////////////////////////
225 // Tests concerning getExtensionKeyByPrefix
226 /////////////////////////////////////////////
229 * @see t3lib_extMgm::getExtensionKeyByPrefix
231 public function getExtensionKeyByPrefixForLoadedExtensionWithUnderscoresReturnsExtensionKey() {
232 \TYPO3\CMS\Core\Extension\ExtensionManager
::clearExtensionKeyMap();
233 $uniqueSuffix = uniqid('test');
234 $extensionKey = 'tt_news' . $uniqueSuffix;
235 $extensionPrefix = 'tx_ttnews' . $uniqueSuffix;
236 $GLOBALS['TYPO3_LOADED_EXT'][$extensionKey] = array();
237 $this->assertEquals($extensionKey, \TYPO3\CMS\Core\Extension\ExtensionManager
::getExtensionKeyByPrefix($extensionPrefix));
242 * @see t3lib_extMgm::getExtensionKeyByPrefix
244 public function getExtensionKeyByPrefixForLoadedExtensionWithoutUnderscoresReturnsExtensionKey() {
245 \TYPO3\CMS\Core\Extension\ExtensionManager
::clearExtensionKeyMap();
246 $uniqueSuffix = uniqid('test');
247 $extensionKey = 'kickstarter' . $uniqueSuffix;
248 $extensionPrefix = 'tx_kickstarter' . $uniqueSuffix;
249 $GLOBALS['TYPO3_LOADED_EXT'][$extensionKey] = array();
250 $this->assertEquals($extensionKey, \TYPO3\CMS\Core\Extension\ExtensionManager
::getExtensionKeyByPrefix($extensionPrefix));
255 * @see t3lib_extMgm::getExtensionKeyByPrefix
257 public function getExtensionKeyByPrefixForNotLoadedExtensionReturnsFalse() {
258 \TYPO3\CMS\Core\Extension\ExtensionManager
::clearExtensionKeyMap();
259 $uniqueSuffix = uniqid('test');
260 $extensionKey = 'unloadedextension' . $uniqueSuffix;
261 $extensionPrefix = 'tx_unloadedextension' . $uniqueSuffix;
262 $this->assertFalse(\TYPO3\CMS\Core\Extension\ExtensionManager
::getExtensionKeyByPrefix($extensionPrefix));
265 //////////////////////////////////////
266 // Tests concerning addToAllTCAtypes
267 //////////////////////////////////////
269 * Tests whether fields can be add to all TCA types and duplicate fields are considered.
272 * @see t3lib_extMgm::addToAllTCAtypes()
274 public function canAddFieldsToAllTCATypesBeforeExistingOnes() {
275 $table = uniqid('tx_coretest_table');
276 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
277 \TYPO3\CMS\Core\Extension\ExtensionManager
::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'before:fieldD');
279 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
281 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
285 * Tests whether fields can be add to all TCA types and duplicate fields are considered.
288 * @see t3lib_extMgm::addToAllTCAtypes()
290 public function canAddFieldsToAllTCATypesAfterExistingOnes() {
291 $table = uniqid('tx_coretest_table');
292 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
293 \TYPO3\CMS\Core\Extension\ExtensionManager
::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'after:fieldC');
295 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
297 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
301 * Tests whether fields can be add to a TCA type before existing ones
304 * @see t3lib_extMgm::addToAllTCAtypes()
306 public function canAddFieldsToTCATypeBeforeExistingOnes() {
307 $table = uniqid('tx_coretest_table');
308 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
309 \TYPO3\CMS\Core\Extension\ExtensionManager
::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', 'typeA', 'before:fieldD');
311 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
313 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
317 * Tests whether fields can be add to a TCA type after existing ones
320 * @see t3lib_extMgm::addToAllTCAtypes()
322 public function canAddFieldsToTCATypeAfterExistingOnes() {
323 $table = uniqid('tx_coretest_table');
324 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
325 \TYPO3\CMS\Core\Extension\ExtensionManager
::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', 'typeA', 'after:fieldC');
327 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
329 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
333 * Test wheter replacing other TCA fields works as promissed
336 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
338 public function canAddFieldsToTCATypeAndReplaceExistingOnes() {
339 $table = uniqid('tx_coretest_table');
340 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
341 $typesBefore = $GLOBALS['TCA'][$table]['types'];
342 \TYPO3\CMS\Core\Extension\ExtensionManager
::addToAllTCAtypes($table, 'fieldZ', '', 'replace:fieldX');
343 $this->assertEquals($typesBefore, $GLOBALS['TCA'][$table]['types'], 'It\'s wrong that the "types" array changes here - the replaced field is only on palettes');
344 // unchanged because the palette is not used
345 $this->assertEquals('fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
346 // unchanged because the palette is not used
347 $this->assertEquals('fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
348 $this->assertEquals('fieldZ, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
349 $this->assertEquals('fieldZ, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
352 ///////////////////////////////////////////////////
353 // Tests concerning addFieldsToAllPalettesOfField
354 ///////////////////////////////////////////////////
356 * Tests whether fields can be added to a palette before existing elements.
359 * @see t3lib_extMgm::addFieldsToPalette()
361 public function canAddFieldsToPaletteBeforeExistingOnes() {
362 $table = uniqid('tx_coretest_table');
363 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
364 \TYPO3\CMS\Core\Extension\ExtensionManager
::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'before:fieldY');
365 $this->assertEquals('fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
369 * Tests whether fields can be added to a palette after existing elements.
372 * @see t3lib_extMgm::addFieldsToPalette()
374 public function canAddFieldsToPaletteAfterExistingOnes() {
375 $table = uniqid('tx_coretest_table');
376 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
377 \TYPO3\CMS\Core\Extension\ExtensionManager
::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'after:fieldX');
378 $this->assertEquals('fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
382 * Tests whether fields can be added to a palette after a not existing elements.
385 * @see t3lib_extMgm::addFieldsToPalette()
387 public function canAddFieldsToPaletteAfterNotExistingOnes() {
388 $table = uniqid('tx_coretest_table');
389 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
390 \TYPO3\CMS\Core\Extension\ExtensionManager
::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'after:' . uniqid('notExisting'));
391 $this->assertEquals('fieldX, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
395 * Tests whether fields can be added to all palettes of a regular field before existing ones.
398 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
400 public function canAddFieldsToAllPalettesOfFieldBeforeExistingOnes() {
401 $table = uniqid('tx_coretest_table');
402 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
403 \TYPO3\CMS\Core\Extension\ExtensionManager
::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'before:fieldY');
404 $this->assertEquals('fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
405 $this->assertEquals('fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
406 $this->assertEquals('fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
407 $this->assertEquals('fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
411 * Tests whether fields can be added to all palettes of a regular field after existing ones.
414 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
416 public function canAddFieldsToAllPalettesOfFieldAfterExistingOnes() {
417 $table = uniqid('tx_coretest_table');
418 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
419 \TYPO3\CMS\Core\Extension\ExtensionManager
::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'after:fieldX');
420 $this->assertEquals('fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
421 $this->assertEquals('fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
422 $this->assertEquals('fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
423 $this->assertEquals('fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
427 * Tests whether fields can be added to all palettes of a regular field after a not existing field.
430 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
432 public function canAddFieldsToAllPalettesOfFieldAfterNotExistingOnes() {
433 $table = uniqid('tx_coretest_table');
434 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
435 \TYPO3\CMS\Core\Extension\ExtensionManager
::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'after:' . uniqid('notExisting'));
436 $this->assertEquals('fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
437 $this->assertEquals('fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
438 $this->assertEquals('fieldX, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
439 $this->assertEquals('fieldX, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
443 * Tests whether fields are added to a new palette that did not exist before.
446 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
448 public function canAddFieldsToAllPalettesOfFieldWithoutPaletteExistingBefore() {
449 $table = uniqid('tx_coretest_table');
450 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
451 \TYPO3\CMS\Core\Extension\ExtensionManager
::addFieldsToAllPalettesOfField($table, 'fieldA', 'newA, newA, newB, fieldX');
452 $this->assertEquals('fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
453 $this->assertEquals('fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
454 $this->assertEquals('fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
455 $this->assertEquals('fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
456 $this->assertEquals('newA, newB, fieldX', $GLOBALS['TCA'][$table]['palettes']['generatedFor-fieldA']['showitem']);
459 /////////////////////////////////////////
460 // Tests concerning addTcaSelectItem
461 /////////////////////////////////////////
464 * @expectedException InvalidArgumentException
466 public function addTcaSelectItemThrowsExceptionIfTableIsNotOfTypeString() {
467 \TYPO3\CMS\Core\Extension\ExtensionManager
::addTcaSelectItem(array(), 'foo', array());
472 * @expectedException InvalidArgumentException
474 public function addTcaSelectItemThrowsExceptionIfFieldIsNotOfTypeString() {
475 \TYPO3\CMS\Core\Extension\ExtensionManager
::addTcaSelectItem('foo', array(), array());
480 * @expectedException InvalidArgumentException
482 public function addTcaSelectItemThrowsExceptionIfRelativeToFieldIsNotOfTypeString() {
483 \TYPO3\CMS\Core\Extension\ExtensionManager
::addTcaSelectItem('foo', 'bar', array(), array());
488 * @expectedException InvalidArgumentException
490 public function addTcaSelectItemThrowsExceptionIfRelativePositionIsNotOfTypeString() {
491 \TYPO3\CMS\Core\Extension\ExtensionManager
::addTcaSelectItem('foo', 'bar', array(), 'foo', array());
496 * @expectedException InvalidArgumentException
498 public function addTcaSelectItemThrowsExceptionIfRelativePositionIsNotOneOfValidKeywords() {
499 \TYPO3\CMS\Core\Extension\ExtensionManager
::addTcaSelectItem('foo', 'bar', array(), 'foo', 'not allowed keyword');
504 * @expectedException RuntimeException
506 public function addTcaSelectItemThrowsExceptionIfFieldIsNotFoundInTca() {
507 $GLOBALS['TCA'] = array();
508 \TYPO3\CMS\Core\Extension\ExtensionManager
::addTcaSelectItem('foo', 'bar', array());
512 * Data provider for addTcaSelectItemInsertsItemAtSpecifiedPosition
514 public function addTcaSelectItemDataProvider() {
515 // Every array splits into:
517 // - relativePosition
518 // - expectedResultArray
520 'add at end of array' => array(
524 0 => array('firstElement'),
525 1 => array('matchMe'),
526 2 => array('thirdElement'),
527 3 => array('insertedElement')
530 'replace element' => array(
534 0 => array('firstElement'),
535 1 => array('insertedElement'),
536 2 => array('thirdElement')
539 'add element after' => array(
543 0 => array('firstElement'),
544 1 => array('matchMe'),
545 2 => array('insertedElement'),
546 3 => array('thirdElement')
549 'add element before' => array(
553 0 => array('firstElement'),
554 1 => array('insertedElement'),
555 2 => array('matchMe'),
556 3 => array('thirdElement')
559 'add at end if relative position was not found' => array(
563 0 => array('firstElement'),
564 1 => array('matchMe'),
565 2 => array('thirdElement'),
566 3 => array('insertedElement')
574 * @dataProvider addTcaSelectItemDataProvider
576 public function addTcaSelectItemInsertsItemAtSpecifiedPosition($relativeToField, $relativePosition, $expectedResultArray) {
577 $GLOBALS['TCA'] = array(
578 'testTable' => array(
580 'testField' => array(
583 '0' => array('firstElement'),
584 '1' => array('matchMe'),
585 2 => array('thirdElement')
592 \TYPO3\CMS\Core\Extension\ExtensionManager
::addTcaSelectItem('testTable', 'testField', array('insertedElement'), $relativeToField, $relativePosition);
593 $this->assertEquals($expectedResultArray, $GLOBALS['TCA']['testTable']['columns']['testField']['config']['items']);
596 /////////////////////////////////////////
597 // Tests concerning loadTypo3LoadedExtensionInformation
598 /////////////////////////////////////////
602 public function loadTypo3LoadedExtensionInformationDoesNotCallCacheIfCachingIsDenied() {
603 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
604 $GLOBALS['typo3CacheManager']->expects($this->never())->method('getCache');
605 \TYPO3\CMS\Core\Extension\ExtensionManager
::loadTypo3LoadedExtensionInformation(FALSE);
611 public function loadTypo3LoadedExtensionInformationRequiresCacheFileIfExistsAndCachingIsAllowed() {
612 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
613 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
614 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
615 $mockCache->expects($this->any())->method('has')->will($this->returnValue(TRUE));
616 $mockCache->expects($this->once())->method('requireOnce');
617 \TYPO3\CMS\Core\Extension\ExtensionManager
::loadTypo3LoadedExtensionInformation(TRUE);
623 public function loadTypo3LoadedExtensionInformationSetsNewCacheEntryIfCacheFileDoesNotExistAndCachingIsAllowed() {
624 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
625 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
626 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
627 $mockCache->expects($this->any())->method('has')->will($this->returnValue(FALSE));
628 $mockCache->expects($this->once())->method('set');
629 \TYPO3\CMS\Core\Extension\ExtensionManager
::loadTypo3LoadedExtensionInformation(TRUE);
635 public function loadTypo3LoadedExtensionInformationSetsNewCacheEntryWithNoTags() {
636 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
637 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
638 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
639 $mockCache->expects($this->any())->method('has')->will($this->returnValue(FALSE));
640 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo(array()));
641 \TYPO3\CMS\Core\Extension\ExtensionManager
::loadTypo3LoadedExtensionInformation(TRUE);
644 /////////////////////////////////////////
645 // Tests concerning createTypo3LoadedExtensionInformationArray
646 /////////////////////////////////////////
648 * Data provider for createTypo3LoadedExtensionInformationArrayReturnsExpectedInformationForCmsExtension
652 public function createTypo3LoadedExtensionInformationArrayReturnsExpectedInformationForCmsExtensionDataProvider() {
654 'System extension' => array('type', 'S'),
655 'Site relative path' => array('siteRelPath', 'typo3/sysext/cms/'),
656 'Typo3 relative path' => array('typo3RelPath', 'sysext/cms/'),
657 'Path ext_localconf.php' => array('ext_localconf.php', '/typo3/sysext/cms/ext_localconf.php'),
658 'Path ext_tables.php' => array('ext_tables.php', '/typo3/sysext/cms/ext_tables.php'),
659 'Path ext_tablps.sql' => array('ext_tables.sql', '/typo3/sysext/cms/ext_tables.sql')
664 * @param string $arrayKeyToTest
665 * @param string $expectedContent
667 * @dataProvider createTypo3LoadedExtensionInformationArrayReturnsExpectedInformationForCmsExtensionDataProvider
669 public function createTypo3LoadedExtensionInformationArrayReturnsExpectedInformationForCmsExtension($arrayKeyToTest, $expectedContent) {
670 $actualArray = \TYPO3\CMS\Core\Extension\ExtensionManagerAccessibleProxy
::createTypo3LoadedExtensionInformationArray();
671 $this->assertStringEndsWith($expectedContent, $actualArray['cms'][$arrayKeyToTest]);
674 /////////////////////////////////////////
675 // Tests concerning getTypo3LoadedExtensionInformationCacheIdentifier
676 /////////////////////////////////////////
680 public function getTypo3LoadedExtensionInformationCacheIdentifierCreatesSha1WithFourtyCharactersAndPrefix() {
681 $prefix = 'loaded_extensions_';
682 $identifier = \TYPO3\CMS\Core\Extension\ExtensionManagerAccessibleProxy
::getTypo3LoadedExtensionInformationCacheIdentifier();
683 $this->assertStringStartsWith($prefix, $identifier);
684 $sha1 = str_replace($prefix, '', $identifier);
685 $this->assertEquals(40, strlen($sha1));
688 /////////////////////////////////////////
689 // Tests concerning loadExtLocalconf
690 /////////////////////////////////////////
694 public function loadExtLocalconfDoesNotReadFromCacheIfCachingIsDenied() {
695 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
696 $GLOBALS['typo3CacheManager']->expects($this->never())->method('getCache');
697 \TYPO3\CMS\Core\Extension\ExtensionManager
::loadExtLocalconf(FALSE);
703 public function loadExtLocalconfRequiresCacheFileIfExistsAndCachingIsAllowed() {
704 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
705 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
706 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
707 $mockCache->expects($this->any())->method('has')->will($this->returnValue(TRUE));
708 $mockCache->expects($this->once())->method('requireOnce');
709 \TYPO3\CMS\Core\Extension\ExtensionManager
::loadExtLocalconf(TRUE);
712 /////////////////////////////////////////
713 // Tests concerning loadSingleExtLocalconfFiles
714 /////////////////////////////////////////
717 * @expectedException RuntimeException
719 public function loadSingleExtLocalconfFilesRequiresExtLocalconfFileRegisteredInGlobalTypo3LoadedExt() {
720 $extensionName = uniqid('foo');
721 $extLocalconfLocation = ((PATH_site
. 'typo3temp/') . uniqid('test_ext_localconf')) . '.php';
722 $this->testFilesToDelete
[] = $extLocalconfLocation;
723 file_put_contents($extLocalconfLocation, '<?php
725 throw new RuntimeException(\'\', 1340559079);
728 $GLOBALS['TYPO3_LOADED_EXT'] = array(
729 $extensionName => array(
730 'ext_localconf.php' => $extLocalconfLocation
733 \TYPO3\CMS\Core\Extension\ExtensionManagerAccessibleProxy
::loadSingleExtLocalconfFiles();
736 /////////////////////////////////////////
737 // Tests concerning createExtLocalconfCacheEntry
738 /////////////////////////////////////////
742 public function createExtLocalconfCacheEntryWritesCacheEntryWithContentOfLoadedExtensionExtLocalconf() {
743 $extensionName = uniqid('foo');
744 $extLocalconfLocation = ((PATH_site
. 'typo3temp/') . uniqid('test_ext_localconf')) . '.php';
745 $this->testFilesToDelete
[] = $extLocalconfLocation;
746 $uniqueStringInLocalconf = uniqid('foo');
747 file_put_contents($extLocalconfLocation, ('<?php
749 ' . $uniqueStringInLocalconf) . '
752 $GLOBALS['TYPO3_LOADED_EXT'] = array(
753 $extensionName => array(
754 'ext_localconf.php' => $extLocalconfLocation
757 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
758 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
759 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
760 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInLocalconf), $this->anything());
761 \TYPO3\CMS\Core\Extension\ExtensionManagerAccessibleProxy
::createExtLocalconfCacheEntry();
767 public function createExtLocalconfCacheEntryWritesCacheEntryWithNoTags() {
768 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
769 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
770 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
771 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo(array()));
772 \TYPO3\CMS\Core\Extension\ExtensionManagerAccessibleProxy
::createExtLocalconfCacheEntry();
775 /////////////////////////////////////////
776 // Tests concerning getExtLocalconfCacheIdentifier
777 /////////////////////////////////////////
781 public function getExtLocalconfCacheIdentifierCreatesSha1WithFourtyCharactersAndPrefix() {
782 $prefix = 'ext_localconf_';
783 $identifier = \TYPO3\CMS\Core\Extension\ExtensionManagerAccessibleProxy
::getExtLocalconfCacheIdentifier();
784 $this->assertStringStartsWith($prefix, $identifier);
785 $sha1 = str_replace($prefix, '', $identifier);
786 $this->assertEquals(40, strlen($sha1));
789 /////////////////////////////////////////
790 // Tests concerning loadExtTables
791 /////////////////////////////////////////
795 public function loadExtTablesDoesNotReadFromCacheIfCachingIsDenied() {
796 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
797 $GLOBALS['typo3CacheManager']->expects($this->never())->method('getCache');
798 \TYPO3\CMS\Core\Extension\ExtensionManager
::loadExtLocalconf(FALSE);
804 public function loadExtTablesRequiresCacheFileIfExistsAndCachingIsAllowed() {
805 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
806 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
807 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
808 $mockCache->expects($this->any())->method('has')->will($this->returnValue(TRUE));
809 $mockCache->expects($this->once())->method('requireOnce');
810 // Reset the internal cache access tracking variable of extMgm
811 // This method is only in the ProxyClass!
812 \TYPO3\CMS\Core\Extension\ExtensionManagerAccessibleProxy
::resetExtTablesWasReadFromCacheOnceBoolean();
813 \TYPO3\CMS\Core\Extension\ExtensionManager
::loadExtTables(TRUE);
816 /////////////////////////////////////////
817 // Tests concerning createExtTablesCacheEntry
818 /////////////////////////////////////////
822 public function createExtTablesCacheEntryWritesCacheEntryWithContentOfLoadedExtensionExtTables() {
823 $extensionName = uniqid('foo');
824 $extTablesLocation = ((PATH_site
. 'typo3temp/') . uniqid('test_ext_tables')) . '.php';
825 $this->testFilesToDelete
[] = $extTablesLocation;
826 $uniqueStringInTables = uniqid('foo');
827 file_put_contents($extTablesLocation, ('<?php
829 ' . $uniqueStringInTables) . '
832 $GLOBALS['TYPO3_LOADED_EXT'] = array(
833 $extensionName => array(
834 'ext_tables.php' => $extTablesLocation
837 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
838 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
839 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
840 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInTables), $this->anything());
841 \TYPO3\CMS\Core\Extension\ExtensionManagerAccessibleProxy
::createExtTablesCacheEntry();
847 public function createExtTablesCacheEntryWritesCacheEntryWithNoTags() {
848 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
849 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
850 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
851 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo(array()));
852 \TYPO3\CMS\Core\Extension\ExtensionManagerAccessibleProxy
::createExtTablesCacheEntry();
855 /////////////////////////////////////////
856 // Tests concerning getExtTablesCacheIdentifier
857 /////////////////////////////////////////
861 public function getExtTablesCacheIdentifierCreatesSha1WithFourtyCharactersAndPrefix() {
862 $prefix = 'ext_tables_';
863 $identifier = \TYPO3\CMS\Core\Extension\ExtensionManagerAccessibleProxy
::getExtTablesCacheIdentifier();
864 $this->assertStringStartsWith($prefix, $identifier);
865 $sha1 = str_replace($prefix, '', $identifier);
866 $this->assertEquals(40, strlen($sha1));
869 /////////////////////////////////////////
870 // Tests concerning removeCacheFiles
871 /////////////////////////////////////////
875 public function removeCacheFilesFlushesCache() {
876 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
877 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
878 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
879 $mockCache->expects($this->once())->method('flush');
880 \TYPO3\CMS\Core\Extension\ExtensionManager
::removeCacheFiles();
883 /////////////////////////////////////////
884 // Tests concerning getExtensionVersion
885 /////////////////////////////////////////
887 * Data provider for negative getExtensionVersion() tests.
891 public function getExtensionVersionFaultyDataProvider() {
895 array(new \
stdClass()),
902 * @expectedException InvalidArgumentException
903 * @dataProvider getExtensionVersionFaultyDataProvider
905 public function getExtensionVersionForFaultyExtensionKeyThrowsException($key) {
906 \TYPO3\CMS\Core\Extension\ExtensionManager
::getExtensionVersion($key);
912 public function getExtensionVersionForNotLoadedExtensionReturnsEmptyString() {
913 \TYPO3\CMS\Core\Extension\ExtensionManager
::clearExtensionKeyMap();
914 $uniqueSuffix = uniqid('test');
915 $extensionKey = 'unloadedextension' . $uniqueSuffix;
916 $this->assertEquals('', \TYPO3\CMS\Core\Extension\ExtensionManager
::getExtensionVersion($extensionKey));
922 public function getExtensionVersionForLoadedExtensionReturnsExtensionVersion() {
923 $namespace = 'TYPO3\\CMS\\Core\\Extension';
924 $className = uniqid('ExtensionManager');
925 eval(((((('namespace ' . $namespace .'; class ' . $className) . ' extends \\TYPO3\\CMS\\Core\\Extension\\ExtensionManager {') . ' public static function isLoaded() {') . ' return TRUE;') . ' }') . '}');
926 $className = $namespace . '\\' . $className;
927 \TYPO3\CMS\Core\Extension\ExtensionManager
::clearExtensionKeyMap();
928 $uniqueSuffix = uniqid('test');
929 $extensionKey = 'unloadedextension' . $uniqueSuffix;
930 $GLOBALS['TYPO3_LOADED_EXT'][$extensionKey] = array(
931 'siteRelPath' => $this->determineFixturesPath()
933 $this->assertEquals('1.2.3', $className::getExtensionVersion($extensionKey));
936 /////////////////////////////////////////
937 // Tests concerning getLoadedExtensionListArray
938 /////////////////////////////////////////
942 public function getLoadedExtensionListArrayConsidersExtListAsString() {
943 unset($GLOBALS['TYPO3_CONF_VARS']['EXT']['extListArray']);
944 $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList'] = 'foo,bar';
945 $this->assertEquals(array('foo', 'bar'), array_intersect(array('foo', 'bar'), \TYPO3\CMS\Core\Extension\ExtensionManager
::getLoadedExtensionListArray()));
951 public function getLoadedExtensionListArrayConsidersExtListAsArray() {
952 $extList = array('foo', 'bar');
953 $GLOBALS['TYPO3_CONF_VARS']['EXT']['extListArray'] = $extList;
954 $this->assertEquals($extList, array_intersect($extList, \TYPO3\CMS\Core\Extension\ExtensionManager
::getLoadedExtensionListArray()));
960 public function getLoadedExtensionListArrayConsidersRequiredExtensions() {
961 $namespace = 'TYPO3\\CMS\\Core\\Extension';
962 $className = uniqid('ExtensionManager');
963 eval(((((('namespace ' . $namespace . '; class ' . $className) . ' extends \\TYPO3\\CMS\\Core\\Extension\\ExtensionManager {') . ' public static function getRequiredExtensionListArray() {') . ' return array(\'baz\');') . ' }') . '}');
964 $className = $namespace . '\\' . $className;
965 $GLOBALS['TYPO3_CONF_VARS']['EXT']['extListArray'] = array();
966 $this->assertEquals(array('baz'), $className::getLoadedExtensionListArray());
972 public function getLoadedExtensionListArrayReturnsUniqueList() {
973 $namespace = 'TYPO3\\CMS\\Core\\Extension';
974 $className = uniqid('ExtensionManager');
975 eval(((((('namespace ' . $namespace . '; class ' . $className) . ' extends \\TYPO3\\CMS\\Core\\Extension\\ExtensionManager {') . ' public static function getRequiredExtensionListArray() {') . ' return array(\'bar\');') . ' }') . '}');
976 $className = $namespace . '\\' . $className;
977 $GLOBALS['TYPO3_CONF_VARS']['EXT']['extListArray'] = array('foo', 'bar', 'foo');
978 $this->assertSame(array('bar', 'foo'), $className::getLoadedExtensionListArray());
981 /////////////////////////////////////////
982 // Tests concerning getRequiredExtensionListArray
983 /////////////////////////////////////////
987 public function getRequiredExtensionListArrayContainsAdditionalRequiredExtensionsAsString() {
988 $GLOBALS['TYPO3_CONF_VARS']['EXT']['requiredExt'] = 'foo,bar';
989 $this->assertEquals(array('foo', 'bar'), array_intersect(array('foo', 'bar'), \TYPO3\CMS\Core\Extension\ExtensionManager
::getLoadedExtensionListArray()));
995 public function getRequiredExtensionListArrayContainsAdditionalRequiredExtensionsAsArray() {
996 $requiredExtList = array('foo', 'bar');
997 $GLOBALS['TYPO3_CONF_VARS']['EXT']['requiredExt'] = $requiredExtList;
998 $this->assertEquals($requiredExtList, array_intersect($requiredExtList, \TYPO3\CMS\Core\Extension\ExtensionManager
::getLoadedExtensionListArray()));
1004 public function getRequiredExtensionListArrayReturnsUniqueList() {
1005 $GLOBALS['TYPO3_CONF_VARS']['EXT']['requiredExt'] = 'foo,bar,foo';
1006 $this->assertEquals(array('foo', 'bar'), array_intersect(array('foo', 'bar'), \TYPO3\CMS\Core\Extension\ExtensionManager
::getLoadedExtensionListArray()));
1009 /////////////////////////////////////////
1010 // Tests concerning loadExtension
1011 /////////////////////////////////////////
1014 * @expectedException RuntimeException
1016 public function loadExtensionThrowsExceptionIfExtensionIsLoaded() {
1017 $namespace = 'TYPO3\\CMS\\Core\\Extension';
1018 $className = uniqid('ExtensionManager');
1019 eval(((((('namespace ' . $namespace . '; class ' . $className) . ' extends \\TYPO3\\CMS\\Core\\Extension\\ExtensionManager {') . ' public static function isLoaded() {') . ' return TRUE;') . ' }') . '}');
1020 $className = $namespace . '\\' . $className;
1021 $className::loadExtension('test');
1026 * @expectedException RuntimeException
1028 public function loadExtensionAddsExtensionToExtList() {
1029 if (!file_exists((PATH_typo3conf
. 'LocalConfiguration.php'))) {
1030 $this->markTestSkipped('Test is not available until update wizard to transform localconf.php was run.');
1032 $extensionKeyToLoad = uniqid('loadMe');
1033 $namespace = 'TYPO3\\CMS\\Core\\Extension';
1034 $className = uniqid('ExtensionManager');
1035 eval(((((((((('namespace ' . $namespace . '; class ' . $className) . ' extends \\TYPO3\\CMS\\Core\\Extension\\ExtensionManager {') . ' public static function writeNewExtensionList($extList) {') . ' if (in_array(') . $extensionKeyToLoad) . ', $extList)) {') . ' throw new \\RuntimeException(\'test\');') . ' }') . ' }') . '}');
1036 $className = $namespace . '\\' . $className;
1037 $className::loadExtension($extensionKeyToLoad);
1040 /////////////////////////////////////////
1041 // Tests concerning unloadExtension
1042 /////////////////////////////////////////
1045 * @expectedException RuntimeException
1047 public function unloadExtensionThrowsExceptionIfExtensionIsNotLoaded() {
1048 $namespace = 'TYPO3\\CMS\\Core\\Extension';
1049 $className = uniqid('ExtensionManager');
1050 eval(((((('namespace ' . $namespace . '; class ' . $className) . ' extends \\TYPO3\\CMS\\Core\\Extension\\ExtensionManager {') . ' public static function isLoaded() {') . ' return FALSE;') . ' }') . '}');
1051 $className = $namespace . '\\' . $className;
1052 $className::unloadExtension('test');
1057 * @expectedException RuntimeException
1059 public function unloadExtensionThrowsExceptionIfExtensionIsRequired() {
1060 $extensionKey = uniqid('test');
1061 $namespace = 'TYPO3\\CMS\\Core\\Extension';
1062 $className = uniqid('ExtensionManager');
1063 eval((((((((((('namespace ' . $namespace . '; class ' . $className) . ' extends \\TYPO3\\CMS\\Core\\Extension\\ExtensionManager {') . ' public static function isLoaded() {') . ' return TRUE;') . ' }') . ' public static function getRequiredExtensionListArray() {') . ' return array(\'') . $extensionKey) . '\');') . ' }') . '}');
1064 $className = $namespace . '\\' . $className;
1065 $className::unloadExtension($extensionKey);
1070 * @expectedException RuntimeException
1072 public function unloadExtensionRemovesExtensionFromExtList() {
1073 if (!file_exists((PATH_typo3conf
. 'LocalConfiguration.php'))) {
1074 $this->markTestSkipped('Test is not available until update wizard to transform localconf.php was run.');
1076 $extensionKeyToUnload = uniqid('unloadMe');
1077 $namespace = 'TYPO3\\CMS\\Core\\Extension';
1078 $className = uniqid('ExtensionManager');
1079 eval((((((((((((('namespace ' . $namespace . '; class ' . $className) . ' extends \\TYPO3\\CMS\\Core\\Extension\\ExtensionManager {') . ' public static function isLoaded() {') . ' return TRUE;') . ' }') . ' public static function writeNewExtensionList($extList) {') . ' if (!in_array(') . $extensionKeyToUnload) . ', $extList)) {') . ' throw new \\RuntimeException(\'test\');') . ' }') . ' }') . '}');
1080 $className = $namespace . '\\' . $className;
1081 $className::unloadExtension($extensionKeyToUnload);
1084 /////////////////////////////////////////
1085 // Tests concerning makeCategorizable
1086 /////////////////////////////////////////
1090 public function isMakeCategorizableAvailableInRegistryWithDefaultField() {
1091 $extensionKey = uniqid('extension');
1092 $tableName = uniqid('table');
1093 $GLOBALS['TCA'][$tableName] = array(
1095 'columns' => array()
1097 $registryMock = $this->getMock('TYPO3\\CMS\\Core\\Category\\CategoryRegistry', array('add'));
1098 $registryMock->expects($this->once())->method('add')->with($extensionKey, $tableName, 'categories');
1099 \TYPO3\CMS\Core\Utility\GeneralUtility
::setSingletonInstance('TYPO3\\CMS\\Core\\Category\\CategoryRegistry', $registryMock);
1100 \TYPO3\CMS\Core\Extension\ExtensionManager
::makeCategorizable($extensionKey, $tableName);
1101 $this->assertNotEmpty($GLOBALS['TCA'][$tableName]['columns']['categories']);
1107 public function isMakeCategorizableAvailableInRegistryWithSpecifictField() {
1108 $extensionKey = uniqid('extension');
1109 $tableName = uniqid('table');
1110 $fieldName = uniqid('field');
1111 $GLOBALS['TCA'][$tableName] = array(
1113 'columns' => array()
1115 $registryMock = $this->getMock('TYPO3\\CMS\\Core\\Category\\CategoryRegistry', array('add'));
1116 $registryMock->expects($this->once())->method('add')->with($extensionKey, $tableName, $fieldName);
1117 \TYPO3\CMS\Core\Utility\GeneralUtility
::setSingletonInstance('TYPO3\\CMS\\Core\\Category\\CategoryRegistry', $registryMock);
1118 \TYPO3\CMS\Core\Extension\ExtensionManager
::makeCategorizable($extensionKey, $tableName, $fieldName);
1119 $this->assertNotEmpty($GLOBALS['TCA'][$tableName]['columns'][$fieldName]);