Revert "[BUGFIX] Assume pid 0 for global backend context" 64/26864/3
authorMarc Bastian Heinrichs <typo3@mbh-software.de>
Wed, 15 Jan 2014 21:43:35 +0000 (22:43 +0100)
committerMarc Bastian Heinrichs <typo3@mbh-software.de>
Wed, 15 Jan 2014 21:44:50 +0000 (22:44 +0100)
formal: the change is not marked as breaking.
functional: removing the functionality fetching the
typoscript from a auto detected page completly without
an alternative breaks all extbase backend modules using
typoscript configuration.

This reverts commit ba2386e7305e0d6e64db5cc485bc38728728ad8e

Change-Id: I0c4c10b1bd8b5d09c54743a4949cce250d962ede
Reviewed-on: https://review.typo3.org/26864
Reviewed-by: Marc Bastian Heinrichs
Tested-by: Marc Bastian Heinrichs
typo3/sysext/extbase/Classes/Configuration/BackendConfigurationManager.php
typo3/sysext/extbase/Tests/Unit/Configuration/BackendConfigurationManagerTest.php

index 8efe169..1e6e8ff 100644 (file)
@@ -127,7 +127,22 @@ 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() {
-               return (integer) \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id');
+               $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;
        }
 
        /**
index bc974ed..ceace03 100644 (file)
@@ -75,8 +75,10 @@ class BackendConfigurationManagerTest extends \TYPO3\CMS\Extbase\Tests\Unit\Base
        /**
         * @test
         */
-       public function getCurrentPageIdReturnsZeroIfIdIsNotSet() {
-               $expectedResult = 0;
+       public function getCurrentPageIdReturnsPageIdFromPost() {
+               \TYPO3\CMS\Core\Utility\GeneralUtility::_GETset(array('id' => 123));
+               $_POST['id'] = 321;
+               $expectedResult = 321;
                $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
                $this->assertEquals($expectedResult, $actualResult);
        }
@@ -84,6 +86,82 @@ 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(