|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2009-2011 Oliver Hader <oliver@typo3.org> 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * 00017 * This script is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU General Public License for more details. 00021 * 00022 * This copyright notice MUST APPEAR in all copies of the script! 00023 ***************************************************************/ 00024 00025 /** 00026 * Testcase for class t3lib_extMgm 00027 * 00028 * @author Oliver Hader <oliver@typo3.org> 00029 * @author Oliver Klee <typo3-coding@oliverklee.de> 00030 * 00031 * @package TYPO3 00032 * @subpackage t3lib 00033 */ 00034 class t3lib_extmgmTest extends tx_phpunit_testcase { 00035 /** 00036 * backup of defined GLOBALS 00037 * 00038 * @var array 00039 */ 00040 protected $globals = array(); 00041 00042 public function setUp() { 00043 $this->globals = array( 00044 'TYPO3_CONF_VARS' => serialize($GLOBALS['TYPO3_CONF_VARS']), 00045 'TYPO3_LOADED_EXT' => serialize($GLOBALS['TYPO3_LOADED_EXT']), 00046 'TCA' => serialize($GLOBALS['TCA']), 00047 ); 00048 } 00049 00050 public function tearDown() { 00051 t3lib_extMgm::clearExtensionKeyMap(); 00052 00053 foreach ($this->globals as $key => $value) { 00054 $GLOBALS[$key] = unserialize($value); 00055 } 00056 } 00057 00058 00059 ////////////////////// 00060 // Utility functions 00061 ////////////////////// 00062 00063 /** 00064 * Generates a basic TCA for a given table. 00065 * 00066 * @param string $table name of the table, must not be empty 00067 * @return array generated TCA for the given table, will not be empty 00068 */ 00069 private function generateTCAForTable($table) { 00070 $tca = array(); 00071 $tca[$table] = array(); 00072 $tca[$table]['columns'] = array( 00073 'fieldA' => array(), 00074 'fieldC' => array(), 00075 ); 00076 $tca[$table]['types'] = array( 00077 'typeA' => array('showitem' => 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD'), 00078 'typeB' => array('showitem' => 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD'), 00079 'typeC' => array('showitem' => 'fieldC;;paletteD'), 00080 ); 00081 $tca[$table]['palettes'] = array( 00082 'paletteA' => array('showitem' => 'fieldX, fieldY'), 00083 'paletteB' => array('showitem' => 'fieldX, fieldY'), 00084 'paletteC' => array('showitem' => 'fieldX, fieldY'), 00085 'paletteD' => array('showitem' => 'fieldX, fieldY'), 00086 ); 00087 00088 return $tca; 00089 } 00090 00091 /** 00092 * Returns the fixtures path for this testcase relative to PATH_site. 00093 * 00094 * @return string the fixtures path for this testcase, will not be empty 00095 */ 00096 private function determineFixturesPath() { 00097 return t3lib_div::makeInstance('Tx_Phpunit_Service_TestFinder') 00098 ->getRelativeCoreTestsPath() . 't3lib/fixtures/'; 00099 } 00100 00101 00102 ///////////////////////////////////////////// 00103 // Tests concerning getExtensionKeyByPrefix 00104 ///////////////////////////////////////////// 00105 00106 /** 00107 * @test 00108 * @see t3lib_extMgm::getExtensionKeyByPrefix 00109 */ 00110 public function getExtensionKeyByPrefixForLoadedExtensionWithUnderscoresReturnsExtensionKey() { 00111 t3lib_extMgm::clearExtensionKeyMap(); 00112 00113 $uniqueSuffix = uniqid('test'); 00114 $extensionKey = 'tt_news' . $uniqueSuffix; 00115 $extensionPrefix = 'tx_ttnews' . $uniqueSuffix; 00116 00117 $GLOBALS['TYPO3_LOADED_EXT'][$extensionKey] = array(); 00118 00119 $this->assertEquals( 00120 $extensionKey, 00121 t3lib_extMgm::getExtensionKeyByPrefix($extensionPrefix) 00122 ); 00123 } 00124 00125 /** 00126 * @test 00127 * @see t3lib_extMgm::getExtensionKeyByPrefix 00128 */ 00129 public function getExtensionKeyByPrefixForLoadedExtensionWithoutUnderscoresReturnsExtensionKey() { 00130 t3lib_extMgm::clearExtensionKeyMap(); 00131 00132 $uniqueSuffix = uniqid('test'); 00133 $extensionKey = 'kickstarter' . $uniqueSuffix; 00134 $extensionPrefix = 'tx_kickstarter' . $uniqueSuffix; 00135 00136 $GLOBALS['TYPO3_LOADED_EXT'][$extensionKey] = array(); 00137 00138 $this->assertEquals( 00139 $extensionKey, 00140 t3lib_extMgm::getExtensionKeyByPrefix($extensionPrefix) 00141 ); 00142 } 00143 00144 /** 00145 * @test 00146 * @see t3lib_extMgm::getExtensionKeyByPrefix 00147 */ 00148 public function getExtensionKeyByPrefixForNotLoadedExtensionReturnsFalse(){ 00149 t3lib_extMgm::clearExtensionKeyMap(); 00150 00151 $uniqueSuffix = uniqid('test'); 00152 $extensionKey = 'unloadedextension' . $uniqueSuffix; 00153 $extensionPrefix = 'tx_unloadedextension' . $uniqueSuffix; 00154 00155 $this->assertFalse( 00156 t3lib_extMgm::getExtensionKeyByPrefix($extensionPrefix) 00157 ); 00158 } 00159 00160 00161 ////////////////////////////////////// 00162 // Tests concerning addToAllTCAtypes 00163 ////////////////////////////////////// 00164 00165 /** 00166 * Tests whether fields can be add to all TCA types and duplicate fields are considered. 00167 * @test 00168 * @see t3lib_extMgm::addToAllTCAtypes() 00169 */ 00170 public function canAddFieldsToAllTCATypesBeforeExistingOnes() { 00171 $table = uniqid('tx_coretest_table'); 00172 $GLOBALS['TCA'] = $this->generateTCAForTable($table); 00173 00174 t3lib_extMgm::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'before:fieldD'); 00175 00176 // Checking typeA: 00177 $this->assertEquals( 00178 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', 00179 $GLOBALS['TCA'][$table]['types']['typeA']['showitem'] 00180 ); 00181 // Checking typeB: 00182 $this->assertEquals( 00183 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', 00184 $GLOBALS['TCA'][$table]['types']['typeB']['showitem'] 00185 ); 00186 } 00187 00188 /** 00189 * Tests whether fields can be add to all TCA types and duplicate fields are considered. 00190 * @test 00191 * @see t3lib_extMgm::addToAllTCAtypes() 00192 */ 00193 public function canAddFieldsToAllTCATypesAfterExistingOnes() { 00194 $table = uniqid('tx_coretest_table'); 00195 $GLOBALS['TCA'] = $this->generateTCAForTable($table); 00196 00197 t3lib_extMgm::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', '', 'after:fieldC'); 00198 00199 // Checking typeA: 00200 $this->assertEquals( 00201 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', 00202 $GLOBALS['TCA'][$table]['types']['typeA']['showitem'] 00203 ); 00204 // Checking typeB: 00205 $this->assertEquals( 00206 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', 00207 $GLOBALS['TCA'][$table]['types']['typeB']['showitem'] 00208 ); 00209 } 00210 00211 /** 00212 * Tests whether fields can be add to a TCA type before existing ones 00213 * @test 00214 * @see t3lib_extMgm::addToAllTCAtypes() 00215 */ 00216 public function canAddFieldsToTCATypeBeforeExistingOnes() { 00217 $table = uniqid('tx_coretest_table'); 00218 $GLOBALS['TCA'] = $this->generateTCAForTable($table); 00219 00220 t3lib_extMgm::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', 'typeA', 'before:fieldD'); 00221 00222 // Checking typeA: 00223 $this->assertEquals( 00224 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', 00225 $GLOBALS['TCA'][$table]['types']['typeA']['showitem'] 00226 ); 00227 // Checking typeB: 00228 $this->assertEquals( 00229 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD', 00230 $GLOBALS['TCA'][$table]['types']['typeB']['showitem'] 00231 ); 00232 } 00233 00234 /** 00235 * Tests whether fields can be add to a TCA type after existing ones 00236 * @test 00237 * @see t3lib_extMgm::addToAllTCAtypes() 00238 */ 00239 public function canAddFieldsToTCATypeAfterExistingOnes() { 00240 $table = uniqid('tx_coretest_table'); 00241 $GLOBALS['TCA'] = $this->generateTCAForTable($table); 00242 00243 t3lib_extMgm::addToAllTCAtypes($table, 'newA, newA, newB, fieldA', 'typeA', 'after:fieldC'); 00244 00245 // Checking typeA: 00246 $this->assertEquals( 00247 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, newA, newB, fieldD', 00248 $GLOBALS['TCA'][$table]['types']['typeA']['showitem'] 00249 ); 00250 // Checking typeB: 00251 $this->assertEquals( 00252 'fieldA, fieldB, fieldC;labelC;paletteC;specialC, fieldD', 00253 $GLOBALS['TCA'][$table]['types']['typeB']['showitem'] 00254 ); 00255 } 00256 00257 00258 /////////////////////////////////////////////////// 00259 // Tests concerning addFieldsToAllPalettesOfField 00260 /////////////////////////////////////////////////// 00261 00262 /** 00263 * Tests whether fields can be added to a palette before existing elements. 00264 * @test 00265 * @see t3lib_extMgm::addFieldsToPalette() 00266 */ 00267 public function canAddFieldsToPaletteBeforeExistingOnes() { 00268 $table = uniqid('tx_coretest_table'); 00269 $GLOBALS['TCA'] = $this->generateTCAForTable($table); 00270 00271 t3lib_extMgm::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'before:fieldY'); 00272 00273 $this->assertEquals( 00274 'fieldX, newA, newB, fieldY', 00275 $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem'] 00276 ); 00277 } 00278 00279 /** 00280 * Tests whether fields can be added to a palette after existing elements. 00281 * @test 00282 * @see t3lib_extMgm::addFieldsToPalette() 00283 */ 00284 public function canAddFieldsToPaletteAfterExistingOnes() { 00285 $table = uniqid('tx_coretest_table'); 00286 $GLOBALS['TCA'] = $this->generateTCAForTable($table); 00287 00288 t3lib_extMgm::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'after:fieldX'); 00289 00290 $this->assertEquals( 00291 'fieldX, newA, newB, fieldY', 00292 $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem'] 00293 ); 00294 } 00295 00296 /** 00297 * Tests whether fields can be added to a palette after a not existing elements. 00298 * @test 00299 * @see t3lib_extMgm::addFieldsToPalette() 00300 */ 00301 public function canAddFieldsToPaletteAfterNotExistingOnes() { 00302 $table = uniqid('tx_coretest_table'); 00303 $GLOBALS['TCA'] = $this->generateTCAForTable($table); 00304 00305 t3lib_extMgm::addFieldsToPalette($table, 'paletteA', 'newA, newA, newB, fieldX', 'after:' . uniqid('notExisting')); 00306 00307 $this->assertEquals( 00308 'fieldX, fieldY, newA, newB', 00309 $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem'] 00310 ); 00311 } 00312 00313 /** 00314 * Tests whether fields can be added to all palettes of a regular field before existing ones. 00315 * @test 00316 * @see t3lib_extMgm::addFieldsToAllPalettesOfField() 00317 */ 00318 public function canAddFieldsToAllPalettesOfFieldBeforeExistingOnes() { 00319 $table = uniqid('tx_coretest_table'); 00320 $GLOBALS['TCA'] = $this->generateTCAForTable($table); 00321 00322 t3lib_extMgm::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'before:fieldY'); 00323 00324 $this->assertEquals( 00325 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem'] 00326 ); 00327 $this->assertEquals( 00328 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem'] 00329 ); 00330 $this->assertEquals( 00331 'fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem'] 00332 ); 00333 $this->assertEquals( 00334 'fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem'] 00335 ); 00336 } 00337 00338 /** 00339 * Tests whether fields can be added to all palettes of a regular field after existing ones. 00340 * @test 00341 * @see t3lib_extMgm::addFieldsToAllPalettesOfField() 00342 */ 00343 public function canAddFieldsToAllPalettesOfFieldAfterExistingOnes() { 00344 $table = uniqid('tx_coretest_table'); 00345 $GLOBALS['TCA'] = $this->generateTCAForTable($table); 00346 00347 t3lib_extMgm::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'after:fieldX'); 00348 00349 $this->assertEquals( 00350 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem'] 00351 ); 00352 $this->assertEquals( 00353 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem'] 00354 ); 00355 $this->assertEquals( 00356 'fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem'] 00357 ); 00358 $this->assertEquals( 00359 'fieldX, newA, newB, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem'] 00360 ); 00361 } 00362 00363 /** 00364 * Tests whether fields can be added to all palettes of a regular field after a not existing field. 00365 * @test 00366 * @see t3lib_extMgm::addFieldsToAllPalettesOfField() 00367 */ 00368 public function canAddFieldsToAllPalettesOfFieldAfterNotExistingOnes() { 00369 $table = uniqid('tx_coretest_table'); 00370 $GLOBALS['TCA'] = $this->generateTCAForTable($table); 00371 00372 t3lib_extMgm::addFieldsToAllPalettesOfField($table, 'fieldC', 'newA, newA, newB, fieldX', 'after:' . uniqid('notExisting')); 00373 00374 $this->assertEquals( 00375 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem'] 00376 ); 00377 $this->assertEquals( 00378 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem'] 00379 ); 00380 $this->assertEquals( 00381 'fieldX, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem'] 00382 ); 00383 $this->assertEquals( 00384 'fieldX, fieldY, newA, newB', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem'] 00385 ); 00386 } 00387 00388 /** 00389 * Tests whether fields are added to a new palette that did not exist before. 00390 * @test 00391 * @see t3lib_extMgm::addFieldsToAllPalettesOfField() 00392 */ 00393 public function canAddFieldsToAllPalettesOfFieldWithoutPaletteExistingBefore() { 00394 $table = uniqid('tx_coretest_table'); 00395 $GLOBALS['TCA'] = $this->generateTCAForTable($table); 00396 00397 t3lib_extMgm::addFieldsToAllPalettesOfField($table, 'fieldA', 'newA, newA, newB, fieldX'); 00398 00399 $this->assertEquals( 00400 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteA']['showitem'] 00401 ); 00402 $this->assertEquals( 00403 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteB']['showitem'] 00404 ); 00405 $this->assertEquals( 00406 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteC']['showitem'] 00407 ); 00408 $this->assertEquals( 00409 'fieldX, fieldY', $GLOBALS['TCA'][$table]['palettes']['paletteD']['showitem'] 00410 ); 00411 $this->assertEquals( 00412 'newA, newB, fieldX', $GLOBALS['TCA'][$table]['palettes']['generatedFor-fieldA']['showitem'] 00413 ); 00414 } 00415 00416 00417 ///////////////////////////////////////// 00418 // Tests concerning getExtensionVersion 00419 ///////////////////////////////////////// 00420 00421 /** 00422 * Data provider for negative getExtensionVersion() tests. 00423 * 00424 * @return array 00425 */ 00426 public function getExtensionVersionFaultyDataProvider() { 00427 return array( 00428 array(''), 00429 array(0), 00430 array(new stdClass()), 00431 array(TRUE), 00432 ); 00433 } 00434 00435 /** 00436 * @test 00437 * @expectedException InvalidArgumentException 00438 * @dataProvider getExtensionVersionFaultyDataProvider 00439 */ 00440 public function getExtensionVersionForFaultyExtensionKeyThrowsException($key) { 00441 t3lib_extMgm::getExtensionVersion($key); 00442 } 00443 00444 /** 00445 * @test 00446 */ 00447 public function getExtensionVersionForNotLoadedExtensionReturnsEmptyString() { 00448 t3lib_extMgm::clearExtensionKeyMap(); 00449 00450 $uniqueSuffix = uniqid('test'); 00451 $extensionKey = 'unloadedextension' . $uniqueSuffix; 00452 00453 $this->assertEquals( 00454 '', 00455 t3lib_extMgm::getExtensionVersion($extensionKey) 00456 ); 00457 } 00458 00459 /** 00460 * @test 00461 */ 00462 public function getExtensionVersionForLoadedExtensionReturnsExtensionVersion() { 00463 t3lib_extMgm::clearExtensionKeyMap(); 00464 00465 $uniqueSuffix = uniqid('test'); 00466 $extensionKey = 'unloadedextension' . $uniqueSuffix; 00467 00468 $GLOBALS['TYPO3_LOADED_EXT'][$extensionKey] = array( 00469 'siteRelPath' => $this->determineFixturesPath(), 00470 ); 00471 $this->assertEquals( 00472 '1.2.3', 00473 t3lib_extMgm::getExtensionVersion($extensionKey) 00474 ); 00475 } 00476 00477 /** 00478 * @test 00479 */ 00480 public function getEnabledExtensionListConsidersRequiredExtensions() { 00481 $testrequiRedExtension = uniqid('test'); 00482 $GLOBALS['TYPO3_CONF_VARS']['EXT']['requiredExt'] = $testrequiRedExtension; 00483 00484 $extensions = explode(',', t3lib_extMgm::getEnabledExtensionList()); 00485 $this->assertTrue(in_array($testrequiRedExtension, $extensions)); 00486 } 00487 00488 /** 00489 * @test 00490 */ 00491 public function getEnabledExtensionListConsidersRequiredAndIgnoredExtensions() { 00492 $testRequiredExtension = uniqid('test'); 00493 $testIgnoredExtension = uniqid('test'); 00494 $GLOBALS['TYPO3_CONF_VARS']['EXT']['requiredExt'] = $testRequiredExtension . ',' . $testIgnoredExtension; 00495 $GLOBALS['TYPO3_CONF_VARS']['EXT']['ignoredExt'] = $testIgnoredExtension; 00496 00497 $extensions = explode(',', t3lib_extMgm::getEnabledExtensionList()); 00498 $this->assertTrue(in_array($testRequiredExtension, $extensions)); 00499 $this->assertFalse(in_array($testIgnoredExtension, $extensions)); 00500 } 00501 } 00502 ?>
1.8.0