From 62cc256c3e142624161a244475379dcaae4d263e Mon Sep 17 00:00:00 2001 From: Sebastian Bumann <bumann.sebastian@gmail.com> Date: Thu, 4 Aug 2016 12:59:40 +0200 Subject: [PATCH] [TASK] Doctrine: Migrate further parts of TSFE Controller Move some unit tests to functional tests. Resolves: #77400 Releases: master Change-Id: I292ceec16a73d29f3bc0d8330921974a6280d684 Reviewed-on: https://review.typo3.org/49373 Tested-by: Bamboo TYPO3com <info@typo3.com> Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de> Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de> Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl> Reviewed-by: Frederic Gaus <frederic.gaus@flagbit.de> Reviewed-by: Benni Mack <benni@typo3.org> Tested-by: Benni Mack <benni@typo3.org> --- .../TypoScriptFrontendController.php | 41 +++++-- .../TypoScriptFrontendControllerTest.php | 116 ++++++++++++++++++ .../TypoScriptFrontendControllerTest.php | 80 ------------ 3 files changed, 147 insertions(+), 90 deletions(-) diff --git a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php index ed553441e93e..21b400b2aace 100644 --- a/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php +++ b/typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php @@ -21,6 +21,8 @@ use TYPO3\CMS\Core\Cache\CacheManager; use TYPO3\CMS\Core\Charset\CharsetConverter; use TYPO3\CMS\Core\Controller\ErrorPageController; use TYPO3\CMS\Core\Database\ConnectionPool; +use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction; +use TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer; use TYPO3\CMS\Core\Error\Http\PageNotFoundException; use TYPO3\CMS\Core\Error\Http\ServiceUnavailableException; use TYPO3\CMS\Core\Localization\Locales; @@ -1347,8 +1349,24 @@ class TypoScriptFrontendController protected function determineIdIsHiddenPage() { $field = MathUtility::canBeInterpretedAsInteger($this->id) ? 'uid' : 'alias'; - $pageSelectCondition = $field . '=' . $this->getDatabaseConnection()->fullQuoteStr($this->id, 'pages'); - $page = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('uid,hidden,starttime,endtime', 'pages', $pageSelectCondition . ' AND pid>=0 AND deleted=0'); + + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable('pages'); + $queryBuilder + ->getRestrictions() + ->removeAll() + ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); + + $page = $queryBuilder + ->select('uid', 'hidden', 'starttime', 'endtime') + ->from('pages') + ->where( + $queryBuilder->expr()->eq($field, $queryBuilder->createNamedParameter($this->id)), + $queryBuilder->expr()->gte('pid', 0) + ) + ->setMaxResults(1) + ->execute() + ->fetch(); $workspace = $this->whichWorkspace(); if ($workspace !== 0 && $workspace !== false) { @@ -4550,15 +4568,18 @@ class TypoScriptFrontendController if ($runtimeCache->has($entryIdentifier)) { $sysDomainData = $runtimeCache->get($entryIdentifier); } else { - $domainRecords = $this->getDatabaseConnection()->exec_SELECTgetRows( - 'uid, pid, domainName, forced', - 'sys_domain', - 'redirectTo=\'\' ' . $this->sys_page->enableFields('sys_domain', 0), - '', - 'sorting ASC' - ); + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_domain'); + $queryBuilder->setRestrictions(GeneralUtility::makeInstance(FrontendRestrictionContainer::class)); + $result = $queryBuilder + ->select('uid', 'pid', 'domainName', 'forced') + ->from('sys_domain') + ->where( + $queryBuilder->expr()->eq('redirectTo', $queryBuilder->createNamedParameter('')) + ) + ->orderBy('sorting', 'ASC') + ->execute(); - foreach ($domainRecords as $row) { + while ($row = $result->fetch()) { // if there is already an entry for this pid, check if we should overwrite it if (isset($sysDomainData[$row['pid']])) { // There is already a "forced" entry, which must not be overwritten diff --git a/typo3/sysext/frontend/Tests/Functional/Controller/TypoScriptFrontendControllerTest.php b/typo3/sysext/frontend/Tests/Functional/Controller/TypoScriptFrontendControllerTest.php index 7e0558871831..7b0e8fa80dd3 100644 --- a/typo3/sysext/frontend/Tests/Functional/Controller/TypoScriptFrontendControllerTest.php +++ b/typo3/sysext/frontend/Tests/Functional/Controller/TypoScriptFrontendControllerTest.php @@ -14,7 +14,10 @@ namespace TYPO3\CMS\Frontend\Tests\Functional\Controller; * The TYPO3 project - inspiring people to share! */ +use TYPO3\CMS\Core\Cache\CacheManager; +use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Tests\FunctionalTestCase; +use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; /** @@ -32,6 +35,7 @@ class TypoScriptFrontendControllerTest extends FunctionalTestCase parent::setUp(); $this->importDataSet(__DIR__ . '/fixtures.xml'); + $GLOBALS['TSFE']->gr_list = ''; $this->tsFrontendController = $this->getAccessibleMock( TypoScriptFrontendController::class, array('dummy'), @@ -81,6 +85,100 @@ class TypoScriptFrontendControllerTest extends FunctionalTestCase ); } + /** + * @param string $currentDomain + * @test + * @dataProvider getSysDomainCacheDataProvider + */ + public function getSysDomainCacheReturnsCurrentDomainRecord($currentDomain) + { + GeneralUtility::flushInternalRuntimeCaches(); + + $_SERVER['HTTP_HOST'] = $currentDomain; + $domainRecords = array( + 'typo3.org' => array( + 'uid' => '1', + 'pid' => '1', + 'domainName' => 'typo3.org', + 'forced' => 0, + ), + 'foo.bar' => array( + 'uid' => '2', + 'pid' => '1', + 'domainName' => 'foo.bar', + 'forced' => 0, + ), + 'example.com' => array( + 'uid' => '3', + 'pid' => '1', + 'domainName' => 'example.com', + 'forced' => 0, + ), + ); + + foreach ($domainRecords as $domainRecord) { + (new ConnectionPool())->getConnectionForTable('sys_domain')->insert( + 'sys_domain', + $domainRecord + ); + } + + GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_runtime')->flush(); + $expectedResult = array( + $domainRecords[$currentDomain]['pid'] => $domainRecords[$currentDomain], + ); + + $actualResult = $this->tsFrontendController->_call('getSysDomainCache'); + $this->assertEquals($expectedResult, $actualResult); + } + + /** + * @param string $currentDomain + * @test + * @dataProvider getSysDomainCacheDataProvider + */ + public function getSysDomainCacheReturnsForcedDomainRecord($currentDomain) + { + GeneralUtility::flushInternalRuntimeCaches(); + + $_SERVER['HTTP_HOST'] = $currentDomain; + $domainRecords = array( + 'typo3.org' => array( + 'uid' => '1', + 'pid' => '1', + 'domainName' => 'typo3.org', + 'forced' => 0, + ), + 'foo.bar' => array( + 'uid' => '2', + 'pid' => '1', + 'domainName' => 'foo.bar', + 'forced' => 1, + ), + 'example.com' => array( + 'uid' => '3', + 'pid' => '1', + 'domainName' => 'example.com', + 'forced' => 0, + ), + ); + + foreach ($domainRecords as $domainRecord) { + (new ConnectionPool())->getConnectionForTable('sys_domain')->insert( + 'sys_domain', + $domainRecord + ); + } + + GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_runtime')->flush(); + $expectedResult = array( + $domainRecords[$currentDomain]['pid'] => $domainRecords['foo.bar'], + ); + $actualResult = $this->tsFrontendController->_call('getSysDomainCache'); + + $this->assertEquals($expectedResult, $actualResult); + } + /** * @param string $tablePid * @param int $now @@ -90,4 +188,22 @@ class TypoScriptFrontendControllerTest extends FunctionalTestCase { return $this->tsFrontendController->_call('getFirstTimeValueForRecord', $tablePid, $now); } + + /** + * @return array + */ + public function getSysDomainCacheDataProvider() + { + return array( + 'typo3.org' => array( + 'typo3.org', + ), + 'foo.bar' => array( + 'foo.bar', + ), + 'example.com' => array( + 'example.com', + ), + ); + } } diff --git a/typo3/sysext/frontend/Tests/Unit/Controller/TypoScriptFrontendControllerTest.php b/typo3/sysext/frontend/Tests/Unit/Controller/TypoScriptFrontendControllerTest.php index 61e990c9e2ae..aceb9ac6fec3 100644 --- a/typo3/sysext/frontend/Tests/Unit/Controller/TypoScriptFrontendControllerTest.php +++ b/typo3/sysext/frontend/Tests/Unit/Controller/TypoScriptFrontendControllerTest.php @@ -14,8 +14,6 @@ namespace TYPO3\CMS\Frontend\Tests\Unit\Controller; * The TYPO3 project - inspiring people to share! */ -use TYPO3\CMS\Core\Cache\CacheManager; -use TYPO3\CMS\Core\Database\DatabaseConnection; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; use TYPO3\CMS\Frontend\Page\PageRepository; @@ -131,84 +129,6 @@ class TypoScriptFrontendControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCas ); } - /** - * @param string $currentDomain - * @test - * @dataProvider getSysDomainCacheDataProvider - */ - public function getSysDomainCacheReturnsCurrentDomainRecord($currentDomain) - { - $_SERVER['HTTP_HOST'] = $currentDomain; - $domainRecords = array( - 'typo3.org' => array( - 'uid' => '1', - 'pid' => '1', - 'domainName' => 'typo3.org', - 'forced' => 0, - ), - 'foo.bar' => array( - 'uid' => '2', - 'pid' => '1', - 'domainName' => 'foo.bar', - 'forced' => 0, - ), - 'example.com' => array( - 'uid' => '3', - 'pid' => '1', - 'domainName' => 'example.com', - 'forced' => 0, - ), - ); - $GLOBALS['TYPO3_DB'] = $this->getMockBuilder(DatabaseConnection::class) - ->setMethods(array('exec_SELECTgetRows')) - ->getMock(); - $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetRows')->willReturn($domainRecords); - GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_runtime')->flush(); - $expectedResult = array( - $domainRecords[$currentDomain]['pid'] => $domainRecords[$currentDomain], - ); - $this->assertEquals($expectedResult, $this->subject->_call('getSysDomainCache')); - } - - /** - * @param string $currentDomain - * @test - * @dataProvider getSysDomainCacheDataProvider - */ - public function getSysDomainCacheReturnsForcedDomainRecord($currentDomain) - { - $_SERVER['HTTP_HOST'] = $currentDomain; - $domainRecords = array( - 'typo3.org' => array( - 'uid' => '1', - 'pid' => '1', - 'domainName' => 'typo3.org', - 'forced' => 0, - ), - 'foo.bar' => array( - 'uid' => '2', - 'pid' => '1', - 'domainName' => 'foo.bar', - 'forced' => 1, - ), - 'example.com' => array( - 'uid' => '3', - 'pid' => '1', - 'domainName' => 'example.com', - 'forced' => 0, - ), - ); - $GLOBALS['TYPO3_DB'] = $this->getMockBuilder(DatabaseConnection::class) - ->setMethods(array('exec_SELECTgetRows')) - ->getMock(); - $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetRows')->willReturn($domainRecords); - GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_runtime')->flush(); - $expectedResult = array( - $domainRecords[$currentDomain]['pid'] => $domainRecords['foo.bar'], - ); - $this->assertEquals($expectedResult, $this->subject->_call('getSysDomainCache')); - } - /** * Tests concerning domainNameMatchesCurrentRequest */ -- GitLab