Commit df2635c6 authored by Marc Bastian Heinrichs's avatar Marc Bastian Heinrichs
Browse files

Revert "[BUGFIX] Assume pid 0 for global backend context"

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 ba2386e7

Change-Id: I0c4c10b1bd8b5d09c54743a4949cce250d962ede
Reviewed-on: https://review.typo3.org/26864
Reviewed-by: Marc Bastian Heinrichs
Tested-by: Marc Bastian Heinrichs
parent 1101f392
......@@ -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;
}
/**
......
......@@ -75,12 +75,90 @@ 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);
}
/**
* @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
*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment