[TASK] Doctrine: Migrate further parts of TSFE Controller 73/49373/6
authorSebastian Bumann <bumann.sebastian@gmail.com>
Thu, 4 Aug 2016 10:59:40 +0000 (12:59 +0200)
committerBenni Mack <benni@typo3.org>
Fri, 5 Aug 2016 13:01:48 +0000 (15:01 +0200)
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>
typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
typo3/sysext/frontend/Tests/Functional/Controller/TypoScriptFrontendControllerTest.php
typo3/sysext/frontend/Tests/Unit/Controller/TypoScriptFrontendControllerTest.php

index ed55344..21b400b 100644 (file)
@@ -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
index 7e05588..7b0e8fa 100644 (file)
@@ -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'),
@@ -82,6 +86,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
      * @return int
@@ -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',
+            ),
+        );
+    }
 }
index 61e990c..aceb9ac 100644 (file)
@@ -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;
@@ -132,84 +130,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
      */