TYPO3 API  SVNRelease
ExtensionTest.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2009 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 Tx_Extbase_Utility_Extension
00027  *
00028  * @package Extbase
00029  * @subpackage extbase
00030  */
00031 class Tx_Extbase_Tests_Unit_Utility_ExtensionTest extends tx_phpunit_testcase {
00032 
00033     /**
00034      * Contains backup of $TYPO3_CONF_VARS
00035      * @var array
00036      */
00037     protected $typo3ConfVars = array();
00038 
00039     /**
00040      * @var t3lib_DB
00041      */
00042     protected $typo3DbBackup;
00043 
00044     /**
00045      * @var t3lib_fe contains a backup of the current $GLOBALS['TSFE']
00046      */
00047     protected $tsfeBackup;
00048 
00049     public function setUp() {
00050         $this->typo3ConfVars = $GLOBALS['TYPO3_CONF_VARS'];
00051         $this->typo3DbBackup = $GLOBALS['TYPO3_DB'];
00052         $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB', array('fullQuoteStr', 'exec_SELECTgetRows'));
00053         $this->tsfeBackup = $GLOBALS['TSFE'];
00054         if (!isset($GLOBALS['TSFE']->tmpl)) {
00055             $GLOBALS['TSFE']->tmpl = new stdClass();
00056         }
00057         if (!isset($GLOBALS['TSFE']->tmpl->setup)) {
00058             $GLOBALS['TSFE']->tmpl->setup = array();
00059         }
00060         $GLOBALS['TSFE']->tmpl->setup['tt_content.']['list.']['20.'] = array(
00061             '9' => 'CASE',
00062             '9.' => array(
00063                 'key.' => array(
00064                     'field' => 'layout'),
00065                     0 => '< plugin.tt_news'
00066                 ),
00067             'extensionname_someplugin' => 'USER',
00068             'extensionname_someplugin.' => array(
00069                 'userFunc' => 'tx_extbase_core_bootstrap->run',
00070                 'extensionName' => 'ExtensionName',
00071                 'pluginName' => 'SomePlugin',
00072             ),
00073             'someotherextensionname_secondplugin' => 'USER',
00074             'someotherextensionname_secondplugin.' => array(
00075                 'userFunc' => 'tx_extbase_core_bootstrap->run',
00076                 'extensionName' => 'SomeOtherExtensionName',
00077                 'pluginName' => 'SecondPlugin',
00078             ),
00079             'extensionname_thirdplugin' => 'USER',
00080             'extensionname_thirdplugin.' => array(
00081                 'userFunc' => 'tx_extbase_core_bootstrap->run',
00082                 'extensionName' => 'ExtensionName',
00083                 'pluginName' => 'ThirdPlugin',
00084             ),
00085         );
00086         $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'] = array(
00087             'ExtensionName' => array(
00088                 'plugins' => array(
00089                     'SomePlugin' => array(
00090                         'controllers' => array(
00091                             'ControllerName' => array(
00092                                 'actions' => array('index', 'otherAction')
00093                             ),
00094                         ),
00095                     ),
00096                     'ThirdPlugin' => array(
00097                         'controllers' => array(
00098                             'ControllerName' => array(
00099                                 'actions' => array('otherAction', 'thirdAction')
00100                             ),
00101                         ),
00102                     ),
00103                 ),
00104             ),
00105             'SomeOtherExtensionName' => array(
00106                 'plugins' => array(
00107                     'SecondPlugin' => array(
00108                         'controllers' => array(
00109                             'ControllerName' => array(
00110                                 'actions' => array('index', 'otherAction')
00111                             ),
00112                             'SecondControllerName' => array(
00113                                 'actions' => array('someAction', 'someOtherAction'),
00114                                 'nonCacheableActions' => array('someOtherAction')
00115                             )
00116                         ),
00117                     ),
00118                 ),
00119             ),
00120         );
00121     }
00122 
00123     public function tearDown() {
00124         $GLOBALS['TYPO3_CONF_VARS'] = $this->typo3ConfVars;
00125         $GLOBALS['TSFE'] = $this->tsfeBackup;
00126         t3lib_div::purgeInstances();
00127     }
00128 
00129     /**
00130      * @test
00131      * @see Tx_Extbase_Utility_Extension::registerPlugin
00132      */
00133     public function configurePluginWorksForMinimalisticSetup() {
00134         $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
00135         Tx_Extbase_Utility_Extension::configurePlugin(
00136             'MyExtension',
00137             'Pi1',
00138             array('Blog' => 'index')
00139         );
00140         $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
00141 
00142         $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
00143         $this->assertContains('
00144     userFunc = tx_extbase_core_bootstrap->run
00145     extensionName = MyExtension
00146     pluginName = Pi1', $staticTypoScript);
00147 
00148     $this->assertNotContains('USER_INT', $staticTypoScript);
00149     }
00150 
00151 
00152     /**
00153      * @test
00154      * @see Tx_Extbase_Utility_Extension::registerPlugin
00155      */
00156     public function configurePluginCreatesCorrectDefaultTypoScriptSetup() {
00157         $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
00158         Tx_Extbase_Utility_Extension::configurePlugin(
00159             'MyExtension',
00160             'Pi1',
00161             array('Blog' => 'index')
00162         );
00163         $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
00164         $defaultTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup'];
00165         $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
00166         $this->assertContains('
00167 plugin.tx_myextension {
00168     settings {
00169     }
00170     persistence {
00171         storagePid =
00172         classes {
00173         }
00174     }
00175     view {
00176         templateRootPath =
00177         layoutRootPath =
00178         partialRootPath =
00179          # with defaultPid you can specify the default page uid of this plugin. If you set this to the string "auto" the target page will be determined automatically. Defaults to an empty string that expects the target page to be the current page.
00180         defaultPid =
00181     }
00182 }', $defaultTypoScript);
00183     }
00184 
00185     /**
00186      * @test
00187      * @see Tx_Extbase_Utility_Extension::registerPlugin
00188      */
00189     public function configurePluginWorksForASingleControllerAction() {
00190         $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
00191         Tx_Extbase_Utility_Extension::configurePlugin(
00192             'MyExtension',
00193             'Pi1',
00194             array(
00195                 'FirstController' => 'index'
00196                 )
00197         );
00198         $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
00199 
00200         $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
00201         $this->assertContains('
00202     extensionName = MyExtension
00203     pluginName = Pi1', $staticTypoScript);
00204 
00205         $expectedResult = array(
00206             'controllers' => array(
00207                 'FirstController' => array(
00208                     'actions' => array('index')
00209                 )
00210             ),
00211             'pluginType' => 'list_type'
00212         );
00213         $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
00214     }
00215 
00216     /**
00217      * @test
00218      * @expectedException InvalidArgumentException
00219      * @see Tx_Extbase_Utility_Extension::registerPlugin
00220      */
00221     public function configurePluginThrowsExceptionIfExtensionNameIsEmpty() {
00222         Tx_Extbase_Utility_Extension::configurePlugin(
00223             '',
00224             'SomePlugin',
00225             array(
00226                 'FirstController' => 'index'
00227                 )
00228         );
00229     }
00230 
00231     /**
00232      * @test
00233      * @expectedException InvalidArgumentException
00234      * @see Tx_Extbase_Utility_Extension::registerPlugin
00235      */
00236     public function configurePluginThrowsExceptionIfPluginNameIsEmpty() {
00237         Tx_Extbase_Utility_Extension::configurePlugin(
00238             'MyExtension',
00239             '',
00240             array(
00241                 'FirstController' => 'index'
00242                 )
00243         );
00244     }
00245 
00246 
00247     /**
00248      * @test
00249      * @see Tx_Extbase_Utility_Extension::registerPlugin
00250      */
00251     public function configurePluginRespectsDefaultActionAsANonCacheableAction() {
00252         $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
00253         Tx_Extbase_Utility_Extension::configurePlugin(
00254             'MyExtension',
00255             'Pi1',
00256             array(
00257                 'FirstController' => 'index,show,new, create,delete,edit,update'
00258                 ),
00259             array(
00260                 'FirstController' => 'index,show'
00261                 )
00262             );
00263         $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
00264         $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
00265         $this->assertContains('
00266     extensionName = MyExtension
00267     pluginName = Pi1', $staticTypoScript);
00268 
00269         $expectedResult = array(
00270             'controllers' => array(
00271                 'FirstController' => array(
00272                     'actions' => array('index', 'show', 'new', 'create', 'delete', 'edit', 'update'),
00273                     'nonCacheableActions' => array('index', 'show')
00274                 )
00275             ),
00276             'pluginType' => 'list_type'
00277         );
00278         $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
00279     }
00280 
00281     /**
00282      * @test
00283      * @see Tx_Extbase_Utility_Extension::registerPlugin
00284      */
00285     public function configurePluginRespectsNonDefaultActionAsANonCacheableAction() {
00286         $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
00287         Tx_Extbase_Utility_Extension::configurePlugin(
00288             'MyExtension',
00289             'Pi1',
00290             array(
00291                 'FirstController' => 'index,show,new, create,delete,edit,update'
00292                 ),
00293             array(
00294                 'FirstController' => 'new,show'
00295                 )
00296             );
00297         $staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
00298         $this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
00299         $this->assertContains('
00300     extensionName = MyExtension
00301     pluginName = Pi1', $staticTypoScript);
00302 
00303         $expectedResult = array(
00304             'controllers' => array(
00305                 'FirstController' => array(
00306                     'actions' => array('index', 'show', 'new', 'create', 'delete', 'edit', 'update'),
00307                     'nonCacheableActions' => array('new', 'show')
00308                 )
00309             ),
00310             'pluginType' => 'list_type'
00311         );
00312         $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
00313     }
00314 
00315     /**
00316      * @test
00317      * @see Tx_Extbase_Utility_Extension::registerPlugin
00318      */
00319     public function configurePluginWorksForMultipleControllerActionsWithCacheableActionAsDefault() {
00320         $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
00321         Tx_Extbase_Utility_Extension::configurePlugin(
00322             'MyExtension',
00323             'Pi1',
00324             array(
00325                 'FirstController' => 'index,show,new,create,delete,edit,update',
00326                 'SecondController' => 'index,show,delete',
00327                 'ThirdController' => 'create'
00328                 ),
00329             array(
00330                 'FirstController' => 'new,create,edit,update',
00331                 'ThirdController' => 'create'
00332                 )
00333             );
00334 
00335         $expectedResult = array(
00336             'controllers' => array(
00337                 'FirstController' => array(
00338                     'actions' => array('index', 'show', 'new', 'create', 'delete', 'edit', 'update'),
00339                     'nonCacheableActions' => array('new', 'create', 'edit', 'update')
00340                 ),
00341                 'SecondController' => array(
00342                     'actions' => array('index', 'show', 'delete')
00343                 ),
00344                 'ThirdController' => array(
00345                     'actions' => array('create'),
00346                     'nonCacheableActions' => array('create')
00347                 )
00348             ),
00349             'pluginType' => 'list_type'
00350         );
00351         $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
00352     }
00353 
00354 
00355     /**
00356      * @test
00357      * @see Tx_Extbase_Utility_Extension::registerPlugin
00358      */
00359     public function configurePluginWorksForMultipleControllerActionsWithNonCacheableActionAsDefault() {
00360         $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
00361         Tx_Extbase_Utility_Extension::configurePlugin(
00362             'MyExtension',
00363             'Pi1',
00364             array(
00365                 'FirstController' => 'index,show,new,create,delete,edit,update',
00366                 'SecondController' => 'index,show,delete',
00367                 'ThirdController' => 'create'
00368                 ),
00369             array(
00370                 'FirstController' => 'index,new,create,edit,update',
00371                 'SecondController' => 'delete',
00372                 'ThirdController' => 'create'
00373                 )
00374             );
00375 
00376         $expectedResult = array(
00377             'controllers' => array(
00378                 'FirstController' => array(
00379                     'actions' => array('index', 'show', 'new', 'create', 'delete', 'edit', 'update'),
00380                     'nonCacheableActions' => array('index', 'new', 'create', 'edit', 'update')
00381                 ),
00382                 'SecondController' => array(
00383                     'actions' => array('index', 'show', 'delete'),
00384                     'nonCacheableActions' => array('delete')
00385                 ),
00386                 'ThirdController' => array(
00387                     'actions' => array('create'),
00388                     'nonCacheableActions' => array('create')
00389                 )
00390             ),
00391             'pluginType' => 'list_type'
00392         );
00393         $this->assertEquals($expectedResult, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['MyExtension']['plugins']['Pi1']);
00394     }
00395 
00396     /**
00397      * DataProvider for getPluginNamespaceByPluginSignatureTests()
00398      *
00399      * @return array
00400      */
00401     public function getPluginNamespaceDataProvider() {
00402         return array(
00403             array('SomeExtension', 'SomePlugin', 'tx_someextension_someplugin'),
00404             array('NonExistingExtension', 'SomePlugin', 'tx_nonexistingextension_someplugin'),
00405             array('Invalid', '', 'tx_invalid_'),
00406         );
00407     }
00408 
00409     /**
00410      * @test
00411      * @dataProvider getPluginNamespaceDataProvider
00412      */
00413     public function getPluginNamespaceTests($extensionName, $pluginName, $expectedResult) {
00414         $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
00415         $mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(array()));
00416         $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
00417         $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
00418         t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
00419 
00420         $actualResult = Tx_Extbase_Utility_Extension::getPluginNamespace($extensionName, $pluginName);
00421         $this->assertEquals($expectedResult, $actualResult, 'Failing for extension: "' . $extensionName . '", plugin: "' . $pluginName . '"');
00422     }
00423 
00424     /**
00425      * @test
00426      */
00427     public function pluginNamespaceCanBeOverridden() {
00428         $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
00429         $mockConfigurationManager->expects($this->once())->method('getConfiguration')->with(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, 'SomeExtension', 'SomePlugin')->will($this->returnValue(array('view' => array('pluginNamespace' => 'overridden_plugin_namespace'))));
00430         $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
00431         $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
00432         t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
00433 
00434         $expectedResult = 'overridden_plugin_namespace';
00435         $actualResult = Tx_Extbase_Utility_Extension::getPluginNamespace('SomeExtension', 'SomePlugin');
00436         $this->assertEquals($expectedResult, $actualResult);
00437     }
00438 
00439     /**
00440      * DataProvider for getPluginNameByActionTests()
00441      *
00442      * @return array
00443      */
00444     public function getPluginNameByActionDataProvider() {
00445         return array(
00446             array('ExtensionName', 'ControllerName', 'someNonExistingAction', NULL),
00447             array('ExtensionName', 'ControllerName', 'index', 'SomePlugin'),
00448             array('ExtensionName', 'ControllerName', 'thirdAction', 'ThirdPlugin'),
00449             array('eXtEnSiOnNaMe', 'cOnTrOlLeRnAmE', 'thirdAction', NULL),
00450             array('eXtEnSiOnNaMe', 'cOnTrOlLeRnAmE', 'ThIrDaCtIoN', NULL),
00451             array('SomeOtherExtensionName', 'ControllerName', 'otherAction', 'SecondPlugin'),
00452         );
00453     }
00454 
00455     /**
00456      * @test
00457      * @dataProvider getPluginNameByActionDataProvider
00458      */
00459     public function getPluginNameByActionTests($extensionName, $controllerName, $actionName, $expectedResult) {
00460         $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
00461         $mockConfigurationManager->expects($this->once())->method('getConfiguration')->with(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK)->will($this->returnValue(array('view' => array('pluginNamespace' => 'overridden_plugin_namespace'))));
00462         $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
00463         $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
00464         t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
00465 
00466         $actualResult = Tx_Extbase_Utility_Extension::getPluginNameByAction($extensionName, $controllerName, $actionName);
00467         $this->assertEquals($expectedResult, $actualResult, 'Failing for $extensionName: "' . $extensionName . '", $controllerName: "' . $controllerName . '", $actionName: "' . $actionName . '" - ');
00468     }
00469 
00470     /**
00471      * @test
00472      * @expectedException Tx_Extbase_Exception
00473      */
00474     public function getPluginNameByActionThrowsExceptionIfMoreThanOnePluginMatches() {
00475         $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
00476         $mockConfigurationManager->expects($this->once())->method('getConfiguration')->with(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK)->will($this->returnValue(array('view' => array('pluginNamespace' => 'overridden_plugin_namespace'))));
00477         $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
00478         $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
00479         t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
00480 
00481         Tx_Extbase_Utility_Extension::getPluginNameByAction('ExtensionName', 'ControllerName', 'otherAction');
00482     }
00483 
00484     /**
00485      * @test
00486      */
00487     public function getPluginNameByActionReturnsCurrentIfItCanHandleTheActionEvenIfMoreThanOnePluginMatches() {
00488         $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
00489         $mockConfigurationManager->expects($this->once())->method('getConfiguration')->with(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK)->will($this->returnValue(array('extensionName' => 'CurrentExtension', 'pluginName' => 'CurrentPlugin', 'controllerConfiguration' => array('ControllerName' => array('actions' => array('otherAction'))))));
00490         $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
00491         $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
00492         t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
00493 
00494         $actualResult = Tx_Extbase_Utility_Extension::getPluginNameByAction('CurrentExtension', 'ControllerName', 'otherAction');
00495         $expectedResult = 'CurrentPlugin';
00496         $this->assertEquals($expectedResult, $actualResult);
00497     }
00498 
00499     /**
00500      * @test
00501      */
00502     public function isActionCacheableReturnsTrueByDefault() {
00503         $mockConfiguration = array();
00504         $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
00505         $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($mockConfiguration));
00506         $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
00507         $mockObjectManager->expects($this->any())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
00508         t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
00509 
00510         $actualResult = Tx_Extbase_Utility_Extension::isActionCacheable('SomeExtension', 'SomePlugin', 'SomeController', 'someAction');
00511         $this->assertTrue($actualResult);
00512     }
00513 
00514     /**
00515      * @test
00516      */
00517     public function isActionCacheableReturnsFalseIfActionIsNotCacheable() {
00518         $mockConfiguration = array(
00519             'controllerConfiguration' => array(
00520                 'SomeController' => array(
00521                     'nonCacheableActions' => array('someAction')
00522                 )
00523             )
00524         );
00525         $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
00526         $mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($mockConfiguration));
00527         $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
00528         $mockObjectManager->expects($this->any())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
00529         t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
00530 
00531         $actualResult = Tx_Extbase_Utility_Extension::isActionCacheable('SomeExtension', 'SomePlugin', 'SomeController', 'someAction');
00532         $this->assertFalse($actualResult);
00533     }
00534 
00535     /**
00536      * @test
00537      */
00538     public function getTargetPidByPluginSignatureReturnsNullIfConfigurationManagerIsNotInitialized() {
00539         $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
00540         $mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(NULL));
00541         $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
00542         $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
00543         t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
00544 
00545         $this->assertNull(Tx_Extbase_Utility_Extension::getTargetPidByPlugin('ExtensionName', 'PluginName'));
00546     }
00547 
00548     /**
00549      * @test
00550      */
00551     public function getTargetPidByPluginSignatureReturnsNullIfDefaultPidIsZero() {
00552         $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
00553         $mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(array('view' => array('defaultPid' => 0))));
00554         $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
00555         $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
00556         t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
00557 
00558         $this->assertNull(Tx_Extbase_Utility_Extension::getTargetPidByPlugin('ExtensionName', 'PluginName'));
00559     }
00560 
00561     /**
00562      * @test
00563      */
00564     public function getTargetPidByPluginSignatureReturnsTheConfiguredDefaultPid() {
00565         $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
00566         $mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(array('view' => array('defaultPid' => 123))));
00567         $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
00568         $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
00569         t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
00570 
00571         $expectedResult = 123;
00572         $actualResult = Tx_Extbase_Utility_Extension::getTargetPidByPlugin('ExtensionName', 'SomePlugin');
00573         $this->assertEquals($expectedResult, $actualResult);
00574     }
00575 
00576     /**
00577      * @test
00578      */
00579     public function getTargetPidByPluginSignatureDeterminesTheTargetPidIfDefaultPidIsAuto() {
00580         $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
00581         $mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(array('view' => array('defaultPid' => 'auto'))));
00582         $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
00583         $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
00584         t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
00585 
00586         $pluginSignature = 'extensionname_someplugin';
00587         $GLOBALS['TSFE']->sys_page = $this->getMock('t3lib_pageSelect', array('enableFields'));
00588         $GLOBALS['TSFE']->sys_page->expects($this->once())->method('enableFields')->with('tt_content')->will($this->returnValue(' AND enable_fields'));
00589         $GLOBALS['TYPO3_DB']->expects($this->once())->method('fullQuoteStr')->with($pluginSignature, 'tt_content')->will($this->returnValue('"pluginSignature"'));
00590         $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_SELECTgetRows')->with(
00591             'pid',
00592             'tt_content',
00593             'list_type="pluginSignature" AND CType="list" AND enable_fields',
00594             '',
00595             ''
00596         )->will($this->returnValue(array(array('pid' => '321'))));
00597         $expectedResult = 321;
00598         $actualResult = Tx_Extbase_Utility_Extension::getTargetPidByPlugin('ExtensionName', 'SomePlugin');
00599         $this->assertEquals($expectedResult, $actualResult);
00600     }
00601 
00602     /**
00603      * @test
00604      */
00605     public function getTargetPidByPluginSignatureReturnsNullIfTargetPidCouldNotBeDetermined() {
00606         $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
00607         $mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(array('view' => array('defaultPid' => 'auto'))));
00608         $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
00609         $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
00610         t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
00611 
00612         $GLOBALS['TSFE']->sys_page = $this->getMock('t3lib_pageSelect', array('enableFields'));
00613         $GLOBALS['TSFE']->sys_page->expects($this->once())->method('enableFields')->will($this->returnValue(' AND enable_fields'));
00614         $GLOBALS['TYPO3_DB']->expects($this->once())->method('fullQuoteStr')->will($this->returnValue('"pluginSignature"'));
00615         $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_SELECTgetRows')->will($this->returnValue(array()));
00616         $this->assertNull(Tx_Extbase_Utility_Extension::getTargetPidByPlugin('ExtensionName', 'SomePlugin'));
00617     }
00618 
00619     /**
00620      * @test
00621      * @expectedException Tx_Extbase_Exception
00622      */
00623     public function getTargetPidByPluginSignatureThrowsExceptionIfMoreThanOneTargetPidsWereFound() {
00624         $mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface');
00625         $mockConfigurationManager->expects($this->once())->method('getConfiguration')->will($this->returnValue(array('view' => array('defaultPid' => 'auto'))));
00626         $mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager');
00627         $mockObjectManager->expects($this->once())->method('get')->with('Tx_Extbase_Configuration_ConfigurationManagerInterface')->will($this->returnValue($mockConfigurationManager));
00628         t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $mockObjectManager);
00629 
00630         $GLOBALS['TSFE']->sys_page = $this->getMock('t3lib_pageSelect', array('enableFields'));
00631         $GLOBALS['TSFE']->sys_page->expects($this->once())->method('enableFields')->will($this->returnValue(' AND enable_fields'));
00632         $GLOBALS['TYPO3_DB']->expects($this->once())->method('fullQuoteStr')->will($this->returnValue('"pluginSignature"'));
00633         $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_SELECTgetRows')->will($this->returnValue(array(array('pid' => 123), array('pid' => 124))));
00634         Tx_Extbase_Utility_Extension::getTargetPidByPlugin('ExtensionName', 'SomePlugin');
00635     }
00636 
00637 }
00638 
00639 ?>