[TASK] Doctrine: Migrate BackendConfigurationManager 22/49322/4
authorSebastian Bumann <bumann.sebastian@gmail.com>
Tue, 2 Aug 2016 15:36:29 +0000 (17:36 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Tue, 2 Aug 2016 19:54:29 +0000 (21:54 +0200)
Resolves: #77354
Releases: master
Change-Id: If725d008965a22fbf3c73d74cf0fb950887b30b5
Reviewed-on: https://review.typo3.org/49322
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/extbase/Classes/Configuration/BackendConfigurationManager.php
typo3/sysext/extbase/Tests/Functional/Configuration/BackendConfigurationManagerTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Configuration/BackendConfigurationManagerTest.php

index 6a0493c..c9f3964 100644 (file)
@@ -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;
         }
diff --git a/typo3/sysext/extbase/Tests/Functional/Configuration/BackendConfigurationManagerTest.php b/typo3/sysext/extbase/Tests/Functional/Configuration/BackendConfigurationManagerTest.php
new file mode 100644 (file)
index 0000000..937c017
--- /dev/null
@@ -0,0 +1,92 @@
+<?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);
+    }
+}
index 141f8b6..c1d9a94 100644 (file)
@@ -67,45 +67,6 @@ class BackendConfigurationManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     /**
      * @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
-     */
     public function getPluginConfigurationReturnsEmptyArrayIfNoPluginConfigurationWasFound()
     {
         $this->backendConfigurationManager->expects($this->once())->method('getTypoScriptSetup')->will($this->returnValue(array('foo' => 'bar')));