[TASK] migrate ext:backend/Utility to doctrine 40/48040/15
authorManuel Selbach <manuel_selbach@yahoo.de>
Fri, 6 May 2016 16:06:59 +0000 (18:06 +0200)
committerMorton Jonuschat <m.jonuschat@mojocode.de>
Thu, 7 Jul 2016 16:38:45 +0000 (18:38 +0200)
Convert all SQL statements in backend utility class
to the new Doctrine DBAL based API.

Change-Id: I8febf022d8a5c40756baf051496521885bed1ab1
Releases: master
Resolves: #75650
Reviewed-on: https://review.typo3.org/48040
Reviewed-by: Manuel Selbach <manuel_selbach@yahoo.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
32 files changed:
typo3/sysext/backend/Classes/Form/FormDataProvider/AbstractDatabaseRecordProvider.php
typo3/sysext/backend/Classes/Form/FormDataProvider/AbstractItemProvider.php
typo3/sysext/backend/Classes/Form/FormDataProvider/DatabaseLanguageRows.php
typo3/sysext/backend/Classes/Form/FormDataProvider/DatabasePageLanguageOverlayRows.php
typo3/sysext/backend/Classes/Form/FormDataProvider/DatabaseRecordTypeValue.php
typo3/sysext/backend/Classes/Utility/BackendUtility.php
typo3/sysext/backend/Tests/Unit/Configuration/TypoScript/ConditionMatching/ConditionMatcherTest.php
typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/DatabaseEditRowTest.php
typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/DatabaseLanguageRowsTest.php
typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/DatabasePageLanguageOverlayRowsTest.php
typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/DatabaseParentPageRowTest.php
typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/DatabaseRecordTypeValueTest.php
typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/TcaSelectItemsTest.php
typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/TcaSelectTreeItemsTest.php
typo3/sysext/backend/Tests/Unit/Utility/BackendUtilityTest.php
typo3/sysext/belog/Classes/Domain/Repository/LogEntryRepository.php
typo3/sysext/belog/Tests/Unit/Domain/Repository/LogEntryRepositoryTest.php
typo3/sysext/core/Tests/Unit/Collection/RecordCollectionRepositoryTest.php
typo3/sysext/core/Tests/Unit/Resource/Repository/AbstractRepositoryTest.php
typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php
typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbQueryParser.php
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Storage/Typo3DbQueryParserTest.php
typo3/sysext/impexp/Classes/Export.php
typo3/sysext/impexp/Tests/Functional/Fixtures/Database/sys_file_corrupt.xml
typo3/sysext/impexp/Tests/Functional/Fixtures/ImportExportXml/impexp-group-file-and-file_reference-item-but-images-not-included.xml
typo3/sysext/impexp/Tests/Functional/Fixtures/ImportExportXml/impexp-group-file-and-file_reference-item-in-ff.xml
typo3/sysext/impexp/Tests/Functional/Fixtures/ImportExportXml/impexp-group-file-and-file_reference-item.xml
typo3/sysext/impexp/Tests/Functional/Fixtures/ImportExportXml/irre-records.xml
typo3/sysext/impexp/Tests/Functional/Fixtures/ImportExportXml/pages-and-ttcontent-with-image-but-not-included.xml
typo3/sysext/impexp/Tests/Functional/Fixtures/ImportExportXml/pages-and-ttcontent-with-image.xml
typo3/sysext/impexp/Tests/Functional/Fixtures/ImportExportXml/pages-and-ttcontent-with-rte-image-n-file-link.xml
typo3/sysext/impexp/Tests/Functional/Fixtures/ImportExportXml/pages-and-ttcontent.xml

index 234775f..79a782c 100644 (file)
@@ -16,7 +16,10 @@ namespace TYPO3\CMS\Backend\Form\FormDataProvider;
 
 use TYPO3\CMS\Backend\Form\Exception\DatabaseRecordException;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
-use TYPO3\CMS\Core\Database\DatabaseConnection;
+use TYPO3\CMS\Core\Database\ConnectionPool;
+use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Styleguide\TcaDataGenerator\TableHandler\General;
 
 /**
  * Extended by other provider that fetch records from database
@@ -41,18 +44,8 @@ abstract class AbstractDatabaseRecordProvider
                 1437656456
             );
         }
-        $database = $this->getDatabase();
-        $tableName = $database->quoteStr($tableName, $tableName);
-        $where = 'uid=' . (int)$uid . BackendUtility::deleteClause($tableName);
-        $row = $database->exec_SELECTgetSingleRow('*', $tableName, $where);
-        if ($row === null) {
-            // Indicates a program / usage error
-            throw new \RuntimeException(
-                'Database error fetching record from tablename ' . $tableName . ' with uid ' . $uid,
-                1437655862
-            );
-        }
-        if ($row === false) {
+        $row = $this->getDatabaseRow($tableName, $uid);
+        if (empty($row)) {
             // Indicates a runtime error (eg. record was killed by other editor meanwhile) can be caught elsewhere
             // and transformed to a message to the user or something
             throw new DatabaseRecordException(
@@ -63,21 +56,29 @@ abstract class AbstractDatabaseRecordProvider
                 (int)$uid
             );
         }
-        if (!is_array($row)) {
-            // Database connection behaves weird ...
-            throw new \UnexpectedValueException(
-                'Database exec_SELECTgetSingleRow() did not return error type or result',
-                1437656323
-            );
-        }
         return $row;
     }
 
     /**
-     * @return DatabaseConnection
+     * Retrieve the requested row from the database
+     *
+     * @param string $tableName
+     * @param int $uid
+     * @return array
      */
-    protected function getDatabase()
+    protected function getDatabaseRow(string $tableName, int $uid): array
     {
-        return $GLOBALS['TYPO3_DB'];
+        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($tableName);
+        $queryBuilder->getRestrictions()
+            ->removeAll()
+            ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
+
+        $row = $queryBuilder->select('*')
+            ->from($tableName)
+            ->where($queryBuilder->expr()->eq('uid', (int)$uid))
+            ->execute()
+            ->fetch();
+
+        return $row ?: [];
     }
 }
index 408c7b4..8a0448f 100644 (file)
@@ -17,7 +17,11 @@ namespace TYPO3\CMS\Backend\Form\FormDataProvider;
 use TYPO3\CMS\Backend\Module\ModuleLoader;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
+use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\DatabaseConnection;
+use TYPO3\CMS\Core\Database\Query\QueryBuilder;
+use TYPO3\CMS\Core\Database\Query\QueryHelper;
+use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
 use TYPO3\CMS\Core\Database\RelationHandler;
 use TYPO3\CMS\Core\Imaging\IconFactory;
 use TYPO3\CMS\Core\Messaging\FlashMessage;
@@ -417,7 +421,6 @@ abstract class AbstractItemProvider
         }
 
         $languageService = $this->getLanguageService();
-        $database = $this->getDatabaseConnection();
 
         $foreignTable = $result['processedTca']['columns'][$fieldName]['config']['foreign_table'];
 
@@ -429,11 +432,11 @@ abstract class AbstractItemProvider
             );
         }
 
-        $foreignTableQueryArray = $this->buildForeignTableQuery($result, $fieldName);
-        $queryResource = $database->exec_SELECT_queryArray($foreignTableQueryArray);
+        $queryBuilder = $this->buildForeignTableQueryBuilder($result, $fieldName);
+        $queryResult = $queryBuilder->execute();
 
         // Early return on error with flash message
-        $databaseError = $database->sql_error();
+        $databaseError = $queryResult->errorInfo();
         if (!empty($databaseError)) {
             $msg = $databaseError . '. ';
             $msg .= $languageService->sL('LLL:EXT:lang/locallang_core.xlf:error.database_schema_mismatch');
@@ -445,7 +448,7 @@ abstract class AbstractItemProvider
             /** @var $defaultFlashMessageQueue FlashMessageQueue */
             $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
             $defaultFlashMessageQueue->enqueue($flashMessage);
-            $database->sql_free_result($queryResource);
+            $queryResult->closeCursor();
             return $items;
         }
 
@@ -457,7 +460,7 @@ abstract class AbstractItemProvider
 
         $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
 
-        while ($foreignRow = $database->sql_fetch_assoc($queryResource)) {
+        while ($foreignRow = $queryResult->fetch()) {
             BackendUtility::workspaceOL($foreignTable, $foreignRow);
             if (is_array($foreignRow)) {
                 // If the foreign table sets selicon_field, this field can contain an image
@@ -487,8 +490,6 @@ abstract class AbstractItemProvider
             }
         }
 
-        $database->sql_free_result($queryResource);
-
         return $items;
     }
 
@@ -899,47 +900,77 @@ abstract class AbstractItemProvider
      *
      * @param array $result Result array
      * @param string $localFieldName Current handle field name
-     * @return array Query array ready to be executed via Database->exec_SELECT_queryArray()
+     * @return QueryBuilder
      */
-    protected function buildForeignTableQuery(array $result, $localFieldName)
+    protected function buildForeignTableQueryBuilder(array $result, string $localFieldName):  QueryBuilder
     {
         $backendUser = $this->getBackendUser();
 
         $foreignTableName = $result['processedTca']['columns'][$localFieldName]['config']['foreign_table'];
         $foreignTableClauseArray = $this->processForeignTableClause($result, $foreignTableName, $localFieldName);
 
-        $queryArray = [];
-        $queryArray['SELECT'] = BackendUtility::getCommonSelectFields($foreignTableName, $foreignTableName . '.');
+        $fieldList = BackendUtility::getCommonSelectFields($foreignTableName, $foreignTableName . '.');
+        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
+            ->getQueryBuilderForTable($foreignTableName);
+
+        $queryBuilder->getRestrictions()
+            ->removeAll()
+            ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
+
+        $queryBuilder
+            ->select(...GeneralUtility::trimExplode(',', $fieldList, true))
+            ->from($foreignTableName);
+
+        if (!empty($foreignTableClauseArray['GROUPBY'])) {
+            $queryBuilder->groupBy($foreignTableClauseArray['GROUPBY']);
+        }
+
+        if (!empty($foreignTableClauseArray['ORDERBY'])) {
+            foreach ($foreignTableClauseArray['ORDERBY'] as $orderPair) {
+                list($fieldName, $order) = $orderPair;
+                $queryBuilder->addOrderBy($fieldName, $order);
+            }
+        }
+
+        if (!empty($foreignTableClauseArray['LIMIT'])) {
+            if (!empty($foreignTableClauseArray['LIMIT'][1])) {
+                $queryBuilder->setMaxResults($foreignTableClauseArray['LIMIT'][1]);
+                $queryBuilder->setFirstResult($foreignTableClauseArray['LIMIT'][0]);
+            } elseif (!empty($foreignTableClauseArray['LIMIT'][0])) {
+                $queryBuilder->setMaxResults($foreignTableClauseArray['LIMIT'][0]);
+            }
+        }
 
         // rootLevel = -1 means that elements can be on the rootlevel OR on any page (pid!=-1)
         // rootLevel = 0 means that elements are not allowed on root level
         // rootLevel = 1 means that elements are only on the root level (pid=0)
         $rootLevel = 0;
         if (isset($GLOBALS['TCA'][$foreignTableName]['ctrl']['rootLevel'])) {
-            $rootLevel = $GLOBALS['TCA'][$foreignTableName]['ctrl']['rootLevel'];
+            $rootLevel = (int)$GLOBALS['TCA'][$foreignTableName]['ctrl']['rootLevel'];
         }
-        $deleteClause = BackendUtility::deleteClause($foreignTableName);
-        if ($rootLevel == 1 || $rootLevel == -1) {
-            $pidWhere = $foreignTableName . '.pid' . (($rootLevel == -1) ? '<>-1' : '=0');
-            $queryArray['FROM'] = $foreignTableName;
-            $queryArray['WHERE'] = $pidWhere . $deleteClause . $foreignTableClauseArray['WHERE'];
+
+        if ($rootLevel === -1) {
+            $queryBuilder->where($queryBuilder->expr()->neq($foreignTableName . '.pid', -1));
+        } elseif ($rootLevel === 1) {
+            $queryBuilder->where($queryBuilder->expr()->neq($foreignTableName . '.pid', 0));
         } else {
-            $pageClause = $backendUser->getPagePermsClause(1);
-            if ($foreignTableName === 'pages') {
-                $queryArray['FROM'] = 'pages';
-                $queryArray['WHERE'] = '1=1' . $deleteClause . ' AND' . $pageClause . $foreignTableClauseArray['WHERE'];
-            } else {
-                $queryArray['FROM'] = $foreignTableName . ', pages';
-                $queryArray['WHERE'] = 'pages.uid=' . $foreignTableName . '.pid AND pages.deleted=0'
-                    . $deleteClause . ' AND' . $pageClause . $foreignTableClauseArray['WHERE'];
+            $queryBuilder->where(
+                $backendUser->getPagePermsClause(1),
+                $foreignTableClauseArray['WHERE']
+            );
+            if ($foreignTableName !== 'pages') {
+                $queryBuilder
+                    ->from('pages')
+                    ->andWhere(
+                        $queryBuilder->expr()->eq(
+                            'pages.uid',
+                            $queryBuilder->quoteIdentifier($foreignTableName . '.pid')
+                        )
+                    );
             }
         }
 
-        $queryArray['GROUPBY'] = $foreignTableClauseArray['GROUPBY'];
-        $queryArray['ORDERBY'] = $foreignTableClauseArray['ORDERBY'];
-        $queryArray['LIMIT'] = $foreignTableClauseArray['LIMIT'];
-
-        return $queryArray;
+        return $queryBuilder;
     }
 
     /**
@@ -960,7 +991,7 @@ abstract class AbstractItemProvider
      */
     protected function processForeignTableClause(array $result, $foreignTableName, $localFieldName)
     {
-        $database = $this->getDatabaseConnection();
+        $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($foreignTableName);
         $localTable = $result['tableName'];
         $effectivePid = $result['effectivePid'];
 
@@ -986,10 +1017,10 @@ abstract class AbstractItemProvider
                             $rowFieldValue = $rowFieldValue[0];
                         }
                         if (substr($whereClauseParts[0], -1) === '\'' && $whereClauseSubParts[1][0] === '\'') {
-                            $whereClauseParts[$key] = $database->quoteStr($rowFieldValue, $foreignTableName) . $whereClauseSubParts[1];
-                        } else {
-                            $whereClauseParts[$key] = $database->fullQuoteStr($rowFieldValue, $foreignTableName) . $whereClauseSubParts[1];
+                            $whereClauseParts[0] = substr($whereClauseParts[0], 0, -1);
+                            $whereClauseSubParts[1] = substr($whereClauseSubParts[1], 1);
                         }
+                        $whereClauseParts[$key] = $connection->quote($rowFieldValue) . $whereClauseSubParts[1];
                     }
                 }
                 $foreignTableClause = implode('', $whereClauseParts);
@@ -1038,11 +1069,11 @@ abstract class AbstractItemProvider
             $pageTsConfigString = '';
             if ($result['pageTsConfig']['flexHack.']['PAGE_TSCONFIG_STR']) {
                 // @deprecated since TYPO3 v8, will be removed in TYPO3 v9 - see also the flexHack part in TcaFlexProcess
-                $pageTsConfigString = $result['pageTsConfig']['flexHack.']['PAGE_TSCONFIG_STR'];
+                $pageTsConfigString = $connection->quote($result['pageTsConfig']['flexHack.']['PAGE_TSCONFIG_STR']);
             }
             if ($result['pageTsConfig']['TCEFORM.'][$localTable . '.'][$localFieldName . '.']['PAGE_TSCONFIG_STR']) {
                 $pageTsConfigString = $result['pageTsConfig']['TCEFORM.'][$localTable . '.'][$localFieldName . '.']['PAGE_TSCONFIG_STR'];
-                $pageTsConfigString = $database->quoteStr($pageTsConfigString, $foreignTableName);
+                $pageTsConfigString = $connection->quote($pageTsConfigString);
             }
 
             $foreignTableClause = str_replace(
@@ -1052,6 +1083,7 @@ abstract class AbstractItemProvider
                     '###SITEROOT###',
                     '###PAGE_TSCONFIG_ID###',
                     '###PAGE_TSCONFIG_IDLIST###',
+                    '\'###PAGE_TSCONFIG_STR###\'',
                     '###PAGE_TSCONFIG_STR###'
                 ],
                 [
@@ -1060,6 +1092,7 @@ abstract class AbstractItemProvider
                     $siteRootUid,
                     $pageTsConfigId,
                     $pageTsConfigIdList,
+                    $pageTsConfigString,
                     $pageTsConfigString
                 ],
                 $foreignTableClause
@@ -1078,23 +1111,23 @@ abstract class AbstractItemProvider
         // Find LIMIT
         $reg = [];
         if (preg_match('/^(.*)[[:space:]]+LIMIT[[:space:]]+([[:alnum:][:space:],._]+)$/i', $foreignTableClause, $reg)) {
-            $foreignTableClauseArray['LIMIT'] = trim($reg[2]);
+            $foreignTableClauseArray['LIMIT'] = GeneralUtility::intExplode(',', trim($reg[2]), true);
             $foreignTableClause = $reg[1];
         }
         // Find ORDER BY
         $reg = [];
         if (preg_match('/^(.*)[[:space:]]+ORDER[[:space:]]+BY[[:space:]]+([[:alnum:][:space:],._]+)$/i', $foreignTableClause, $reg)) {
-            $foreignTableClauseArray['ORDERBY'] = trim($reg[2]);
+            $foreignTableClauseArray['ORDERBY'] = QueryHelper::parseOrderBy(trim($reg[2]));
             $foreignTableClause = $reg[1];
         }
         // Find GROUP BY
         $reg = [];
         if (preg_match('/^(.*)[[:space:]]+GROUP[[:space:]]+BY[[:space:]]+([[:alnum:][:space:],._]+)$/i', $foreignTableClause, $reg)) {
-            $foreignTableClauseArray['GROUPBY'] = trim($reg[2]);
+            $foreignTableClauseArray['GROUPBY'] = QueryHelper::parseGroupBy(trim($reg[2]));
             $foreignTableClause = $reg[1];
         }
         // Rest is assumed to be "WHERE" clause
-        $foreignTableClauseArray['WHERE'] = $foreignTableClause;
+        $foreignTableClauseArray['WHERE'] = QueryHelper::stripLogicalOperatorPrefix($foreignTableClause);
 
         return $foreignTableClauseArray;
     }
index be76457..47608aa 100644 (file)
@@ -52,11 +52,11 @@ class DatabaseLanguageRows implements FormDataProviderInterface
                 }
 
                 // Default language record of localized record
-                $defaultLanguageRow = BackendUtility::getRecordWSOL(
+                $defaultLanguageRow = $this->getRecordWorkspaceOverlay(
                     $tableNameWithDefaultRecords,
                     (int)$result['databaseRow'][$fieldWithUidOfDefaultRecord]
                 );
-                if (!is_array($defaultLanguageRow)) {
+                if (empty($defaultLanguageRow)) {
                     throw new DatabaseDefaultLanguageException(
                         'Default language record with id ' . (int)$result['databaseRow'][$fieldWithUidOfDefaultRecord]
                         . ' not found in table ' . $result['tableName'] . ' while editing record ' . $result['databaseRow']['uid'],
@@ -95,7 +95,10 @@ class DatabaseLanguageRows implements FormDataProviderInterface
                             $additionalLanguageUid
                         );
                         if (!empty($translationInfo['translations'][$additionalLanguageUid]['uid'])) {
-                            $record = BackendUtility::getRecordWSOL($result['tableName'], (int)$translationInfo['translations'][$additionalLanguageUid]['uid']);
+                            $record = $this->getRecordWorkspaceOverlay(
+                                $result['tableName'],
+                                (int)$translationInfo['translations'][$additionalLanguageUid]['uid']
+                            );
                             $result['additionalLanguageRows'][$additionalLanguageUid] = $record;
                         }
                     }
@@ -105,4 +108,18 @@ class DatabaseLanguageRows implements FormDataProviderInterface
 
         return $result;
     }
+
+    /**
+     * Retrieve the requested row from the database
+     *
+     * @param string $tableName
+     * @param int $uid
+     * @return array
+     */
+    protected function getRecordWorkspaceOverlay(string $tableName, int $uid): array
+    {
+        $row = BackendUtility::getRecordWSOL($tableName, $uid);
+
+        return $row ?: [];
+    }
 }
index b2e66fe..40a95ed 100644 (file)
@@ -15,8 +15,10 @@ namespace TYPO3\CMS\Backend\Form\FormDataProvider;
  */
 
 use TYPO3\CMS\Backend\Form\FormDataProviderInterface;
-use TYPO3\CMS\Backend\Utility\BackendUtility;
-use TYPO3\CMS\Core\Database\DatabaseConnection;
+use TYPO3\CMS\Core\Database\ConnectionPool;
+use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
+use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Fill the "pageLanguageOverlayRows" part of the result array
@@ -36,33 +38,32 @@ class DatabasePageLanguageOverlayRows implements FormDataProviderInterface
             return $result;
         }
 
-        $database = $this->getDatabase();
-
-        $dbRows = $database->exec_SELECTgetRows(
-            '*',
-            'pages_language_overlay',
-            'pid=' . (int)$result['effectivePid']
-                . BackendUtility::deleteClause('pages_language_overlay')
-                . BackendUtility::versioningPlaceholderClause('pages_language_overlay')
-        );
-
-        if ($dbRows === null) {
-            throw new \UnexpectedValueException(
-                'Database query error ' . $database->sql_error(),
-                1440777705
-            );
-        }
-
-        $result['pageLanguageOverlayRows'] = $dbRows;
+        $result['pageLanguageOverlayRows'] = $this->getDatabaseRows((int)$result['effectivePid']);
 
         return $result;
     }
 
     /**
-     * @return DatabaseConnection
+     * Retrieve the requested overlay row from the database
+     *
+     * @param int $pid
+     * @return array
      */
-    protected function getDatabase()
+    protected function getDatabaseRows(int $pid): array
     {
-        return $GLOBALS['TYPO3_DB'];
+        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
+            ->getQueryBuilderForTable('pages_language_overlay');
+        $queryBuilder->getRestrictions()
+            ->removeAll()
+            ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
+            ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
+
+        $rows = $queryBuilder->select('*')
+            ->from('pages_language_overlay')
+            ->where($queryBuilder->expr()->eq('pid', $pid))
+            ->execute()
+            ->fetchAll();
+
+        return $rows;
     }
 }
index 70db428..e78cb7a 100644 (file)
@@ -100,7 +100,7 @@ class DatabaseRecordTypeValue implements FormDataProviderInterface
                         $foreignUid = str_replace($foreignTable . '_', '', $foreignUid);
                     }
                     // Fetch field of this foreign row from db
