Commit 1c3952d0 authored by Sebastian Bumann's avatar Sebastian Bumann Committed by Anja Leichsenring
Browse files

[TASK] Doctrine: Migrate BackendConfigurationManager

Resolves: #77354
Releases: master
Change-Id: If725d008965a22fbf3c73d74cf0fb950887b30b5
Reviewed-on: https://review.typo3.org/49322


Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: default avatarBamboo TYPO3com <info@typo3.com>
Reviewed-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
parent 1bc76a2e
......@@ -13,6 +13,10 @@ namespace TYPO3\CMS\Extbase\Configuration;
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* A general purpose configuration manager used in backend mode.
......@@ -159,9 +163,25 @@ class BackendConfigurationManager extends \TYPO3\CMS\Extbase\Configuration\Abstr
*/
protected function getCurrentPageIdFromCurrentSiteRoot()
{
$rootPage = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
'uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', 'sorting'
);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('pages');
$queryBuilder
->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(HiddenRestriction::class));
$rootPage = $queryBuilder
->select('uid')
->from('pages')
->where(
$queryBuilder->expr()->eq('is_siteroot', 1)
)
->orderBy('sorting')
->execute()
->fetch();
if (empty($rootPage)) {
return 0;
}
......@@ -176,9 +196,25 @@ class BackendConfigurationManager extends \TYPO3\CMS\Extbase\Configuration\Abstr
*/
protected function getCurrentPageIdFromRootTemplate()
{
$rootTemplate = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
'pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', 'crdate'
);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('sys_template');
$queryBuilder
->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(HiddenRestriction::class));
$rootTemplate = $queryBuilder
->select('pid')
->from('sys_template')
->where(
$queryBuilder->expr()->eq('root', 1)
)
->orderBy('crdate')
->execute()
->fetch();
if (empty($rootTemplate)) {
return 0;
}
......
<?php
namespace TYPO3\CMS\Extbase\Tests\Functional\Configuration;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Tests\FunctionalTestCase;
use TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager;
use TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager;
use TYPO3\CMS\Extbase\Service\TypoScriptService;
/**
* Test case
*/
class BackendConfigurationManagerTest extends FunctionalTestCase
{
/**
* Warning: white box test
*
* @test
*/
public function getCurrentPageIdReturnsPidFromFirstRootTemplateIfIdIsNotSetAndNoRootPageWasFound()
{
$backendConfigurationManager = $this->getAccessibleMock(BackendConfigurationManager::class, ['getTypoScriptSetup']);
$mockTypoScriptService = $this->getMockBuilder(TypoScriptService::class)->getMock();
$backendConfigurationManager->_set('typoScriptService', $mockTypoScriptService);
(new ConnectionPool())->getConnectionForTable('sys_template')->insert(
'sys_template',
[
'pid' => 123,
'deleted' => 0,
'hidden' => 0,
'root' => 1
]
);
$actualResult = $backendConfigurationManager->_call('getCurrentPageId');
$this->assertEquals(123, $actualResult);
}
/**
* Warning: white box test
*
* @test
*/
public function getCurrentPageIdReturnsUidFromFirstRootPageIfIdIsNotSet()
{
$backendConfigurationManager = $this->getAccessibleMock(BackendConfigurationManager::class, ['getTypoScriptSetup']);
$mockTypoScriptService = $this->getMockBuilder(TypoScriptService::class)->getMock();
$backendConfigurationManager->_set('typoScriptService', $mockTypoScriptService);
(new ConnectionPool())->getConnectionForTable('pages')->insert(
'pages',
[
'deleted' => 0,
'hidden' => 0,
'is_siteroot' => 1
]
);
$actualResult = $backendConfigurationManager->_call('getCurrentPageId');
$this->assertEquals(1, $actualResult);
}
/**
* Warning: white box test
*
* @test
*/
public function getCurrentPageIdReturnsDefaultStoragePidIfIdIsNotSetNoRootTemplateAndRootPageWasFound()
{
$backendConfigurationManager = $this->getAccessibleMock(BackendConfigurationManager::class, ['getTypoScriptSetup']);
$mockTypoScriptService = $this->getMockBuilder(TypoScriptService::class)->getMock();
$backendConfigurationManager->_set('typoScriptService', $mockTypoScriptService);
$expectedResult = AbstractConfigurationManager::DEFAULT_BACKEND_STORAGE_PID;
$actualResult = $backendConfigurationManager->_call('getCurrentPageId');
$this->assertEquals($expectedResult, $actualResult);
}
}
......@@ -64,45 +64,6 @@ class BackendConfigurationManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
$this->assertEquals($expectedResult, $actualResult);
}
/**
* @test
*/
public function getCurrentPageIdReturnsPidFromFirstRootTemplateIfIdIsNotSetAndNoRootPageWasFound()
{
$GLOBALS['TYPO3_DB']->expects($this->at(0))->method('exec_SELECTgetSingleRow')->with('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', 'sorting')->will($this->returnValue(array()));
$GLOBALS['TYPO3_DB']->expects($this->at(1))->method('exec_SELECTgetSingleRow')->with('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', 'crdate')->will($this->returnValue(
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_SELECTgetSingleRow')->with('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', 'sorting')->will($this->returnValue(
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_SELECTgetSingleRow')->with('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', 'sorting')->will($this->returnValue(array()));
$GLOBALS['TYPO3_DB']->expects($this->at(1))->method('exec_SELECTgetSingleRow')->with('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', 'crdate')->will($this->returnValue(array()));
$expectedResult = \TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager::DEFAULT_BACKEND_STORAGE_PID;
$actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
$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