[TASK] Migrate abstract functional test case to use Doctrine DBAL. 14/48514/5
authorGleb Levitin <gleb.levitin@dkd.de>
Wed, 8 Jun 2016 10:00:25 +0000 (12:00 +0200)
committerSusanne Moog <typo3@susannemoog.de>
Thu, 9 Jun 2016 08:01:40 +0000 (10:01 +0200)
Resolves: #76517
Releases: master
Change-Id: I08c0a1bbffa53598687ee7589d3ea09d4397453e
Reviewed-on: https://review.typo3.org/48514
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Reviewed-by: Susanne Moog <typo3@susannemoog.de>
Tested-by: Susanne Moog <typo3@susannemoog.de>
typo3/sysext/core/Classes/Tests/FunctionalTestCase.php

index 9e60acd..5dc01fe 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Core\Tests;
 
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 use TYPO3\CMS\Core\Core\Bootstrap;
+use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Tests\Functional\Framework\Frontend\Response;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
@@ -259,9 +260,11 @@ abstract class FunctionalTestCase extends BaseTestCase
      * $GLOBALS['TYPO3_DB'] for easy IDE auto completion.
      *
      * @return \TYPO3\CMS\Core\Database\DatabaseConnection
+     * @deprecated since TYPO3 v8, will be removed in TYPO3 v9
      */
     protected function getDatabaseConnection()
     {
+        GeneralUtility::logDeprecatedFunction();
         return $GLOBALS['TYPO3_DB'];
     }
 
@@ -275,8 +278,15 @@ abstract class FunctionalTestCase extends BaseTestCase
     protected function setUpBackendUserFromFixture($userUid)
     {
         $this->importDataSet(ORIGINAL_ROOT . $this->backendUserFixture);
-        $database = $this->getDatabaseConnection();
-        $userRow = $database->exec_SELECTgetSingleRow('*', 'be_users', 'uid = ' . (int)$userUid);
+
+        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('be_users');
+        $queryBuilder->getRestrictions()->removeAll();
+
+        $userRow = $queryBuilder->select('*')
+            ->from('be_users')
+            ->where($queryBuilder->expr()->eq('uid', (int) $userUid))
+            ->execute()
+            ->fetch();
 
         /** @var $backendUser BackendUserAuthentication */
         $backendUser = GeneralUtility::makeInstance(BackendUserAuthentication::class);
@@ -320,31 +330,36 @@ abstract class FunctionalTestCase extends BaseTestCase
     protected function setUpFrontendRootPage($pageId, array $typoScriptFiles = array())
     {
         $pageId = (int)$pageId;
-        $page = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', 'pages', 'uid=' . $pageId);
+
+        $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('pages');
+        $page = $connection->select(['*'], 'pages', ['uid' => $pageId])->fetch();
 
         if (empty($page)) {
             $this->fail('Cannot set up frontend root page "' . $pageId . '"');
         }
 
-        $pagesFields = array(
-            'is_siteroot' => 1
+        $connection->update(
+            'pages',
+            ['is_siteroot' => 1],
+            ['uid' => $pageId]
         );
 
-        $this->getDatabaseConnection()->exec_UPDATEquery('pages', 'uid=' . $pageId, $pagesFields);
-
-        $templateFields = array(
+        $templateFields = [
             'pid' => $pageId,
             'title' => '',
             'config' => '',
             'clear' => 3,
             'root' => 1,
-        );
+        ];
 
         foreach ($typoScriptFiles as $typoScriptFile) {
             $templateFields['config'] .= '<INCLUDE_TYPOSCRIPT: source="FILE:' . $typoScriptFile . '">' . LF;
         }
 
-        $this->getDatabaseConnection()->exec_INSERTquery('sys_template', $templateFields);
+        GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('sys_template')->insert(
+            'sys_template',
+            $templateFields
+        );
     }
 
     /**