Commit ba2386e7 authored by Felix Oertel's avatar Felix Oertel Committed by Anja Leichsenring
Browse files

[BUGFIX] Assume pid 0 for global backend context

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
parent 545610af
......@@ -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');
}
/**
......
......@@ -75,90 +75,12 @@ 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);
}
/**
* @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