TYPO3 API  SVNRelease
FrontendConfigurationManagerTest.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
00006 *  All rights reserved
00007 *
00008 *  This class is a backport of the corresponding class of FLOW3.
00009 *  All credits go to the v5 team.
00010 *
00011 *  This script is part of the TYPO3 project. The TYPO3 project is
00012 *  free software; you can redistribute it and/or modify
00013 *  it under the terms of the GNU General Public License as published by
00014 *  the Free Software Foundation; either version 2 of the License, or
00015 *  (at your option) any later version.
00016 *
00017 *  The GNU General Public License can be found at
00018 *  http://www.gnu.org/copyleft/gpl.html.
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00027 
00028 class Tx_Extbase_Tests_Unit_Configuration_FrontendConfigurationManagerTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
00029 
00030     /**
00031      * @var tslib_fe
00032      */
00033     protected $tsfeBackup;
00034 
00035     /**
00036      * @var tslib_cObj
00037      */
00038     protected $mockContentObject;
00039 
00040     /**
00041      * @var Tx_Extbase_Configuration_FrontendConfigurationManager
00042      */
00043     protected $frontendConfigurationManager;
00044 
00045     /**
00046      * @var array
00047      */
00048     protected $extConfBackup;
00049 
00050     /**
00051      * Sets up this testcase
00052      */
00053     public function setUp() {
00054         $this->tsfeBackup = $GLOBALS['TSFE'];
00055         $this->mockContentObject = $this->getMock('tslib_cObj');
00056         $this->extConfBackup = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase'];
00057         $this->frontendConfigurationManager = $this->getAccessibleMock('Tx_Extbase_Configuration_FrontendConfigurationManager', array('dummy'));
00058         $this->frontendConfigurationManager->_set('contentObject', $this->mockContentObject);
00059     }
00060 
00061     /**
00062      * Tears down this testcase
00063      */
00064     public function tearDown() {
00065         $GLOBALS['TSFE']->tmpl->setup;
00066         $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase'] = $this->extConfBackup;
00067     }
00068 
00069     /**
00070      * @test
00071      */
00072     public function getTypoScriptSetupReturnsSetupFromTSFE() {
00073         $GLOBALS['TSFE']->tmpl->setup = array('foo' => 'bar');
00074         $this->assertEquals(array('foo' => 'bar'), $this->frontendConfigurationManager->_call('getTypoScriptSetup'));
00075     }
00076 
00077     /**
00078      * @test
00079      */
00080     public function getPluginConfigurationReturnsEmptyArrayIfNoPluginConfigurationWasFound() {
00081         $GLOBALS['TSFE']->tmpl->setup = array('foo' => 'bar');
00082         $expectedResult = array();
00083         $actualResult = $this->frontendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
00084         $this->assertEquals($expectedResult, $actualResult);
00085     }
00086 
00087     /**
00088      * @test
00089      */
00090     public function getPluginConfigurationReturnsExtensionConfiguration() {
00091         $testSetup = array(
00092             'plugin.' => array(
00093                 'tx_someextensionname.' => array(
00094                     'settings.' => array(
00095                         'foo' => 'bar'
00096                     )
00097                 ),
00098             ),
00099         );
00100         $GLOBALS['TSFE']->tmpl->setup = $testSetup;
00101         $expectedResult = array(
00102             'settings' => array(
00103                 'foo' => 'bar'
00104             )
00105         );
00106         $actualResult = $this->frontendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
00107         $this->assertEquals($expectedResult, $actualResult);
00108     }
00109 
00110     /**
00111      * @test
00112      */
00113     public function getPluginConfigurationReturnsPluginConfiguration() {
00114         $testSetup = array(
00115             'plugin.' => array(
00116                 'tx_someextensionname_somepluginname.' => array(
00117                     'settings.' => array(
00118                         'foo' => 'bar'
00119                     )
00120                 ),
00121             ),
00122         );
00123         $GLOBALS['TSFE']->tmpl->setup = $testSetup;
00124         $expectedResult = array(
00125             'settings' => array(
00126                 'foo' => 'bar'
00127             )
00128         );
00129         $actualResult = $this->frontendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
00130         $this->assertEquals($expectedResult, $actualResult);
00131     }
00132 
00133     /**
00134      * @test
00135      */
00136     public function getPluginConfigurationRecursivelyMergesExtensionAndPluginConfiguration() {
00137         $testSetup = array(
00138             'plugin.' => array(
00139                 'tx_someextensionname.' => array(
00140                     'settings.' => array(
00141                         'foo' => 'bar',
00142                         'some.' => array(
00143                             'nested' => 'value'
00144                         ),
00145                     ),
00146                 ),
00147                 'tx_someextensionname_somepluginname.' => array(
00148                     'settings.' => array(
00149                         'some.' => array(
00150                             'nested' => 'valueOverridde',
00151                             'new' => 'value',
00152                         ),
00153                     ),
00154                 ),
00155             ),
00156         );
00157         $GLOBALS['TSFE']->tmpl->setup = $testSetup;
00158         $expectedResult = array(
00159             'settings' => array(
00160                 'foo' => 'bar',
00161                 'some' => array(
00162                     'nested' => 'valueOverridde',
00163                     'new' => 'value'
00164                 ),
00165             ),
00166         );
00167         $actualResult = $this->frontendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
00168         $this->assertEquals($expectedResult, $actualResult);
00169     }
00170 
00171     /**
00172      * @test
00173      */
00174     public function getSwitchableControllerActionsReturnsEmptyArrayByDefault() {
00175         $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase'] = NULL;
00176         $expectedResult = array();
00177         $actualResult = $this->frontendConfigurationManager->_call('getSwitchableControllerActions', 'SomeExtensionName', 'SomePluginName');
00178         $this->assertEquals($expectedResult, $actualResult);
00179     }
00180 
00181     /**
00182      * @test
00183      */
00184     public function getSwitchableControllerActionsReturnsConfigurationStoredInExtconf() {
00185         $testSwitchableControllerActions = array(
00186             'Controller1' => array(
00187                 'actions' => array(
00188                     'action1', 'action2'
00189                 ),
00190                 'nonCacheableActions' => array(
00191                     'action1'
00192                 ),
00193             ),
00194             'Controller2' => array(
00195                 'actions' => array(
00196                     'action3', 'action4'
00197                 ),
00198             )
00199         );
00200         $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions']['SomeExtensionName']['plugins']['SomePluginName']['controllers'] = $testSwitchableControllerActions;
00201         $expectedResult = $testSwitchableControllerActions;
00202         $actualResult = $this->frontendConfigurationManager->_call('getSwitchableControllerActions', 'SomeExtensionName', 'SomePluginName');
00203         $this->assertEquals($expectedResult, $actualResult);
00204     }
00205 
00206     /**
00207      * @test
00208      */
00209     public function overrideSwitchableControllerActionsFromFlexformReturnsUnchangedFrameworkConfigurationIfNoFlexformConfigurationIsFound() {
00210         $frameworkConfiguration = array(
00211             'pluginName' => 'Pi1',
00212             'extensionName' => 'SomeExtension',
00213             'controllerConfiguration' => array(
00214                 'Controller1' => array(
00215                     'controller' => 'Controller1',
00216                     'actions' => 'action1 , action2'
00217                 ),
00218                 'Controller2' => array(
00219                     'controller' => 'Controller2',
00220                     'actions' => 'action2 , action1,action3',
00221                     'nonCacheableActions' => 'action2, action3'
00222                 )
00223             )
00224         );
00225         $flexformConfiguration = array();
00226         $actualResult = $this->frontendConfigurationManager->_call('overrideSwitchableControllerActionsFromFlexform', $frameworkConfiguration, $flexformConfiguration);
00227         $this->assertSame($frameworkConfiguration, $actualResult);
00228     }
00229 
00230     /**
00231      * @test
00232      */
00233     public function overrideSwitchableControllerActionsFromFlexformMergesNonCacheableActions() {
00234         $frameworkConfiguration = array(
00235             'pluginName' => 'Pi1',
00236             'extensionName' => 'SomeExtension',
00237             'controllerConfiguration' => array(
00238                 'Controller1' => array(
00239                     'actions' => array('action1 , action2')
00240                 ),
00241                 'Controller2' => array(
00242                     'actions' => array('action2', 'action1','action3'),
00243                     'nonCacheableActions' => array('action2', 'action3')
00244                 )
00245             )
00246         );
00247         $flexformConfiguration = array(
00248             'switchableControllerActions' => 'Controller1  -> action2;Controller2->action3;  Controller2->action1'
00249         );
00250         $expectedResult = array(
00251             'pluginName' => 'Pi1',
00252             'extensionName' => 'SomeExtension',
00253             'controllerConfiguration' => array(
00254                 'Controller1' => array(
00255                     'actions' => array('action2'),
00256                 ),
00257                 'Controller2' => array(
00258                     'actions' => array('action3', 'action1'),
00259                     'nonCacheableActions' => array(1 => 'action3'),
00260                 )
00261             )
00262         );
00263         $actualResult = $this->frontendConfigurationManager->_call('overrideSwitchableControllerActionsFromFlexform', $frameworkConfiguration, $flexformConfiguration);
00264         $this->assertEquals($expectedResult, $actualResult);
00265     }
00266 
00267     /**
00268      * @test
00269      * @expectedException Tx_Extbase_Configuration_Exception_ParseError
00270      */
00271     public function overrideSwitchableControllerActionsThrowsExceptionIfFlexformConfigurationIsInvalid() {
00272         $frameworkConfiguration = array(
00273             'pluginName' => 'Pi1',
00274             'extensionName' => 'SomeExtension',
00275             'controllerConfiguration' => array(
00276                 'Controller1' => array(
00277                     'actions' => array('action1 , action2')
00278                 ),
00279                 'Controller2' => array(
00280                     'actions' => array('action2', 'action1','action3'),
00281                     'nonCacheableActions' => array('action2', 'action3')
00282                 )
00283             )
00284         );
00285         $flexformConfiguration = array(
00286             'switchableControllerActions' => 'Controller1->;Controller2->action3;Controller2->action1'
00287         );
00288         $this->frontendConfigurationManager->_call('overrideSwitchableControllerActionsFromFlexform', $frameworkConfiguration, $flexformConfiguration);
00289     }
00290 
00291     /**
00292      * @test
00293      */
00294     public function getContextSpecificFrameworkConfigurationCorrectlyCallsOverrideMethods() {
00295         $frameworkConfiguration = array(
00296             'some' => array(
00297                 'framework' => 'configuration'
00298             ),
00299         );
00300         $frontendConfigurationManager = $this->getAccessibleMock('Tx_Extbase_Configuration_FrontendConfigurationManager', array('overrideStoragePidIfStartingPointIsSet', 'overrideConfigurationFromPlugin', 'overrideConfigurationFromFlexform'));
00301         $frontendConfigurationManager->expects($this->at(0))->method('overrideStoragePidIfStartingPointIsSet')->with($frameworkConfiguration)->will($this->returnValue(array('overridden' => 'storagePid')));
00302         $frontendConfigurationManager->expects($this->at(1))->method('overrideConfigurationFromPlugin')->with(array('overridden' => 'storagePid'))->will($this->returnValue(array('overridden' => 'pluginConfiguration')));
00303         $frontendConfigurationManager->expects($this->at(2))->method('overrideConfigurationFromFlexform')->with(array('overridden' => 'pluginConfiguration'))->will($this->returnValue(array('overridden' => 'flexformConfiguration')));
00304         $expectedResult = array('overridden' => 'flexformConfiguration');
00305         $actualResult = $frontendConfigurationManager->_call('getContextSpecificFrameworkConfiguration', $frameworkConfiguration);
00306         $this->assertEquals($expectedResult, $actualResult);
00307     }
00308 }
00309 ?>