[TASK] Move fixture files from tests/
[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 // Tests concerning getExtensionKeyByPrefix
217 /////////////////////////////////////////////
218 /**
219 * @test
220 * @see t3lib_extMgm::getExtensionKeyByPrefix
221 */
222 public function getExtensionKeyByPrefixForLoadedExtensionWithUnderscoresReturnsExtensionKey() {
223 \TYPO3\CMS\Core\Extension\ExtensionManager::clearExtensionKeyMap();
224 $uniqueSuffix = uniqid('test');
225 $extensionKey = 'tt_news' . $uniqueSuffix;
226 $extensionPrefix = 'tx_ttnews' . $uniqueSuffix;
227 $GLOBALS['TYPO3_LOADED_EXT'][$extensionKey] = array();
228 $this->assertEquals($extensionKey, \TYPO3\CMS\Core\Extension\ExtensionManager::getExtensionKeyByPrefix($extensionPrefix));
229 }
230
231 /**
232 * @test
233 * @see t3lib_extMgm::getExtensionKeyByPrefix
234 */
235 public function getExtensionKeyByPrefixForLoadedExtensionWithoutUnderscoresReturnsExtensionKey() {
236 \TYPO3\CMS\Core\Extension\ExtensionManager::clearExtensionKeyMap();
237 $uniqueSuffix = uniqid('test');
238 $extensionKey = 'kickstarter' . $uniqueSuffix;
239 $extensionPrefix = 'tx_kickstarter' . $uniqueSuffix;
240 $GLOBALS['TYPO3_LOADED_EXT'][$extensionKey] = array();
241 $this->assertEquals($extensionKey, \TYPO3\CMS\Core\Extension\ExtensionManager::getExtensionKeyByPrefix($extensionPrefix));
242 }
243
244 /**
245 * @test
246 * @see t3lib_extMgm::getExtensionKeyByPrefix
247 */
248 public function getExtensionKeyByPrefixForNotLoadedExtensionReturnsFalse() {
249 \TYPO3\CMS\Core\Extension\ExtensionManager::clearExtensionKeyMap();
250 $uniqueSuffix = uniqid('test');
251 $extensionKey = 'unloadedextension' . $uniqueSuffix;
252 $extensionPrefix = 'tx_unloadedextension' . $uniqueSuffix;
253 $this->assertFalse(\TYPO3\CMS\Core\Extension\ExtensionManager::getExtensionKeyByPrefix($extensionPrefix));
254 }
255
256 //////////////////////////////////////
257 // Tests concerning addToAllTCAtypes
258 //////////////////////////////////////
259 /**
260 * Tests whether fields can be add to all TCA types and duplicate fields are considered.
261 *
262 * @test
263 * @see t3lib_extMgm::addToAllTCAtypes()
264 */
265 public function canAddFieldsToAllTCATypesBeforeExistingOnes() {
266 $table = uniqid('tx_coretest_table');
267 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
268 \TYPO3\CMS\Core\Extension\ExtensionManager::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'before:fieldD');
269 // Checking typeA:
270 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
271 // Checking typeB:
272 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
273 }
274
275 /**
276 * Tests whether fields can be add to all TCA types and duplicate fields are considered.
277 *
278 * @test
279 * @see t3lib_extMgm::addToAllTCAtypes()
280 */
281 public function canAddFieldsToAllTCATypesAfterExistingOnes() {
282 $table = uniqid('tx_coretest_table');
283 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
284 \TYPO3\CMS\Core\Extension\ExtensionManager::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'after:fieldC');
285 // Checking typeA:
286 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
287 // Checking typeB:
288 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
289 }
290
291 /**
292 * Tests whether fields can be add to a TCA type before existing ones
293 *
294 * @test
295 * @see t3lib_extMgm::addToAllTCAtypes()
296 */
297 public function canAddFieldsToTCATypeBeforeExistingOnes() {
298 $table = uniqid('tx_coretest_table');
299 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
300 \TYPO3\CMS\Core\Extension\ExtensionManager::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', 'typeA', 'before:fieldD');
301 // Checking typeA:
302 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
303 // Checking typeB:
304 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
305 }
306
307 /**
308 * Tests whether fields can be add to a TCA type after existing ones
309 *
310 * @test
311 * @see t3lib_extMgm::addToAllTCAtypes()
312 */
313 public function canAddFieldsToTCATypeAfterExistingOnes() {
314 $table = uniqid('tx_coretest_table');
315 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
316 \TYPO3\CMS\Core\Extension\ExtensionManager::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', 'typeA', 'after:fieldC');
317 // Checking typeA:
318 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', $GLOBALS['TCA'][$table]['types']['typeA']['showitem']);
319 // Checking typeB:
320 $this->assertEquals('fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD', $GLOBALS['TCA'][$table]['types']['typeB']['showitem']);
321 }
322
323 /**
324 * Test wheter replacing other TCA fields works as promissed
325 *
326 * @test
327 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
328 */
329 public function canAddFieldsToTCATypeAndReplaceExistingOnes() {
330 $table = uniqid('tx_coretest_table');
331 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
332 $typesBefore = $GLOBALS['TCA'][$table]['types'];
333 \TYPO3\CMS\Core\Extension\ExtensionManager::addToAllTCAtypes($table, 'fieldZ', '', 'replace:fieldX');
334 $this->assertEquals($typesBefore, $GLOBALS['TCA'][$table]['types'], 'It\'s wrong that the "types" array changes here - the replaced field is only on palettes');
335 // unchanged because the palette is not used
336 $this->assertEquals('fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
337 // unchanged because the palette is not used
338 $this->assertEquals('fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
339 $this->assertEquals('fieldZ, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
340 $this->assertEquals('fieldZ, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
341 }
342
343 ///////////////////////////////////////////////////
344 // Tests concerning addFieldsToAllPalettesOfField
345 ///////////////////////////////////////////////////
346 /**
347 * Tests whether fields can be added to a palette before existing elements.
348 *
349 * @test
350 * @see t3lib_extMgm::addFieldsToPalette()
351 */
352 public function canAddFieldsToPaletteBeforeExistingOnes() {
353 $table = uniqid('tx_coretest_table');
354 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
355 \TYPO3\CMS\Core\Extension\ExtensionManager::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'before:fieldY');
356 $this->assertEquals('fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
357 }
358
359 /**
360 * Tests whether fields can be added to a palette after existing elements.
361 *
362 * @test
363 * @see t3lib_extMgm::addFieldsToPalette()
364 */
365 public function canAddFieldsToPaletteAfterExistingOnes() {
366 $table = uniqid('tx_coretest_table');
367 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
368 \TYPO3\CMS\Core\Extension\ExtensionManager::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'after:fieldX');
369 $this->assertEquals('fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
370 }
371
372 /**
373 * Tests whether fields can be added to a palette after a not existing elements.
374 *
375 * @test
376 * @see t3lib_extMgm::addFieldsToPalette()
377 */
378 public function canAddFieldsToPaletteAfterNotExistingOnes() {
379 $table = uniqid('tx_coretest_table');
380 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
381 \TYPO3\CMS\Core\Extension\ExtensionManager::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'after:' . uniqid('notExisting'));
382 $this->assertEquals('fieldX, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
383 }
384
385 /**
386 * Tests whether fields can be added to all palettes of a regular field before existing ones.
387 *
388 * @test
389 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
390 */
391 public function canAddFieldsToAllPalettesOfFieldBeforeExistingOnes() {
392 $table = uniqid('tx_coretest_table');
393 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
394 \TYPO3\CMS\Core\Extension\ExtensionManager::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'before:fieldY');
395 $this->assertEquals('fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
396 $this->assertEquals('fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
397 $this->assertEquals('fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
398 $this->assertEquals('fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
399 }
400
401 /**
402 * Tests whether fields can be added to all palettes of a regular field after existing ones.
403 *
404 * @test
405 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
406 */
407 public function canAddFieldsToAllPalettesOfFieldAfterExistingOnes() {
408 $table = uniqid('tx_coretest_table');
409 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
410 \TYPO3\CMS\Core\Extension\ExtensionManager::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'after:fieldX');
411 $this->assertEquals('fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
412 $this->assertEquals('fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
413 $this->assertEquals('fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
414 $this->assertEquals('fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
415 }
416
417 /**
418 * Tests whether fields can be added to all palettes of a regular field after a not existing field.
419 *
420 * @test
421 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
422 */
423 public function canAddFieldsToAllPalettesOfFieldAfterNotExistingOnes() {
424 $table = uniqid('tx_coretest_table');
425 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
426 \TYPO3\CMS\Core\Extension\ExtensionManager::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'after:' . uniqid('notExisting'));
427 $this->assertEquals('fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
428 $this->assertEquals('fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
429 $this->assertEquals('fieldX, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
430 $this->assertEquals('fieldX, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
431 }
432
433 /**
434 * Tests whether fields are added to a new palette that did not exist before.
435 *
436 * @test
437 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
438 */
439 public function canAddFieldsToAllPalettesOfFieldWithoutPaletteExistingBefore() {
440 $table = uniqid('tx_coretest_table');
441 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
442 \TYPO3\CMS\Core\Extension\ExtensionManager::addFieldsToAllPalettesOfField($table, 'fieldA', 'newA, newA, newB, fieldX');
443 $this->assertEquals('fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']);
444 $this->assertEquals('fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']);
445 $this->assertEquals('fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']);
446 $this->assertEquals('fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']);
447 $this->assertEquals('newA, newB, fieldX', $GLOBALS['TCA'][$table]['palettes']['generatedFor-fieldA']['showitem']);
448 }
449
450 /////////////////////////////////////////
451 // Tests concerning addTcaSelectItem
452 /////////////////////////////////////////
453 /**
454 * @test
455 * @expectedException InvalidArgumentException
456 */
457 public function addTcaSelectItemThrowsExceptionIfTableIsNotOfTypeString() {
458 \TYPO3\CMS\Core\Extension\ExtensionManager::addTcaSelectItem(array(), 'foo', array());
459 }
460
461 /**
462 * @test
463 * @expectedException InvalidArgumentException
464 */
465 public function addTcaSelectItemThrowsExceptionIfFieldIsNotOfTypeString() {
466 \TYPO3\CMS\Core\Extension\ExtensionManager::addTcaSelectItem('foo', array(), array());
467 }
468
469 /**
470 * @test
471 * @expectedException InvalidArgumentException
472 */
473 public function addTcaSelectItemThrowsExceptionIfRelativeToFieldIsNotOfTypeString() {
474 \TYPO3\CMS\Core\Extension\ExtensionManager::addTcaSelectItem('foo', 'bar', array(), array());
475 }
476
477 /**
478 * @test
479 * @expectedException InvalidArgumentException
480 */
481 public function addTcaSelectItemThrowsExceptionIfRelativePositionIsNotOfTypeString() {
482 \TYPO3\CMS\Core\Extension\ExtensionManager::addTcaSelectItem('foo', 'bar', array(), 'foo', array());
483 }
484
485 /**
486 * @test
487 * @expectedException InvalidArgumentException
488 */
489 public function addTcaSelectItemThrowsExceptionIfRelativePositionIsNotOneOfValidKeywords() {
490 \TYPO3\CMS\Core\Extension\ExtensionManager::addTcaSelectItem('foo', 'bar', array(), 'foo', 'not allowed keyword');
491 }
492
493 /**
494 * @test
495 * @expectedException RuntimeException
496 */
497 public function addTcaSelectItemThrowsExceptionIfFieldIsNotFoundInTca() {
498 $GLOBALS['TCA'] = array();
499 \TYPO3\CMS\Core\Extension\ExtensionManager::addTcaSelectItem('foo', 'bar', array());
500 }
501
502 /**
503 * Data provider for addTcaSelectItemInsertsItemAtSpecifiedPosition
504 */
505 public function addTcaSelectItemDataProvider() {
506 // Every array splits into:
507 // - relativeToField
508 // - relativePosition
509 // - expectedResultArray
510 return array(
511 'add at end of array' => array(
512 '',
513 '',
514 array(
515 0 => array('firstElement'),
516 1 => array('matchMe'),
517 2 => array('thirdElement'),
518 3 => array('insertedElement')
519 )
520 ),
521 'replace element' => array(
522 'matchMe',
523 'replace',
524 array(
525 0 => array('firstElement'),
526 1 => array('insertedElement'),
527 2 => array('thirdElement')
528 )
529 ),
530 'add element after' => array(
531 'matchMe',
532 'after',
533 array(
534 0 => array('firstElement'),
535 1 => array('matchMe'),
536 2 => array('insertedElement'),
537 3 => array('thirdElement')
538 )
539 ),
540 'add element before' => array(
541 'matchMe',
542 'before',
543 array(
544 0 => array('firstElement'),
545 1 => array('insertedElement'),
546 2 => array('matchMe'),
547 3 => array('thirdElement')
548 )
549 ),
550 'add at end if relative position was not found' => array(
551 'notExistingItem',
552 'after',
553 array(
554 0 => array('firstElement'),
555 1 => array('matchMe'),
556 2 => array('thirdElement'),
557 3 => array('insertedElement')
558 )
559 )
560 );
561 }
562
563 /**
564 * @test
565 * @dataProvider addTcaSelectItemDataProvider
566 */
567 public function addTcaSelectItemInsertsItemAtSpecifiedPosition($relativeToField, $relativePosition, $expectedResultArray) {
568 $GLOBALS['TCA'] = array(
569 'testTable' => array(
570 'columns' => array(
571 'testField' => array(
572 'config' => array(
573 'items' => array(
574 '0' => array('firstElement'),
575 '1' => array('matchMe'),
576 2 => array('thirdElement')
577 )
578 )
579 )
580 )
581 )
582 );
583 \TYPO3\CMS\Core\Extension\ExtensionManager::addTcaSelectItem('testTable', 'testField', array('insertedElement'), $relativeToField, $relativePosition);
584 $this->assertEquals($expectedResultArray, $GLOBALS['TCA']['testTable']['columns']['testField']['config']['items']);
585 }
586
587 /////////////////////////////////////////
588 // Tests concerning loadTypo3LoadedExtensionInformation
589 /////////////////////////////////////////
590 /**
591 * @test
592 */
593 public function loadTypo3LoadedExtensionInformationDoesNotCallCacheIfCachingIsDenied() {
594 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
595 $GLOBALS['typo3CacheManager']->expects($this->never())->method('getCache');
596 \TYPO3\CMS\Core\Extension\ExtensionManager::loadTypo3LoadedExtensionInformation(FALSE);
597 }
598
599 /**
600 * @test
601 */
602 public function loadTypo3LoadedExtensionInformationRequiresCacheFileIfExistsAndCachingIsAllowed() {
603 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
604 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
605 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
606 $mockCache->expects($this->any())->method('has')->will($this->returnValue(TRUE));
607 $mockCache->expects($this->once())->method('requireOnce');
608 \TYPO3\CMS\Core\Extension\ExtensionManager::loadTypo3LoadedExtensionInformation(TRUE);
609 }
610
611 /**
612 * @test
613 */
614 public function loadTypo3LoadedExtensionInformationSetsNewCacheEntryIfCacheFileDoesNotExistAndCachingIsAllowed() {
615 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
616 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
617 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
618 $mockCache->expects($this->any())->method('has')->will($this->returnValue(FALSE));
619 $mockCache->expects($this->once())->method('set');
620 \TYPO3\CMS\Core\Extension\ExtensionManager::loadTypo3LoadedExtensionInformation(TRUE);
621 }
622
623 /**
624 * @test
625 */
626 public function loadTypo3LoadedExtensionInformationSetsNewCacheEntryWithNoTags() {
627 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
628 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
629 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
630 $mockCache->expects($this->any())->method('has')->will($this->returnValue(FALSE));
631 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo(array()));
632 \TYPO3\CMS\Core\Extension\ExtensionManager::loadTypo3LoadedExtensionInformation(TRUE);
633 }
634
635 /////////////////////////////////////////
636 // Tests concerning createTypo3LoadedExtensionInformationArray
637 /////////////////////////////////////////
638 /**
639 * Data provider for createTypo3LoadedExtensionInformationArrayReturnsExpectedInformationForCmsExtension
640 *
641 * @return array
642 */
643 public function createTypo3LoadedExtensionInformationArrayReturnsExpectedInformationForCmsExtensionDataProvider() {
644 return array(
645 'System extension' => array('type', 'S'),
646 'Site relative path' => array('siteRelPath', 'typo3/sysext/cms/'),
647 'Typo3 relative path' => array('typo3RelPath', 'sysext/cms/'),
648 'Path ext_localconf.php' => array('ext_localconf.php', '/typo3/sysext/cms/ext_localconf.php'),
649 'Path ext_tables.php' => array('ext_tables.php', '/typo3/sysext/cms/ext_tables.php'),
650 'Path ext_tablps.sql' => array('ext_tables.sql', '/typo3/sysext/cms/ext_tables.sql')
651 );
652 }
653
654 /**
655 * @param string $arrayKeyToTest
656 * @param string $expectedContent
657 * @test
658 * @dataProvider createTypo3LoadedExtensionInformationArrayReturnsExpectedInformationForCmsExtensionDataProvider
659 */
660 public function createTypo3LoadedExtensionInformationArrayReturnsExpectedInformationForCmsExtension($arrayKeyToTest, $expectedContent) {
661 $actualArray = \TYPO3\CMS\Core\Extension\ExtensionManagerAccessibleProxy::createTypo3LoadedExtensionInformationArray();
662 $this->assertStringEndsWith($expectedContent, $actualArray['cms'][$arrayKeyToTest]);
663 }
664
665 /////////////////////////////////////////
666 // Tests concerning getTypo3LoadedExtensionInformationCacheIdentifier
667 /////////////////////////////////////////
668 /**
669 * @test
670 */
671 public function getTypo3LoadedExtensionInformationCacheIdentifierCreatesSha1WithFourtyCharactersAndPrefix() {
672 $prefix = 'loaded_extensions_';
673 $identifier = \TYPO3\CMS\Core\Extension\ExtensionManagerAccessibleProxy::getTypo3LoadedExtensionInformationCacheIdentifier();
674 $this->assertStringStartsWith($prefix, $identifier);
675 $sha1 = str_replace($prefix, '', $identifier);
676 $this->assertEquals(40, strlen($sha1));
677 }
678
679 /////////////////////////////////////////
680 // Tests concerning loadExtLocalconf
681 /////////////////////////////////////////
682 /**
683 * @test
684 */
685 public function loadExtLocalconfDoesNotReadFromCacheIfCachingIsDenied() {
686 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
687 $GLOBALS['typo3CacheManager']->expects($this->never())->method('getCache');
688 \TYPO3\CMS\Core\Extension\ExtensionManager::loadExtLocalconf(FALSE);
689 }
690
691 /**
692 * @test
693 */
694 public function loadExtLocalconfRequiresCacheFileIfExistsAndCachingIsAllowed() {
695 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
696 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
697 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
698 $mockCache->expects($this->any())->method('has')->will($this->returnValue(TRUE));
699 $mockCache->expects($this->once())->method('requireOnce');
700 \TYPO3\CMS\Core\Extension\ExtensionManager::loadExtLocalconf(TRUE);
701 }
702
703 /////////////////////////////////////////
704 // Tests concerning loadSingleExtLocalconfFiles
705 /////////////////////////////////////////
706 /**
707 * @test
708 * @expectedException RuntimeException
709 */
710 public function loadSingleExtLocalconfFilesRequiresExtLocalconfFileRegisteredInGlobalTypo3LoadedExt() {
711 $extensionName = uniqid('foo');
712 $extLocalconfLocation = ((PATH_site . 'typo3temp/') . uniqid('test_ext_localconf')) . '.php';
713 $this->testFilesToDelete[] = $extLocalconfLocation;
714 file_put_contents($extLocalconfLocation, '<?php
715
716 throw new RuntimeException(\'\', 1340559079);
717
718 ?>');
719 $GLOBALS['TYPO3_LOADED_EXT'] = array(
720 $extensionName => array(
721 'ext_localconf.php' => $extLocalconfLocation
722 )
723 );
724 \TYPO3\CMS\Core\Extension\ExtensionManagerAccessibleProxy::loadSingleExtLocalconfFiles();
725 }
726
727 /////////////////////////////////////////
728 // Tests concerning createExtLocalconfCacheEntry
729 /////////////////////////////////////////
730 /**
731 * @test
732 */
733 public function createExtLocalconfCacheEntryWritesCacheEntryWithContentOfLoadedExtensionExtLocalconf() {
734 $extensionName = uniqid('foo');
735 $extLocalconfLocation = ((PATH_site . 'typo3temp/') . uniqid('test_ext_localconf')) . '.php';
736 $this->testFilesToDelete[] = $extLocalconfLocation;
737 $uniqueStringInLocalconf = uniqid('foo');
738 file_put_contents($extLocalconfLocation, ('<?php
739
740 ' . $uniqueStringInLocalconf) . '
741
742 ?>');
743 $GLOBALS['TYPO3_LOADED_EXT'] = array(
744 $extensionName => array(
745 'ext_localconf.php' => $extLocalconfLocation
746 )
747 );
748 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
749 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
750 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
751 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInLocalconf), $this->anything());
752 \TYPO3\CMS\Core\Extension\ExtensionManagerAccessibleProxy::createExtLocalconfCacheEntry();
753 }
754
755 /**
756 * @test
757 */
758 public function createExtLocalconfCacheEntryWritesCacheEntryWithNoTags() {
759 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
760 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
761 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
762 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo(array()));
763 \TYPO3\CMS\Core\Extension\ExtensionManagerAccessibleProxy::createExtLocalconfCacheEntry();
764 }
765
766 /////////////////////////////////////////
767 // Tests concerning getExtLocalconfCacheIdentifier
768 /////////////////////////////////////////
769 /**
770 * @test
771 */
772 public function getExtLocalconfCacheIdentifierCreatesSha1WithFourtyCharactersAndPrefix() {
773 $prefix = 'ext_localconf_';
774 $identifier = \TYPO3\CMS\Core\Extension\ExtensionManagerAccessibleProxy::getExtLocalconfCacheIdentifier();
775 $this->assertStringStartsWith($prefix, $identifier);
776 $sha1 = str_replace($prefix, '', $identifier);
777 $this->assertEquals(40, strlen($sha1));
778 }
779
780 /////////////////////////////////////////
781 // Tests concerning loadExtTables
782 /////////////////////////////////////////
783 /**
784 * @test
785 */
786 public function loadExtTablesDoesNotReadFromCacheIfCachingIsDenied() {
787 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
788 $GLOBALS['typo3CacheManager']->expects($this->never())->method('getCache');
789 \TYPO3\CMS\Core\Extension\ExtensionManager::loadExtLocalconf(FALSE);
790 }
791
792 /**
793 * @test
794 */
795 public function loadExtTablesRequiresCacheFileIfExistsAndCachingIsAllowed() {
796 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
797 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
798 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
799 $mockCache->expects($this->any())->method('has')->will($this->returnValue(TRUE));
800 $mockCache->expects($this->once())->method('requireOnce');
801 // Reset the internal cache access tracking variable of extMgm
802 // This method is only in the ProxyClass!
803 \TYPO3\CMS\Core\Extension\ExtensionManagerAccessibleProxy::resetExtTablesWasReadFromCacheOnceBoolean();
804 \TYPO3\CMS\Core\Extension\ExtensionManager::loadExtTables(TRUE);
805 }
806
807 /////////////////////////////////////////
808 // Tests concerning createExtTablesCacheEntry
809 /////////////////////////////////////////
810 /**
811 * @test
812 */
813 public function createExtTablesCacheEntryWritesCacheEntryWithContentOfLoadedExtensionExtTables() {
814 $extensionName = uniqid('foo');
815 $extTablesLocation = ((PATH_site . 'typo3temp/') . uniqid('test_ext_tables')) . '.php';
816 $this->testFilesToDelete[] = $extTablesLocation;
817 $uniqueStringInTables = uniqid('foo');
818 file_put_contents($extTablesLocation, ('<?php
819
820 ' . $uniqueStringInTables) . '
821
822 ?>');
823 $GLOBALS['TYPO3_LOADED_EXT'] = array(
824 $extensionName => array(
825 'ext_tables.php' => $extTablesLocation
826 )
827 );
828 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
829 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
830 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
831 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->stringContains($uniqueStringInTables), $this->anything());
832 \TYPO3\CMS\Core\Extension\ExtensionManagerAccessibleProxy::createExtTablesCacheEntry();
833 }
834
835 /**
836 * @test
837 */
838 public function createExtTablesCacheEntryWritesCacheEntryWithNoTags() {
839 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
840 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
841 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
842 $mockCache->expects($this->once())->method('set')->with($this->anything(), $this->anything(), $this->equalTo(array()));
843 \TYPO3\CMS\Core\Extension\ExtensionManagerAccessibleProxy::createExtTablesCacheEntry();
844 }
845
846 /////////////////////////////////////////
847 // Tests concerning getExtTablesCacheIdentifier
848 /////////////////////////////////////////
849 /**
850 * @test
851 */
852 public function getExtTablesCacheIdentifierCreatesSha1WithFourtyCharactersAndPrefix() {
853 $prefix = 'ext_tables_';
854 $identifier = \TYPO3\CMS\Core\Extension\ExtensionManagerAccessibleProxy::getExtTablesCacheIdentifier();
855 $this->assertStringStartsWith($prefix, $identifier);
856 $sha1 = str_replace($prefix, '', $identifier);
857 $this->assertEquals(40, strlen($sha1));
858 }
859
860 /////////////////////////////////////////
861 // Tests concerning removeCacheFiles
862 /////////////////////////////////////////
863 /**
864 * @test
865 */
866 public function removeCacheFilesFlushesCache() {
867 $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'), array(), '', FALSE);
868 $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
869 $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
870 $mockCache->expects($this->once())->method('flush');
871 \TYPO3\CMS\Core\Extension\ExtensionManager::removeCacheFiles();
872 }
873
874 /////////////////////////////////////////
875 // Tests concerning getExtensionVersion
876 /////////////////////////////////////////
877 /**
878 * Data provider for negative getExtensionVersion() tests.
879 *
880 * @return array
881 */
882 public function getExtensionVersionFaultyDataProvider() {
883 return array(
884 array(''),
885 array(0),
886 array(new \stdClass()),
887 array(TRUE)
888 );
889 }
890
891 /**
892 * @test
893 * @expectedException InvalidArgumentException
894 * @dataProvider getExtensionVersionFaultyDataProvider
895 */
896 public function getExtensionVersionForFaultyExtensionKeyThrowsException($key) {
897 \TYPO3\CMS\Core\Extension\ExtensionManager::getExtensionVersion($key);
898 }
899
900 /**
901 * @test
902 */
903 public function getExtensionVersionForNotLoadedExtensionReturnsEmptyString() {
904 \TYPO3\CMS\Core\Extension\ExtensionManager::clearExtensionKeyMap();
905 $uniqueSuffix = uniqid('test');
906 $extensionKey = 'unloadedextension' . $uniqueSuffix;
907 $this->assertEquals('', \TYPO3\CMS\Core\Extension\ExtensionManager::getExtensionVersion($extensionKey));
908 }
909
910 /**
911 * @test
912 */
913 public function getExtensionVersionForLoadedExtensionReturnsExtensionVersion() {
914 $namespace = 'TYPO3\\CMS\\Core\\Extension';
915 $className = uniqid('ExtensionManager');
916 eval(
917 'namespace ' . $namespace .';' .
918 'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\Extension\\ExtensionManager {' .
919 ' public static function isLoaded() {' .
920 ' return TRUE;' .
921 ' }' .
922 '}'
923 );
924 $className = $namespace . '\\' . $className;
925 \TYPO3\CMS\Core\Extension\ExtensionManager::clearExtensionKeyMap();
926 $uniqueSuffix = uniqid('test');
927 $extensionKey = 'unloadedextension' . $uniqueSuffix;
928 $GLOBALS['TYPO3_LOADED_EXT'][$extensionKey] = array(
929 'siteRelPath' => 'typo3/sysext/core/Tests/Unit/Extension/Fixtures/',
930 );
931 $this->assertEquals('1.2.3', $className::getExtensionVersion($extensionKey));
932 }
933
934 /////////////////////////////////////////
935 // Tests concerning getLoadedExtensionListArray
936 /////////////////////////////////////////
937 /**
938 * @test
939 */
940 public function getLoadedExtensionListArrayConsidersExtListAsString() {
941 unset($GLOBALS['TYPO3_CONF_VARS']['EXT']['extListArray']);
942 $GLOBALS['TYPO3_CONF_VARS']['EXT']['extList'] = 'foo,bar';
943 $this->assertEquals(array('foo', 'bar'), array_intersect(array('foo', 'bar'), \TYPO3\CMS\Core\Extension\ExtensionManager::getLoadedExtensionListArray()));
944 }
945
946 /**
947 * @test
948 */
949 public function getLoadedExtensionListArrayConsidersExtListAsArray() {
950 $extList = array('foo', 'bar');
951 $GLOBALS['TYPO3_CONF_VARS']['EXT']['extListArray'] = $extList;
952 $this->assertEquals($extList, array_intersect($extList, \TYPO3\CMS\Core\Extension\ExtensionManager::getLoadedExtensionListArray()));
953 }
954
955 /**
956 * @test
957 */
958 public function getLoadedExtensionListArrayConsidersRequiredExtensions() {
959 $namespace = 'TYPO3\\CMS\\Core\\Extension';
960 $className = uniqid('ExtensionManager');
961 eval(((((('namespace ' . $namespace . '; class ' . $className) . ' extends \\TYPO3\\CMS\\Core\\Extension\\ExtensionManager {') . ' public static function getRequiredExtensionListArray() {') . ' return array(\'baz\');') . ' }') . '}');
962 $className = $namespace . '\\' . $className;
963 $GLOBALS['TYPO3_CONF_VARS']['EXT']['extListArray'] = array();
964 $this->assertEquals(array('baz'), $className::getLoadedExtensionListArray());
965 }
966
967 /**
968 * @test
969 */
970 public function getLoadedExtensionListArrayReturnsUniqueList() {
971 $namespace = 'TYPO3\\CMS\\Core\\Extension';
972 $className = uniqid('ExtensionManager');
973 eval(((((('namespace ' . $namespace . '; class ' . $className) . ' extends \\TYPO3\\CMS\\Core\\Extension\\ExtensionManager {') . ' public static function getRequiredExtensionListArray() {') . ' return array(\'bar\');') . ' }') . '}');
974 $className = $namespace . '\\' . $className;
975 $GLOBALS['TYPO3_CONF_VARS']['EXT']['extListArray'] = array('foo', 'bar', 'foo');
976 $this->assertSame(array('bar', 'foo'), $className::getLoadedExtensionListArray());
977 }
978
979 /////////////////////////////////////////
980 // Tests concerning getRequiredExtensionListArray
981 /////////////////////////////////////////
982 /**
983 * @test
984 */
985 public function getRequiredExtensionListArrayContainsAdditionalRequiredExtensionsAsString() {
986 $GLOBALS['TYPO3_CONF_VARS']['EXT']['requiredExt'] = 'foo,bar';
987 $this->assertEquals(array('foo', 'bar'), array_intersect(array('foo', 'bar'), \TYPO3\CMS\Core\Extension\ExtensionManager::getLoadedExtensionListArray()));
988 }
989
990 /**
991 * @test
992 */
993 public function getRequiredExtensionListArrayContainsAdditionalRequiredExtensionsAsArray() {
994 $requiredExtList = array('foo', 'bar');
995 $GLOBALS['TYPO3_CONF_VARS']['EXT']['requiredExt'] = $requiredExtList;
996 $this->assertEquals($requiredExtList, array_intersect($requiredExtList, \TYPO3\CMS\Core\Extension\ExtensionManager::getLoadedExtensionListArray()));
997 }
998
999 /**
1000 * @test
1001 */
1002 public function getRequiredExtensionListArrayReturnsUniqueList() {
1003 $GLOBALS['TYPO3_CONF_VARS']['EXT']['requiredExt'] = 'foo,bar,foo';
1004 $this->assertEquals(array('foo', 'bar'), array_intersect(array('foo', 'bar'), \TYPO3\CMS\Core\Extension\ExtensionManager::getLoadedExtensionListArray()));
1005 }
1006
1007 /////////////////////////////////////////
1008 // Tests concerning loadExtension
1009 /////////////////////////////////////////
1010 /**
1011 * @test
1012 * @expectedException RuntimeException
1013 */
1014 public function loadExtensionThrowsExceptionIfExtensionIsLoaded() {
1015 $namespace = 'TYPO3\\CMS\\Core\\Extension';
1016 $className = uniqid('ExtensionManager');
1017 eval(((((('namespace ' . $namespace . '; class ' . $className) . ' extends \\TYPO3\\CMS\\Core\\Extension\\ExtensionManager {') . ' public static function isLoaded() {') . ' return TRUE;') . ' }') . '}');
1018 $className = $namespace . '\\' . $className;
1019 $className::loadExtension('test');
1020 }
1021
1022 /**
1023 * @test
1024 * @expectedException RuntimeException
1025 */
1026 public function loadExtensionAddsExtensionToExtList() {
1027 if (!file_exists((PATH_typo3conf . 'LocalConfiguration.php'))) {
1028 $this->markTestSkipped('Test is not available until update wizard to transform localconf.php was run.');
1029 }
1030 $extensionKeyToLoad = uniqid('loadMe');
1031 $namespace = 'TYPO3\\CMS\\Core\\Extension';
1032 $className = uniqid('ExtensionManager');
1033 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\');') . ' }') . ' }') . '}');
1034 $className = $namespace . '\\' . $className;
1035 $className::loadExtension($extensionKeyToLoad);
1036 }
1037
1038 /////////////////////////////////////////
1039 // Tests concerning unloadExtension
1040 /////////////////////////////////////////
1041 /**
1042 * @test
1043 * @expectedException RuntimeException
1044 */
1045 public function unloadExtensionThrowsExceptionIfExtensionIsNotLoaded() {
1046 $namespace = 'TYPO3\\CMS\\Core\\Extension';
1047 $className = uniqid('ExtensionManager');
1048 eval(((((('namespace ' . $namespace . '; class ' . $className) . ' extends \\TYPO3\\CMS\\Core\\Extension\\ExtensionManager {') . ' public static function isLoaded() {') . ' return FALSE;') . ' }') . '}');
1049 $className = $namespace . '\\' . $className;
1050 $className::unloadExtension('test');
1051 }
1052
1053 /**
1054 * @test
1055 * @expectedException RuntimeException
1056 */
1057 public function unloadExtensionThrowsExceptionIfExtensionIsRequired() {
1058 $extensionKey = uniqid('test');
1059 $namespace = 'TYPO3\\CMS\\Core\\Extension';
1060 $className = uniqid('ExtensionManager');
1061 eval((((((((((('namespace ' . $namespace . '; class ' . $className) . ' extends \\TYPO3\\CMS\\Core\\Extension\\ExtensionManager {') . ' public static function isLoaded() {') . ' return TRUE;') . ' }') . ' public static function getRequiredExtensionListArray() {') . ' return array(\'') . $extensionKey) . '\');') . ' }') . '}');
1062 $className = $namespace . '\\' . $className;
1063 $className::unloadExtension($extensionKey);
1064 }
1065
1066 /**
1067 * @test
1068 * @expectedException RuntimeException
1069 */
1070 public function unloadExtensionRemovesExtensionFromExtList() {
1071 if (!file_exists((PATH_typo3conf . 'LocalConfiguration.php'))) {
1072 $this->markTestSkipped('Test is not available until update wizard to transform localconf.php was run.');
1073 }
1074 $extensionKeyToUnload = uniqid('unloadMe');
1075 $namespace = 'TYPO3\\CMS\\Core\\Extension';
1076 $className = uniqid('ExtensionManager');
1077 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\');') . ' }') . ' }') . '}');
1078 $className = $namespace . '\\' . $className;
1079 $className::unloadExtension($extensionKeyToUnload);
1080 }
1081
1082 /////////////////////////////////////////
1083 // Tests concerning makeCategorizable
1084 /////////////////////////////////////////
1085 /**
1086 * @test
1087 */
1088 public function isMakeCategorizableAvailableInRegistryWithDefaultField() {
1089 $extensionKey = uniqid('extension');
1090 $tableName = uniqid('table');
1091 $GLOBALS['TCA'][$tableName] = array(
1092 'ctrl' => array(),
1093 'columns' => array()
1094 );
1095 $registryMock = $this->getMock('TYPO3\\CMS\\Core\\Category\\CategoryRegistry', array('add'));
1096 $registryMock->expects($this->once())->method('add')->with($extensionKey, $tableName, 'categories');
1097 \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Category\\CategoryRegistry', $registryMock);
1098 \TYPO3\CMS\Core\Extension\ExtensionManager::makeCategorizable($extensionKey, $tableName);
1099 $this->assertNotEmpty($GLOBALS['TCA'][$tableName]['columns']['categories']);
1100 }
1101
1102 /**
1103 * @test
1104 */
1105 public function isMakeCategorizableAvailableInRegistryWithSpecifictField() {
1106 $extensionKey = uniqid('extension');
1107 $tableName = uniqid('table');
1108 $fieldName = uniqid('field');
1109 $GLOBALS['TCA'][$tableName] = array(
1110 'ctrl' => array(),
1111 'columns' => array()
1112 );
1113 $registryMock = $this->getMock('TYPO3\\CMS\\Core\\Category\\CategoryRegistry', array('add'));
1114 $registryMock->expects($this->once())->method('add')->with($extensionKey, $tableName, $fieldName);
1115 \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Category\\CategoryRegistry', $registryMock);
1116 \TYPO3\CMS\Core\Extension\ExtensionManager::makeCategorizable($extensionKey, $tableName, $fieldName);
1117 $this->assertNotEmpty($GLOBALS['TCA'][$tableName]['columns'][$fieldName]);
1118 }
1119
1120 }
1121
1122 ?>