2 /***************************************************************
5 * (c) 2009-2011 Oliver Hader <oliver@typo3.org>
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
26 * Testcase for class t3lib_extMgm
28 * @author Oliver Hader <oliver@typo3.org>
29 * @author Oliver Klee <typo3-coding@oliverklee.de>
34 class t3lib_extmgmTest
extends tx_phpunit_testcase
{
36 * backup of defined GLOBALS
40 protected $globals = array();
42 public function setUp() {
43 $this->globals
= array(
44 'TYPO3_CONF_VARS' => serialize($GLOBALS['TYPO3_CONF_VARS']),
45 'TYPO3_LOADED_EXT' => serialize($GLOBALS['TYPO3_LOADED_EXT']),
46 'TCA' => serialize($GLOBALS['TCA']),
50 public function tearDown() {
51 t3lib_extMgm
::clearExtensionKeyMap();
53 foreach ($this->globals
as $key => $value) {
54 $GLOBALS[$key] = unserialize($value);
59 //////////////////////
61 //////////////////////
64 * Generates a basic TCA for a given table.
66 * @param string $table name of the table, must not be empty
67 * @return array generated TCA for the given table, will not be empty
69 private function generateTCAForTable($table) {
71 $tca[$table] = array();
72 $tca[$table]['columns'] = array(
76 $tca[$table]['types'] = array(
77 'typeA' => array('showitem' => 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD'),
78 'typeB' => array('showitem' => 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD'),
79 'typeC' => array('showitem' => 'fieldC;;paletteD'),
81 $tca[$table]['palettes'] = array(
82 'paletteA' => array('showitem' => 'fieldX, fieldY'),
83 'paletteB' => array('showitem' => 'fieldX, fieldY'),
84 'paletteC' => array('showitem' => 'fieldX, fieldY'),
85 'paletteD' => array('showitem' => 'fieldX, fieldY'),
92 * Returns the fixtures path for this testcase relative to PATH_site.
94 * @return string the fixtures path for this testcase, will not be empty
96 private function determineFixturesPath() {
97 return t3lib_div
::makeInstance('Tx_Phpunit_Service_TestFinder')
98 ->getRelativeCoreTestsPath() . 't3lib/fixtures/';
102 /////////////////////////////////////////////
103 // Tests concerning getExtensionKeyByPrefix
104 /////////////////////////////////////////////
108 * @see t3lib_extMgm::getExtensionKeyByPrefix
110 public function getExtensionKeyByPrefixForLoadedExtensionWithUnderscoresReturnsExtensionKey() {
111 t3lib_extMgm
::clearExtensionKeyMap();
113 $uniqueSuffix = uniqid('test');
114 $extensionKey = 'tt_news' . $uniqueSuffix;
115 $extensionPrefix = 'tx_ttnews' . $uniqueSuffix;
117 $GLOBALS['TYPO3_LOADED_EXT'][$extensionKey] = array();
121 t3lib_extMgm
::getExtensionKeyByPrefix($extensionPrefix)
127 * @see t3lib_extMgm::getExtensionKeyByPrefix
129 public function getExtensionKeyByPrefixForLoadedExtensionWithoutUnderscoresReturnsExtensionKey() {
130 t3lib_extMgm
::clearExtensionKeyMap();
132 $uniqueSuffix = uniqid('test');
133 $extensionKey = 'kickstarter' . $uniqueSuffix;
134 $extensionPrefix = 'tx_kickstarter' . $uniqueSuffix;
136 $GLOBALS['TYPO3_LOADED_EXT'][$extensionKey] = array();
140 t3lib_extMgm
::getExtensionKeyByPrefix($extensionPrefix)
146 * @see t3lib_extMgm::getExtensionKeyByPrefix
148 public function getExtensionKeyByPrefixForNotLoadedExtensionReturnsFalse(){
149 t3lib_extMgm
::clearExtensionKeyMap();
151 $uniqueSuffix = uniqid('test');
152 $extensionKey = 'unloadedextension' . $uniqueSuffix;
153 $extensionPrefix = 'tx_unloadedextension' . $uniqueSuffix;
156 t3lib_extMgm
::getExtensionKeyByPrefix($extensionPrefix)
161 //////////////////////////////////////
162 // Tests concerning addToAllTCAtypes
163 //////////////////////////////////////
166 * Tests whether fields can be add to all TCA types and duplicate fields are considered.
168 * @see t3lib_extMgm::addToAllTCAtypes()
170 public function canAddFieldsToAllTCATypesBeforeExistingOnes() {
171 $table = uniqid('tx_coretest_table');
172 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
174 t3lib_extMgm
::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'before:fieldD');
178 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD',
179 $GLOBALS['TCA'][$table]['types']['typeA']['showitem']
183 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD',
184 $GLOBALS['TCA'][$table]['types']['typeB']['showitem']
189 * Tests whether fields can be add to all TCA types and duplicate fields are considered.
191 * @see t3lib_extMgm::addToAllTCAtypes()
193 public function canAddFieldsToAllTCATypesAfterExistingOnes() {
194 $table = uniqid('tx_coretest_table');
195 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
197 t3lib_extMgm
::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'after:fieldC');
201 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD',
202 $GLOBALS['TCA'][$table]['types']['typeA']['showitem']
206 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD',
207 $GLOBALS['TCA'][$table]['types']['typeB']['showitem']
212 * Tests whether fields can be add to a TCA type before existing ones
214 * @see t3lib_extMgm::addToAllTCAtypes()
216 public function canAddFieldsToTCATypeBeforeExistingOnes() {
217 $table = uniqid('tx_coretest_table');
218 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
220 t3lib_extMgm
::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', 'typeA', 'before:fieldD');
224 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD',
225 $GLOBALS['TCA'][$table]['types']['typeA']['showitem']
229 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD',
230 $GLOBALS['TCA'][$table]['types']['typeB']['showitem']
235 * Tests whether fields can be add to a TCA type after existing ones
237 * @see t3lib_extMgm::addToAllTCAtypes()
239 public function canAddFieldsToTCATypeAfterExistingOnes() {
240 $table = uniqid('tx_coretest_table');
241 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
243 t3lib_extMgm
::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', 'typeA', 'after:fieldC');
247 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD',
248 $GLOBALS['TCA'][$table]['types']['typeA']['showitem']
252 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD',
253 $GLOBALS['TCA'][$table]['types']['typeB']['showitem']
258 * Test wheter replacing other TCA fields works as promissed
260 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
262 public function canAddFieldsToTCATypeAndReplaceExistingOnes() {
263 $table = uniqid('tx_coretest_table');
264 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
266 $typesBefore = $GLOBALS['TCA'][$table]['types'];
268 t3lib_extMgm
::addToAllTCAtypes($table, 'fieldZ', '', 'replace:fieldX');
272 $GLOBALS['TCA'][$table]['types'],
273 'It\'s wrong that the "types" array changes here - the replaced field is only on palettes'
276 // unchanged because the palette is not used
278 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']
280 // unchanged because the palette is not used
282 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']
286 'fieldZ, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']
290 'fieldZ, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']
296 ///////////////////////////////////////////////////
297 // Tests concerning addFieldsToAllPalettesOfField
298 ///////////////////////////////////////////////////
301 * Tests whether fields can be added to a palette before existing elements.
303 * @see t3lib_extMgm::addFieldsToPalette()
305 public function canAddFieldsToPaletteBeforeExistingOnes() {
306 $table = uniqid('tx_coretest_table');
307 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
309 t3lib_extMgm
::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'before:fieldY');
312 'fieldX, newA, newB, fieldY',
313 $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']
318 * Tests whether fields can be added to a palette after existing elements.
320 * @see t3lib_extMgm::addFieldsToPalette()
322 public function canAddFieldsToPaletteAfterExistingOnes() {
323 $table = uniqid('tx_coretest_table');
324 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
326 t3lib_extMgm
::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'after:fieldX');
329 'fieldX, newA, newB, fieldY',
330 $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']
335 * Tests whether fields can be added to a palette after a not existing elements.
337 * @see t3lib_extMgm::addFieldsToPalette()
339 public function canAddFieldsToPaletteAfterNotExistingOnes() {
340 $table = uniqid('tx_coretest_table');
341 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
343 t3lib_extMgm
::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'after:' . uniqid('notExisting'));
346 'fieldX, fieldY, newA, newB',
347 $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']
352 * Tests whether fields can be added to all palettes of a regular field before existing ones.
354 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
356 public function canAddFieldsToAllPalettesOfFieldBeforeExistingOnes() {
357 $table = uniqid('tx_coretest_table');
358 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
360 t3lib_extMgm
::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'before:fieldY');
363 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']
366 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']
369 'fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']
372 'fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']
377 * Tests whether fields can be added to all palettes of a regular field after existing ones.
379 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
381 public function canAddFieldsToAllPalettesOfFieldAfterExistingOnes() {
382 $table = uniqid('tx_coretest_table');
383 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
385 t3lib_extMgm
::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'after:fieldX');
388 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']
391 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']
394 'fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']
397 'fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']
402 * Tests whether fields can be added to all palettes of a regular field after a not existing field.
404 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
406 public function canAddFieldsToAllPalettesOfFieldAfterNotExistingOnes() {
407 $table = uniqid('tx_coretest_table');
408 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
410 t3lib_extMgm
::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'after:' . uniqid('notExisting'));
413 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']
416 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']
419 'fieldX, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']
422 'fieldX, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']
427 * Tests whether fields are added to a new palette that did not exist before.
429 * @see t3lib_extMgm::addFieldsToAllPalettesOfField()
431 public function canAddFieldsToAllPalettesOfFieldWithoutPaletteExistingBefore() {
432 $table = uniqid('tx_coretest_table');
433 $GLOBALS['TCA'] = $this->generateTCAForTable($table);
435 t3lib_extMgm
::addFieldsToAllPalettesOfField($table, 'fieldA', 'newA, newA, newB, fieldX');
438 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem']
441 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem']
444 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem']
447 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem']
450 'newA, newB, fieldX', $GLOBALS['TCA'][$table]['palettes']['generatedFor-fieldA']['showitem']
455 /////////////////////////////////////////
456 // Tests concerning getExtensionVersion
457 /////////////////////////////////////////
460 * Data provider for negative getExtensionVersion() tests.
464 public function getExtensionVersionFaultyDataProvider() {
468 array(new stdClass()),
475 * @expectedException InvalidArgumentException
476 * @dataProvider getExtensionVersionFaultyDataProvider
478 public function getExtensionVersionForFaultyExtensionKeyThrowsException($key) {
479 t3lib_extMgm
::getExtensionVersion($key);
485 public function getExtensionVersionForNotLoadedExtensionReturnsEmptyString() {
486 t3lib_extMgm
::clearExtensionKeyMap();
488 $uniqueSuffix = uniqid('test');
489 $extensionKey = 'unloadedextension' . $uniqueSuffix;
493 t3lib_extMgm
::getExtensionVersion($extensionKey)
500 public function getExtensionVersionForLoadedExtensionReturnsExtensionVersion() {
501 t3lib_extMgm
::clearExtensionKeyMap();
503 $uniqueSuffix = uniqid('test');
504 $extensionKey = 'unloadedextension' . $uniqueSuffix;
506 $GLOBALS['TYPO3_LOADED_EXT'][$extensionKey] = array(
507 'siteRelPath' => $this->determineFixturesPath(),
511 t3lib_extMgm
::getExtensionVersion($extensionKey)
518 public function getEnabledExtensionListConsidersRequiredExtensions() {
519 $testrequiRedExtension = uniqid('test');
520 $GLOBALS['TYPO3_CONF_VARS']['EXT']['requiredExt'] = $testrequiRedExtension;
522 $extensions = explode(',', t3lib_extMgm
::getEnabledExtensionList());
523 $this->assertTrue(in_array($testrequiRedExtension, $extensions));
529 public function getEnabledExtensionListConsidersRequiredAndIgnoredExtensions() {
530 $testRequiredExtension = uniqid('test');
531 $testIgnoredExtension = uniqid('test');
532 $GLOBALS['TYPO3_CONF_VARS']['EXT']['requiredExt'] = $testRequiredExtension . ',' . $testIgnoredExtension;
533 $GLOBALS['TYPO3_CONF_VARS']['EXT']['ignoredExt'] = $testIgnoredExtension;
535 $extensions = explode(',', t3lib_extMgm
::getEnabledExtensionList());
536 $this->assertTrue(in_array($testRequiredExtension, $extensions));
537 $this->assertFalse(in_array($testIgnoredExtension, $extensions));