[BUGFIX] Assume pid 0 for global backend context 75/26675/3
authorFelix Oertel <felix@oer.tel>
Tue, 7 Jan 2014 17:03:56 +0000 (18:03 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Thu, 9 Jan 2014 19:26:48 +0000 (20:26 +0100)
If outside from "Web", extbase modules try to figure out some pid,
while in reality there is just none. The core takes "0" in this
situations, for looking for typoscript templates and tagging
cf_cache_pagesection entries.

To enable extbase to use the core's cache entries, we should streamline
this.

* Return 0, if no pid is set
* Remove needless unit-tests

Resolves: #54813
Releases: 6.2
Change-Id: I58cbaac0b40323e1766229488973b775accd1b97
Reviewed-on: https://review.typo3.org/26675
Reviewed-by: Oliver Klee
Reviewed-by: Stefan Froemken
Tested-by: Stefan Froemken
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
typo3/sysext/extbase/Classes/Configuration/BackendConfigurationManager.php
typo3/sysext/extbase/Tests/Unit/Configuration/BackendConfigurationManagerTest.php

index 85447cc..8f70ee4 100644 (file)
@@ -127,22 +127,7 @@ class BackendConfigurationManager extends \TYPO3\CMS\Extbase\Configuration\Abstr
         * @return integer current page id. If no page is selected current root page id is returned
         */
        protected function getCurrentPageId() {
-               $pageId = (integer) \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id');
-               if ($pageId > 0) {
-                       return $pageId;
-               }
-               // get current site root
-               $rootPages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', '', '1');
-               if (count($rootPages) > 0) {
-                       return $rootPages[0]['uid'];
-               }
-               // get root template
-               $rootTemplates = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', '', '1');
-               if (count($rootTemplates) > 0) {
-                       return $rootTemplates[0]['pid'];
-               }
-               // fallback
-               return self::DEFAULT_BACKEND_STORAGE_PID;
+               return (integer) \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id');
        }
 
        /**
index 196fc7b..18fd147 100644 (file)
@@ -75,10 +75,8 @@ class BackendConfigurationManagerTest extends \TYPO3\CMS\Extbase\Tests\Unit\Base
        /**
         * @test
         */
-       public function getCurrentPageIdReturnsPageIdFromPost() {
-               \TYPO3\CMS\Core\Utility\GeneralUtility::_GETset(array('id' => 123));
-               $_POST['id'] = 321;
-               $expectedResult = 321;
+       public function getCurrentPageIdReturnsZeroIfIdIsNotSet() {
+               $expectedResult = 0;
                $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
                $this->assertEquals($expectedResult, $actualResult);
        }
@@ -86,82 +84,6 @@ class BackendConfigurationManagerTest extends \TYPO3\CMS\Extbase\Tests\Unit\Base
        /**
         * @test
         */
-       public function getCurrentPageIdReturnsPidFromFirstRootTemplateIfIdIsNotSetAndNoRootPageWasFound() {
-               $GLOBALS['TYPO3_DB']->expects($this->at(0))->method('exec_SELECTgetRows')->with('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', '', '1')->will($this->returnValue(array()));
-               $GLOBALS['TYPO3_DB']->expects($this->at(1))->method('exec_SELECTgetRows')->with('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', '', '1')->will($this->returnValue(array(
-                       array('pid' => 123)
-               )));
-               $expectedResult = 123;
-               $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
-               $this->assertEquals($expectedResult, $actualResult);
-       }
-
-       /**
-        * @test
-        */
-       public function getCurrentPageIdReturnsUidFromFirstRootPageIfIdIsNotSet() {
-               $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_SELECTgetRows')->with('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', '', '1')->will($this->returnValue(array(
-                       array('uid' => 321)
-               )));
-               $expectedResult = 321;
-               $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
-               $this->assertEquals($expectedResult, $actualResult);
-       }
-
-       /**
-        * @test
-        */
-       public function getCurrentPageIdReturnsDefaultStoragePidIfIdIsNotSetNoRootTemplateAndRootPageWasFound() {
-               $GLOBALS['TYPO3_DB']->expects($this->at(0))->method('exec_SELECTgetRows')->with('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', '', '1')->will($this->returnValue(array()));
-               $GLOBALS['TYPO3_DB']->expects($this->at(1))->method('exec_SELECTgetRows')->with('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', '', '1')->will($this->returnValue(array()));
-               $expectedResult = \TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager::DEFAULT_BACKEND_STORAGE_PID;
-               $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
-               $this->assertEquals($expectedResult, $actualResult);
-       }
-
-       /**
-        * @test
-        */
-       public function getPluginConfigurationReturnsEmptyArrayIfNoPluginConfigurationWasFound() {
-               $this->backendConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue(array('foo' => 'bar')));
-               $expectedResult = array();
-               $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName', 'SomePluginName');
-               $this->assertEquals($expectedResult, $actualResult);
-       }
-
-       /**
-        * @test
-        */
-       public function getPluginConfigurationReturnsExtensionConfiguration() {
-               $testSettings = array(
-                       'settings.' => array(
-                               'foo' => 'bar'
-                       )
-               );
-               $testSettingsConverted = array(
-                       'settings' => array(
-                               'foo' => 'bar'
-                       )
-               );
-               $testSetup = array(
-                       'module.' => array(
-                               'tx_someextensionname.' => $testSettings
-                       )
-               );
-               $this->mockTypoScriptService->expects($this->any())->method('convertTypoScriptArrayToPlainArray')->with($testSettings)->will($this->returnValue($testSettingsConverted));
-               $this->backendConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue($testSetup));
-               $expectedResult = array(
-                       'settings' => array(
-                               'foo' => 'bar'
-                       )
-               );
-               $actualResult = $this->backendConfigurationManager->_call('getPluginConfiguration', 'SomeExtensionName');
-               $this->assertEquals($expectedResult, $actualResult);
-       }
-
-       /**
-        * @test
-        */
        public function getPluginConfigurationReturnsPluginConfiguration() {
                $testSettings = array(
                        'settings.' => array(