26206d17da06dca239096bbe1425722d92494b44
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Extension / ExtensionManagerTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Extension;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009-2011 Oliver Hader <oliver@typo3.org>
8 * All rights reserved
9 *
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.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
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.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Testcase for \TYPO3\CMS\Core\Extension\ExtensionManager
29 *
30 * @author Oliver Hader <oliver@typo3.org>
31 * @author Oliver Klee <typo3-coding@oliverklee.de>
32 * @package TYPO3
33 * @subpackage t3lib
34 */
35 class ExtensionManagerTest extends \tx_phpunit_testcase {
36
37 /**
38 * @var array A backup of registered singleton instances
39 */
40 protected $singletonInstances = array();
41
42 /**
43 * Enable backup of global and system variables
44 *
45 * @var boolean
46 */
47 protected $backupGlobals = TRUE;
48
49 /**
50 * Exclude TYPO3_DB from backup/ restore of $GLOBALS
51 * because resource types cannot be handled during serializing
52 *
53 * @var array
54 */
55 protected $backupGlobalsBlacklist = array('TYPO3_DB');
56
57 /**
58 * phpunit still needs some globals that are
59 * reconstructed before $backupGlobals is handled. Those
60 * important globals are handled in tearDown() directly.
61 *
62 * @var array
63 */
64 protected $globals = array();
65
66 /**
67 * Absolute path to files that must be removed
68 * after a test - handled in tearDown
69 *
70 * @TODO : Check if the tests can use vfs:// instead
71 */
72 protected $testFilesToDelete = array();
73
74 public function setUp() {
75 $this->createAccessibleProxyClass();
76 $this->globals = array(
77 'TYPO3_LOADED_EXT' => serialize($GLOBALS['TYPO3_LOADED_EXT'])
78 );
79 $this->testFilesToDelete = array();
80 $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
81 }
82
83 public function tearDown() {
84 \TYPO3\CMS\Core\Extension\ExtensionManager::clearExtensionKeyMap();
85 foreach ($this->globals as $key => $value) {
86 $GLOBALS[$key] = unserialize($value);
87 }
88 foreach ($this->testFilesToDelete as $absoluteFileName) {
89 \TYPO3\CMS\Core\Utility\GeneralUtility::unlink_tempfile($absoluteFileName);
90 }
91 \TYPO3\CMS\Core\Utility\GeneralUtility::resetSingletonInstances($this->singletonInstances);
92 }
93
94 /**
95 * Create a subclass with protected methods made public
96 *
97 * @return void
98 */
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();') . ' }') . '}');
104 }
105 }
106
107 ///////////////////////////////
108 // Tests concerning isLoaded
109 ///////////////////////////////
110 /**
111 * @test
112 */
113 public function isLoadedReturnsTrueIfExtensionIsLoaded() {
114 $this->assertTrue(\TYPO3\CMS\Core\Extension\ExtensionManager::isLoaded('cms'));
115 }
116
117 /**
118 * @test
119 */
120 public function isLoadedReturnsFalseIfExtensionIsNotLoadedAndExitIsDisabled() {
121 $this->assertFalse(\TYPO3\CMS\Core\Extension\ExtensionManager::isLoaded(uniqid('foobar'), FALSE));
122 }
123
124 /**
125 * @test
126 * @expectedException BadFunctionCallException
127 */
128 public function isLoadedThrowsExceptionIfExtensionIsNotLoaded() {
129 $this->assertFalse(\TYPO3\CMS\Core\Extension\ExtensionManager::isLoaded(uniqid('foobar'), TRUE));
130 }
131
132 ///////////////////////////////
133 // Tests concerning extPath
134 ///////////////////////////////
135 /**
136 * @test
137 * @expectedException BadFunctionCallException
138 */
139 public function extPathThrowsExceptionIfExtensionIsNotLoaded() {
140 $GLOBALS['TYPO3_LOADED_EXT']['foo'] = array();
141 \TYPO3\CMS\Core\Extension\ExtensionManager::extPath('bar');
142 }
143
144 /**
145 * @test
146 */
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'));
150 }
151
152 /**
153 * @test
154 * @expectedException BadFunctionCallException
155 */
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');
161 }
162
163 /**
164 * @test
165 */
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');
172 }
173
174 /**
175 * @test
176 */
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');
183 }
184
185 //////////////////////
186 // Utility functions
187 //////////////////////
188 /**
189 * Generates a basic TCA for a given table.
190 *
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
193 */
194 private function generateTCAForTable($table) {
195 $tca = array();
196 $tca[$table] = array();
197 $tca[$table]['columns'] = array(
198 'fieldA' => array(),
199 'fieldC' => array()
200 );
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')
205 );
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')
211 );
212 return $tca;
213 }
214
215 /**
216 * Returns the fixtures path for this testcase relative to PATH_site.
217 *
218 * @return string the fixtures path for this testcase, will not be empty
219 */
220 private function determineFixturesPath() {
221 return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Phpunit_Service_TestFinder')->getRelativeCoreTestsPath() . 'Unit/t3lib/fixtures/';
222 }
223
224 /////////////////////////////////////////////
225 // Tests concerning getExtensionKeyByPrefix
226 /////////////////////////////////////////////
227 /**
228 * @test
229 * @see t3lib_extMgm::getExtensionKeyByPrefix
230 */
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));
238 }
239
240 /**
241 * @test
242 * @see t3lib_extMgm::getExtensionKeyByPrefix
243 */
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));
251 }
252
253 /**
254 * @test
255 * @see t3lib_extMgm::getExtensionKeyByPrefix
256 */
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));
263 }
264
265 //////////////////////////////////////
266 // Tests concerning addToAllTCAtypes
267 //////////////////////////////////////
268 /**
269 * Tests whether fields can be add to all TCA types and duplicate fields are considered.
270 *
271 * @test
272 * @see t3lib_extMgm::addToAllTCAtypes()
273 */
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');
278 // Checking typeA:
279 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
280 // Checking typeB:
281 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
282 }
283
284 /**
285 * Tests whether fields can be add to all TCA types and duplicate fields are considered.
286 *
287 * @test
288 * @see t3lib_extMgm::addToAllTCAtypes()
289 */
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');
294 // Checking typeA:
295 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
296 // Checking typeB:
297 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
298 }
299
300 /**
301 * Tests whether fields can be add to a TCA type before existing ones
302 *
303 * @test
304 * @see t3lib_extMgm::addToAllTCAtypes()
305 */
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');
310 // Checking typeA:
311 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
312 // Checking typeB:
313 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
314 }
315
316 /**
317 * Tests whether fields can be add to a TCA type after existing ones
318 *
319 * @test
320 * @see t3lib_extMgm::addToAllTCAtypes()
321 */
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');
326 // Checking typeA:
327 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
328 // Checking typeB:
329 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
330 }
331
332 /**
333 * Test wheter replacing other TCA fields works as promissed
334 *
335 * @test
336 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
337 */
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']);
350 }
351
352 ///////////////////////////////////////////////////
353 // Tests concerning addFieldsToAllPalettesOfField
354 ///////////////////////////////////////////////////
355 /**
356 * Tests whether fields can be added to a palette before existing elements.
357 *
358 * @test
359 * @see t3lib_extMgm::addFieldsToPalette()
360 */
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']);
366 }
367
368 /**
369 * Tests whether fields can be added to a palette after existing elements.
370 *
371 * @test
372 * @see t3lib_extMgm::addFieldsToPalette()
373 */
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']);
379 }
380
381 /**
382 * Tests whether fields can be added to a palette after a not existing elements.
383 *
384 * @test
385 * @see t3lib_extMgm::addFieldsToPalette()
386 */
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']);
392 }
393
394 /**
395 * Tests whether fields can be added to all palettes of a regular field before existing ones.
396 *
397 * @test
398 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
399 */
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']);
408 }
409
410 /**
411 * Tests whether fields can be added to all palettes of a regular field after existing ones.
412 *
413 * @test
414 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
415 */
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']);
424 }
425
426 /**
427 * Tests whether fields can be added to all palettes of a regular field after a not existing field.
428 *
429 * @test
430 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
431 */
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']);
440 }
441
442 /**
443 * Tests whether fields are added to a new palette that did not exist before.
444 *
445 * @test
446 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
447 */
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']);
457 }
458
459 /////////////////////////////////////////
460 // Tests concerning addTcaSelectItem
461 /////////////////////////////////////////
462 /**
463 * @test
464 * @expectedException InvalidArgumentException
465 */
466 public function addTcaSelectItemThrowsExceptionIfTableIsNotOfTypeString() {
467 \TYPO3\CMS\Core\Extension\ExtensionManager::addTcaSelectItem(array(), 'foo', array());
468 }
469
470 /**
471 * @test
472 * @expectedException InvalidArgumentException
473 */
474 public function addTcaSelectItemThrowsExceptionIfFieldIsNotOfTypeString() {
475 \TYPO3\CMS\Core\Extension\ExtensionManager::addTcaSelectItem('foo', array(), array());
476 }
477
478 /**
479 * @test
480 * @expectedException InvalidArgumentException
481 */
482 public function addTcaSelectItemThrowsExceptionIfRelativeToFieldIsNotOfTypeString() {
483 \TYPO3\CMS\Core\Extension\ExtensionManager::addTcaSelectItem('foo', 'bar', array(), array());
484 }
485
486 /**
487 * @test
488 * @expectedException InvalidArgumentException
489 */
490 public function addTcaSelectItemThrowsExceptionIfRelativePositionIsNotOfTypeString() {
491 \TYPO3\CMS\Core\Extension\ExtensionManager::addTcaSelectItem('foo', 'bar', array(), 'foo', array());
492 }
493
494 /**
495 * @test
496 * @expectedException InvalidArgumentException
497 */
498 public function addTcaSelectItemThrowsExceptionIfRelativePositionIsNotOneOfValidKeywords() {
499 \TYPO3\CMS\Core\Extension\ExtensionManager::addTcaSelectItem('foo', 'bar', array(), 'foo', 'not allowed keyword');
500 }
501
502 /**
503 * @test
504 * @expectedException RuntimeException
505 */
506 public function addTcaSelectItemThrowsExceptionIfFieldIsNotFoundInTca() {
507 $GLOBALS['TCA'] = array();
508 \TYPO3\CMS\Core\Extension\ExtensionManager::addTcaSelectItem('foo', 'bar', array());
509 }
510
511 /**
512 * Data provider for addTcaSelectItemInsertsItemAtSpecifiedPosition
513 */
514 public function addTcaSelectItemDataProvider() {
515 // Every array splits into:
516 // - relativeToField
517 // - relativePosition
518 // - expectedResultArray
519 return array(
520 'add at end of array' => array(
521 '',
522 '',
523 array(
524 0 => array('firstElement'),
525 1 => array('matchMe'),
526 2 => array('thirdElement'),
527 3 => array('insertedElement')
528 )
529 ),
530 'replace element' => array(
531 'matchMe',
532 'replace',
533 array(
534 0 => array('firstElement'),
535 1 => array('insertedElement'),
536 2 => array('thirdElement')
537 )
538 ),
539 'add element after' => array(
540 'matchMe',
541 'after',
542 array(
543 0 => array('firstElement'),
544 1 => array('matchMe'),
545 2 => array('insertedElement'),
546 3 => array('thirdElement')
547 )
548 ),
549 'add element before' => array(
550 'matchMe',
551 'before',
552 array(
553 0 => array('firstElement'),
554 1 => array('insertedElement'),
555 2 => array('matchMe'),
556 3 => array('thirdElement')
557 )
558 ),
559 'add at end if relative position was not found' => array(
560 'notExistingItem',
561 'after',
562 array(
563 0 => array('firstElement'),
564 1 => array('matchMe'),
565 2 => array('thirdElement'),
566 3 => array('insertedElement')
567 )
568 )
569 );
570 }
571
572 /**
573 * @test
574 * @dataProvider addTcaSelectItemDataProvider
575 */
576 public function addTcaSelectItemInsertsItemAtSpecifiedPosition($relativeToField, $relativePosition, $expectedResultArray) {
577 $GLOBALS['TCA'] = array(
578 'testTable' => array(
579 'columns' => array(
580 'testField' => array(
581 'config' => array(
582 'items' => array(
583 '0' => array('firstElement'),
584 '1' => array('matchMe'),
585 2 => array('thirdElement')
586 )
587 )
588 )
589 )
590 )
591 );
592 \TYPO3\CMS\Core\Extension\ExtensionManager::addTcaSelectItem('testTable', 'testField', array('insertedElement'), $relativeToField, $relativePosition);
593 $this->assertEquals($expectedResultArray, $GLOBALS['TCA']['testTable']['columns']['testField']['config']['items']);
594 }
595
596 /////////////////////////////////////////
597 // Tests concerning loadTypo3LoadedExtensionInformation
598 /////////////////////////////////////////
599 /**
600 * @test
601 */
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);
606 }
607
608 /**
609 * @test
610 */
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);
618 }
619
620 /**
621 * @test
622 */
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);
630 }
631
632 /**
633 * @test
634 */
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);
642 }
643
644 /////////////////////////////////////////
645 // Tests concerning createTypo3LoadedExtensionInformationArray
646 /////////////////////////////////////////
647 /**
648 * Data provider for createTypo3LoadedExtensionInformationArrayReturnsExpectedInformationForCmsExtension
649 *
650 * @return array
651 */
652 public function createTypo3LoadedExtensionInformationArrayReturnsExpectedInformationForCmsExtensionDataProvider() {
653 return array(
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')
660 );
661 }
662
663 /**
664 * @param string $arrayKeyToTest
665 * @param string $expectedContent
666 * @test
667 * @dataProvider createTypo3LoadedExtensionInformationArrayReturnsExpectedInformationForCmsExtensionDataProvider
668 */
669 public function createTypo3LoadedExtensionInformationArrayReturnsExpectedInformationForCmsExtension($arrayKeyToTest, $expectedContent) {
670 $actualArray = \TYPO3\CMS\Core\Extension\ExtensionManagerAccessibleProxy::createTypo3LoadedExtensionInformationArray();
671 $this->assertStringEndsWith($expectedContent, $actualArray['cms'][$arrayKeyToTest]);
672 }
673
674 /////////////////////////////////////////
675 // Tests concerning getTypo3LoadedExtensionInformationCacheIdentifier
676 /////////////////////////////////////////
677 /**
678 * @test
679 */
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));
686 }
687
688 /////////////////////////////////////////
689 // Tests concerning loadExtLocalconf
690 /////////////////////////////////////////
691 /**
692 * @test
693 */
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);
698 }
699
700 /**
701 * @test
702 */
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);
710 }
711
712 /////////////////////////////////////////
713 // Tests concerning loadSingleExtLocalconfFiles
714 /////////////////////////////////////////
715 /**
716 * @test
717 * @expectedException RuntimeException
718 */
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
724
725 throw new RuntimeException(\'\', 1340559079);
726
727 ?>');
728 $GLOBALS['TYPO3_LOADED_EXT'] = array(
729 $extensionName => array(
730 'ext_localconf.php' => $extLocalconfLocation
731 )
732 );
733 \TYPO3\CMS\Core\Extension\ExtensionManagerAccessibleProxy::loadSingleExtLocalconfFiles();
734 }
735
736 /////////////////////////////////////////
737 // Tests concerning createExtLocalconfCacheEntry
738 /////////////////////////////////////////
739 /**
740 * @test
741 */
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
748
749 ' . $uniqueStringInLocalconf) . '
750
751 ?>');
752 $GLOBALS['TYPO3_LOADED_EXT'] = array(
753 $extensionName => array(
754 'ext_localconf.php' => $extLocalconfLocation
755 )
756 );
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();
762 }
763
764 /**
765 * @test
766 */
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();
773 }
774
775 /////////////////////////////////////////
776 // Tests concerning getExtLocalconfCacheIdentifier
777 /////////////////////////////////////////
778 /**
779 * @test
780 */
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));
787 }
788
789 /////////////////////////////////////////
790 // Tests concerning loadExtTables
791 /////////////////////////////////////////
792 /**
793 * @test
794 */
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);
799 }
800
801 /**
802 * @test
803 */
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);
814 }
815
816 /////////////////////////////////////////
817 // Tests concerning createExtTablesCacheEntry
818 /////////////////////////////////////////
819 /**
820 * @test
821 */
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
828
829 ' . $uniqueStringInTables) . '
830
831 ?>');
832 $GLOBALS['TYPO3_LOADED_EXT'] = array(
833 $extensionName => array(
834 'ext_tables.php' => $extTablesLocation
835 )
836 );
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();
842 }
843
844 /**
845 * @test
846 */
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();
853 }
854
855 /////////////////////////////////////////
856 // Tests concerning getExtTablesCacheIdentifier
857 /////////////////////////////////////////
858 /**
859 * @test
860 */
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));
867 }
868
869 /////////////////////////////////////////
870 // Tests concerning removeCacheFiles
871 /////////////////////////////////////////
872 /**
873 * @test
874 */
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();
881 }
882
883 /////////////////////////////////////////
884 // Tests concerning getExtensionVersion
885 /////////////////////////////////////////
886 /**
887 * Data provider for negative getExtensionVersion() tests.
888 *
889 * @return array
890 */
891 public function getExtensionVersionFaultyDataProvider() {
892 return array(
893 array(''),
894 array(0),
895 array(new \stdClass()),
896 array(TRUE)
897 );
898 }
899
900 /**
901 * @test
902 * @expectedException InvalidArgumentException
903 * @dataProvider getExtensionVersionFaultyDataProvider
904 */
905 public function getExtensionVersionForFaultyExtensionKeyThrowsException($key) {
906 \TYPO3\CMS\Core\Extension\ExtensionManager::getExtensionVersion($key);
907 }
908
909 /**
910 * @test
911 */
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));
917 }
918
919 /**
920 * @test
921 */
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()
932 );
933 $this->assertEquals('1.2.3', $className::getExtensionVersion($extensionKey));
934 }
935
936 /////////////////////////////////////////
937 // Tests concerning getLoadedExtensionListArray
938 /////////////////////////////////////////
939 /**
940 * @test
941 */
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()));
946 }
947
948 /**
949 * @test
950 */
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()));
955 }
956
957 /**
958 * @test
959 */
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());
967 }
968
969 /**
970 * @test
971 */
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());
979 }
980
981 /////////////////////////////////////////
982 // Tests concerning getRequiredExtensionListArray
983 /////////////////////////////////////////
984 /**
985 * @test
986 */
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()));
990 }
991
992 /**
993 * @test
994 */
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()));
999 }
1000
1001 /**
1002 * @test
1003 */
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()));
1007 }
1008
1009 /////////////////////////////////////////
1010 // Tests concerning loadExtension
1011 /////////////////////////////////////////
1012 /**
1013 * @test
1014 * @expectedException RuntimeException
1015 */
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');
1022 }
1023
1024 /**
1025 * @test
1026 * @expectedException RuntimeException
1027 */
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.');
1031 }
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);
1038 }
1039
1040 /////////////////////////////////////////
1041 // Tests concerning unloadExtension
1042 /////////////////////////////////////////
1043 /**
1044 * @test
1045 * @expectedException RuntimeException
1046 */
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');
1053 }
1054
1055 /**
1056 * @test
1057 * @expectedException RuntimeException
1058 */
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);
1066 }
1067
1068 /**
1069 * @test
1070 * @expectedException RuntimeException
1071 */
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.');
1075 }
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);
1082 }
1083
1084 /////////////////////////////////////////
1085 // Tests concerning makeCategorizable
1086 /////////////////////////////////////////
1087 /**
1088 * @test
1089 */
1090 public function isMakeCategorizableAvailableInRegistryWithDefaultField() {
1091 $extensionKey = uniqid('extension');
1092 $tableName = uniqid('table');
1093 $GLOBALS['TCA'][$tableName] = array(
1094 'ctrl' => array(),
1095 'columns' => array()
1096 );
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']);
1102 }
1103
1104 /**
1105 * @test
1106 */
1107 public function isMakeCategorizableAvailableInRegistryWithSpecifictField() {
1108 $extensionKey = uniqid('extension');
1109 $tableName = uniqid('table');
1110 $fieldName = uniqid('field');
1111 $GLOBALS['TCA'][$tableName] = array(
1112 'ctrl' => array(),
1113 'columns' => array()
1114 );
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]);
1120 }
1121
1122 }
1123
1124 ?>