-                    $foreignRow = BackendUtility::getRecord($foreignTable, $foreignUid, $foreignTableTypeField);
+                    $foreignRow = $this->getDatabaseRow($foreignTable, $foreignUid, $foreignTableTypeField);
                     if ($foreignRow[$foreignTableTypeField]) {
                         // @todo: It might be necessary to fetch the value from default language record as well here,
                         // @todo: this was buggy in the "old" implementation and never worked. It was therefor left out here for now.
@@ -134,6 +134,20 @@ class DatabaseRecordTypeValue implements FormDataProviderInterface
     }
 
     /**
+     * Retrieve the requested row from the database
+     *
+     * @param string $tableName
+     * @param int $uid
+     * @param string $fieldName
+     * @return array
+     */
+    protected function getDatabaseRow(string $tableName, int $uid, string $fieldName): array
+    {
+        $row = BackendUtility::getRecord($tableName, $uid, $fieldName);
+
+        return $row ?: [];
+    }
+    /**
      * If a localized row is handled, the field value of the default language record
      * is used instead if tca is configured as "exclude" or "mergeIfNotBlank" with
      * empty localized value.
index 5150d2b..e08df47 100755 (executable)
@@ -18,8 +18,13 @@ use TYPO3\CMS\Backend\Routing\UriBuilder;
 use TYPO3\CMS\Backend\Template\DocumentTemplate;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 use TYPO3\CMS\Core\Cache\CacheManager;
+use TYPO3\CMS\Core\Database\Connection;
+use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\DatabaseConnection;
-use TYPO3\CMS\Core\Database\PreparedStatement;
+use TYPO3\CMS\Core\Database\Query\QueryBuilder;
+use TYPO3\CMS\Core\Database\Query\QueryHelper;
+use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
+use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
 use TYPO3\CMS\Core\Database\RelationHandler;
 use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
@@ -79,8 +84,15 @@ class BackendUtility
      */
     public static function deleteClause($table, $tableAlias = '')
     {
+        $expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
+            ->getQueryBuilderForTable($table)
+            ->expr();
+
         if (!empty($GLOBALS['TCA'][$table]['ctrl']['delete'])) {
-            return ' AND ' . ($tableAlias ?: $table) . '.' . $GLOBALS['TCA'][$table]['ctrl']['delete'] . '=0';
+            return ' AND ' . $expressionBuilder->eq(
+                ($tableAlias ?: $table) . '.' . $GLOBALS['TCA'][$table]['ctrl']['delete'],
+                0
+            );
         } else {
             return '';
         }
@@ -104,8 +116,28 @@ class BackendUtility
     {
         // Ensure we have a valid uid (not 0 and not NEWxxxx) and a valid TCA
         if ((int)$uid && !empty($GLOBALS['TCA'][$table])) {
-            $where = 'uid=' . (int)$uid . ($useDeleteClause ? self::deleteClause($table) : '') . $where;
-            $row = static::getDatabaseConnection()->exec_SELECTgetSingleRow($fields, $table, $where);
+            $queryBuilder = static::getQueryBuilderForTable($table);
+
+            // do not use enabled fields here
+            $queryBuilder->getRestrictions()->removeAll();
+
+            // should the delete clause be used
+            if ($useDeleteClause) {
+                $queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
+            }
+
+            // set table and where clause
+            $queryBuilder
+                ->select(...GeneralUtility::trimExplode(',', $fields, true))
+                ->from($table)
+                ->where($queryBuilder->expr()->eq('uid', (int)$uid));
+
+            // add custom where clause
+            if ($where) {
+                $queryBuilder->andWhere(QueryHelper::stripLogicalOperatorPrefix($where));
+            }
+
+            $row = $queryBuilder->execute()->fetch();
             if ($row) {
                 return $row;
             }
@@ -158,13 +190,17 @@ class BackendUtility
      */
     public static function getRecordRaw($table, $where = '', $fields = '*')
     {
-        $row = false;
-        $db = static::getDatabaseConnection();
-        if (false !== ($res = $db->exec_SELECTquery($fields, $table, $where, '', '', '1'))) {
-            $row = $db->sql_fetch_assoc($res);
-            $db->sql_free_result($res);
-        }
-        return $row;
+        $queryBuilder = static::getQueryBuilderForTable($table);
+        $queryBuilder->getRestrictions()->removeAll();
+
+        $row = $queryBuilder
+            ->select(...GeneralUtility::trimExplode(',', $fields, true))
+            ->from($table)
+            ->where(QueryHelper::stripLogicalOperatorPrefix($where))
+            ->execute()
+            ->fetch();
+
+        return $row ?: false;
     }
 
     /**
@@ -182,29 +218,65 @@ class BackendUtility
      * @param bool $useDeleteClause Use the deleteClause to check if a record is deleted (default TRUE)
      * @return mixed Multidimensional array with selected records (if any is selected)
      */
-    public static function getRecordsByField($theTable, $theField, $theValue, $whereClause = '', $groupBy = '', $orderBy = '', $limit = '', $useDeleteClause = true)
-    {
+    public static function getRecordsByField(
+        $theTable,
+        $theField,
+        $theValue,
+        $whereClause = '',
+        $groupBy = '',
+        $orderBy = '',
+        $limit = '',
+        $useDeleteClause = true
+    ) {
         if (is_array($GLOBALS['TCA'][$theTable])) {
-            $db = static::getDatabaseConnection();
-            $res = $db->exec_SELECTquery(
-                '*',
-                $theTable,
-                $theField . '=' . $db->fullQuoteStr($theValue, $theTable) .
-                    ($useDeleteClause ? self::deleteClause($theTable) . ' ' : '') .
-                    self::versioningPlaceholderClause($theTable) . ' ' .
-                    $whereClause,
-                $groupBy,
-                $orderBy,
-                $limit
-            );
-            $rows = array();
-            while ($row = $db->sql_fetch_assoc($res)) {
-                $rows[] = $row;
+            $queryBuilder = static::getQueryBuilderForTable($theTable);
+            // Show all records except versioning placeholders
+            $queryBuilder->getRestrictions()
+                ->removeAll()
+                ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
+
+            // Remove deleted records from the query result
+            if ($useDeleteClause) {
+                $queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
+            }
+
+            // build fields to select
+            $queryBuilder
+                ->select('*')
+                ->from($theTable)
+                ->where($queryBuilder->expr()->eq($theField, $queryBuilder->createNamedParameter($theValue)));
+
+            // additional where
+            if ($whereClause) {
+                $queryBuilder->andWhere(QueryHelper::stripLogicalOperatorPrefix($whereClause));
+            }
+
+            // group by
+            if ($groupBy !== '') {
+                $queryBuilder->groupBy(QueryHelper::parseGroupBy($groupBy));
             }
-            $db->sql_free_result($res);
-            if (!empty($rows)) {
-                return $rows;
+
+            // order by
+            if ($orderBy !== '') {
+                foreach (QueryHelper::parseOrderBy($orderBy) as $orderPair) {
+                    list($fieldName, $order) = $orderPair;
+                    $queryBuilder->addOrderBy($fieldName, $order);
+                }
             }
+
+            // limit
+            if ($limit !== '') {
+                if (strpos($limit, ',')) {
+                    $limitOffsetAndMax = GeneralUtility::intExplode(',', $limit);
+                    $queryBuilder->setFirstResult((int)$limitOffsetAndMax[0]);
+                    $queryBuilder->setMaxResults((int)$limitOffsetAndMax[1]);
+                } else {
+                    $queryBuilder->setMaxResults((int)$limit);
+                }
+            }
+
+            $rows = $queryBuilder->execute()->fetchAll();
+            return $rows;
         }
         return null;
     }
@@ -311,7 +383,25 @@ class BackendUtility
 
         if (self::isTableLocalizable($table)) {
             $tcaCtrl = $GLOBALS['TCA'][$table]['ctrl'];
-            $recordLocalization = self::getRecordsByField($table, $tcaCtrl['transOrigPointerField'], $uid, 'AND ' . $tcaCtrl['languageField'] . '=' . (int)$language . ($andWhereClause ? ' ' . $andWhereClause : ''), '', '', '1');
+
+            $expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
+                ->getQueryBuilderForTable($table)
+                ->expr();
+
+            $constraint = $expressionBuilder->andX(
+                $expressionBuilder->eq($tcaCtrl['languageField'], (int)$language),
+                QueryHelper::stripLogicalOperatorPrefix($andWhereClause)
+            );
+
+            $recordLocalization = self::getRecordsByField(
+                $table,
+                $tcaCtrl['transOrigPointerField'],
+                $uid,
+                (string)$constraint,
+                '',
+                '',
+                1
+            );
         }
         return $recordLocalization;
     }
@@ -397,9 +487,34 @@ class BackendUtility
         if (is_array($getPageForRootline_cache[$ident])) {
             $row = $getPageForRootline_cache[$ident];
         } else {
-            $db = static::getDatabaseConnection();
-            $res = $db->exec_SELECTquery('pid,uid,title,doktype,tsconfig_includes,TSconfig,is_siteroot,t3ver_oid,t3ver_wsid,t3ver_state,t3ver_stage,backend_layout_next_level', 'pages', 'uid=' . (int)$uid . ' ' . self::deleteClause('pages') . ' ' . $clause);
-            $row = $db->sql_fetch_assoc($res);
+            $queryBuilder = static::getQueryBuilderForTable('pages');
+            $queryBuilder->getRestrictions()
+                ->removeAll()
+                ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
+
+            $row = $queryBuilder
+                ->select(
+                    'pid',
+                    'uid',
+                    'title',
+                    'doktype',
+                    'tsconfig_includes',
+                    'TSconfig',
+                    'is_siteroot',
+                    't3ver_oid',
+                    't3ver_wsid',
+                    't3ver_state',
+                    't3ver_stage',
+                    'backend_layout_next_level'
+                )
+                ->from('pages')
+                ->where(
+                    $queryBuilder->expr()->eq('uid', (int)$uid),
+                    QueryHelper::stripLogicalOperatorPrefix($clause)
+                )
+                ->execute()
+                ->fetch();
+
             if ($row) {
                 $newLocation = false;
                 if ($workspaceOL) {
@@ -415,7 +530,6 @@ class BackendUtility
                     $getPageForRootline_cache[$ident] = $row;
                 }
             }
-            $db->sql_free_result($res);
         }
         return $row;
     }
@@ -576,7 +690,7 @@ class BackendUtility
                     return $pageinfo;
                 }
             } else {
-                $pageinfo = self::getRecord('pages', $id, '*', $perms_clause ? ' AND ' . $perms_clause : '');
+                $pageinfo = self::getRecord('pages', $id, '*', $perms_clause);
                 if ($pageinfo['uid'] && static::getBackendUserAuthentication()->isInWebMount($id, $perms_clause)) {
                     self::workspaceOL('pages', $pageinfo);
                     if (is_array($pageinfo)) {
@@ -867,15 +981,30 @@ class BackendUtility
                     self::workspaceOL($table, $rr);
                     self::fixVersioningPid($table, $rr, true);
                 }
-                $db = static::getDatabaseConnection();
-                $uidAcc = array();
+
+                $queryBuilder = static::getQueryBuilderForTable($table);
+                $queryBuilder->getRestrictions()
+                    ->removeAll()
+                    ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
+
+                $uidAcc = [];
                 // Used to avoid looping, if any should happen.
                 $subFieldPointer = $conf['ds_pointerField_searchParent_subField'];
                 while (!$srcPointer) {
-                    $res = $db->exec_SELECTquery('uid,' . $ds_pointerField . ',' . $ds_searchParentField . ($subFieldPointer ? ',' . $subFieldPointer : ''), $table, 'uid=' . (int)($newRecordPidValue ?: $rr[$ds_searchParentField]) . self::deleteClause($table));
+                    // select fields
+                    $queryBuilder
+                        ->select('uid', $ds_pointerField, $ds_searchParentField)
+                        ->from($table)
+                        ->where(
+                            $queryBuilder->expr()->eq('uid', (int)($newRecordPidValue ?: $rr[$ds_searchParentField]))
+                        );
+                    if ($subFieldPointer) {
+                        $queryBuilder->addSelect($subFieldPointer);
+                    }
+
+                    $rr = $queryBuilder->execute()->fetch();
+
                     $newRecordPidValue = 0;
-                    $rr = $db->sql_fetch_assoc($res);
-                    $db->sql_free_result($res);
                     // Break if no result from SQL db or if looping...
                     if (!is_array($rr) || isset($uidAcc[$rr['uid']])) {
                         break;
@@ -1139,10 +1268,20 @@ class BackendUtility
         // Make sure the titleField is amongst the fields when getting sorted
         $fieldsIndex[$titleField] = 1;
 
-        $result = array();
-        $db = static::getDatabaseConnection();
-        $res = $db->exec_SELECTquery('*', $table, '1=1 ' . $where . self::deleteClause($table));
-        while ($record = $db->sql_fetch_assoc($res)) {
+        $result = [];
+
+        $queryBuilder = static::getQueryBuilderForTable($table);
+        $queryBuilder->getRestrictions()
+            ->removeAll()
+            ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
+
+        $res = $queryBuilder
+            ->select('*')
+            ->from($table)
+            ->where(QueryHelper::stripLogicalOperatorPrefix($where))
+            ->execute();
+
+        while ($record = $res->fetch()) {
             // store the uid, because it might be unset if it's not among the requested $fields
             $recordId = $record['uid'];
             $record[$titleField] = self::getRecordTitle($table, $record);
@@ -1150,7 +1289,6 @@ class BackendUtility
             // include only the requested fields in the result
             $result[$recordId] = array_intersect_key($record, $fieldsIndex);
         }
-        $db->sql_free_result($res);
 
         // sort records by $sortField. This is not done in the query because the title might have been overwritten by
         // self::getRecordTitle();
@@ -2029,15 +2167,32 @@ class BackendUtility
                         $dbGroup->start($value, $theColConf['foreign_table'], $theColConf['MM'], $uid, $table, $theColConf);
                         $selectUids = $dbGroup->tableArray[$theColConf['foreign_table']];
                         if (is_array($selectUids) && !empty($selectUids)) {
-                            $MMres = $db->exec_SELECTquery('uid, ' . $MMfield, $theColConf['foreign_table'], 'uid IN (' . implode(',', $selectUids) . ')' . self::deleteClause($theColConf['foreign_table']));
-                            $mmlA = array();
-                            while ($MMrow = $db->sql_fetch_assoc($MMres)) {
+                            $queryBuilder = static::getQueryBuilderForTable($theColConf['foreign_table']);
+                            $queryBuilder->getRestrictions()
+                                ->removeAll()
+                                ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
+
+                            $result = $queryBuilder
+                                ->select('uid', $MMfield)
+                                ->from($theColConf['foreign_table'])
+                                ->where($queryBuilder->expr()->in('uid', $selectUids))
+                                ->execute();
+
+                            $mmlA = [];
+                            while ($MMrow = $result->fetch()) {
                                 // Keep sorting of $selectUids
-                                $mmlA[array_search($MMrow['uid'], $selectUids)] = $noRecordLookup ?
-                                    $MMrow['uid'] :
-                                    static::getRecordTitle($theColConf['foreign_table'], $MMrow, false, $forceResult);
+                                $selectedUid = array_search($MMrow['uid'], $selectUids);
+                                $mmlA[$selectedUid] =  $MMrow['uid'];
+                                if (!$noRecordLookup) {
+                                    $mmlA[$selectedUid] =  static::getRecordTitle(
+                                        $theColConf['foreign_table'],
+                                        $MMrow,
+                                        false,
+                                        $forceResult
+                                    );
+                                }
                             }
-                            $db->sql_free_result($MMres);
+
                             if (!empty($mmlA)) {
                                 ksort($mmlA);
                                 $l = implode('; ', $mmlA);
@@ -2065,20 +2220,38 @@ class BackendUtility
                         } else {
                             $rParts = array();
                             if ($uid && isset($theColConf['foreign_field']) && $theColConf['foreign_field'] !== '') {
-                                $whereClause = '';
+                                $queryBuilder = static::getQueryBuilderForTable($theColConf['foreign_table']);
+                                $queryBuilder->getRestrictions()
+                                    ->removeAll()
+                                    ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
+                                $constraints = [
+                                    $queryBuilder->expr()->eq($theColConf['foreign_field'], (int)$uid)
+                                ];
+
                                 if (!empty($theColConf['foreign_table_field'])) {
-                                    $whereClause .= ' AND ' . $theColConf['foreign_table_field'] . ' = ' . static::getDatabaseConnection()->fullQuoteStr($table, $theColConf['foreign_table']);
+                                    $constraints[] = $queryBuilder->expr()->eq(
+                                        $theColConf['foreign_table_field'],
+                                        $queryBuilder->createNamedParameter($table)
+                                    );
                                 }
+
                                 // Add additional where clause if foreign_match_fields are defined
                                 $foreignMatchFields = is_array($theColConf['foreign_match_fields']) ? $theColConf['foreign_match_fields'] : array();
                                 foreach ($foreignMatchFields as $matchField => $matchValue) {
-                                    $whereClause .= ' AND ' . $matchField . '=' . static::getDatabaseConnection()->fullQuoteStr($matchValue, $theColConf['foreign_table']);
+                                    $constraints[] = $queryBuilder->expr()->eq(
+                                        $matchField,
+                                        $queryBuilder->createNamedParameter($matchValue)
+                                    );
                                 }
-                                $records = self::getRecordsByField($theColConf['foreign_table'], $theColConf['foreign_field'], $uid, $whereClause);
-                                if (!empty($records)) {
-                                    foreach ($records as $record) {
-                                        $rParts[] = $record['uid'];
-                                    }
+
+                                $result = $queryBuilder
+                                    ->select('*')
+                                    ->from($theColConf['foreign_table'])
+                                    ->where(...$constraints)
+                                    ->execute();
+
+                                while ($record = $result->fetch()) {
+                                    $rParts[] = $record['uid'];
                                 }
                             }
                             if (empty($rParts)) {
@@ -2127,19 +2300,32 @@ class BackendUtility
                             $dbGroup->start($value, $theColConf['foreign_table'], $theColConf['MM'], $uid, $table, $theColConf);
                             $selectUids = $dbGroup->tableArray[$theColConf['foreign_table']];
                             if (!empty($selectUids) && is_array($selectUids)) {
-                                $MMres = $db->exec_SELECTquery(
-                                    'uid, ' . $MMfield,
-                                    $theColConf['foreign_table'],
-                                    'uid IN (' . implode(',', $selectUids) . ')' . static::deleteClause($theColConf['foreign_table'])
-                                );
-                                $mmlA = array();
-                                while ($MMrow = $db->sql_fetch_assoc($MMres)) {
+                                $queryBuilder = static::getQueryBuilderForTable($theColConf['foreign_table']);
+                                $queryBuilder->getRestrictions()
+                                    ->removeAll()
+                                    ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
+
+                                $result = $queryBuilder
+                                    ->select('uid', $MMfield)
+                                    ->from($theColConf['foreign_table'])
+                                    ->where($queryBuilder->expr()->in('uid', $selectUids))
+                                    ->execute();
+
+                                $mmlA = [];
+                                while ($MMrow = $result->fetch()) {
                                     // Keep sorting of $selectUids
-                                    $mmlA[array_search($MMrow['uid'], $selectUids)] = $noRecordLookup
-                                        ? $MMrow['uid']
-                                        : static::getRecordTitle($theColConf['foreign_table'], $MMrow, false, $forceResult);
+                                    $selectedUid = array_search($MMrow['uid'], $selectUids);
+                                    $mmlA[$selectedUid] =  $MMrow['uid'];
+                                    if (!$noRecordLookup) {
+                                        $mmlA[$selectedUid] =  static::getRecordTitle(
+                                            $theColConf['foreign_table'],
+                                            $MMrow,
+                                            false,
+                                            $forceResult
+                                        );
+                                    }
                                 }
-                                $db->sql_free_result($MMres);
+
                                 if (!empty($mmlA)) {
                                     ksort($mmlA);
                                     $l = implode('; ', $mmlA);
@@ -3301,15 +3487,25 @@ class BackendUtility
     public static function isRecordLocked($table, $uid)
     {
         if (!is_array($GLOBALS['LOCKED_RECORDS'])) {
-            $GLOBALS['LOCKED_RECORDS'] = array();
-            $db = static::getDatabaseConnection();
-            $res = $db->exec_SELECTquery(
-                '*',
-                'sys_lockedrecords',
-                'sys_lockedrecords.userid<>' . (int)static::getBackendUserAuthentication()->user['uid']
-                    . ' AND sys_lockedrecords.tstamp > ' . ($GLOBALS['EXEC_TIME'] - 2 * 3600)
-            );
-            while ($row = $db->sql_fetch_assoc($res)) {
+            $GLOBALS['LOCKED_RECORDS'] = [];
+
+            $queryBuilder = static::getQueryBuilderForTable('sys_lockedrecords');
+            $result = $queryBuilder
+                ->select('*')
+                ->from('sys_lockedrecords')
+                ->where(
+                    $queryBuilder->expr()->neq(
+                        'sys_lockedrecords' . '.userid',
+                        (int)static::getBackendUserAuthentication()->user['uid']
+                    ),
+                    $queryBuilder->expr()->gt(
+                        'sys_lockedrecords' . '.tstamp',
+                        ($GLOBALS['EXEC_TIME'] - 2 * 3600)
+                    )
+                )
+                ->execute();
+
+            while ($row = $result->fetch()) {
                 // Get the type of the user that locked this record:
                 if ($row['userid']) {
                     $userTypeLabel = 'beUser';
@@ -3331,18 +3527,23 @@ class BackendUtility
                     $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.lockedRecordUser'),
                     $userType,
                     $userName,
-                    self::calcAge($GLOBALS['EXEC_TIME'] - $row['tstamp'], $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears'))
+                    self::calcAge(
+                        $GLOBALS['EXEC_TIME'] - $row['tstamp'],
+                        $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears')
+                    )
                 );
                 if ($row['record_pid'] && !isset($GLOBALS['LOCKED_RECORDS'][$row['record_table'] . ':' . $row['record_pid']])) {
                     $GLOBALS['LOCKED_RECORDS']['pages:' . $row['record_pid']]['msg'] = sprintf(
                         $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.lockedRecordUser_content'),
                         $userType,
                         $userName,
-                        self::calcAge($GLOBALS['EXEC_TIME'] - $row['tstamp'], $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears'))
+                        self::calcAge(
+                            $GLOBALS['EXEC_TIME'] - $row['tstamp'],
+                            $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears')
+                        )
                     );
                 }
             }
-            $db->sql_free_result($res);
         }
         return $GLOBALS['LOCKED_RECORDS'][$table . ':' . $uid];
     }
@@ -3501,8 +3702,13 @@ class BackendUtility
      */
     public static function firstDomainRecord($rootLine)
     {
+        $expressionBuilder = $queryBuilder = static::getQueryBuilderForTable('sys_domain')->expr();
+        $constraint = $expressionBuilder->andX(
+            $expressionBuilder->eq('redirectTo', $expressionBuilder->literal('')),
+            $expressionBuilder->eq('hidden', 0)
+        );
         foreach ($rootLine as $row) {
-            $dRec = self::getRecordsByField('sys_domain', 'pid', $row['uid'], ' AND redirectTo=\'\' AND hidden=0', '', 'sorting');
+            $dRec = self::getRecordsByField('sys_domain', 'pid', $row['uid'], (string)$constraint, '', 'sorting');
             if (is_array($dRec)) {
                 $dRecord = reset($dRec);
                 return rtrim($dRecord['domainName'], '/');
@@ -3516,7 +3722,7 @@ class BackendUtility
      *
      * @param string $domain Domain name
      * @param string $path Appended path
-     * @return array Domain record, if found
+     * @return array|bool Domain record, if found, false otherwise
      */
     public static function getDomainStartPage($domain, $path = '')
     {
@@ -3526,14 +3732,36 @@ class BackendUtility
         $path = trim(preg_replace('/\\/[^\\/]*$/', '', $path));
         // Stuff
         $domain .= $path;
-        $db = static::getDatabaseConnection();
-        $res = $db->exec_SELECTquery('sys_domain.*', 'pages,sys_domain', '
-                       pages.uid=sys_domain.pid
-                       AND sys_domain.hidden=0
-                       AND (sys_domain.domainName=' . $db->fullQuoteStr($domain, 'sys_domain') . ' OR sys_domain.domainName='
-            . $db->fullQuoteStr(($domain . '/'), 'sys_domain') . ')' . self::deleteClause('pages'), '', '', '1');
-        $result = $db->sql_fetch_assoc($res);
-        $db->sql_free_result($res);
+
+        $queryBuilder = static::getQueryBuilderForTable('sys_domain');
+        $queryBuilder->getRestrictions()
+            ->removeAll()
+            ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
+
+        $result = $queryBuilder
+            ->select('sys_domain.*')
+            ->from('sys_domain')
+            ->from('pages')
+            ->where(
+                $queryBuilder->expr()->eq(
+                    'sys_domain.pid',
+                    $queryBuilder->quoteIdentifier('pages.uid')
+                ),
+                $queryBuilder->expr()->orX(
+                    $queryBuilder->expr()->eq(
+                        'sys_domain.domainName',
+                        $queryBuilder->createNamedParameter($domain)
+                    ),
+                    $queryBuilder->expr()->eq(
+                        'sys_domain.domainName',
+                        $queryBuilder->createNamedParameter($domain . '/')
+                    )
+                )
+
+            )
+            ->execute()
+            ->fetch();
+
         return $result;
     }
 
@@ -3669,21 +3897,39 @@ class BackendUtility
     public static function referenceCount($table, $ref, $msg = '', $count = null)
     {
         if ($count === null) {
-            $db = static::getDatabaseConnection();
+
+            // Build base query
+            $queryBuilder = static::getQueryBuilderForTable('sys_refindex');
+            $queryBuilder
+                ->count('*')
+                ->from('sys_refindex')
+                ->where(
+                    $queryBuilder->expr()->eq('ref_table', $queryBuilder->quote($table)),
+                    $queryBuilder->expr()->eq('deleted', 0)
+                );
+
             // Look up the path:
             if ($table == '_FILE') {
-                if (GeneralUtility::isFirstPartOfStr($ref, PATH_site)) {
-                    $ref = PathUtility::stripPathSitePrefix($ref);
-                    $condition = 'ref_string=' . $db->fullQuoteStr($ref, 'sys_refindex');
-                } else {
+                if (!GeneralUtility::isFirstPartOfStr($ref, PATH_site)) {
                     return '';
                 }
+
+                $ref = PathUtility::stripPathSitePrefix($ref);
+                $queryBuilder->andWhere(
+                    $queryBuilder->expr()->eq('ref_string', $queryBuilder->createNamedParameter($ref))
+                );
             } else {
-                $condition = 'ref_uid=' . (int)$ref;
+                $queryBuilder->andWhere($queryBuilder->expr()->eq('ref_uid', (int)$ref));
             }
-            $count = $db->exec_SELECTcountRows('*', 'sys_refindex', 'ref_table=' . $db->fullQuoteStr($table, 'sys_refindex') . ' AND ' . $condition . ' AND deleted=0');
+
+            $count = $queryBuilder->execute()->fetchColumn(0);
+        }
+
+        if ($count && $msg) {
+            return sprintf($msg, $count);
         }
-        return $count ? ($msg ? sprintf($msg, $count) : $count) : '';
+
+        return $count ?? '';
     }
 
     /**
@@ -3697,14 +3943,32 @@ class BackendUtility
     public static function translationCount($table, $ref, $msg = '')
     {
         $count = null;
-        if (empty($GLOBALS['TCA'][$table]['ctrl']['transForeignTable']) && $GLOBALS['TCA'][$table]['ctrl']['languageField'] && $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] && !$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerTable']) {
-            $where = $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] . '=' . (int)$ref . ' AND ' . $GLOBALS['TCA'][$table]['ctrl']['languageField'] . '<>0';
-            if (!empty($GLOBALS['TCA'][$table]['ctrl']['delete'])) {
-                $where .= ' AND ' . $GLOBALS['TCA'][$table]['ctrl']['delete'] . '=0';
-            }
-            $count = static::getDatabaseConnection()->exec_SELECTcountRows('*', $table, $where);
+        if (empty($GLOBALS['TCA'][$table]['ctrl']['transForeignTable'])
+            && $GLOBALS['TCA'][$table]['ctrl']['languageField']
+            && $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']
+            && !$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerTable']
+        ) {
+            $queryBuilder = static::getQueryBuilderForTable($table);
+            $queryBuilder->getRestrictions()
+                ->removeAll()
+                ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
+
+            $count = (int)$queryBuilder
+                ->count('*')
+                ->from($table)
+                ->where(
+                    $queryBuilder->expr()->eq($GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'], (int)$ref),
+                    $queryBuilder->expr()->neq($GLOBALS['TCA'][$table]['ctrl']['languageField'], 0)
+                )
+                ->execute()
+                ->fetchColumn(0);
+        }
+
+        if ($count && $msg) {
+            return sprintf($msg, $count);
         }
-        return $count ? ($msg ? sprintf($msg, $count) : $count) : '';
+
+        return $count ?? '';
     }
 
     /*******************************************
@@ -3742,24 +4006,36 @@ class BackendUtility
                     $outputRows[] = $row;
                 }
             }
-            $workspaceSqlPart = '';
+
+            $queryBuilder = static::getQueryBuilderForTable($table);
+            $queryBuilder->getRestrictions()->removeAll();
+
+            // build fields to select
+            $queryBuilder->select(...GeneralUtility::trimExplode(',', $fields));
+
+            $queryBuilder
+                ->from($table)
+                ->where(
+                    $queryBuilder->expr()->eq('pid', -1),
+                    $queryBuilder->expr()->neq('uid', (int)$uid),
+                    $queryBuilder->expr()->eq('t3ver_oid', (int)$uid)
+                )
+                ->orderBy('t3ver_id', 'DESC');
+
+            if ($includeDeletedRecords === false) {
+                $queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
+            }
+
             if ($workspace === 0) {
                 // Only in Live WS
-                $workspaceSqlPart = ' AND t3ver_wsid=0';
+                $queryBuilder->andWhere($queryBuilder->expr()->eq('t3ver_wsid', 0));
             } elseif ($workspace !== null) {
                 // In Live WS and Workspace with given ID
-                $workspaceSqlPart = ' AND t3ver_wsid IN (0,' . (int)$workspace . ')';
+                $queryBuilder->andWhere($queryBuilder->expr()->in('t3ver_wsid', [0, (int)$workspace]));
             }
-            // Select all offline versions of record:
-            $rows = static::getDatabaseConnection()->exec_SELECTgetRows(
-                $fields,
-                $table,
-                'pid=-1 AND uid<>' . (int)$uid . ' AND t3ver_oid=' . (int)$uid
-                    . $workspaceSqlPart
-                    . ($includeDeletedRecords ? '' : self::deleteClause($table)),
-                '',
-                't3ver_id DESC'
-            );
+
+            $rows = $queryBuilder->execute()->fetchAll();
+
             // Add rows to output array:
             if (is_array($rows)) {
                 $outputRows = array_merge($outputRows, $rows);
@@ -3965,11 +4241,27 @@ class BackendUtility
     {
         if (ExtensionManagementUtility::isLoaded('version')) {
             if ($workspace !== 0 && $GLOBALS['TCA'][$table] && self::isTableWorkspaceEnabled($table)) {
+
                 // Select workspace version of record:
-                $row = static::getDatabaseConnection()->exec_SELECTgetSingleRow($fields, $table, 'pid=-1 AND ' . 't3ver_oid=' . (int)$uid . ' AND ' . 't3ver_wsid=' . (int)$workspace . self::deleteClause($table));
-                if (is_array($row)) {
-                    return $row;
-                }
+                $queryBuilder = static::getQueryBuilderForTable($table);
+                $queryBuilder->getRestrictions()
+                    ->removeAll()
+                    ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
+
+                // build fields to select
+                $queryBuilder->select(...GeneralUtility::trimExplode(',', $fields));
+
+                $row = $queryBuilder
+                    ->from($table)
+                    ->where(
+                        $queryBuilder->expr()->eq('pid', -1),
+                        $queryBuilder->expr()->eq('t3ver_oid', (int)$uid),
+                        $queryBuilder->expr()->eq('t3ver_wsid', (int)$workspace)
+                    )
+                    ->execute()
+                    ->fetch();
+
+                return $row;
             }
         }
         return false;
@@ -4077,15 +4369,24 @@ class BackendUtility
         }
         if ((int)$workspace !== 0 && $GLOBALS['TCA'][$table] && static::isTableWorkspaceEnabled($table)) {
             // Select workspace version of record:
-            $row = static::getDatabaseConnection()->exec_SELECTgetSingleRow(
-                $fields,
-                $table,
-                'pid<>-1 AND t3ver_state=' . new VersionState(VersionState::MOVE_PLACEHOLDER) . ' AND t3ver_move_id='
-                    . (int)$uid . ' AND t3ver_wsid=' . (int)$workspace . self::deleteClause($table)
-            );
-            if (is_array($row)) {
-                return $row;
-            }
+            $queryBuilder = static::getQueryBuilderForTable($table);
+            $queryBuilder->getRestrictions()
+                ->removeAll()
+                ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
+
+            $row = $queryBuilder
+                ->select(...GeneralUtility::trimExplode(',', $fields, true))
+                ->from($table)
+                ->where(
+                    $queryBuilder->expr()->neq('pid', -1),
+                    $queryBuilder->expr()->eq('t3ver_state', new VersionState(VersionState::MOVE_PLACEHOLDER)),
+                    $queryBuilder->expr()->eq('t3ver_move_id', (int)$uid),
+                    $queryBuilder->expr()->eq('t3ver_wsid', (int)$workspace)
+                )
+                ->execute()
+                ->fetch();
+
+            return $row ?: false;
         }
         return false;
     }
@@ -4268,23 +4569,20 @@ class BackendUtility
      */
     public static function shortcutExists($url)
     {
-        $statement = self::getDatabaseConnection()->prepare_SELECTquery(
-            'uid',
-            'sys_be_shortcuts',
-            'userid = :userid AND url = :url'
-        );
-
-        $statement->bindValues([
-            ':userid' => self::getBackendUserAuthentication()->user['uid'],
-            ':url' => $url
-        ]
-        );
-
-        $statement->execute();
-        $rows = $statement->fetch(PreparedStatement::FETCH_ASSOC);
-        $statement->free();
-
-        return !empty($rows);
+        $queryBuilder = static::getQueryBuilderForTable('sys_be_shortcuts');
+        $queryBuilder->getRestrictions()->removeAll();
+
+        $count = $queryBuilder
+            ->count('uid')
+            ->from('sys_be_shortcuts')
+            ->where(
+                $queryBuilder->expr()->eq('userid', (int)self::getBackendUserAuthentication()->user['uid']),
+                $queryBuilder->expr()->eq('url', $queryBuilder->createNamedParameter($url))
+            )
+            ->execute()
+            ->fetchColumn(0);
+
+        return (bool)$count;
     }
 
     /**
@@ -4321,6 +4619,24 @@ class BackendUtility
     }
 
     /**
+     * @param string $table
+     * @return Connection
+     */
+    protected static function getConnectionForTable($table)
+    {
+        return GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table);
+    }
+
+    /**
+     * @param string $table
+     * @return QueryBuilder
+     */
+    protected static function getQueryBuilderForTable($table)
+    {
+        return GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
+    }
+
+    /**
      * @return LanguageService
      */
     protected static function getLanguageService()
index f47eb4a..e2aa7a0 100644 (file)
@@ -81,11 +81,13 @@ class ConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
      */
     private function setUpDatabaseMockForDeterminePageId()
     {
-        $GLOBALS['TYPO3_DB'] = $this->getMockBuilder(\TYPO3\CMS\Core\Database\DatabaseConnection::class)
-            ->setMethods(array('exec_SELECTquery', 'sql_fetch_assoc', 'sql_free_result'))
+        $this->matchCondition = $this->getMockBuilder(\TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching\ConditionMatcher::class)
+            ->setMethods(['determineRootline', 'determinePageId'])
+            ->disableOriginalConstructor()
             ->getMock();
-        $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTquery')->will($this->returnCallback(array($this, 'determinePageIdByRecordDatabaseExecuteCallback')));
-        $GLOBALS['TYPO3_DB']->expects($this->any())->method('sql_fetch_assoc')->will($this->returnCallback(array($this, 'determinePageIdByRecordDatabaseFetchCallback')));
+
+        $this->matchCondition->expects($this->once())->method('determineRootline');
+        $this->matchCondition->expects($this->once())->method('determinePageId')->willReturn(999);
     }
 
     /**
@@ -911,46 +913,6 @@ class ConditionMatcherTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     }
 
     /**
-     * Callback method for pageIdCanBeDetermined test cases.
-     * Simulates TYPO3_DB->exec_SELECTquery().
-     *
-     * @param string $fields
-     * @param string $table
-     * @param string $where
-     * @return mixed
-     */
-    public function determinePageIdByRecordDatabaseExecuteCallback($fields, $table, $where)
-    {
-        if ($table === $this->testTableName) {
-            return array(
-                'scope' => $this->testTableName,
-                'data' => array(
-                    'pid' => 999,
-                    'uid' => 998
-                )
-            );
-        } else {
-            return false;
-        }
-    }
-
-    /**
-     * Callback method for pageIdCanBeDetermined test cases.
-     * Simulates TYPO3_DB->sql_fetch_assoc().
-     *
-     * @param mixed $resource
-     * @return mixed
-     */
-    public function determinePageIdByRecordDatabaseFetchCallback($resource)
-    {
-        if (is_array($resource) && $resource['scope'] === $this->testTableName) {
-            return $resource['data'];
-        } else {
-            return false;
-        }
-    }
-
-    /**
      * @test
      */
     public function matchCallsTestConditionAndHandsOverParameters()
index 5a10ebf..cec1930 100644 (file)
@@ -14,7 +14,6 @@ namespace TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider;
  * The TYPO3 project - inspiring people to share!
  */
 
-use Prophecy\Argument;
 use Prophecy\Prophecy\ObjectProphecy;
 use TYPO3\CMS\Backend\Form\Exception\DatabaseRecordException;
 use TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseEditRow;
@@ -27,7 +26,7 @@ use TYPO3\CMS\Core\Tests\UnitTestCase;
 class DatabaseEditRowTest extends UnitTestCase
 {
     /**
-     * @var DatabaseEditRow
+     * @var DatabaseEditRow|\PHPUnit_Framework_MockObject_MockObject
      */
     protected $subject;
 
@@ -41,7 +40,9 @@ class DatabaseEditRowTest extends UnitTestCase
         $this->dbProphecy = $this->prophesize(DatabaseConnection::class);
         $GLOBALS['TYPO3_DB'] = $this->dbProphecy->reveal();
 
-        $this->subject = new DatabaseEditRow();
+        $this->subject = $this->getMockBuilder(DatabaseEditRow::class)
+            ->setMethods(['getDatabaseRow'])
+            ->getMock();
     }
 
     /**
@@ -58,9 +59,7 @@ class DatabaseEditRowTest extends UnitTestCase
             'uid' => 10,
             'pid' => 123
         ];
-        $this->dbProphecy->quoteStr($input['tableName'], $input['tableName'])->willReturn($input['tableName']);
-        $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=' . $input['vanillaUid'])->willReturn($resultRow);
-        $this->dbProphecy->exec_SELECTgetSingleRow(Argument::cetera())->willReturn([]);
+        $this->subject->expects($this->once())->method('getDatabaseRow')->willReturn($resultRow);
 
         $result = $this->subject->addData($input);
 
@@ -80,8 +79,7 @@ class DatabaseEditRowTest extends UnitTestCase
         $resultRow = [
             'uid' => 10,
         ];
-        $this->dbProphecy->quoteStr($input['tableName'], $input['tableName'])->willReturn($input['tableName']);
-        $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=' . $input['vanillaUid'])->willReturn($resultRow);
+        $this->subject->expects($this->once())->method('getDatabaseRow')->willReturn($resultRow);
 
         $this->expectException(\UnexpectedValueException::class);
         $this->expectExceptionCode(1437663061);
@@ -109,32 +107,14 @@ class DatabaseEditRowTest extends UnitTestCase
     /**
      * @test
      */
-    public function addDataThrowsExceptionIfNoRecordForEditingCouldBeRetrievedFromDatabase()
+    public function addDataThrowsExceptionIfDatabaseFetchingReturnsNoRow()
     {
         $input = [
             'tableName' => 'tt_content',
             'command' => 'edit',
             'vanillaUid' => 10,
         ];
-
-        $this->expectException(\RuntimeException::class);
-        $this->expectExceptionCode(1437655862);
-
-        $this->subject->addData($input);
-    }
-
-    /**
-     * @test
-     */
-    public function addDataThrowsExceptionIfDatabaseFetchingReturnsFalse()
-    {
-        $input = [
-            'tableName' => 'tt_content',
-            'command' => 'edit',
-            'vanillaUid' => 10,
-        ];
-        $this->dbProphecy->quoteStr(Argument::cetera())->willReturn($input['tableName']);
-        $this->dbProphecy->exec_SELECTgetSingleRow(Argument::cetera())->willReturn(false);
+        $this->subject->expects($this->once())->method('getDatabaseRow')->willReturn([]);
 
         $this->expectException(DatabaseRecordException::class);
         $this->expectExceptionCode(1437656081);
@@ -152,8 +132,7 @@ class DatabaseEditRowTest extends UnitTestCase
             'command' => 'edit',
             'vanillaUid' => 10,
         ];
-        $this->dbProphecy->quoteStr(Argument::cetera())->willReturn($input['tableName']);
-        $this->dbProphecy->exec_SELECTgetSingleRow(Argument::cetera())->willReturn(false);
+        $this->subject->expects($this->once())->method('getDatabaseRow')->willReturn([]);
 
         try {
             $this->subject->addData($input);
@@ -162,23 +141,4 @@ class DatabaseEditRowTest extends UnitTestCase
             $this->assertSame(10, $e->getUid());
         }
     }
-
-    /**
-     * @test
-     */
-    public function addDataThrowsExceptionIfDatabaseFetchingReturnsInvalidRowResultData()
-    {
-        $input = [
-            'tableName' => 'tt_content',
-            'command' => 'edit',
-            'vanillaUid' => 10,
-        ];
-        $this->dbProphecy->quoteStr(Argument::cetera())->willReturn($input['tableName']);
-        $this->dbProphecy->exec_SELECTgetSingleRow(Argument::cetera())->willReturn('invalid result data');
-
-        $this->expectException(\UnexpectedValueException::class);
-        $this->expectExceptionCode(1437656323);
-
-        $this->subject->addData($input);
-    }
 }
index 8005a92..fbb532e 100644 (file)
@@ -29,7 +29,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
 class DatabaseLanguageRowsTest extends UnitTestCase
 {
     /**
-     * @var DatabaseLanguageRows
+     * @var DatabaseLanguageRows|\PHPUnit_Framework_MockObject_MockObject
      */
     protected $subject;
 
@@ -45,13 +45,12 @@ class DatabaseLanguageRowsTest extends UnitTestCase
 
     protected function setUp()
     {
-        $this->dbProphecy = $this->prophesize(DatabaseConnection::class);
-        $GLOBALS['TYPO3_DB'] = $this->dbProphecy->reveal();
-
         $this->beUserProphecy = $this->prophesize(BackendUserAuthentication::class);
         $GLOBALS['BE_USER'] = $this->beUserProphecy;
 
-        $this->subject = new DatabaseLanguageRows();
+        $this->subject = $this->getMockBuilder(DatabaseLanguageRows::class)
+            ->setMethods(['getRecordWorkspaceOverlay'])
+            ->getMock();
     }
 
     /**
@@ -94,9 +93,7 @@ class DatabaseLanguageRowsTest extends UnitTestCase
             ],
         ];
 
-        // Needed for BackendUtility::getRecord
-        $GLOBALS['TCA']['tt_content'] = array('foo');
-        $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=23')->shouldBeCalled()->willReturn(null);
+        $this->subject->expects($this->once())->method('getRecordWorkspaceOverlay')->willReturn([]);
 
         $this->expectException(DatabaseDefaultLanguageException::class);
         $this->expectExceptionCode(1438249426);
@@ -131,9 +128,8 @@ class DatabaseLanguageRowsTest extends UnitTestCase
             'text' => 'default language text',
             'sys_language_uid' => 0,
         ];
-        // Needed for BackendUtility::getRecord
-        $GLOBALS['TCA']['tt_content'] = array('foo');
-        $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=23')->shouldBeCalled()->willReturn($defaultLanguageRow);
+
+        $this->subject->expects($this->once())->method('getRecordWorkspaceOverlay')->willReturn($defaultLanguageRow);
 
         $expected = $input;
         $expected['defaultLanguageRow'] = $defaultLanguageRow;
@@ -176,9 +172,8 @@ class DatabaseLanguageRowsTest extends UnitTestCase
             'text' => 'default language text',
             'sys_language_uid' => 0,
         ];
-        // Needed for BackendUtility::getRecord
-        $GLOBALS['TCA']['tt_content'] = array('foo');
-        $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=23')->shouldBeCalled()->willReturn($defaultLanguageRow);
+
+        $this->subject->expects($this->once())->method('getRecordWorkspaceOverlay')->willReturn($defaultLanguageRow);
 
         $expected = $input;
         $expected['defaultLanguageRow'] = $defaultLanguageRow;
@@ -249,9 +244,10 @@ class DatabaseLanguageRowsTest extends UnitTestCase
             'text' => 'default language text',
             'sys_language_uid' => 0,
         ];
-        // Needed for BackendUtility::getRecord
-        $GLOBALS['TCA']['tt_content'] = array('foo');
-        $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=23')->shouldBeCalled()->willReturn($defaultLanguageRow);
+        $this->subject->expects($this->at(0))
+            ->method('getRecordWorkspaceOverlay')
+            ->with('tt_content', 23)
+            ->willReturn($defaultLanguageRow);
 
         /** @var TranslationConfigurationProvider|ObjectProphecy $translationProphecy */
         $translationProphecy = $this->prophesize(TranslationConfigurationProvider::class);
@@ -259,7 +255,10 @@ class DatabaseLanguageRowsTest extends UnitTestCase
         $translationProphecy->translationInfo('tt_content', 23, 3)->shouldBeCalled()->willReturn($translationResult);
 
         // This is the real check: The "additional overlay" should be fetched
-        $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=43')->shouldBeCalled()->willReturn($recordWsolResult);
+        $this->subject->expects($this->at(1))
+            ->method('getRecordWorkspaceOverlay')
+            ->with('tt_content', 43)
+            ->willReturn($recordWsolResult);
 
         $expected = $input;
         $expected['defaultLanguageRow'] = $defaultLanguageRow;
@@ -340,9 +339,10 @@ class DatabaseLanguageRowsTest extends UnitTestCase
             'text' => 'default language text',
             'sys_language_uid' => 0,
         ];
-        // Needed for BackendUtility::getRecord
-        $GLOBALS['TCA']['tt_content'] = array('foo');
-        $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=23')->shouldBeCalled()->willReturn($defaultLanguageRow);
+        $this->subject->expects($this->at(0))
+            ->method('getRecordWorkspaceOverlay')
+            ->with('tt_content', 23)
+            ->willReturn($defaultLanguageRow);
 
         /** @var TranslationConfigurationProvider|ObjectProphecy $translationProphecy */
         $translationProphecy = $this->prophesize(TranslationConfigurationProvider::class);
@@ -351,7 +351,10 @@ class DatabaseLanguageRowsTest extends UnitTestCase
         $translationProphecy->translationInfo('tt_content', 23, 2)->shouldNotBeCalled();
 
         // This is the real check: The "additional overlay" should be fetched
-        $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=43')->shouldBeCalled()->willReturn($recordWsolResult);
+        $this->subject->expects($this->at(1))
+            ->method('getRecordWorkspaceOverlay')
+            ->with('tt_content', 43)
+            ->willReturn($recordWsolResult);
 
         $expected = $input;
         $expected['defaultLanguageRow'] = $defaultLanguageRow;
index 412071d..a35eb73 100644 (file)
@@ -14,10 +14,7 @@ namespace TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider;
  * The TYPO3 project - inspiring people to share!
  */
 
-use Prophecy\Argument;
-use Prophecy\Prophecy\ObjectProphecy;
 use TYPO3\CMS\Backend\Form\FormDataProvider\DatabasePageLanguageOverlayRows;
-use TYPO3\CMS\Core\Database\DatabaseConnection;
 use TYPO3\CMS\Core\Tests\UnitTestCase;
 
 /**
@@ -26,34 +23,15 @@ use TYPO3\CMS\Core\Tests\UnitTestCase;
 class DatabasePageLanguageOverlayRowsTest extends UnitTestCase
 {
     /**
-     * @var DatabasePageLanguageOverlayRows
+     * @var DatabasePageLanguageOverlayRows|\PHPUnit_Framework_MockObject_MockObject
      */
     protected $subject;
 
-    /**
-     * @var DatabaseConnection | ObjectProphecy
-     */
-    protected $dbProphecy;
-
     protected function setUp()
     {
-        $this->dbProphecy = $this->prophesize(DatabaseConnection::class);
-        $GLOBALS['TYPO3_DB'] = $this->dbProphecy->reveal();
-        $GLOBALS['TCA']['pages_language_overlay'] = array();
-
-        $this->subject = new DatabasePageLanguageOverlayRows();
-    }
-
-    /**
-     * @test
-     */
-    public function addDataThrowsExceptionOnDatabaseError()
-    {
-        $this->dbProphecy->exec_SELECTgetRows(Argument::cetera())->willReturn(null);
-        $this->dbProphecy->sql_error(Argument::cetera())->willReturn(null);
-        $this->expectException(\UnexpectedValueException::class);
-        $this->expectExceptionCode(1440777705);
-        $this->subject->addData(['effectivePid' => 1]);
+        $this->subject = $this->getMockBuilder(DatabasePageLanguageOverlayRows::class)
+            ->setMethods(['getDatabaseRows'])
+            ->getMock();
     }
 
     /**
@@ -72,9 +50,10 @@ class DatabasePageLanguageOverlayRowsTest extends UnitTestCase
                 'sys_language_uid' => '2',
             ],
         ];
-        $this->dbProphecy->exec_SELECTgetRows('*', 'pages_language_overlay', 'pid=23')
-            ->shouldBeCalled()
+        $this->subject->expects($this->once())
+            ->method('getDatabaseRows')
             ->willReturn($expected['pageLanguageOverlayRows']);
+
         $this->assertSame($expected, $this->subject->addData($input));
     }
 }
index 58ccab3..d4e7731 100644 (file)
@@ -14,7 +14,6 @@ namespace TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider;
  * The TYPO3 project - inspiring people to share!
  */
 
-use Prophecy\Argument;
 use Prophecy\Prophecy\ObjectProphecy;
 use TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseParentPageRow;
 use TYPO3\CMS\Core\Database\DatabaseConnection;
@@ -26,7 +25,7 @@ use TYPO3\CMS\Core\Tests\UnitTestCase;
 class DatabaseParentPageRowTest extends UnitTestCase
 {
     /**
-     * @var DatabaseParentPageRow
+     * @var DatabaseParentPageRow|\PHPUnit_Framework_MockObject_MockObject
      */
     protected $subject;
 
@@ -37,10 +36,9 @@ class DatabaseParentPageRowTest extends UnitTestCase
 
     protected function setUp()
     {
-        $this->subject = new DatabaseParentPageRow();
-
-        $this->dbProphecy = $this->prophesize(DatabaseConnection::class);
-        $GLOBALS['TYPO3_DB'] = $this->dbProphecy->reveal();
+        $this->subject = $this->getMockBuilder(DatabaseParentPageRow::class)
+            ->setMethods(['getDatabaseRow'])
+            ->getMock();
     }
 
     /**
@@ -57,9 +55,16 @@ class DatabaseParentPageRowTest extends UnitTestCase
             'uid' => 123,
             'pid' => 321
         ];
-        $this->dbProphecy->quoteStr(Argument::cetera())->willReturnArgument(0);
-        $this->dbProphecy->exec_SELECTgetSingleRow('*', $input['tableName'], 'uid=10')->willReturn(['pid' => 123]);
-        $this->dbProphecy->exec_SELECTgetSingleRow('*', 'pages', 'uid=123')->willReturn($parentPageRow);
+
+        $this->subject->expects($this->at(0))
+            ->method('getDatabaseRow')
+            ->with($input['tableName'], 10)
+            ->willReturn(['pid' => 123]);
+
+        $this->subject->expects($this->at(1))
+            ->method('getDatabaseRow')
+            ->with('pages', 123)
+            ->willReturn($parentPageRow);
 
         $result = $this->subject->addData($input);
 
@@ -80,9 +85,19 @@ class DatabaseParentPageRowTest extends UnitTestCase
             'uid' => 10,
             'pid' => 321
         ];
-        $this->dbProphecy->quoteStr(Argument::cetera())->willReturnArgument(0);
-        $this->dbProphecy->exec_SELECTgetSingleRow('*', $input['tableName'], 'uid=10')->willReturn($neigborRow);
-        $this->dbProphecy->exec_SELECTgetSingleRow('*', 'pages', 'uid=321')->willReturn(array());
+        $parentPageRow = [
+            'uid' => 123,
+            'pid' => 321
+        ];
+        $this->subject->expects($this->at(0))
+            ->method('getDatabaseRow')
+            ->with($input['tableName'], 10)
+            ->willReturn($neigborRow);
+
+        $this->subject->expects($this->at(1))
+            ->method('getDatabaseRow')
+            ->with('pages', 321)
+            ->willReturn($parentPageRow);
 
         $result = $this->subject->addData($input);
 
@@ -99,8 +114,11 @@ class DatabaseParentPageRowTest extends UnitTestCase
             'command' => 'new',
             'vanillaUid' => -10,
         ];
-        $this->dbProphecy->quoteStr(Argument::cetera())->willReturnArgument(0);
-        $this->dbProphecy->exec_SELECTgetSingleRow('*', $input['tableName'], 'uid=10')->willReturn(['pid' => 0]);
+
+        $this->subject->expects($this->once())
+            ->method('getDatabaseRow')
+            ->with($input['tableName'], 10)
+            ->willReturn(['pid' => 0]);
 
         $result = $this->subject->addData($input);
 
@@ -121,8 +139,11 @@ class DatabaseParentPageRowTest extends UnitTestCase
             'uid' => 123,
             'pid' => 321
         ];
-        $this->dbProphecy->quoteStr(Argument::cetera())->willReturnArgument(0);
-        $this->dbProphecy->exec_SELECTgetSingleRow('*', 'pages', 'uid=123')->willReturn($parentPageRow);
+
+        $this->subject->expects($this->once())
+            ->method('getDatabaseRow')
+            ->with('pages', 123)
+            ->willReturn($parentPageRow);
 
         $result = $this->subject->addData($input);
 
@@ -147,8 +168,10 @@ class DatabaseParentPageRowTest extends UnitTestCase
             'uid' => 321,
             'pid' => 456
         ];
-        $this->dbProphecy->quoteStr(Argument::cetera())->willReturnArgument(0);
-        $this->dbProphecy->exec_SELECTgetSingleRow('*', 'pages', 'uid=321')->willReturn($parentPageRow);
+        $this->subject->expects($this->once())
+            ->method('getDatabaseRow')
+            ->with('pages', 321)
+            ->willReturn($parentPageRow);
 
         $result = $this->subject->addData($input);
 
index a8d6056..2193388 100644 (file)
@@ -25,7 +25,7 @@ use TYPO3\CMS\Core\Tests\UnitTestCase;
 class DatabaseRecordTypeValueTest extends UnitTestCase
 {
     /**
-     * @var DatabaseRecordTypeValue
+     * @var DatabaseRecordTypeValue|\PHPUnit_Framework_MockObject_MockObject
      */
     protected $subject;
 
@@ -36,10 +36,9 @@ class DatabaseRecordTypeValueTest extends UnitTestCase
 
     protected function setUp()
     {
-        $this->dbProphecy = $this->prophesize(DatabaseConnection::class);
-        $GLOBALS['TYPO3_DB'] = $this->dbProphecy->reveal();
-
-        $this->subject = new DatabaseRecordTypeValue();
+        $this->subject = $this->getMockBuilder(DatabaseRecordTypeValue::class)
+            ->setMethods(['getDatabaseRow'])
+            ->getMock();
     }
 
     /**
@@ -417,10 +416,11 @@ class DatabaseRecordTypeValueTest extends UnitTestCase
         $foreignRecordResult = [
             'foreignField' => 3,
         ];
-        // Required for BackendUtility::getRecord
-        $GLOBALS['TCA']['foreignTable'] = array('foo');
 
-        $this->dbProphecy->exec_SELECTgetSingleRow('foreignField', 'foreignTable', 'uid=42')->shouldBeCalled()->willReturn($foreignRecordResult);
+        $this->subject->expects($this->once())
+            ->method('getDatabaseRow')
+            ->with('foreignTable', 42, 'foreignField')
+            ->willReturn($foreignRecordResult);
 
         $expected = $input;
         $expected['recordTypeValue'] = '3';
@@ -463,10 +463,11 @@ class DatabaseRecordTypeValueTest extends UnitTestCase
         $foreignRecordResult = [
             'type' => 2,
         ];
-        // Required for BackendUtility::getRecord
-        $GLOBALS['TCA']['sys_file'] = array('foo');
 
-        $this->dbProphecy->exec_SELECTgetSingleRow('type', 'sys_file', 'uid=222')->shouldBeCalled()->willReturn($foreignRecordResult);
+        $this->subject->expects($this->once())
+            ->method('getDatabaseRow')
+            ->with('sys_file', 222, 'type')
+            ->willReturn($foreignRecordResult);
 
         $expected = $input;
         $expected['recordTypeValue'] = '2';
index bda79a6..65a9080 100644 (file)
@@ -14,12 +14,17 @@ namespace TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider;
  * The TYPO3 project - inspiring people to share!
  */
 
+use Doctrine\DBAL\Driver\Statement;
 use Prophecy\Argument;
 use Prophecy\Prophecy\ObjectProphecy;
 use TYPO3\CMS\Backend\Form\FormDataProvider\TcaSelectItems;
 use TYPO3\CMS\Backend\Module\ModuleLoader;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
-use TYPO3\CMS\Core\Database\DatabaseConnection;
+use TYPO3\CMS\Core\Database\Connection;
+use TYPO3\CMS\Core\Database\ConnectionPool;
+use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
+use TYPO3\CMS\Core\Database\Query\QueryBuilder;
+use TYPO3\CMS\Core\Database\Query\Restriction\DefaultRestrictionContainer;
 use TYPO3\CMS\Core\Database\RelationHandler;
 use TYPO3\CMS\Core\Messaging\FlashMessage;
 use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
@@ -35,7 +40,7 @@ use TYPO3\CMS\Lang\LanguageService;
 class TcaSelectItemsTest extends UnitTestCase
 {
     /**
-     * @var TcaSelectItems
+     * @var TcaSelectItems|\PHPUnit_Framework_MockObject_MockObject
      */
     protected $subject;
 
@@ -47,6 +52,10 @@ class TcaSelectItemsTest extends UnitTestCase
     protected function setUp()
     {
         $this->singletonInstances = GeneralUtility::getSingletonInstances();
+        $this->subject = $this->getMockBuilder(TcaSelectItems::class)
+            ->setMethods(['getDatabaseRow'])
+            ->getMock();
+
         $this->subject = new TcaSelectItems();
     }
 
@@ -58,6 +67,83 @@ class TcaSelectItemsTest extends UnitTestCase
     }
 
     /**
+     * Prepare a mock database setup for a Doctrine connection
+     * and return an array of all prophets to set expectations upon.
+     *
+     * @param string $tableName
+     * @return array
+     */
+    protected function mockDatabaseConnection($tableName = 'fTable')
+    {
+        $connectionProphet = $this->prophesize(Connection::class);
+        $connectionProphet->quote(Argument::cetera())->will(function ($arguments) {
+            return "'" . $arguments[0] . "'";
+        });
+        $connectionProphet->quoteIdentifier(Argument::cetera())->will(function ($arguments) {
+            return '`' . $arguments[0] . '`';
+        });
+
+        $restrictionProphet = $this->prophesize(DefaultRestrictionContainer::class);
+        $restrictionProphet->removeAll()->willReturn($restrictionProphet->reveal());
+        $restrictionProphet->add(Argument::cetera())->willReturn($restrictionProphet->reveal());
+
+        $queryBuilderProphet = $this->prophesize(QueryBuilder::class);
+        $queryBuilderProphet->expr()->willReturn(
+            GeneralUtility::makeInstance(ExpressionBuilder::class, $connectionProphet->reveal())
+        );
+        $queryBuilderProphet->getRestrictions()->willReturn($restrictionProphet->reveal());
+        $queryBuilderProphet->quoteIdentifier(Argument::cetera())->will(function ($arguments) {
+            return '`' . $arguments[0] . '`';
+        });
+
+        $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
+        $connectionPoolProphet->getConnectionForTable($tableName)
+            ->willReturn($connectionProphet->reveal());
+        $connectionPoolProphet->getQueryBuilderForTable($tableName)
+            ->shouldBeCalled()
+            ->willReturn($queryBuilderProphet->reveal());
+
+        return [$queryBuilderProphet, $connectionPoolProphet, $connectionProphet, $restrictionProphet];
+    }
+
+    /**
+     * Mock a doctrine database connection with all expectations
+     * required for the processSelectField* tests.
+     */
+    protected function mockDatabaseConnectionForProcessSelectField()
+    {
+        list($queryBuilderProphet, $connectionPoolProphet) = $this->mockDatabaseConnection('foreignTable');
+
+        /** @var Statement|ObjectProphecy $statementProphet */
+        $statementProphet = $this->prophesize(Statement::class);
+        $statementProphet->errorInfo()->shouldBeCalled();
+        $statementProphet->fetch()->shouldBeCalled();
+
+        $queryBuilderProphet->select('foreignTable.uid')
+            ->shouldBeCalled()
+            ->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->from('foreignTable')
+            ->shouldBeCalled()
+            ->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->from('pages')
+            ->shouldBeCalled()
+            ->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->where(' 1=1', '')
+            ->shouldBeCalled()
+            ->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->andWhere('`pages.uid` = `foreignTable.pid`')
+            ->shouldBeCalled()
+            ->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->execute()
+            ->shouldBeCalled()
+            ->willReturn($statementProphet->reveal());
+
+        # Two instances are needed due to the push/pop behavior of addInstance()
+        GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
+        GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
+    }
+
+    /**
      * @test
      */
     public function addDataKeepExistingItems()
@@ -1274,12 +1360,18 @@ class TcaSelectItemsTest extends UnitTestCase
         return [
             'replace REC_FIELD' => [
                 'AND fTable.title=\'###REC_FIELD_rowField###\'',
-                'pages.uid=fTable.pid AND pages.deleted=0 AND 1=1 AND fTable.title=\'rowFieldValue\'',
+                [
+                    [' 1=1', 'fTable.title=\'rowFieldValue\''],
+                    ['`pages.uid` = `fTable.pid`']
+                ],
                 [],
             ],
             'replace REC_FIELD within FlexForm' => [
                 'AND fTable.title=###REC_FIELD_rowFieldFlexForm###',
-                'pages.uid=fTable.pid AND pages.deleted=0 AND 1=1 AND fTable.title=\'rowFieldFlexFormValue\'',
+                [
+                    [' 1=1', 'fTable.title=\'rowFieldFlexFormValue\''],
+                    ['`pages.uid` = `fTable.pid`']
+                ],
                 [
                     'databaseRow' => [
                         'rowFieldThree' => [
@@ -1295,12 +1387,18 @@ class TcaSelectItemsTest extends UnitTestCase
             ],
             'replace REC_FIELD fullQuote' => [
                 'AND fTable.title=###REC_FIELD_rowField###',
-                'pages.uid=fTable.pid AND pages.deleted=0 AND 1=1 AND fTable.title=\'rowFieldValue\'',
+                [
+                    [' 1=1', 'fTable.title=\'rowFieldValue\''],
+                    ['`pages.uid` = `fTable.pid`']
+                ],
                 [],
             ],
             'replace REC_FIELD fullQuoteWithArray' => [
                 'AND fTable.title=###REC_FIELD_rowFieldThree###',
-                'pages.uid=fTable.pid AND pages.deleted=0 AND 1=1 AND fTable.title=\'rowFieldThreeValue\'',
+                [
+                    [' 1=1', 'fTable.title=\'rowFieldThreeValue\''],
+                    ['`pages.uid` = `fTable.pid`']
+                ],
                 [
                     'databaseRow' => [
                         'rowFieldThree' => [
@@ -1311,17 +1409,26 @@ class TcaSelectItemsTest extends UnitTestCase
             ],
             'replace REC_FIELD multiple markers' => [
                 'AND fTable.title=\'###REC_FIELD_rowField###\' AND fTable.pid=###REC_FIELD_rowFieldTwo###',
-                'pages.uid=fTable.pid AND pages.deleted=0 AND 1=1 AND fTable.title=\'rowFieldValue\' AND fTable.pid=\'rowFieldTwoValue\'',
+                [
+                    [' 1=1', 'fTable.title=\'rowFieldValue\' AND fTable.pid=\'rowFieldTwoValue\''],
+                    ['`pages.uid` = `fTable.pid`']
+                ],
                 [],
             ],
             'replace CURRENT_PID' => [
                 'AND fTable.uid=###CURRENT_PID###',
-                'pages.uid=fTable.pid AND pages.deleted=0 AND 1=1 AND fTable.uid=43',
+                [
+                    [' 1=1', 'fTable.uid=43'],
+                    ['`pages.uid` = `fTable.pid`']
+                ],
                 [],
             ],
             'replace CURRENT_PID within FlexForm' => [
                 'AND fTable.uid=###CURRENT_PID###',
-                'pages.uid=fTable.pid AND pages.deleted=0 AND 1=1 AND fTable.uid=77',
+                [
+                    [' 1=1', 'fTable.uid=77'],
+                    ['`pages.uid` = `fTable.pid`']
+                ],
                 [
                     'flexParentDatabaseRow' => [
                         'pid' => '77',
@@ -1330,19 +1437,28 @@ class TcaSelectItemsTest extends UnitTestCase
             ],
             'replace CURRENT_PID integer cast' => [
                 'AND fTable.uid=###CURRENT_PID###',
-                'pages.uid=fTable.pid AND pages.deleted=0 AND 1=1 AND fTable.uid=431',
+                [
+                    [' 1=1', 'fTable.uid=431'],
+                    ['`pages.uid` = `fTable.pid`']
+                ],
                 [
                     'effectivePid' => '431string',
                 ],
             ],
             'replace THIS_UID' => [
                 'AND fTable.uid=###THIS_UID###',
-                'pages.uid=fTable.pid AND pages.deleted=0 AND 1=1 AND fTable.uid=42',
+                [
+                    [' 1=1', 'fTable.uid=42'],
+                    ['`pages.uid` = `fTable.pid`']
+                ],
                 [],
             ],
             'replace THIS_UID integer cast' => [
                 'AND fTable.uid=###THIS_UID###',
-                'pages.uid=fTable.pid AND pages.deleted=0 AND 1=1 AND fTable.uid=421',
+                [
+                    [' 1=1', 'fTable.uid=421'],
+                    ['`pages.uid` = `fTable.pid`']
+                ],
                 [
                     'databaseRow' => [
                         'uid' => '421string',
@@ -1351,12 +1467,18 @@ class TcaSelectItemsTest extends UnitTestCase
             ],
             'replace SITEROOT' => [
                 'AND fTable.uid=###SITEROOT###',
-                'pages.uid=fTable.pid AND pages.deleted=0 AND 1=1 AND fTable.uid=44',
+                [
+                    [' 1=1', 'fTable.uid=44'],
+                    ['`pages.uid` = `fTable.pid`']
+                ],
                 [],
             ],
             'replace SITEROOT integer cast' => [
                 'AND fTable.uid=###SITEROOT###',
-                'pages.uid=fTable.pid AND pages.deleted=0 AND 1=1 AND fTable.uid=441',
+                [
+                    [' 1=1', 'fTable.uid=441'],
+                    ['`pages.uid` = `fTable.pid`']
+                ],
                 [
                     'rootline' => [
                         1 => [
@@ -1367,7 +1489,10 @@ class TcaSelectItemsTest extends UnitTestCase
             ],
             'replace PAGE_TSCONFIG_ID' => [
                 'AND fTable.uid=###PAGE_TSCONFIG_ID###',
-                'pages.uid=fTable.pid AND pages.deleted=0 AND 1=1 AND fTable.uid=45',
+                [
+                    [' 1=1', 'fTable.uid=45'],
+                    ['`pages.uid` = `fTable.pid`']
+                ],
                 [
                     'pageTsConfig' => [
                         'TCEFORM.' => [
@@ -1382,7 +1507,10 @@ class TcaSelectItemsTest extends UnitTestCase
             ],
             'replace PAGE_TSCONFIG_ID integer cast' => [
                 'AND fTable.uid=###PAGE_TSCONFIG_ID###',
-                'pages.uid=fTable.pid AND pages.deleted=0 AND 1=1 AND fTable.uid=451',
+                [
+                    [' 1=1', 'fTable.uid=451'],
+                    ['`pages.uid` = `fTable.pid`']
+                ],
                 [
                     'pageTsConfig' => [
                         'TCEFORM.' => [
@@ -1397,7 +1525,10 @@ class TcaSelectItemsTest extends UnitTestCase
             ],
             'replace PAGE_TSCONFIG_STR' => [
                 'AND fTable.uid=\'###PAGE_TSCONFIG_STR###\'',
-                'pages.uid=fTable.pid AND pages.deleted=0 AND 1=1 AND fTable.uid=\'46\'',
+                [
+                    [' 1=1', 'fTable.uid=\'46\''],
+                    ['`pages.uid` = `fTable.pid`']
+                ],
                 [
                     'pageTsConfig' => [
                         'TCEFORM.' => [
@@ -1412,7 +1543,10 @@ class TcaSelectItemsTest extends UnitTestCase
             ],
             'replace PAGE_TSCONFIG_IDLIST' => [
                 'AND fTable.uid IN (###PAGE_TSCONFIG_IDLIST###)',
-                'pages.uid=fTable.pid AND pages.deleted=0 AND 1=1 AND fTable.uid IN (47,48)',
+                [
+                    [' 1=1', 'fTable.uid IN (47,48)'],
+                    ['`pages.uid` = `fTable.pid`']
+                ],
                 [
                     'pageTsConfig' => [
                         'TCEFORM.' => [
@@ -1427,7 +1561,10 @@ class TcaSelectItemsTest extends UnitTestCase
             ],
             'replace PAGE_TSCONFIG_IDLIST cleans list' => [
                 'AND fTable.uid IN (###PAGE_TSCONFIG_IDLIST###)',
-                'pages.uid=fTable.pid AND pages.deleted=0 AND 1=1 AND fTable.uid IN (471,481)',
+                [
+                    [' 1=1', 'fTable.uid IN (471,481)'],
+                    ['`pages.uid` = `fTable.pid`']
+                ],
                 [
                     'pageTsConfig' => [
                         'TCEFORM.' => [
@@ -1442,7 +1579,10 @@ class TcaSelectItemsTest extends UnitTestCase
             ],
             'deprecated flexHack PAGE_TSCONFIG_ID is substituted' => [
                 'AND fTable.uid=###PAGE_TSCONFIG_ID###',
-                'pages.uid=fTable.pid AND pages.deleted=0 AND 1=1 AND fTable.uid=123',
+                [
+                    [' 1=1', 'fTable.uid=123'],
+                    ['`pages.uid` = `fTable.pid`']
+                ],
                 [
                     'pageTsConfig' => [
                         'flexHack.' => [
@@ -1453,7 +1593,10 @@ class TcaSelectItemsTest extends UnitTestCase
             ],
             'deprecated flexHack PAGE_TSCONFIG_IDLIST is substituted' => [
                 'AND fTable.uid IN (###PAGE_TSCONFIG_IDLIST###)',
-                'pages.uid=fTable.pid AND pages.deleted=0 AND 1=1 AND fTable.uid IN (123,124)',
+                [
+                    [' 1=1', 'fTable.uid IN (123,124)'],
+                    ['`pages.uid` = `fTable.pid`']
+                ],
                 [
                     'pageTsConfig' => [
                         'flexHack.' => [
@@ -1464,7 +1607,10 @@ class TcaSelectItemsTest extends UnitTestCase
             ],
             'deprecated flexHack PAGE_TSCONFIG_STR is substituted' => [
                 'AND fTable.uid=\'###PAGE_TSCONFIG_STR###\'',
-                'pages.uid=fTable.pid AND pages.deleted=0 AND 1=1 AND fTable.uid=\'aString\'',
+                [
+                    [' 1=1', 'fTable.uid=\'aString\''],
+                    ['`pages.uid` = `fTable.pid`']
+                ],
                 [
                     'pageTsConfig' => [
                         'flexHack.' => [
@@ -1522,33 +1668,32 @@ class TcaSelectItemsTest extends UnitTestCase
 
         $GLOBALS['TCA']['fTable'] = [];
 
-        $expectedQueryArray = [
-            'SELECT' => 'fTable.uid',
-            'FROM' => 'fTable, pages',
-            'WHERE' => $expectedWhere,
-            'GROUPBY' => '',
-            'ORDERBY' => '',
-            'LIMIT' => '',
-        ];
+        list($queryBuilderProphet, $connectionPoolProphet) = $this->mockDatabaseConnection();
+
+        /** @var Statement|ObjectProphecy $statementProphet */
+        $statementProphet = $this->prophesize(Statement::class);
+
+        $queryBuilderProphet->select('fTable.uid')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->from('fTable')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->from('pages')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->where(...array_shift($expectedWhere))->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->execute()->shouldBeCalled()->willReturn($statementProphet->reveal());
+
+        while ($constraint = array_shift($expectedWhere)) {
+            $queryBuilderProphet->andWhere(...$constraint)
+                ->shouldBeCalled()
+                ->willReturn($queryBuilderProphet->reveal());
+        }
+
+        # Two instances are needed due to the push/pop behavior of addInstance()
+        GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
+        GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
 
         /** @var BackendUserAuthentication|ObjectProphecy $backendUserProphecy */
         $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
         $GLOBALS['BE_USER'] = $backendUserProphecy->reveal();
         $backendUserProphecy->getPagePermsClause(1)->shouldBeCalled()->willReturn(' 1=1');
 
-        /** @var DatabaseConnection|ObjectProphecy $databaseProphecy */
-        $databaseProphecy = $this->prophesize(DatabaseConnection::class);
-        $GLOBALS['TYPO3_DB'] = $databaseProphecy->reveal();
-        $databaseProphecy->sql_error()->shouldBeCalled()->willReturn(false);
-        $databaseProphecy->quoteStr(Argument::cetera())->willReturnArgument(0);
-        $databaseProphecy->fullQuoteStr(Argument::cetera())->will(function ($args) {
-            return '\'' . $args[0] . '\'';
-        });
-        $databaseProphecy->sql_fetch_assoc(Argument::cetera())->shouldBeCalled()->willReturn(false);
-        $databaseProphecy->sql_free_result(Argument::cetera())->shouldBeCalled()->willReturn(null);
-
-        $databaseProphecy->exec_SELECT_queryArray($expectedQueryArray)->shouldBeCalled()->willReturn(false);
-
         $this->subject->addData($input);
     }
 
@@ -1603,32 +1748,30 @@ class TcaSelectItemsTest extends UnitTestCase
 
         $GLOBALS['TCA']['fTable'] = [];
 
-        $expectedQueryArray = [
-            'SELECT' => 'fTable.uid',
-            'FROM' => 'fTable, pages',
-            'WHERE' => 'pages.uid=fTable.pid AND pages.deleted=0 AND 1=1 AND ftable.uid=1',
-            'GROUPBY' => 'groupField',
-            'ORDERBY' => 'orderField',
-            'LIMIT' => '1,2',
-        ];
-
         /** @var BackendUserAuthentication|ObjectProphecy $backendUserProphecy */
         $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
         $GLOBALS['BE_USER'] = $backendUserProphecy->reveal();
         $backendUserProphecy->getPagePermsClause(1)->shouldBeCalled()->willReturn(' 1=1');
 
-        /** @var DatabaseConnection|ObjectProphecy $databaseProphecy */
-        $databaseProphecy = $this->prophesize(DatabaseConnection::class);
-        $GLOBALS['TYPO3_DB'] = $databaseProphecy->reveal();
-        $databaseProphecy->sql_error()->shouldBeCalled()->willReturn(false);
-        $databaseProphecy->quoteStr(Argument::cetera())->willReturnArgument(0);
-        $databaseProphecy->fullQuoteStr(Argument::cetera())->will(function ($args) {
-            return '\'' . $args[0] . '\'';
-        });
-        $databaseProphecy->sql_fetch_assoc(Argument::cetera())->shouldBeCalled()->willReturn(false);
-        $databaseProphecy->sql_free_result(Argument::cetera())->shouldBeCalled()->willReturn(null);
+        list($queryBuilderProphet, $connectionPoolProphet) = $this->mockDatabaseConnection();
+
+        /** @var Statement|ObjectProphecy $statementProphet */
+        $statementProphet = $this->prophesize(Statement::class);
+
+        $queryBuilderProphet->select('fTable.uid')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->from('fTable')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->from('pages')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->groupBy(['groupField'])->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->addOrderBy('orderField', null)->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->setFirstResult(1)->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->setMaxResults(2)->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->where(' 1=1', 'ftable.uid=1')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->andWhere('`pages.uid` = `fTable.pid`')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->execute()->shouldBeCalled()->willReturn($statementProphet->reveal());
 
-        $databaseProphecy->exec_SELECT_queryArray($expectedQueryArray)->shouldBeCalled()->willReturn(false);
+        # Two instances are needed due to the push/pop behavior of addInstance()
+        GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
+        GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
 
         $this->subject->addData($input);
     }
@@ -1678,13 +1821,23 @@ class TcaSelectItemsTest extends UnitTestCase
         $GLOBALS['LANG'] = $languageServiceProphecy->reveal();
         $languageServiceProphecy->sL(Argument::cetera())->willReturnArgument(0);
 
-        /** @var DatabaseConnection|ObjectProphecy $databaseProphecy */
-        $databaseProphecy = $this->prophesize(DatabaseConnection::class);
-        $GLOBALS['TYPO3_DB'] = $databaseProphecy->reveal();
-        $databaseProphecy->exec_SELECT_queryArray(Argument::cetera())->willReturn(false);
+        list($queryBuilderProphet, $connectionPoolProphet) = $this->mockDatabaseConnection();
+
+        /** @var Statement|ObjectProphecy $statementProphet */
+        $statementProphet = $this->prophesize(Statement::class);
+        $statementProphet->errorInfo()->shouldBeCalled()->willReturn('anError');
+        $statementProphet->closeCursor()->shouldBeCalled();
+
+        $queryBuilderProphet->select('fTable.uid')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->from('fTable')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->from('pages')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->where(' 1=1', '')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->andWhere('`pages.uid` = `fTable.pid`')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->execute()->shouldBeCalled()->willReturn($statementProphet->reveal());
 
-        $databaseProphecy->sql_error()->shouldBeCalled()->willReturn('anError');
-        $databaseProphecy->sql_free_result(Argument::cetera())->shouldBeCalled()->willReturn(null);
+        # Two instances are needed due to the push/pop behavior of addInstance()
+        GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
+        GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
 
         /** @var FlashMessage|ObjectProphecy $flashMessage */
         $flashMessage = $this->prophesize(FlashMessage::class);
@@ -1743,15 +1896,25 @@ class TcaSelectItemsTest extends UnitTestCase
         $GLOBALS['LANG'] = $languageServiceProphecy->reveal();
         $languageServiceProphecy->sL(Argument::cetera())->willReturnArgument(0);
 
-        /** @var DatabaseConnection|ObjectProphecy $databaseProphecy */
-        $databaseProphecy = $this->prophesize(DatabaseConnection::class);
-        $GLOBALS['TYPO3_DB'] = $databaseProphecy->reveal();
-        $databaseProphecy->sql_error()->shouldBeCalled()->willReturn(false);
-        $databaseProphecy->sql_free_result(Argument::cetera())->willReturn(null);
-        $databaseProphecy->exec_SELECT_queryArray(Argument::cetera())->willReturn(true);
+        list($queryBuilderProphet, $connectionPoolProphet) = $this->mockDatabaseConnection();
+
+        /** @var Statement|ObjectProphecy $statementProphet */
+        $statementProphet = $this->prophesize(Statement::class);
+        $statementProphet->errorInfo()->shouldBeCalled();
+
+        $queryBuilderProphet->select('fTable.uid')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->from('fTable')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->from('pages')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->where(' 1=1', '')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->andWhere('`pages.uid` = `fTable.pid`')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->execute()->shouldBeCalled()->willReturn($statementProphet->reveal());
+
+        # Two instances are needed due to the push/pop behavior of addInstance()
+        GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
+        GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
 
         $counter = 0;
-        $databaseProphecy->sql_fetch_assoc(Argument::cetera())->shouldBeCalled()->will(function ($args) use (&$counter) {
+        $statementProphet->fetch()->shouldBeCalled()->will(function ($args) use (&$counter) {
             $counter++;
             if ($counter >= 3) {
                 return false;
@@ -1830,19 +1993,29 @@ class TcaSelectItemsTest extends UnitTestCase
         $GLOBALS['LANG'] = $languageServiceProphecy->reveal();
         $languageServiceProphecy->sL(Argument::cetera())->willReturnArgument(0);
 
-        /** @var DatabaseConnection|ObjectProphecy $databaseProphecy */
-        $databaseProphecy = $this->prophesize(DatabaseConnection::class);
-        $GLOBALS['TYPO3_DB'] = $databaseProphecy->reveal();
-        $databaseProphecy->sql_error()->shouldBeCalled()->willReturn(false);
-        $databaseProphecy->sql_free_result(Argument::cetera())->willReturn(null);
-        // Query on foreign table is successful
-        $databaseProphecy->exec_SELECT_queryArray(Argument::cetera())->willReturn(true);
+        list($queryBuilderProphet, $connectionPoolProphet) = $this->mockDatabaseConnection();
+
+        /** @var Statement|ObjectProphecy $statementProphet */
+        $statementProphet = $this->prophesize(Statement::class);
+        $statementProphet->errorInfo()->shouldBeCalled();
+
+        $queryBuilderProphet->select('fTable.uid', 'fTable.icon')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->from('fTable')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->from('pages')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->where(' 1=1', '')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->andWhere('`pages.uid` = `fTable.pid`')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->execute()->shouldBeCalled()->willReturn($statementProphet->reveal());
+
+        # Two instances are needed due to the push/pop behavior of addInstance()
+        GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
+        GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
+
         // Query returns one row, then false on second call
         $foreignTableRowResultOne = [
             'uid' => 1,
             'icon' => 'foo.jpg',
         ];
-        $databaseProphecy->sql_fetch_assoc(Argument::cetera())->shouldBeCalled()->willReturn($foreignTableRowResultOne, false);
+        $statementProphet->fetch()->shouldBeCalled()->willReturn($foreignTableRowResultOne, false);
 
         $expected = $input;
         $expected['processedTca']['columns']['aField']['config']['items'] = [
@@ -2634,10 +2807,9 @@ class TcaSelectItemsTest extends UnitTestCase
         /** @var BackendUserAuthentication|ObjectProphecy $backendUserProphecy */
         $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
         $GLOBALS['BE_USER'] = $backendUserProphecy->reveal();
+        $backendUserProphecy->getPagePermsClause(1)->shouldBeCalled()->willReturn(' 1=1');
 
-        /** @var DatabaseConnection|ObjectProphecy $database */
-        $database = $this->prophesize(DatabaseConnection::class);
-        $GLOBALS['TYPO3_DB'] = $database->reveal();
+        $this->mockDatabaseConnectionForProcessSelectField();
 
         $input = [
             'tableName' => 'aTable',
@@ -2690,10 +2862,9 @@ class TcaSelectItemsTest extends UnitTestCase
         /** @var BackendUserAuthentication|ObjectProphecy $backendUserProphecy */
         $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
         $GLOBALS['BE_USER'] = $backendUserProphecy->reveal();
+        $backendUserProphecy->getPagePermsClause(1)->shouldBeCalled()->willReturn(' 1=1');
 
-        /** @var DatabaseConnection|ObjectProphecy $database */
-        $database = $this->prophesize(DatabaseConnection::class);
-        $GLOBALS['TYPO3_DB'] = $database->reveal();
+        $this->mockDatabaseConnectionForProcessSelectField();
 
         $input = [
             'tableName' => 'aTable',
@@ -2749,10 +2920,9 @@ class TcaSelectItemsTest extends UnitTestCase
         /** @var BackendUserAuthentication|ObjectProphecy $backendUserProphecy */
         $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
         $GLOBALS['BE_USER'] = $backendUserProphecy->reveal();
+        $backendUserProphecy->getPagePermsClause(1)->shouldBeCalled()->willReturn(' 1=1');
 
-        /** @var DatabaseConnection|ObjectProphecy $database */
-        $database = $this->prophesize(DatabaseConnection::class);
-        $GLOBALS['TYPO3_DB'] = $database->reveal();
+        $this->mockDatabaseConnectionForProcessSelectField();
 
         $relationHandlerProphecy = $this->prophesize(RelationHandler::class);
         GeneralUtility::addInstance(RelationHandler::class, $relationHandlerProphecy->reveal());
@@ -3132,10 +3302,9 @@ class TcaSelectItemsTest extends UnitTestCase
         /** @var BackendUserAuthentication|ObjectProphecy $backendUserProphecy */
         $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
         $GLOBALS['BE_USER'] = $backendUserProphecy->reveal();
+        $backendUserProphecy->getPagePermsClause(Argument::cetera())->willReturn(' 1=1');
 
-        /** @var DatabaseConnection|ObjectProphecy $database */
-        $database = $this->prophesize(DatabaseConnection::class);
-        $GLOBALS['TYPO3_DB'] = $database->reveal();
+        $this->mockDatabaseConnectionForProcessSelectField();
 
         /** @var RelationHandler|ObjectProphecy $relationHandlerProphecy */
         $relationHandlerProphecy = $this->prophesize(RelationHandler::class);
index 2f97747..f99bf80 100644 (file)
@@ -14,11 +14,16 @@ namespace TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider;
  * The TYPO3 project - inspiring people to share!
  */
 
+use Doctrine\DBAL\Driver\Statement;
 use Prophecy\Argument;
 use Prophecy\Prophecy\ObjectProphecy;
 use TYPO3\CMS\Backend\Form\FormDataProvider\TcaSelectTreeItems;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
-use TYPO3\CMS\Core\Database\DatabaseConnection;
+use TYPO3\CMS\Core\Database\Connection;
+use TYPO3\CMS\Core\Database\ConnectionPool;
+use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
+use TYPO3\CMS\Core\Database\Query\QueryBuilder;
+use TYPO3\CMS\Core\Database\Query\Restriction\DefaultRestrictionContainer;
 use TYPO3\CMS\Core\Tests\UnitTestCase;
 use TYPO3\CMS\Core\Tree\TableConfiguration\DatabaseTreeDataProvider;
 use TYPO3\CMS\Core\Tree\TableConfiguration\TableConfigurationTree;
@@ -60,19 +65,81 @@ class TcaSelectTreeItemsTest extends UnitTestCase
     }
 
     /**
+     * Setup a mock database connection with expectations for
+     * the testsuite.
+     */
+    protected function mockDatabaseConnection()
+    {
+        $connectionProphet = $this->prophesize(Connection::class);
+        $connectionProphet->quote(Argument::cetera())->will(function ($arguments) {
+            return "'" . $arguments[0] . "'";
+        });
+        $connectionProphet->quoteIdentifier(Argument::cetera())->will(function ($arguments) {
+            return '`' . $arguments[0] . '`';
+        });
+
+        /** @var Statement|ObjectProphecy $statementProphet */
+        $statementProphet = $this->prophesize(Statement::class);
+        $statementProphet->errorInfo()->shouldBeCalled();
+        $statementProphet->fetch()->shouldBeCalled();
+
+        $restrictionProphet = $this->prophesize(DefaultRestrictionContainer::class);
+        $restrictionProphet->removeAll()->willReturn($restrictionProphet->reveal());
+        $restrictionProphet->add(Argument::cetera())->willReturn($restrictionProphet->reveal());
+
+        $queryBuilderProphet = $this->prophesize(QueryBuilder::class);
+        $queryBuilderProphet->expr()->willReturn(
+            GeneralUtility::makeInstance(ExpressionBuilder::class, $connectionProphet->reveal())
+        );
+        $queryBuilderProphet->getRestrictions()->willReturn($restrictionProphet->reveal());
+        $queryBuilderProphet->quoteIdentifier(Argument::cetera())->will(function ($arguments) {
+            return '`' . $arguments[0] . '`';
+        });
+
+        $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
+        $connectionPoolProphet->getConnectionForTable('foreignTable')
+            ->willReturn($connectionProphet->reveal());
+        $connectionPoolProphet->getQueryBuilderForTable('foreignTable')
+            ->shouldBeCalled()
+            ->willReturn($queryBuilderProphet->reveal());
+
+        $queryBuilderProphet->select('foreignTable.uid')
+            ->shouldBeCalled()
+            ->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->from('foreignTable')
+            ->shouldBeCalled()
+            ->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->from('pages')
+            ->shouldBeCalled()
+            ->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->where(' 1=1', '')
+            ->shouldBeCalled()
+            ->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->andWhere('`pages.uid` = `foreignTable.pid`')
+            ->shouldBeCalled()
+            ->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->execute()
+            ->shouldBeCalled()
+            ->willReturn($statementProphet->reveal());
+
+        # Two instances are needed due to the push/pop behavior of addInstance()
+        GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
+        GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
+    }
+
+    /**
      * @test
      */
     public function addDataAddsTreeConfigurationForExtJs()
     {
         $GLOBALS['TCA']['foreignTable'] = [];
 
-        /** @var DatabaseConnection|ObjectProphecy $database */
-        $database = $this->prophesize(DatabaseConnection::class);
-        $GLOBALS['TYPO3_DB'] = $database->reveal();
-
         /** @var BackendUserAuthentication|ObjectProphecy $backendUserProphecy */
         $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
         $GLOBALS['BE_USER'] = $backendUserProphecy->reveal();
+        $backendUserProphecy->getPagePermsClause(Argument::cetera())->willReturn(' 1=1');
+
+        $this->mockDatabaseConnection();
 
         /** @var  DatabaseTreeDataProvider|ObjectProphecy $treeDataProviderProphecy */
         $treeDataProviderProphecy = $this->prophesize(DatabaseTreeDataProvider::class);
@@ -124,13 +191,12 @@ class TcaSelectTreeItemsTest extends UnitTestCase
     {
         $GLOBALS['TCA']['foreignTable'] = [];
 
-        /** @var DatabaseConnection|ObjectProphecy $database */
-        $database = $this->prophesize(DatabaseConnection::class);
-        $GLOBALS['TYPO3_DB'] = $database->reveal();
-
         /** @var BackendUserAuthentication|ObjectProphecy $backendUserProphecy */
         $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
         $GLOBALS['BE_USER'] = $backendUserProphecy->reveal();
+        $backendUserProphecy->getPagePermsClause(Argument::cetera())->willReturn(' 1=1');
+
+        $this->mockDatabaseConnection();
 
         /** @var DatabaseTreeDataProvider|ObjectProphecy $treeDataProviderProphecy */
         $treeDataProviderProphecy = $this->prophesize(DatabaseTreeDataProvider::class);
index 4efcaa2..6172c40 100644 (file)
@@ -23,7 +23,12 @@ use TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures\ProcessedValueForGroupWithOneA
 use TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures\ProcessedValueForSelectWithMMRelationFixture;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
-use TYPO3\CMS\Core\Database\DatabaseConnection;
+use TYPO3\CMS\Core\Database\Connection;
+use TYPO3\CMS\Core\Database\ConnectionPool;
+use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
+use TYPO3\CMS\Core\Database\Query\QueryBuilder;
+use TYPO3\CMS\Core\Database\Query\Restriction\DefaultRestrictionContainer;
+use TYPO3\CMS\Core\Database\RelationHandler;
 use TYPO3\CMS\Core\Tests\UnitTestCase;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Lang\LanguageService;
@@ -219,57 +224,79 @@ class BackendUtilityTest extends UnitTestCase
     }
 
     /**
+     * Prepare a mock database setup for a Doctrine connection
+     * and return an array of all prophets to set expectations upon.
+     *
+     * @param string $tableName
+     * @return array
+     */
+    protected function mockDatabaseConnection($tableName = 'sys_category')
+    {
+        $connectionProphet = $this->prophesize(Connection::class);
+        $connectionProphet->quote(Argument::cetera())->will(function ($arguments) {
+            return "'" . $arguments[0] . "'";
+        });
+        $connectionProphet->quoteIdentifier(Argument::cetera())->will(function ($arguments) {
+            return '`' . $arguments[0] . '`';
+        });
+
+        $restrictionProphet = $this->prophesize(DefaultRestrictionContainer::class);
+        $restrictionProphet->removeAll()->willReturn($restrictionProphet->reveal());
+        $restrictionProphet->add(Argument::cetera())->willReturn($restrictionProphet->reveal());
+
+        $queryBuilderProphet = $this->prophesize(QueryBuilder::class);
+        $queryBuilderProphet->expr()->willReturn(
+            GeneralUtility::makeInstance(ExpressionBuilder::class, $connectionProphet->reveal())
+        );
+        $queryBuilderProphet->getRestrictions()->willReturn($restrictionProphet->reveal());
+        $queryBuilderProphet->quoteIdentifier(Argument::cetera())->will(function ($arguments) {
+            return '`' . $arguments[0] . '`';
+        });
+
+        $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
+        $connectionPoolProphet->getConnectionForTable($tableName)
+            ->willReturn($connectionProphet->reveal());
+        $connectionPoolProphet->getQueryBuilderForTable($tableName)
+            ->shouldBeCalled()
+            ->willReturn($queryBuilderProphet->reveal());
+
+        return [$queryBuilderProphet, $connectionPoolProphet, $connectionProphet, $restrictionProphet];
+    }
+
+    /**
      * @test
      */
     public function getProcessedValueForSelectWithMMRelation()
     {
-        $GLOBALS['TYPO3_DB'] = $this->createMock(DatabaseConnection::class);
-        $GLOBALS['TYPO3_DB']->expects($this->any())->method('fullQuoteStr')
-            ->will($this->returnCallback(
-                function ($quoteStr) {
-                    return "'" . $quoteStr . "'";
-                }
-            )
-            );
-        $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTquery')->will($this->returnValue(0));
-        $GLOBALS['TYPO3_DB']->expects($this->any())->method('sql_free_result');
-        $GLOBALS['TYPO3_DB']->expects($this->any())->method('sql_fetch_assoc')
-            ->will($this->returnCallback(
-                function () {
-                    static $called = 0;
-                    ++$called;
-                    switch ($called) {
-                        // SELECT * FROM sys_category_record_mm
-                        case 1:
-                            return array(
-                                'uid_local' => 1,    // uid of a sys_category record
-                                'uid_foreign' => 1,    // uid of a pages record
-                            );
-                        case 2:
-                            return array(
-                                'uid_local' => 2,    // uid of a sys_category record
-                                'uid_foreign' => 1,    // uid of a pages record
-                            );
-                        case 3:
-                            return null;
-                        // SELECT * FROM sys_catgory
-                        case 4:
-                            return array(
-                                'uid' => 1,
-                                'title' => 'Category 1',
-                            );
-                        case 5:
-                            return array(
-                                'uid' => 2,
-                                'title' => 'Category 2',
-                            );
-                        case 6:
-                            return null;
-                    }
-                    return null;
-                }
-            )
-            );
+        /** @var RelationHandler|ObjectProphecy $relationHandlerProphet */
+        $relationHandlerProphet = $this->prophesize(RelationHandler::class);
+        $relationHandlerProphet->start(Argument::cetera())->shouldBeCalled();
+
+        $relationHandlerInstance = $relationHandlerProphet->reveal();
+        $relationHandlerInstance->tableArray['sys_category'] = [1, 2];
+
+        list($queryBuilderProphet, $connectionPoolProphet) = $this->mockDatabaseConnection('sys_category');
+        $statementProphet = $this->prophesize(\Doctrine\DBAL\Driver\Statement::class);
+        $statementProphet->fetch()->shouldBeCalled()->willReturn(
+            [
+                'uid' => 1,
+                'title' => 'Category 1',
+            ],
+            [
+                'uid' => 2,
+                'title' => 'Category 2',
+            ],
+            false
+        );
+
+        /** @var QueryBuilder|ObjectProphecy $queryBuilderProphet */
+        $queryBuilderProphet->select('uid', 'sys_category.title')->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->from('sys_category')->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->where('`uid` IN (1, 2)')->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->execute()->willReturn($statementProphet->reveal());
+
+        GeneralUtility::addInstance(RelationHandler::class, $relationHandlerInstance);
+        GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
 
         $GLOBALS['TCA'] = array(
             'pages' => array(
@@ -289,6 +316,7 @@ class BackendUtilityTest extends UnitTestCase
                 ),
             ),
             'sys_category' => array(
+                'ctrl' => array('label' => 'title'),
                 'columns' => array(
                     'items' => array(
                         'config' => array(
@@ -303,7 +331,18 @@ class BackendUtilityTest extends UnitTestCase
             ),
         );
 
-        $this->assertSame('Category 1; Category 2', ProcessedValueForSelectWithMMRelationFixture::getProcessedValue('pages', 'categories', '2', 0, false, false, 1));
+        $this->assertSame(
+            'Category 1; Category 2',
+            ProcessedValueForSelectWithMMRelationFixture::getProcessedValue(
+                'pages',
+                'categories',
+                '2',
+                0,
+                false,
+                false,
+                1
+            )
+        );
     }
 
     /**
@@ -1016,9 +1055,33 @@ class BackendUtilityTest extends UnitTestCase
      */
     public function replaceL10nModeFieldsReplacesFields($table, array $row, array $tca, array $originalRow, $expected)
     {
+        if (!empty($tca[$table]['ctrl']['transOrigPointerTable'])) {
+            $tableName = $tca[$table]['ctrl']['transOrigPointerTable'];
+        } else {
+            $tableName = $table;
+        }
+
+        list($queryBuilderProphet, $connectionPoolProphet) = $this->mockDatabaseConnection($tableName);
+
+        $statementProphet = $this->prophesize(\Doctrine\DBAL\Driver\Statement::class);
+        $statementProphet->fetch()->willReturn($originalRow, false);
+
+        $queryBuilderProphet->select('*')
+            ->shouldBeCalled()
+            ->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->from($tableName)
+            ->shouldBeCalled()
+            ->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->where('`uid` = ' . $row['origUid'])
+            ->shouldBeCalled()
+            ->willReturn($queryBuilderProphet->reveal());
+        $queryBuilderProphet->execute()
+            ->shouldBeCalled()
+            ->willReturn($statementProphet->reveal());
+
+        GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
+
         $GLOBALS['TCA'] = $tca;
-        $GLOBALS['TYPO3_DB'] = $this->createMock(DatabaseConnection::class);
-        $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetSingleRow')->will($this->returnValue($originalRow));
 
         /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|BackendUtility $subject */
         $subject = $this->getAccessibleMock(BackendUtility::class, array('dummy'));
index 318733e..e939cc2 100644 (file)
@@ -33,7 +33,7 @@ class LogEntryRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
      */
     public function initializeObject()
     {
-        $this->beUserList = \TYPO3\CMS\Backend\Utility\BackendUtility::getUserNames();
+        $this->beUserList = $this->getBackendUsers();
         /** @var $defaultQuerySettings \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface */
         $defaultQuerySettings = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface::class);
         $defaultQuerySettings->setRespectStoragePage(false);
@@ -153,4 +153,14 @@ class LogEntryRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
             $queryConstraints[] = $query->equals('userid', (int)$GLOBALS['BE_USER']->user['uid']);
         }
     }
+
+    /**
+     * Get a list of all backend users that are not deleted
+     *
+     * @return array
+     */
+    protected function getBackendUsers()
+    {
+        return \TYPO3\CMS\Backend\Utility\BackendUtility::getUserNames();
+    }
 }
index 2f5a677..81d1b70 100644 (file)
@@ -32,7 +32,7 @@ class LogEntryRepositoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
         $querySettings->expects($this->atLeastOnce())->method('setRespectStoragePage')->with(false);
         /** @var \TYPO3\CMS\Belog\Domain\Repository\LogEntryRepository|\PHPUnit_Framework_MockObject_MockObject $subject */
         $subject = $this->getMockBuilder(\TYPO3\CMS\Belog\Domain\Repository\LogEntryRepository::class)
-            ->setMethods(array('setDefaultQuerySettings'))
+            ->setMethods(array('setDefaultQuerySettings', 'getBackendUsers'))
             ->setConstructorArgs(array($objectManager))
             ->getMock();
         $subject->expects($this->once())->method('setDefaultQuerySettings')->with($querySettings);
index 45035da..c6f842a 100644 (file)
@@ -13,6 +13,12 @@ namespace TYPO3\CMS\Core\Tests\Unit\Collection;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use Prophecy\Argument;
+use TYPO3\CMS\Core\Database\Connection;
+use TYPO3\CMS\Core\Database\ConnectionPool;
+use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
+use TYPO3\CMS\Core\Database\Query\QueryBuilder;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Test case for \TYPO3\CMS\Core\Collection\RecordCollectionRepository
@@ -45,20 +51,49 @@ class RecordCollectionRepositoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     protected $testTableName;
 
     /**
+     * @var array
+     */
+    protected $singletonInstances;
+
+    /**
      * Sets up this test case.
      */
     protected function setUp()
     {
+        $this->singletonInstances = GeneralUtility::getSingletonInstances();
+
+        // Setup mocking for BackendUtility::deleteClause()
+        $connectionProphet = $this->prophesize(Connection::class);
+        $connectionProphet->quoteIdentifier(Argument::cetera())->willReturnArgument(0);
+
+        $queryBuilderProphet = $this->prophesize(QueryBuilder::class);
+        $queryBuilderProphet->expr()->willReturn(
+            GeneralUtility::makeInstance(ExpressionBuilder::class, $connectionProphet->reveal())
+        );
+
+        $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
+        $connectionPoolProphet->getQueryBuilderForTable(Argument::cetera())->willReturn($queryBuilderProphet->reveal());
+        GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
+
         $this->databaseMock = $this->getMockBuilder(\TYPO3\CMS\Core\Database\DatabaseConnection::class)
             ->setMethods(array('exec_UPDATEquery', 'exec_SELECTgetSingleRow', 'exec_SELECTgetRows', 'fullQuoteStr'))
             ->getMock();
         $this->subject = $this->getMockBuilder(\TYPO3\CMS\Core\Collection\RecordCollectionRepository::class)
             ->setMethods(array('getDatabaseConnection'))
             ->getMock();
-        $this->subject->expects($this->any())->method('getDatabaseConnection')->will($this->returnValue($this->databaseMock));
+        $this->subject->expects($this->any())
+            ->method('getDatabaseConnection')
+            ->will($this->returnValue($this->databaseMock));
         $this->testTableName = $this->getUniqueId('tx_testtable');
     }
 
+    protected function tearDown()
+    {
+        GeneralUtility::purgeInstances();
+        GeneralUtility::resetSingletonInstances($this->singletonInstances);
+        parent::tearDown();
+    }
+
     /**
      * @test
      */
index c2cb1a4..f7146c3 100644 (file)
@@ -13,6 +13,12 @@ namespace TYPO3\CMS\Core\Tests\Unit\Resource\Repository;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use Prophecy\Argument;
+use TYPO3\CMS\Core\Database\Connection;
+use TYPO3\CMS\Core\Database\ConnectionPool;
+use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
+use TYPO3\CMS\Core\Database\Query\QueryBuilder;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Test case
@@ -28,6 +34,18 @@ class AbstractRepositoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 
     protected function createDatabaseMock()
     {
+        $connectionProphet = $this->prophesize(Connection::class);
+        $connectionProphet->quoteIdentifier(Argument::cetera())->willReturnArgument(0);
+
+        $queryBuilderProphet = $this->prophesize(QueryBuilder::class);
+        $queryBuilderProphet->expr()->willReturn(
+            GeneralUtility::makeInstance(ExpressionBuilder::class, $connectionProphet->reveal())
+        );
+
+        $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
+        $connectionPoolProphet->getQueryBuilderForTable(Argument::cetera())->willReturn($queryBuilderProphet->reveal());
+        GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
+
         $this->mockedDb = $this->createMock(\TYPO3\CMS\Core\Database\DatabaseConnection::class);
         $GLOBALS['TYPO3_DB'] = $this->mockedDb;
     }
@@ -65,6 +83,8 @@ class AbstractRepositoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
      */
     public function getWhereClauseForEnabledFieldsIncludesDeletedCheckInBackend()
     {
+        $this->createDatabaseMock();
+
         $GLOBALS['TCA'] = array(
             'sys_file_storage' => array(
                 'ctrl' => array(
@@ -81,7 +101,7 @@ class AbstractRepositoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
             false
         );
         $result = $storageRepositoryMock->_call('getWhereClauseForEnabledFields');
-        $this->assertContains('sys_file_storage.deleted=0', $result);
+        $this->assertContains('sys_file_storage.deleted = 0', $result);
     }
 
     /**
index 32d1742..bc9b96d 100644 (file)
@@ -14,7 +14,12 @@ namespace TYPO3\CMS\Core\Tests\Unit\Resource;
  * The TYPO3 project - inspiring people to share!
  */
 
+use Prophecy\Argument;
+use TYPO3\CMS\Core\Database\Connection;
+use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\DatabaseConnection;
+use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
+use TYPO3\CMS\Core\Database\Query\QueryBuilder;
 use TYPO3\CMS\Core\Resource\Driver\AbstractDriver;
 use TYPO3\CMS\Core\Resource\Driver\LocalDriver;
 use TYPO3\CMS\Core\Resource\File;
@@ -266,6 +271,18 @@ class ResourceStorageTest extends BaseTestCase
      */
     public function isWithinFileMountBoundariesRespectsReadOnlyFileMounts($fileIdentifier, $fileMountFolderIdentifier, $isFileMountReadOnly, $checkWriteAccess, $expectedResult)
     {
+        $connectionProphet = $this->prophesize(Connection::class);
+        $connectionProphet->quoteIdentifier(Argument::cetera())->willReturnArgument(0);
+
+        $queryBuilderProphet = $this->prophesize(QueryBuilder::class);
+        $queryBuilderProphet->expr()->willReturn(
+            GeneralUtility::makeInstance(ExpressionBuilder::class, $connectionProphet->reveal())
+        );
+
+        $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
+        $connectionPoolProphet->getQueryBuilderForTable(Argument::cetera())->willReturn($queryBuilderProphet->reveal());
+        GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
+
         /** @var AbstractDriver|\PHPUnit_Framework_MockObject_MockObject $driverMock */
         $driverMock = $this->getMockForAbstractClass(AbstractDriver::class, array(), '', false);
         $driverMock->expects($this->any())
index cb6f32a..9b88409 100644 (file)
@@ -15,6 +15,8 @@ namespace TYPO3\CMS\Extbase\Persistence\Generic\Storage;
  */
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Database\ConnectionPool;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Persistence\Generic\Exception\InconsistentQuerySettingsException;
 use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap;
 use TYPO3\CMS\Extbase\Persistence\Generic\Qom;
@@ -944,7 +946,14 @@ class Typo3DbQueryParser implements \TYPO3\CMS\Core\SingletonInterface
     protected function replaceTableNameWithAlias($statement, $tableName, $tableAlias)
     {
         if ($tableAlias !== $tableName) {
-            $statement = str_replace($tableName . '.', $tableAlias . '.', $statement);
+            $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($tableName);
+            $quotedTableName = $connection->quoteIdentifier($tableName);
+            $quotedTableAliase = $connection->quoteIdentifier($tableAlias);
+            $statement = str_replace(
+                [$tableName . '.', $quotedTableName . '.'],
+                [$tableAlias . '.', $quotedTableAliase . '.'],
+                $statement
+            );
         }
 
         return $statement;
index e780eba..5dbcfda 100644 (file)
@@ -14,13 +14,42 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\Storage;
  * The TYPO3 project - inspiring people to share!
  */
 use Prophecy\Argument;
+use TYPO3\CMS\Core\Database\Connection;
+use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\DatabaseConnection;
+use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
+use TYPO3\CMS\Core\Database\Query\QueryBuilder;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Persistence\Generic\Exception\InconsistentQuerySettingsException;
 use TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedOrderException;
 
 class Typo3DbQueryParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
 {
     /**
+     * @var array
+     */
+    protected $singletonInstances;
+
+    /**
+     * Set up tests
+     */
+    protected function setUp()
+    {
+        parent::setUp();
+        $this->singletonInstances = GeneralUtility::getSingletonInstances();
+    }
+
+    /**
+     * Clean up after tests
+     */
+    protected function tearDown()
+    {
+        GeneralUtility::purgeInstances();
+        GeneralUtility::resetSingletonInstances($this->singletonInstances);
+        parent::tearDown();
+    }
+
+    /**
      * @test
      */
     public function addSysLanguageStatementWorksForDefaultLanguage()
@@ -256,9 +285,9 @@ class Typo3DbQueryParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     {
         return array(
             'in be: include all' => array('BE', true, array(), true, ''),
-            'in be: ignore enable fields but do not include deleted' => array('BE', true, array(), false, 'tx_foo_table.deleted_column=0'),
+            'in be: ignore enable fields but do not include deleted' => array('BE', true, array(), false, 'tx_foo_table.deleted_column = 0'),
             'in be: respect enable fields but include deleted' => array('BE', false, array(), true, 'tx_foo_table.disabled_column=0 AND (tx_foo_table.starttime_column<=123456789)'),
-            'in be: respect enable fields and do not include deleted' => array('BE', false, array(), false, 'tx_foo_table.disabled_column=0 AND (tx_foo_table.starttime_column<=123456789) AND tx_foo_table.deleted_column=0'),
+            'in be: respect enable fields and do not include deleted' => array('BE', false, array(), false, 'tx_foo_table.disabled_column=0 AND (tx_foo_table.starttime_column<=123456789) AND tx_foo_table.deleted_column = 0'),
             'in fe: include all' => array('FE', true, array(), true, ''),
             'in fe: ignore enable fields but do not include deleted' => array('FE', true, array(), false, 'tx_foo_table.deleted_column=0'),
             'in fe: ignore only starttime and do not include deleted' => array('FE', true, array('starttime'), false, 'tx_foo_table.deleted_column=0 AND tx_foo_table.disabled_column=0'),
@@ -283,6 +312,19 @@ class Typo3DbQueryParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
         $GLOBALS['TSFE'] = new \stdClass();
         $GLOBALS['TSFE']->sys_page = new \TYPO3\CMS\Frontend\Page\PageRepository();
         $GLOBALS['SIM_ACCESS_TIME'] = 123456789;
+
+        $connectionProphet = $this->prophesize(Connection::class);
+        $connectionProphet->quoteIdentifier(Argument::cetera())->willReturnArgument(0);
+
+        $queryBuilderProphet = $this->prophesize(QueryBuilder::class);
+        $queryBuilderProphet->expr()->willReturn(
+            GeneralUtility::makeInstance(ExpressionBuilder::class, $connectionProphet->reveal())
+        );
+
+        $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
+        $connectionPoolProphet->getQueryBuilderForTable($tableName)->willReturn($queryBuilderProphet->reveal());
+        GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
+
         $mockQuerySettings = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings::class)
             ->setMethods(array('getIgnoreEnableFields', 'getEnableFieldsToBeIgnored', 'getIncludeDeleted'))
             ->disableOriginalConstructor()
@@ -308,7 +350,7 @@ class Typo3DbQueryParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     {
         return array(
             'in be: respectEnableFields=false' => array('BE', false, ''),
-            'in be: respectEnableFields=true' => array('BE', true, 'tx_foo_table.disabled_column=0 AND (tx_foo_table.starttime_column<=123456789) AND tx_foo_table.deleted_column=0'),
+            'in be: respectEnableFields=true' => array('BE', true, 'tx_foo_table.disabled_column=0 AND (tx_foo_table.starttime_column<=123456789) AND tx_foo_table.deleted_column = 0'),
             'in FE: respectEnableFields=false' => array('FE', false, ''),
             'in FE: respectEnableFields=true' => array('FE', true, 'tx_foo_table.deleted_column=0 AND tx_foo_table.disabled_column=0 AND tx_foo_table.starttime_column<=123456789')
         );
@@ -331,6 +373,19 @@ class Typo3DbQueryParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
         $GLOBALS['TSFE'] = new \stdClass();
         $GLOBALS['TSFE']->sys_page = new \TYPO3\CMS\Frontend\Page\PageRepository();
         $GLOBALS['SIM_ACCESS_TIME'] = 123456789;
+
+        $connectionProphet = $this->prophesize(Connection::class);
+        $connectionProphet->quoteIdentifier(Argument::cetera())->willReturnArgument(0);
+
+        $queryBuilderProphet = $this->prophesize(QueryBuilder::class);
+        $queryBuilderProphet->expr()->willReturn(
+            GeneralUtility::makeInstance(ExpressionBuilder::class, $connectionProphet->reveal())
+        );
+
+        $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
+        $connectionPoolProphet->getQueryBuilderForTable($tableName)->willReturn($queryBuilderProphet->reveal());
+        GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
+
         /** @var \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings $mockQuerySettings */
         $mockQuerySettings = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings::class)
             ->setMethods(array('dummy'))
index a8788b9..4378e64 100644 (file)
@@ -690,9 +690,8 @@ class Export extends ImportExport
         }
         $fileUid = $file->getUid();
         $fileInfo = $file->getStorage()->getFileInfo($file);
-        // we sadly have to cast it to string here, because the size property is also returning a string
-        $fileSize = (string)$fileInfo['size'];
-        if ($fileSize !== $file->getProperty('size')) {
+        $fileSize = (int)$fileInfo['size'];
+        if ($fileSize !== (int)$file->getProperty('size')) {
             $this->error('File size of ' . $file->getCombinedIdentifier() . ' is not up-to-date in index! File added with current size.');
             $this->dat['records']['sys_file:' . $fileUid]['data']['size'] = $fileSize;
         }
index 7a9b0d0..fb6cb55 100644 (file)
@@ -16,4 +16,4 @@
                <creation_date>1389878273</creation_date>
                <modification_date>1389878273</modification_date>
        </sys_file>
-</dataset>
\ No newline at end of file
+</dataset>
index 725391d..d53b697 100644 (file)
@@ -7,7 +7,7 @@
                                        <uid>1</uid>
                                        <pid>0</pid>
                                        <title>Root</title>
-                                       <size>162</size>
+                                       <size>138</size>
                                        <relations index="rels" type="array"></relations>
                                        <softrefs type="array"></softrefs>
                                </rec>
@@ -17,7 +17,7 @@
                                        <uid>1</uid>
                                        <pid>1</pid>
                                        <title>Test item</title>
-                                       <size>220</size>
+                                       <size>204</size>
                                        <relations index="rels" type="array">
                                                <element index="sys_file:3" type="array">
                                                        <table>sys_file</table>
@@ -35,7 +35,7 @@
                                        <uid>3</uid>
                                        <pid>0</pid>
                                        <title>typo3_image5.jpg</title>
-                                       <size>558</size>
+                                       <size>528</size>
                                        <relationLevel>1</relationLevel>
                                        <relations index="rels" type="array">
                                                <element index="sys_file_storage:1" type="array">
@@ -51,7 +51,7 @@
                                        <uid>1</uid>
                                        <pid>0</pid>
                                        <title>fileadmin/ (auto-created)</title>
-                                       <size>722</size>
+                                       <size>694</size>
                                        <relationLevel>2</relationLevel>
                                        <relations index="rels" type="array"></relations>
                                        <softrefs type="array"></softrefs>
        <records type="array">
                <tablerow index="pages:1" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">1</field>
-                               <field index="pid">0</field>
-                               <field index="deleted">0</field>
-                               <field index="perms_everybody">15</field>
-                               <field index="hidden">0</field>
+                               <field index="uid" type="integer">1</field>
+                               <field index="pid" type="integer">0</field>
+                               <field index="deleted" type="integer">0</field>
+                               <field index="perms_everybody" type="integer">15</field>
+                               <field index="hidden" type="integer">0</field>
                                <field index="title">Root</field>
-                               <field index="doktype">1</field>
+                               <field index="doktype" type="integer">1</field>
                        </fieldlist>
                        <related index="rels" type="array"></related>
                </tablerow>
                <tablerow index="tx_impexpgroupfiles_item:1" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">1</field>
-                               <field index="pid">1</field>
-                               <field index="deleted">0</field>
-                               <field index="hidden">0</field>
+                               <field index="uid" type="integer">1</field>
+                               <field index="pid" type="integer">1</field>
+                               <field index="deleted" type="integer">0</field>
+                               <field index="hidden" type="integer">0</field>
                                <field index="title">Test item</field>
                                <field index="images">typo3_image4.jpg</field>
                                <field index="image_references">fileadmin/user_upload/typo3_image5.jpg</field>
                </tablerow>
                <tablerow index="sys_file:3" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">3</field>
-                               <field index="pid">0</field>
-                               <field index="storage">1</field>
+                               <field index="uid" type="integer">3</field>
+                               <field index="pid" type="integer">0</field>
+                               <field index="storage" type="integer">1</field>
                                <field index="type">2</field>
-                               <field index="metadata">0</field>
+                               <field index="metadata" type="integer">0</field>
                                <field index="identifier">/user_upload/typo3_image5.jpg</field>
                                <field index="identifier_hash">8180e85d25c96697ec9d2004683216831b91ffc1</field>
                                <field index="folder_hash">19669f1e02c2f16705ec7587044c66443be70725</field>
                                <field index="mime_type">image/jpeg</field>
                                <field index="name">typo3_image5.jpg</field>
                                <field index="sha1">c3511df85d21bc578faf71c6a19eeb3ff44af370</field>
-                               <field index="size">7425</field>
-                               <field index="creation_date">1393432184</field>
-                               <field index="modification_date">1393432183</field>
+                               <field index="size" type="integer">7425</field>
+                               <field index="creation_date" type="integer">1393432184</field>
+                               <field index="modification_date" type="integer">1393432183</field>
                        </fieldlist>
                        <related index="rels" type="array">
                                <field index="storage" type="array">
                </tablerow>
                <tablerow index="sys_file_storage:1" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">1</field>
-                               <field index="pid">0</field>
+                               <field index="uid" type="integer">1</field>
+                               <field index="pid" type="integer">0</field>
                                <field index="name">fileadmin/ (auto-created)</field>
                                <field index="description" type="NULL"></field>
                                <field index="driver">Local</field>
                &lt;/sheet&gt;
        &lt;/data&gt;
 &lt;/T3FlexForms&gt;</field>
-                               <field index="is_default">0</field>
-                               <field index="is_browsable">1</field>
-                               <field index="is_public">1</field>
-                               <field index="is_writable">1</field>
-                               <field index="is_online">1</field>
+                               <field index="is_default" type="integer">0</field>
+                               <field index="is_browsable" type="integer">1</field>
+                               <field index="is_public" type="integer">1</field>
+                               <field index="is_writable" type="integer">1</field>
+                               <field index="is_online" type="integer">1</field>
                        </fieldlist>
                        <related index="rels" type="array">
                                <field index="configuration" type="array">
                        <content_sha1>c3511df85d21bc578faf71c6a19eeb3ff44af370</content_sha1>
                </file>
        </files_fal>
-</T3RecordDocument>
\ No newline at end of file
+</T3RecordDocument>
index 324ebc3..a0ee45f 100644 (file)
@@ -7,7 +7,7 @@
                                        <uid>2</uid>
                                        <pid>1</pid>
                                        <title>Dummy 1-2</title>
-                                       <size>167</size>
+                                       <size>143</size>
                                        <relations index="rels" type="array"></relations>
                                        <softrefs type="array"></softrefs>
                                </rec>
@@ -17,7 +17,7 @@
                                        <uid>2</uid>
                                        <pid>2</pid>
                                        <title>Test item 2</title>
-                                       <size>659</size>
+                                       <size>643</size>
                                        <relations index="rels" type="array">
                                                <element index="sys_file:3" type="array">
                                                        <table>sys_file</table>
@@ -48,7 +48,7 @@
                                        <uid>3</uid>
                                        <pid>0</pid>
                                        <title>typo3_image5.jpg</title>
-                                       <size>558</size>
+                                       <size>528</size>
                                        <relationLevel>1</relationLevel>
                                        <relations index="rels" type="array">
                                                <element index="sys_file_storage:1" type="array">
@@ -62,7 +62,7 @@
                                        <uid>2</uid>
                                        <pid>0</pid>
                                        <title>typo3_image3.jpg</title>
-                                       <size>558</size>
+                                       <size>528</size>
                                        <relationLevel>1</relationLevel>
                                        <relations index="rels" type="array">
                                                <element index="sys_file_storage:1" type="array">
@@ -78,7 +78,7 @@
                                        <uid>1</uid>
                                        <pid>0</pid>
                                        <title>fileadmin/ (auto-created)</title>
-                                       <size>722</size>
+                                       <size>694</size>
                                        <relationLevel>2</relationLevel>
                                        <relations index="rels" type="array"></relations>
                                        <softrefs type="array"></softrefs>
        <records type="array">
                <tablerow index="pages:2" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">2</field>
-                               <field index="pid">1</field>
-                               <field index="deleted">0</field>
-                               <field index="perms_everybody">15</field>
-                               <field index="hidden">0</field>
+                               <field index="uid" type="integer">2</field>
+                               <field index="pid" type="integer">1</field>
+                               <field index="deleted" type="integer">0</field>
+                               <field index="perms_everybody" type="integer">15</field>
+                               <field index="hidden" type="integer">0</field>
                                <field index="title">Dummy 1-2</field>
-                               <field index="doktype">1</field>
+                               <field index="doktype" type="integer">1</field>
                        </fieldlist>
                        <related index="rels" type="array"></related>
                </tablerow>
                <tablerow index="tx_impexpgroupfiles_item:2" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">2</field>
-                               <field index="pid">2</field>
-                               <field index="deleted">0</field>
-                               <field index="hidden">0</field>
+                               <field index="uid" type="integer">2</field>
+                               <field index="pid" type="integer">2</field>
+                               <field index="deleted" type="integer">0</field>
+                               <field index="hidden" type="integer">0</field>
                                <field index="title">Test item 2</field>
                                <field index="images"></field>
                                <field index="image_references"></field>
                </tablerow>
                <tablerow index="sys_file:3" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">3</field>
-                               <field index="pid">0</field>
-                               <field index="storage">1</field>
+                               <field index="uid" type="integer">3</field>
+                               <field index="pid" type="integer">0</field>
+                               <field index="storage" type="integer">1</field>
                                <field index="type">2</field>
-                               <field index="metadata">0</field>
+                               <field index="metadata" type="integer">0</field>
                                <field index="identifier">/user_upload/typo3_image5.jpg</field>
                                <field index="identifier_hash">8180e85d25c96697ec9d2004683216831b91ffc1</field>
                                <field index="folder_hash">19669f1e02c2f16705ec7587044c66443be70725</field>
                                <field index="mime_type">image/jpeg</field>
                                <field index="name">typo3_image5.jpg</field>
                                <field index="sha1">c3511df85d21bc578faf71c6a19eeb3ff44af370</field>
-                               <field index="size">7425</field>
-                               <field index="creation_date">1393432184</field>
-                               <field index="modification_date">1393432183</field>
+                               <field index="size" type="integer">7425</field>
+                               <field index="creation_date" type="integer">1393432184</field>
+                               <field index="modification_date" type="integer">1393432183</field>
                        </fieldlist>
                        <related index="rels" type="array">
                                <field index="storage" type="array">
                </tablerow>
                <tablerow index="sys_file:2" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">2</field>
-                               <field index="pid">0</field>
-                               <field index="storage">1</field>
+                               <field index="uid" type="integer">2</field>
+                               <field index="pid" type="integer">0</field>
+                               <field index="storage" type="integer">1</field>
                                <field index="type">2</field>
-                               <field index="metadata">0</field>
+                               <field index="metadata" type="integer">0</field>
                                <field index="identifier">/user_upload/typo3_image3.jpg</field>
                                <field index="identifier_hash">25777b72e5e1cbed2d1b33e4fe5b737304b5bd28</field>
                                <field index="folder_hash">19669f1e02c2f16705ec7587044c66443be70725</field>
                                <field index="mime_type">image/jpeg</field>
                                <field index="name">typo3_image3.jpg</field>
                                <field index="sha1">e873c1e2ffd0f191e183a1057de3eef4d62e782d</field>
-                               <field index="size">5565</field>
-                               <field index="creation_date">1393346082</field>
-                               <field index="modification_date">1392907534</field>
+                               <field index="size" type="integer">5565</field>
+                               <field index="creation_date" type="integer">1393346082</field>
+                               <field index="modification_date" type="integer">1392907534</field>
                        </fieldlist>
                        <related index="rels" type="array">
                                <field index="storage" type="array">
                </tablerow>
                <tablerow index="sys_file_storage:1" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">1</field>
-                               <field index="pid">0</field>
+                               <field index="uid" type="integer">1</field>
+                               <field index="pid" type="integer">0</field>
                                <field index="name">fileadmin/ (auto-created)</field>
                                <field index="description" type="NULL"></field>
                                <field index="driver">Local</field>
                &lt;/sheet&gt;
        &lt;/data&gt;
 &lt;/T3FlexForms&gt;</field>
-                               <field index="is_default">0</field>
-                               <field index="is_browsable">1</field>
-                               <field index="is_public">1</field>
-                               <field index="is_writable">1</field>
-                               <field index="is_online">1</field>
+                               <field index="is_default" type="integer">0</field>
+                               <field index="is_browsable" type="integer">1</field>
+                               <field index="is_public" type="integer">1</field>
+                               <field index="is_writable" type="integer">1</field>
+                               <field index="is_online" type="integer">1</field>
                        </fieldlist>
                        <related index="rels" type="array">
                                <field index="configuration" type="array">
@@ -697,4 +697,4 @@ tiNwZbSZIYCCxuK0ABsLFY0aTIrYWKxkjYuQsVgSZAQAw//Z
                        <content_sha1>e873c1e2ffd0f191e183a1057de3eef4d62e782d</content_sha1>
                </file>
        </files_fal>
-</T3RecordDocument>
\ No newline at end of file
+</T3RecordDocument>
index 98d516b..0f22e24 100644 (file)
@@ -7,7 +7,7 @@
                                        <uid>1</uid>
                                        <pid>0</pid>
                                        <title>Root</title>
-                                       <size>162</size>
+                                       <size>138</size>
                                        <relations index="rels" type="array"></relations>
                                        <softrefs type="array"></softrefs>
                                </rec>
@@ -17,7 +17,7 @@
                                        <uid>1</uid>
                                        <pid>1</pid>
                                        <title>Test item</title>
-                                       <size>220</size>
+                                       <size>204</size>
                                        <relations index="rels" type="array">
                                                <element index="sys_file:3" type="array">
                                                        <table>sys_file</table>
@@ -35,7 +35,7 @@
                                        <uid>3</uid>
                                        <pid>0</pid>
                                        <title>typo3_image5.jpg</title>
-                                       <size>558</size>
+                                       <size>528</size>
                                        <relationLevel>1</relationLevel>
                                        <relations index="rels" type="array">
                                                <element index="sys_file_storage:1" type="array">
@@ -51,7 +51,7 @@
                                        <uid>1</uid>
                                        <pid>0</pid>
                                        <title>fileadmin/ (auto-created)</title>
-                                       <size>722</size>
+                                       <size>694</size>
                                        <relationLevel>2</relationLevel>
                                        <relations index="rels" type="array"></relations>
                                        <softrefs type="array"></softrefs>
        <records type="array">
                <tablerow index="pages:1" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">1</field>
-                               <field index="pid">0</field>
-                               <field index="deleted">0</field>
-                               <field index="perms_everybody">15</field>
-                               <field index="hidden">0</field>
+                               <field index="uid" type="integer">1</field>
+                               <field index="pid" type="integer">0</field>
+                               <field index="deleted" type="integer">0</field>
+                               <field index="perms_everybody" type="integer">15</field>
+                               <field index="hidden" type="integer">0</field>
                                <field index="title">Root</field>
-                               <field index="doktype">1</field>
+                               <field index="doktype" type="integer">1</field>
                        </fieldlist>
                        <related index="rels" type="array"></related>
                </tablerow>
                <tablerow index="tx_impexpgroupfiles_item:1" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">1</field>
-                               <field index="pid">1</field>
-                               <field index="deleted">0</field>
-                               <field index="hidden">0</field>
+                               <field index="uid" type="integer">1</field>
+                               <field index="pid" type="integer">1</field>
+                               <field index="deleted" type="integer">0</field>
+                               <field index="hidden" type="integer">0</field>
                                <field index="title">Test item</field>
                                <field index="images">typo3_image4.jpg</field>
                                <field index="image_references">fileadmin/user_upload/typo3_image5.jpg</field>
                </tablerow>
                <tablerow index="sys_file:3" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">3</field>
-                               <field index="pid">0</field>
-                               <field index="storage">1</field>
+                               <field index="uid" type="integer">3</field>
+                               <field index="pid" type="integer">0</field>
+                               <field index="storage" type="integer">1</field>
                                <field index="type">2</field>
-                               <field index="metadata">0</field>
+                               <field index="metadata" type="integer">0</field>
                                <field index="identifier">/user_upload/typo3_image5.jpg</field>
                                <field index="identifier_hash">8180e85d25c96697ec9d2004683216831b91ffc1</field>
                                <field index="folder_hash">19669f1e02c2f16705ec7587044c66443be70725</field>
                                <field index="mime_type">image/jpeg</field>
                                <field index="name">typo3_image5.jpg</field>
                                <field index="sha1">c3511df85d21bc578faf71c6a19eeb3ff44af370</field>
-                               <field index="size">7425</field>
-                               <field index="creation_date">1393432184</field>
-                               <field index="modification_date">1393432183</field>
+                               <field index="size" type="integer">7425</field>
+                               <field index="creation_date" type="integer">1393432184</field>
+                               <field index="modification_date" type="integer">1393432183</field>
                        </fieldlist>
                        <related index="rels" type="array">
                                <field index="storage" type="array">
                </tablerow>
                <tablerow index="sys_file_storage:1" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">1</field>
-                               <field index="pid">0</field>
+                               <field index="uid" type="integer">1</field>
+                               <field index="pid" type="integer">0</field>
                                <field index="name">fileadmin/ (auto-created)</field>
                                <field index="description" type="NULL"></field>
                                <field index="driver">Local</field>
                &lt;/sheet&gt;
        &lt;/data&gt;
 &lt;/T3FlexForms&gt;</field>
-                               <field index="is_default">0</field>
-                               <field index="is_browsable">1</field>
-                               <field index="is_public">1</field>
-                               <field index="is_writable">1</field>
-                               <field index="is_online">1</field>
+                               <field index="is_default" type="integer">0</field>
+                               <field index="is_browsable" type="integer">1</field>
+                               <field index="is_public" type="integer">1</field>
+                               <field index="is_writable" type="integer">1</field>
+                               <field index="is_online" type="integer">1</field>
                        </fieldlist>
                        <related index="rels" type="array">
                                <field index="configuration" type="array">
@@ -487,4 +487,4 @@ oDglIOy49+o2eaEKg//Z
                        <content_sha1>c3511df85d21bc578faf71c6a19eeb3ff44af370</content_sha1>
                </file>
        </files_fal>
-</T3RecordDocument>
\ No newline at end of file
+</T3RecordDocument>
index 27d40cd..361f8cf 100644 (file)
@@ -7,7 +7,7 @@
                                        <uid>1</uid>
                                        <pid>0</pid>
                                        <title>IRRE</title>
-                                       <size>162</size>
+                                       <size>138</size>
                                        <relations index="rels" type="array"></relations>
                                        <softrefs type="array"></softrefs>
                                </rec>
        <records type="array">
                <tablerow index="pages:1" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">1</field>
-                               <field index="pid">0</field>
-                               <field index="deleted">0</field>
-                               <field index="perms_everybody">15</field>
-                               <field index="hidden">0</field>
+                               <field index="uid" type="integer">1</field>
+                               <field index="pid" type="integer">0</field>
+                               <field index="deleted" type="integer">0</field>
+                               <field index="perms_everybody" type="integer">15</field>
+                               <field index="hidden" type="integer">0</field>
                                <field index="title">IRRE</field>
-                               <field index="doktype">1</field>
+                               <field index="doktype" type="integer">1</field>
                        </fieldlist>
                        <related index="rels" type="array"></related>
                </tablerow>
                        </related>
                </tablerow>
        </records>
-</T3RecordDocument>
\ No newline at end of file
+</T3RecordDocument>
index f590e22..fc99068 100644 (file)
@@ -7,7 +7,7 @@
                                        <uid>1</uid>
                                        <pid>0</pid>
                                        <title>Root</title>
-                                       <size>162</size>
+                                       <size>138</size>
                                        <relations index="rels" type="array"></relations>
                                        <softrefs type="array"></softrefs>
                                </rec>
@@ -15,7 +15,7 @@
                                        <uid>2</uid>
                                        <pid>1</pid>
                                        <title>Dummy 1-2</title>
-                                       <size>167</size>
+                                       <size>143</size>
                                        <relations index="rels" type="array"></relations>
                                        <softrefs type="array"></softrefs>
                                </rec>
@@ -25,7 +25,7 @@
                                        <uid>1</uid>
                                        <pid>1</pid>
                                        <title>Test content</title>
-                                       <size>220</size>
+                                       <size>196</size>
                                        <relations index="rels" type="array">
                                                <element index="sys_file_reference:1" type="array">
                                                        <id>1</id>
@@ -52,7 +52,7 @@
                                        <uid>1</uid>
                                        <pid>0</pid>
                                        <title>Deutsch</title>
-                                       <size>109</size>
+                                       <size>97</size>
                                        <relations index="rels" type="array"></relations>
                                        <softrefs type="array"></softrefs>
                                </rec>
@@ -62,7 +62,7 @@
                                        <uid>1</uid>
                                        <pid>1</pid>
                                        <title>typo3_image2.jpg</title>
-                                       <size>297</size>
+                                       <size>277</size>
                                        <relations index="rels" type="array">
                                                <element index="sys_file:1" type="array">
                                                        <id>1</id>
@@ -77,7 +77,7 @@
                                        <uid>1</uid>
                                        <pid>0</pid>
                                        <title>typo3_image2.jpg</title>
-                                       <size>532</size>
+                                       <size>502</size>
                                        <relationLevel>1</relationLevel>
                                        <relations index="rels" type="array">
                                                <element index="sys_file_storage:1" type="array">
                                        <uid>1</uid>
                                        <pid>0</pid>
                                        <title>fileadmin/ (auto-created)</title>
-                                       <size>722</size>
+                                       <size>694</size>
                                        <relationLevel>2</relationLevel>
                                        <relations index="rels" type="array"></relations>
                                        <softrefs type="array"></softrefs>
                                        <uid>1</uid>
                                        <pid>0</pid>
                                        <title>typo3_image2.jpg</title>
-                                       <size>294</size>
+                                       <size>266</size>
                                        <relationLevel>2</relationLevel>
                                        <relations index="rels" type="array">
                                                <element index="sys_file:1" type="array">
                                        <uid>2</uid>
                                        <pid>0</pid>
                                        <title>typo3_image2.jpg</title>
-                                       <size>291</size>
+                                       <size>263</size>
                                        <relationLevel>2</relationLevel>
                                        <relations index="rels" type="array">
                                                <element index="sys_language:1" type="array">
        <records type="array">
                <tablerow index="pages:1" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">1</field>
-                               <field index="pid">0</field>
-                               <field index="deleted">0</field>
-                               <field index="perms_everybody">15</field>
-                               <field index="hidden">0</field>
+                               <field index="uid" type="integer">1</field>
+                               <field index="pid" type="integer">0</field>
+                               <field index="deleted" type="integer">0</field>
+                               <field index="perms_everybody" type="integer">15</field>
+                               <field index="hidden" type="integer">0</field>
                                <field index="title">Root</field>
-                               <field index="doktype">1</field>
+                               <field index="doktype" type="integer">1</field>
                        </fieldlist>
                        <related index="rels" type="array"></related>
                </tablerow>
                <tablerow index="pages:2" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">2</field>
-                               <field index="pid">1</field>
-                               <field index="deleted">0</field>
-                               <field index="perms_everybody">15</field>
-                               <field index="hidden">0</field>
+                               <field index="uid" type="integer">2</field>
+                               <field index="pid" type="integer">1</field>
+                               <field index="deleted" type="integer">0</field>
+                               <field index="perms_everybody" type="integer">15</field>
+                               <field index="hidden" type="integer">0</field>
                                <field index="title">Dummy 1-2</field>
-                               <field index="doktype">1</field>
+                               <field index="doktype" type="integer">1</field>
                        </fieldlist>
                        <related index="rels" type="array"></related>
                </tablerow>
                <tablerow index="tt_content:1" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">1</field>
-                               <field index="pid">1</field>
-                               <field index="t3ver_oid">0</field>
-                               <field index="hidden">0</field>
+                               <field index="uid" type="integer">1</field>
+                               <field index="pid" type="integer">1</field>
+                               <field index="t3ver_oid" type="integer">0</field>
+                               <field index="hidden" type="integer">0</field>
                                <field index="CType">textpic</field>
                                <field index="header">Test content</field>
-                               <field index="image">1</field>
-                               <field index="deleted">0</field>
+                               <field index="image" type="integer">1</field>
+                               <field index="deleted" type="integer">0</field>
                                <field index="header_link">file:1</field>
                        </fieldlist>
                        <related index="rels" type="array">
                </tablerow>
                <tablerow index="sys_language:1" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">1</field>
-                               <field index="pid">0</field>
-                               <field index="hidden">0</field>
+                               <field index="uid" type="integer">1</field>
+                               <field index="pid" type="integer">0</field>
+                               <field index="hidden" type="integer">0</field>
                                <field index="title">Deutsch</field>
                                <field index="flag">de</field>
                        </fieldlist>
                </tablerow>
                <tablerow index="sys_file_reference:1" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">1</field>
-                               <field index="pid">1</field>
-                               <field index="uid_local">1</field>
-                               <field index="uid_foreign">1</field>
+                               <field index="uid" type="integer">1</field>
+                               <field index="pid" type="integer">1</field>
+                               <field index="uid_local" type="integer">1</field>
+                               <field index="uid_foreign" type="integer">1</field>
                                <field index="tablenames">tt_content</field>
                                <field index="fieldname">image</field>
-                               <field index="sorting_foreign">0</field>
+                               <field index="sorting_foreign" type="integer">0</field>
                                <field index="table_local">sys_file</field>
                                <field index="title" type="NULL"></field>
                                <field index="description" type="NULL"></field>
                </tablerow>
                <tablerow index="sys_file:1" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">1</field>
-                               <field index="pid">0</field>
-                               <field index="storage">1</field>
+                               <field index="uid" type="integer">1</field>
+                               <field index="pid" type="integer">0</field>
+                               <field index="storage" type="integer">1</field>
                                <field index="type">2</field>
-                               <field index="metadata">0</field>
+                               <field index="metadata" type="integer">0</field>
                                <field index="identifier">/user_upload/typo3_image2.jpg</field>
                                <field index="identifier_hash">f90bb9a35622f35b5279195e324eddbaec8164b2</field>
                                <field index="folder_hash">19669f1e02c2f16705ec7587044c66443be70725</field>
                                <field index="mime_type">image/jpeg</field>
                                <field index="name">typo3_image2.jpg</field>
                                <field index="sha1">da9acdf1e105784a57bbffec9520969578287797</field>
-                               <field index="size">7958</field>
-                               <field index="creation_date">1389878273</field>
-                               <field index="modification_date">1389878273</field>
+                               <field index="size" type="integer">7958</field>
+                               <field index="creation_date" type="integer">1389878273</field>
+                               <field index="modification_date" type="integer">1389878273</field>
                        </fieldlist>
                        <related index="rels" type="array">
                                <field index="storage" type="array">
                </tablerow>
                <tablerow index="sys_file_storage:1" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">1</field>
-                               <field index="pid">0</field>
+                               <field index="uid" type="integer">1</field>
+                               <field index="pid" type="integer">0</field>
                                <field index="name">fileadmin/ (auto-created)</field>
                                <field index="description" type="NULL"></field>
                                <field index="driver">Local</field>
                &lt;/sheet&gt;
        &lt;/data&gt;
 &lt;/T3FlexForms&gt;</field>
-                               <field index="is_default">0</field>
-                               <field index="is_browsable">1</field>
-                               <field index="is_public">1</field>
-                               <field index="is_writable">1</field>
-                               <field index="is_online">1</field>
+                               <field index="is_default" type="integer">0</field>
+                               <field index="is_browsable" type="integer">1</field>
+                               <field index="is_public" type="integer">1</field>
+                               <field index="is_writable" type="integer">1</field>
+                               <field index="is_online" type="integer">1</field>
                        </fieldlist>
                        <related index="rels" type="array">
                                <field index="configuration" type="array">
                </tablerow>
                <tablerow index="sys_file_metadata:1" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">1</field>
-                               <field index="pid">0</field>
-                               <field index="sys_language_uid">0</field>
-                               <field index="l10n_parent">0</field>
-                               <field index="file">1</field>
+                               <field index="uid" type="integer">1</field>
+                               <field index="pid" type="integer">0</field>
+                               <field index="sys_language_uid" type="integer">0</field>
+                               <field index="l10n_parent" type="integer">0</field>
+                               <field index="file" type="integer">1</field>
                                <field index="title">Dummy image</field>
-                               <field index="width">400</field>
-                               <field index="height">300</field>
+                               <field index="width" type="integer">400</field>
+                               <field index="height" type="integer">300</field>
                                <field index="description">This is a dummy image.</field>
                                <field index="alternative">Photo of program code</field>
                        </fieldlist>
                </tablerow>
                <tablerow index="sys_file_metadata:2" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">2</field>
-                               <field index="pid">0</field>
-                               <field index="sys_language_uid">1</field>
-                               <field index="l10n_parent">1</field>
-                               <field index="file">1</field>
+                               <field index="uid" type="integer">2</field>
+                               <field index="pid" type="integer">0</field>
+                               <field index="sys_language_uid" type="integer">1</field>
+                               <field index="l10n_parent" type="integer">1</field>
+                               <field index="file" type="integer">1</field>
                                <field index="title">Beispiel Bild</field>
-                               <field index="width">0</field>
-                               <field index="height">0</field>
+                               <field index="width" type="integer">0</field>
+                               <field index="height" type="integer">0</field>
                                <field index="description">Nur ein Beispielbild.</field>
                                <field index="alternative">Foto von Programmcode</field>
                        </fieldlist>
index b73d329..23580a6 100644 (file)
@@ -7,7 +7,7 @@
                                        <uid>1</uid>
                                        <pid>0</pid>
                                        <title>Root</title>
-                                       <size>162</size>
+                                       <size>138</size>
                                        <relations index="rels" type="array"></relations>
                                        <softrefs type="array"></softrefs>
                                </rec>
@@ -15,7 +15,7 @@
                                        <uid>2</uid>
                                        <pid>1</pid>
                                        <title>Dummy 1-2</title>
-                                       <size>167</size>
+                                       <size>143</size>
                                        <relations index="rels" type="array"></relations>
                                        <softrefs type="array"></softrefs>
                                </rec>
@@ -25,7 +25,7 @@
                                        <uid>1</uid>
                                        <pid>1</pid>
                                        <title>Test content</title>
-                                       <size>220</size>
+                                       <size>196</size>
                                        <relations index="rels" type="array">
                                                <element index="sys_file_reference:1" type="array">
                                                        <id>1</id>
@@ -52,7 +52,7 @@
                                        <uid>1</uid>
                                        <pid>0</pid>
                                        <title>Deutsch</title>
-                                       <size>109</size>
+                                       <size>97</size>
                                        <relations index="rels" type="array"></relations>
                                        <softrefs type="array"></softrefs>
                                </rec>
@@ -62,7 +62,7 @@
                                        <uid>1</uid>
                                        <pid>1</pid>
                                        <title>typo3_image2.jpg</title>
-                                       <size>297</size>
+                                       <size>277</size>
                                        <relations index="rels" type="array">
                                                <element index="sys_file:1" type="array">
                                                        <id>1</id>
@@ -77,7 +77,7 @@
                                        <uid>1</uid>
                                        <pid>0</pid>
                                        <title>typo3_image2.jpg</title>
-                                       <size>532</size>
+                                       <size>502</size>
                                        <relationLevel>1</relationLevel>
                                        <relations index="rels" type="array">
                                                <element index="sys_file_storage:1" type="array">
                                        <uid>1</uid>
                                        <pid>0</pid>
                                        <title>fileadmin/ (auto-created)</title>
-                                       <size>722</size>
+                                       <size>694</size>
                                        <relationLevel>2</relationLevel>
                                        <relations index="rels" type="array"></relations>
                                        <softrefs type="array"></softrefs>
                                        <uid>1</uid>
                                        <pid>0</pid>
                                        <title>typo3_image2.jpg</title>
-                                       <size>294</size>
+                                       <size>266</size>
                                        <relationLevel>2</relationLevel>
                                        <relations index="rels" type="array">
                                                <element index="sys_file:1" type="array">
                                        <uid>2</uid>
                                        <pid>0</pid>
                                        <title>typo3_image2.jpg</title>
-                                       <size>291</size>
+                                       <size>263</size>
                                        <relationLevel>2</relationLevel>
                                        <relations index="rels" type="array">
                                                <element index="sys_language:1" type="array">
        <records type="array">
                <tablerow index="pages:1" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">1</field>
-                               <field index="pid">0</field>
-                               <field index="deleted">0</field>
-                               <field index="perms_everybody">15</field>
-                               <field index="hidden">0</field>
+                               <field index="uid" type="integer">1</field>
+                               <field index="pid" type="integer">0</field>
+                               <field index="deleted" type="integer">0</field>
+                               <field index="perms_everybody" type="integer">15</field>
+                               <field index="hidden" type="integer">0</field>
                                <field index="title">Root</field>
-                               <field index="doktype">1</field>
+                               <field index="doktype" type="integer">1</field>
                        </fieldlist>
                        <related index="rels" type="array"></related>
                </tablerow>
                <tablerow index="pages:2" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">2</field>
-                               <field index="pid">1</field>
-                               <field index="deleted">0</field>
-                               <field index="perms_everybody">15</field>
-                               <field index="hidden">0</field>
+                               <field index="uid" type="integer">2</field>
+                               <field index="pid" type="integer">1</field>
+                               <field index="deleted" type="integer">0</field>
+                               <field index="perms_everybody" type="integer">15</field>
+                               <field index="hidden" type="integer">0</field>
                                <field index="title">Dummy 1-2</field>
-                               <field index="doktype">1</field>
+                               <field index="doktype" type="integer">1</field>
                        </fieldlist>
                        <related index="rels" type="array"></related>
                </tablerow>
                <tablerow index="tt_content:1" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">1</field>
-                               <field index="pid">1</field>
-                               <field index="t3ver_oid">0</field>
-                               <field index="hidden">0</field>
+                               <field index="uid" type="integer">1</field>
+                               <field index="pid" type="integer">1</field>
+                               <field index="t3ver_oid" type="integer">0</field>
+                               <field index="hidden" type="integer">0</field>
                                <field index="CType">textpic</field>
                                <field index="header">Test content</field>
-                               <field index="image">1</field>
-                               <field index="deleted">0</field>
+                               <field index="image" type="integer">1</field>
+                               <field index="deleted" type="integer">0</field>
                                <field index="header_link">file:1</field>
                        </fieldlist>
                        <related index="rels" type="array">
                </tablerow>
                <tablerow index="sys_language:1" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">1</field>
-                               <field index="pid">0</field>
-                               <field index="hidden">0</field>
+                               <field index="uid" type="integer">1</field>
+                               <field index="pid" type="integer">0</field>
+                               <field index="hidden" type="integer">0</field>
                                <field index="title">Deutsch</field>
                                <field index="flag">de</field>
                        </fieldlist>
                </tablerow>
                <tablerow index="sys_file_reference:1" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">1</field>
-                               <field index="pid">1</field>
-                               <field index="uid_local">1</field>
-                               <field index="uid_foreign">1</field>
+                               <field index="uid" type="integer">1</field>
+                               <field index="pid" type="integer">1</field>
+                               <field index="uid_local" type="integer">1</field>
+                               <field index="uid_foreign" type="integer">1</field>
                                <field index="tablenames">tt_content</field>
                                <field index="fieldname">image</field>
-                               <field index="sorting_foreign">0</field>
+                               <field index="sorting_foreign" type="integer">0</field>
                                <field index="table_local">sys_file</field>
                                <field index="title" type="NULL"></field>
                                <field index="description" type="NULL"></field>
                </tablerow>
                <tablerow index="sys_file:1" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">1</field>
-                               <field index="pid">0</field>
-                               <field index="storage">1</field>
+                               <field index="uid" type="integer">1</field>
+                               <field index="pid" type="integer">0</field>
+                               <field index="storage" type="integer">1</field>
                                <field index="type">2</field>
-                               <field index="metadata">0</field>
+                               <field index="metadata" type="integer">0</field>
                                <field index="identifier">/user_upload/typo3_image2.jpg</field>
                                <field index="identifier_hash">f90bb9a35622f35b5279195e324eddbaec8164b2</field>
                                <field index="folder_hash">19669f1e02c2f16705ec7587044c66443be70725</field>
                                <field index="mime_type">image/jpeg</field>
                                <field index="name">typo3_image2.jpg</field>
                                <field index="sha1">da9acdf1e105784a57bbffec9520969578287797</field>
-                               <field index="size">7958</field>
-                               <field index="creation_date">1389878273</field>
-                               <field index="modification_date">1389878273</field>
+                               <field index="size" type="integer">7958</field>
+                               <field index="creation_date" type="integer">1389878273</field>
+                               <field index="modification_date" type="integer">1389878273</field>
                        </fieldlist>
                        <related index="rels" type="array">
                                <field index="storage" type="array">
                </tablerow>
                <tablerow index="sys_file_storage:1" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">1</field>
-                               <field index="pid">0</field>
+                               <field index="uid" type="integer">1</field>
+                               <field index="pid" type="integer">0</field>
                                <field index="name">fileadmin/ (auto-created)</field>
                                <field index="description" type="NULL"></field>
                                <field index="driver">Local</field>
                &lt;/sheet&gt;
        &lt;/data&gt;
 &lt;/T3FlexForms&gt;</field>
-                               <field index="is_default">0</field>
-                               <field index="is_browsable">1</field>
-                               <field index="is_public">1</field>
-                               <field index="is_writable">1</field>
-                               <field index="is_online">1</field>
+                               <field index="is_default" type="integer">0</field>
+                               <field index="is_browsable" type="integer">1</field>
+                               <field index="is_public" type="integer">1</field>
+                               <field index="is_writable" type="integer">1</field>
+                               <field index="is_online" type="integer">1</field>
                        </fieldlist>
                        <related index="rels" type="array">
                                <field index="configuration" type="array">
                </tablerow>
                <tablerow index="sys_file_metadata:1" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">1</field>
-                               <field index="pid">0</field>
-                               <field index="sys_language_uid">0</field>
-                               <field index="l10n_parent">0</field>
-                               <field index="file">1</field>
+                               <field index="uid" type="integer">1</field>
+                               <field index="pid" type="integer">0</field>
+                               <field index="sys_language_uid" type="integer">0</field>
+                               <field index="l10n_parent" type="integer">0</field>
+                               <field index="file" type="integer">1</field>
                                <field index="title">Dummy image</field>
-                               <field index="width">400</field>
-                               <field index="height">300</field>
+                               <field index="width" type="integer">400</field>
+                               <field index="height" type="integer">300</field>
                                <field index="description">This is a dummy image.</field>
                                <field index="alternative">Photo of program code</field>
                        </fieldlist>
                </tablerow>
                <tablerow index="sys_file_metadata:2" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">2</field>
-                               <field index="pid">0</field>
-                               <field index="sys_language_uid">1</field>
-                               <field index="l10n_parent">1</field>
-                               <field index="file">1</field>
+                               <field index="uid" type="integer">2</field>
+                               <field index="pid" type="integer">0</field>
+                               <field index="sys_language_uid" type="integer">1</field>
+                               <field index="l10n_parent" type="integer">1</field>
+                               <field index="file" type="integer">1</field>
                                <field index="title">Beispiel Bild</field>
-                               <field index="width">0</field>
-                               <field index="height">0</field>
+                               <field index="width" type="integer">0</field>
+                               <field index="height" type="integer">0</field>
                                <field index="description">Nur ein Beispielbild.</field>
                                <field index="alternative">Foto von Programmcode</field>
                        </fieldlist>
index 616e361..c79ec37 100644 (file)
@@ -7,7 +7,7 @@
                                        <uid>1</uid>
                                        <pid>0</pid>
                                        <title>Root</title>
-                                       <size>162</size>
+                                       <size>138</size>
                                        <relations index="rels" type="array"></relations>
                                        <softrefs type="array"></softrefs>
                                </rec>
@@ -15,7 +15,7 @@
                                        <uid>2</uid>
                                        <pid>1</pid>
                                        <title>Dummy 1-2</title>
-                                       <size>167</size>
+                                       <size>143</size>
                                        <relations index="rels" type="array"></relations>
                                        <softrefs type="array"></softrefs>
                                </rec>
@@ -25,7 +25,7 @@
                                        <uid>1</uid>
                                        <pid>2</pid>
                                        <title>Text element with image in RTE</title>
-                                       <size>464</size>
+                                       <size>444</size>
                                        <relations index="rels" type="array"></relations>
                                        <softrefs type="array">
                                                <softref_element index="bodytext:rtehtmlarea_images:1" type="array">
@@ -58,7 +58,7 @@
                                        <uid>1</uid>
                                        <pid>0</pid>
                                        <title>typo3_image2.jpg</title>
-                                       <size>558</size>
+                                       <size>528</size>
                                        <relationLevel>1</relationLevel>
                                        <relations index="rels" type="array">
                                                <element index="sys_file_storage:1" type="array">
@@ -72,7 +72,7 @@
                                        <uid>2</uid>
                                        <pid>0</pid>
                                        <title>typo3_image3.jpg</title>
-                                       <size>558</size>
+                                       <size>528</size>
                                        <relationLevel>1</relationLevel>
                                        <relations index="rels" type="array">
                                                <element index="sys_file_storage:1" type="array">
@@ -88,7 +88,7 @@
                                        <uid>1</uid>
                                        <pid>0</pid>
                                        <title>fileadmin/ (auto-created)</title>
-                                       <size>722</size>
+                                       <size>694</size>
                                        <relationLevel>2</relationLevel>
                                        <relations index="rels" type="array"></relations>
                                        <softrefs type="array"></softrefs>
        <records type="array">
                <tablerow index="pages:1" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">1</field>
-                               <field index="pid">0</field>
-                               <field index="deleted">0</field>
-                               <field index="perms_everybody">15</field>
-                               <field index="hidden">0</field>
+                               <field index="uid" type="integer">1</field>
+                               <field index="pid" type="integer">0</field>
+                               <field index="deleted" type="integer">0</field>
+                               <field index="perms_everybody" type="integer">15</field>
+                               <field index="hidden" type="integer">0</field>
                                <field index="title">Root</field>
-                               <field index="doktype">1</field>
+                               <field index="doktype" type="integer">1</field>
                        </fieldlist>
                        <related index="rels" type="array"></related>
                </tablerow>
                <tablerow index="pages:2" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">2</field>
-                               <field index="pid">1</field>
-                               <field index="deleted">0</field>
-                               <field index="perms_everybody">15</field>
-                               <field index="hidden">0</field>
+                               <field index="uid" type="integer">2</field>
+                               <field index="pid" type="integer">1</field>
+                               <field index="deleted" type="integer">0</field>
+                               <field index="perms_everybody" type="integer">15</field>
+                               <field index="hidden" type="integer">0</field>
                                <field index="title">Dummy 1-2</field>
-                               <field index="doktype">1</field>
+                               <field index="doktype" type="integer">1</field>
                        </fieldlist>
                        <related index="rels" type="array"></related>
                </tablerow>
                <tablerow index="tt_content:1" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">1</field>
-                               <field index="pid">2</field>
-                               <field index="t3ver_oid">0</field>
-                               <field index="hidden">0</field>
+                               <field index="uid" type="integer">1</field>
+                               <field index="pid" type="integer">2</field>
+                               <field index="t3ver_oid" type="integer">0</field>
+                               <field index="hidden" type="integer">0</field>
                                <field index="CType">text</field>
                                <field index="header">Text element with image in RTE</field>
                                <field index="bodytext">&lt;img src=&quot;fileadmin/_processed_/csm_typo3_image2_5c2670fd59.jpg&quot; title=&quot;typo3_image2.jpg&quot; data-htmlarea-file-uid=&quot;1&quot; height=&quot;225&quot; width=&quot;300&quot; alt=&quot;&quot; style=&quot;&quot; /&gt;&amp;nbsp;&amp;nbsp;And here a &lt;link file:2 - download &quot;Initiates file download&quot;&gt;link to an image&lt;/link&gt;.</field>
-                               <field index="deleted">0</field>
+                               <field index="deleted" type="integer">0</field>
                        </fieldlist>
                        <related index="rels" type="array">
                                <field index="bodytext" type="array">
                </tablerow>
                <tablerow index="sys_file:1" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">1</field>
-                               <field index="pid">0</field>
-                               <field index="storage">1</field>
+                               <field index="uid" type="integer">1</field>
+                               <field index="pid" type="integer">0</field>
+                               <field index="storage" type="integer">1</field>
                                <field index="type">2</field>
-                               <field index="metadata">0</field>
+                               <field index="metadata" type="integer">0</field>
                                <field index="identifier">/user_upload/typo3_image2.jpg</field>
                                <field index="identifier_hash">f90bb9a35622f35b5279195e324eddbaec8164b2</field>
                                <field index="folder_hash">19669f1e02c2f16705ec7587044c66443be70725</field>
                                <field index="mime_type">image/jpeg</field>
                                <field index="name">typo3_image2.jpg</field>
                                <field index="sha1">da9acdf1e105784a57bbffec9520969578287797</field>
-                               <field index="size">7958</field>
-                               <field index="creation_date">1389878273</field>
-                               <field index="modification_date">1389878273</field>
+                               <field index="size" type="integer">7958</field>
+                               <field index="creation_date" type="integer">1389878273</field>
+                               <field index="modification_date" type="integer">1389878273</field>
                        </fieldlist>
                        <related index="rels" type="array">
                                <field index="storage" type="array">
                </tablerow>
                <tablerow index="sys_file:2" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">2</field>
-                               <field index="pid">0</field>
-                               <field index="storage">1</field>
+                               <field index="uid" type="integer">2</field>
+                               <field index="pid" type="integer">0</field>
+                               <field index="storage" type="integer">1</field>
                                <field index="type">2</field>
-                               <field index="metadata">0</field>
+                               <field index="metadata" type="integer">0</field>
                                <field index="identifier">/user_upload/typo3_image3.jpg</field>
                                <field index="identifier_hash">25777b72e5e1cbed2d1b33e4fe5b737304b5bd28</field>
                                <field index="folder_hash">19669f1e02c2f16705ec7587044c66443be70725</field>
                                <field index="mime_type">image/jpeg</field>
                                <field index="name">typo3_image3.jpg</field>
                                <field index="sha1">e873c1e2ffd0f191e183a1057de3eef4d62e782d</field>
-                               <field index="size">5565</field>
-                               <field index="creation_date">1393346082</field>
-                               <field index="modification_date">1392907534</field>
+                               <field index="size" type="integer">5565</field>
+                               <field index="creation_date" type="integer">1393346082</field>
+                               <field index="modification_date" type="integer">1392907534</field>
                        </fieldlist>
                        <related index="rels" type="array">
                                <field index="storage" type="array">
                </tablerow>
                <tablerow index="sys_file_storage:1" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">1</field>
-                               <field index="pid">0</field>
+                               <field index="uid" type="integer">1</field>
+                               <field index="pid" type="integer">0</field>
                                <field index="name">fileadmin/ (auto-created)</field>
                                <field index="description" type="NULL"></field>
                                <field index="driver">Local</field>
                &lt;/sheet&gt;
        &lt;/data&gt;
 &lt;/T3FlexForms&gt;</field>
-                               <field index="is_default">0</field>
-                               <field index="is_browsable">1</field>
-                               <field index="is_public">1</field>
-                               <field index="is_writable">1</field>
-                               <field index="is_online">1</field>
+                               <field index="is_default" type="integer">0</field>
+                               <field index="is_browsable" type="integer">1</field>
+                               <field index="is_public" type="integer">1</field>
+                               <field index="is_writable" type="integer">1</field>
+                               <field index="is_online" type="integer">1</field>
                        </fieldlist>
                        <related index="rels" type="array">
                                <field index="configuration" type="array">
index 29a2485..660289c 100644 (file)
@@ -7,7 +7,7 @@
                                        <uid>1</uid>
                                        <pid>0</pid>
                                        <title>Root</title>
-                                       <size>162</size>
+                                       <size>138</size>
                                        <relations index="rels" type="array"></relations>
                                        <softrefs type="array"></softrefs>
                                </rec>
@@ -15,7 +15,7 @@
                                        <uid>2</uid>
                                        <pid>1</pid>
                                        <title>Dummy 1-2</title>
-                                       <size>167</size>
+                                       <size>143</size>
                                        <relations index="rels" type="array"></relations>
                                        <softrefs type="array"></softrefs>
                                </rec>
@@ -25,7 +25,7 @@
                                        <uid>1</uid>
                                        <pid>1</pid>
                                        <title>Test content</title>
-                                       <size>197</size>
+                                       <size>177</size>
                                        <relations index="rels" type="array"></relations>
                                        <softrefs type="array">
                                                <softref_element index="header_link:typolink:2487ce518ed56d22f20f259928ff43f1:0" type="array">
@@ -45,7 +45,7 @@
                                        <uid>2</uid>
                                        <pid>1</pid>
                                        <title>Test content 2</title>
-                                       <size>199</size>
+                                       <size>179</size>
                                        <relations index="rels" type="array"></relations>
                                        <softrefs type="array">
                                                <softref_element index="header_link:typolink:81b8b33df54ef433f1cbc7c3e513e6c4:0" type="array">
@@ -67,7 +67,7 @@
                                        <uid>2</uid>
                                        <pid>0</pid>
                                        <title>typo3_image3.jpg</title>
-                                       <size>532</size>
+                                       <size>502</size>
                                        <relationLevel>1</relationLevel>
                                        <relations index="rels" type="array">
                                                <element index="sys_file_storage:1" type="array">
@@ -81,7 +81,7 @@
                                        <uid>4</uid>
                                        <pid>0</pid>
                                        <title>Empty.html</title>
-                                       <size>564</size>
+                                       <size>534</size>
                                        <relationLevel>1</relationLevel>
                                        <relations index="rels" type="array"></relations>
                                        <softrefs type="array"></softrefs>
        <records type="array">
                <tablerow index="pages:1" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">1</field>
-                               <field index="pid">0</field>
-                               <field index="deleted">0</field>
-                               <field index="perms_everybody">15</field>
-                               <field index="hidden">0</field>
+                               <field index="uid" type="integer">1</field>
+                               <field index="pid" type="integer">0</field>
+                               <field index="deleted" type="integer">0</field>
+                               <field index="perms_everybody" type="integer">15</field>
+                               <field index="hidden" type="integer">0</field>
                                <field index="title">Root</field>
-                               <field index="doktype">1</field>
+                               <field index="doktype" type="integer">1</field>
                        </fieldlist>
                        <related index="rels" type="array"></related>
                </tablerow>
                <tablerow index="pages:2" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">2</field>
-                               <field index="pid">1</field>
-                               <field index="deleted">0</field>
-                               <field index="perms_everybody">15</field>
-                               <field index="hidden">0</field>
+                               <field index="uid" type="integer">2</field>
+                               <field index="pid" type="integer">1</field>
+                               <field index="deleted" type="integer">0</field>
+                               <field index="perms_everybody" type="integer">15</field>
+                               <field index="hidden" type="integer">0</field>
                                <field index="title">Dummy 1-2</field>
-                               <field index="doktype">1</field>
+                               <field index="doktype" type="integer">1</field>
                        </fieldlist>
                        <related index="rels" type="array"></related>
                </tablerow>
                <tablerow index="tt_content:1" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">1</field>
-                               <field index="pid">1</field>
-                               <field index="t3ver_oid">0</field>
-                               <field index="hidden">0</field>
+                               <field index="uid" type="integer">1</field>
+                               <field index="pid" type="integer">1</field>
+                               <field index="t3ver_oid" type="integer">0</field>
+                               <field index="hidden" type="integer">0</field>
                                <field index="CType">text</field>
                                <field index="header">Test content</field>
-                               <field index="deleted">0</field>
+                               <field index="deleted" type="integer">0</field>
                                <field index="header_link">file:2</field>
                        </fieldlist>
                        <related index="rels" type="array">
                </tablerow>
                <tablerow index="tt_content:2" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">2</field>
-                               <field index="pid">1</field>
-                               <field index="t3ver_oid">0</field>
-                               <field index="hidden">0</field>
+                               <field index="uid" type="integer">2</field>
+                               <field index="pid" type="integer">1</field>
+                               <field index="t3ver_oid" type="integer">0</field>
+                               <field index="hidden" type="integer">0</field>
                                <field index="CType">text</field>
                                <field index="header">Test content 2</field>
-                               <field index="deleted">0</field>
+                               <field index="deleted" type="integer">0</field>
                                <field index="header_link">file:4</field>
                        </fieldlist>
                        <related index="rels" type="array">
                </tablerow>
                <tablerow index="sys_file:2" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">2</field>
-                               <field index="pid">0</field>
-                               <field index="storage">1</field>
+                               <field index="uid" type="integer">2</field>
+                               <field index="pid" type="integer">0</field>
+                               <field index="storage" type="integer">1</field>
                                <field index="type">2</field>
-                               <field index="metadata">0</field>
+                               <field index="metadata" type="integer">0</field>
                                <field index="identifier">/user_upload/typo3_image3.jpg</field>
                                <field index="identifier_hash">25777b72e5e1cbed2d1b33e4fe5b737304b5bd28</field>
                                <field index="folder_hash">19669f1e02c2f16705ec7587044c66443be70725</field>
                                <field index="mime_type">image/jpeg</field>
                                <field index="name">typo3_image3.jpg</field>
                                <field index="sha1">e873c1e2ffd0f191e183a1057de3eef4d62e782d</field>
-                               <field index="size">5565</field>
-                               <field index="creation_date">1393346082</field>
-                               <field index="modification_date">1392907534</field>
+                               <field index="size" type="integer">5565</field>
+                               <field index="creation_date" type="integer">1393346082</field>
+                               <field index="modification_date" type="integer">1392907534</field>
                        </fieldlist>
                        <related index="rels" type="array">
                                <field index="storage" type="array">
                </tablerow>
                <tablerow index="sys_file:4" type="array">
                        <fieldlist index="data" type="array">
-                               <field index="uid">4</field>
-                               <field index="pid">0</field>
-                               <field index="storage">0</field>
+                               <field index="uid" type="integer">4</field>
+                               <field index="pid" type="integer">0</field>
+                               <field index="storage" type="integer">0</field>
                                <field index="type">1</field>
-                               <field index="metadata">0</field>
+                               <field index="metadata" type="integer">0</field>
                                <field index="identifier">/typo3conf/ext/template_extension/Resources/Public/Templates/Empty.html</field>
                                <field index="identifier_hash">ae03df120da87352822f4aae6d476086cb8c0cf8</field>
                                <field index="folder_hash">85051482e1ba204348a9b9f6c1a37069e77de027</field>
                                <field index="mime_type">text/html</field>
                                <field index="name">Empty.html</field>
                                <field index="sha1">4a53ba5b5a156b82e3efd443f9a402f8c6e6dd08</field>
-                               <field index="size">92</field>
-                               <field index="creation_date">1400176659</field>
-                               <field index="modification_date">1400176659</field>
+                               <field index="size" type="integer">92</field>
+                               <field index="creation_date" type="integer">1400176659</field>
+                               <field index="modification_date" type="integer">1400176659</field>
                        </fieldlist>
                        <related index="rels" type="array"></related>
                </tablerow>
@@ -390,4 +390,4 @@ tiNwZbSZIYCCxuK0ABsLFY0aTIrYWKxkjYuQsVgSZAQAw//Z
                        <content_sha1>4a53ba5b5a156b82e3efd443f9a402f8c6e6dd08</content_sha1>
     </file>
        </files_fal>
-</T3RecordDocument>
\ No newline at end of file
+</T3RecordDocument>