From 59c9009b38b8651f1b9b59ba541977db97a5e732 Mon Sep 17 00:00:00 2001 From: Oliver Hader <oliver@typo3.org> Date: Mon, 15 Aug 2016 18:52:43 +0200 Subject: [PATCH] [TASK] Doctrine: Migrate functional test cases in ext:core The removed IRRE\AbstractTestCase was a left-over from the initial functional test introduction with TYPO3 CMS 6.2 that was refactored later on and has not been used any further. Adjustments in the asserted test values have been necessary since previously data has been retrieved as string and is now implicitly casted to double for accordant database column types. Resolves: #77507 Releases: master Change-Id: I2aaf493f4401c7eb438b948dfe450acb52411451 Reviewed-on: https://review.typo3.org/49490 Tested-by: Bamboo TYPO3com <info@typo3.com> Reviewed-by: Georg Ringer <georg.ringer@gmail.com> Tested-by: Georg Ringer <georg.ringer@gmail.com> Reviewed-by: Oliver Hader <oliver.hader@typo3.org> Tested-by: Oliver Hader <oliver.hader@typo3.org> --- .../Collection/CategoryCollectionTest.php | 167 ++++--- .../AbstractDataHandlerActionTestCase.php | 52 +- .../FlexformIrre/ActionTestCase.php | 12 +- .../DataHandling/Framework/ActionService.php | 35 +- .../DataHandling/IRRE/AbstractTestCase.php | 449 ------------------ .../Frontend/Hook/BackendUserHandler.php | 14 +- .../Frontend/Hook/FrontendUserHandler.php | 14 +- .../DataSet/Assertion/importIrreRecords.csv | 24 +- 8 files changed, 196 insertions(+), 571 deletions(-) delete mode 100644 typo3/sysext/core/Tests/Functional/DataHandling/IRRE/AbstractTestCase.php diff --git a/typo3/sysext/core/Tests/Functional/Category/Collection/CategoryCollectionTest.php b/typo3/sysext/core/Tests/Functional/Category/Collection/CategoryCollectionTest.php index 8b31cd61d538..bd2aae405e2a 100644 --- a/typo3/sysext/core/Tests/Functional/Category/Collection/CategoryCollectionTest.php +++ b/typo3/sysext/core/Tests/Functional/Category/Collection/CategoryCollectionTest.php @@ -14,6 +14,8 @@ namespace TYPO3\CMS\Core\Tests\Functional\Category\Collection; * The TYPO3 project - inspiring people to share! */ +use Doctrine\DBAL\Types\Type; +use TYPO3\CMS\Core\Category\Collection\CategoryCollection; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -23,7 +25,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; class CategoryCollectionTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase { /** - * @var \TYPO3\CMS\Core\Category\Collection\CategoryCollection + * @var CategoryCollection */ private $subject; @@ -52,11 +54,6 @@ class CategoryCollectionTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase */ private $numberOfRecords = 5; - /** - * @var \TYPO3\CMS\Core\Database\DatabaseConnection - */ - private $database; - /** * Sets up this test suite. * @@ -65,8 +62,7 @@ class CategoryCollectionTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase protected function setUp() { parent::setUp(); - $this->database = $this->getDatabaseConnection(); - $this->subject = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Category\Collection\CategoryCollection::class, $this->tableName); + $this->subject = GeneralUtility::makeInstance(CategoryCollection::class, $this->tableName); $this->collectionRecord = array( 'uid' => 0, 'title' => $this->getUniqueId('title'), @@ -81,6 +77,16 @@ class CategoryCollectionTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase $this->makeRelationBetweenCategoryAndDummyTable(); } + /** + * Tears down this test suite. + */ + protected function tearDown() + { + $this->purgePreparedTables(); + $this->dropDummyTable(); + parent::tearDown(); + } + /** * @test * @covers \TYPO3\CMS\Core\Category\Collection\CategoryCollection::fromArray @@ -103,8 +109,8 @@ class CategoryCollectionTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase */ public function canCreateDummyCollection() { - $collection = \TYPO3\CMS\Core\Category\Collection\CategoryCollection::create($this->collectionRecord); - $this->assertInstanceOf(\TYPO3\CMS\Core\Category\Collection\CategoryCollection::class, $collection); + $collection = CategoryCollection::create($this->collectionRecord); + $this->assertInstanceOf(CategoryCollection::class, $collection); } /** @@ -114,8 +120,8 @@ class CategoryCollectionTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase */ public function canCreateDummyCollectionAndFillItems() { - $collection = \TYPO3\CMS\Core\Category\Collection\CategoryCollection::create($this->collectionRecord, true); - $this->assertInstanceOf(\TYPO3\CMS\Core\Category\Collection\CategoryCollection::class, $collection); + $collection = CategoryCollection::create($this->collectionRecord, true); + $this->assertInstanceOf(CategoryCollection::class, $collection); } /** @@ -125,7 +131,7 @@ class CategoryCollectionTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase */ public function getCollectedRecordsReturnsEmptyRecordSet() { - $method = new \ReflectionMethod(\TYPO3\CMS\Core\Category\Collection\CategoryCollection::class, 'getCollectedRecords'); + $method = new \ReflectionMethod(CategoryCollection::class, 'getCollectedRecords'); $method->setAccessible(true); $records = $method->invoke($this->subject); $this->assertInternalType('array', $records); @@ -139,7 +145,7 @@ class CategoryCollectionTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase */ public function isStorageTableNameEqualsToSysCategory() { - $this->assertEquals('sys_category', \TYPO3\CMS\Core\Category\Collection\CategoryCollection::getStorageTableName()); + $this->assertEquals('sys_category', CategoryCollection::getStorageTableName()); } /** @@ -149,7 +155,7 @@ class CategoryCollectionTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase */ public function isStorageItemsFieldEqualsToItems() { - $this->assertEquals('items', \TYPO3\CMS\Core\Category\Collection\CategoryCollection::getStorageItemsField()); + $this->assertEquals('items', CategoryCollection::getStorageItemsField()); } /** @@ -158,12 +164,20 @@ class CategoryCollectionTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase */ public function canLoadADummyCollectionFromDatabase() { - /** @var $collection \TYPO3\CMS\Core\Category\Collection\CategoryCollection */ - $collection = \TYPO3\CMS\Core\Category\Collection\CategoryCollection::load($this->categoryUid, true, $this->tableName); + /** @var $collection CategoryCollection */ + $collection = CategoryCollection::load($this->categoryUid, true, $this->tableName); // Check the number of record $this->assertEquals($this->numberOfRecords, $collection->count()); // Check that the first record is the one expected - $record = $this->database->exec_SELECTgetSingleRow('*', $this->tableName, 'uid=1'); + $queryBuilder = $this->getConnectionPool() + ->getQueryBuilderForTable($this->tableName); + $queryBuilder->getRestrictions()->removeAll(); + $statement = $queryBuilder + ->select('*') + ->from($this->tableName) + ->where($queryBuilder->expr()->eq('uid', 1)) + ->execute(); + $record = $statement->fetch(); $collection->rewind(); $this->assertEquals($record, $collection->current()); // Add a new record @@ -184,7 +198,7 @@ class CategoryCollectionTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase */ public function canLoadADummyCollectionFromDatabaseAndAddRecord() { - $collection = \TYPO3\CMS\Core\Category\Collection\CategoryCollection::load($this->categoryUid, true, $this->tableName); + $collection = CategoryCollection::load($this->categoryUid, true, $this->tableName); // Add a new record $fakeRecord = array( 'uid' => $this->numberOfRecords + 1, @@ -203,8 +217,8 @@ class CategoryCollectionTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase */ public function canLoadADummyCollectionWithoutContentFromDatabase() { - /** @var $collection \TYPO3\CMS\Core\Category\Collection\CategoryCollection */ - $collection = \TYPO3\CMS\Core\Category\Collection\CategoryCollection::load($this->categoryUid, false, $this->tableName); + /** @var $collection CategoryCollection */ + $collection = CategoryCollection::load($this->categoryUid, false, $this->tableName); // Check the number of record $this->assertEquals(0, $collection->count()); } @@ -219,13 +233,11 @@ class CategoryCollectionTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase $fakeName = array( 'tablenames' => $this->getUniqueId('name') ); - $this->database->exec_UPDATEquery( - 'sys_category_record_mm', - 'uid_foreign = 1', - $fakeName - ); + $this->getConnectionPool() + ->getConnectionForTable('sys_category_record_mm') + ->update('sys_category_record_mm', $fakeName, ['uid_foreign' => 1]); // Check the number of records - $collection = \TYPO3\CMS\Core\Category\Collection\CategoryCollection::load($this->categoryUid, true, $this->tableName); + $collection = CategoryCollection::load($this->categoryUid, true, $this->tableName); $this->assertEquals($this->numberOfRecords - 1, $collection->count()); } @@ -243,10 +255,9 @@ class CategoryCollectionTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase $values = array( 'title' => $this->getUniqueId('title') ); - (new ConnectionPool())->getConnectionForTable($this->tableName)->insert( - $this->tableName, - $values - ); + $this->getConnectionPool() + ->getConnectionForTable($this->tableName) + ->insert($this->tableName, $values); } } @@ -264,10 +275,9 @@ class CategoryCollectionTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase 'tablenames' => $this->tableName, 'fieldname' => 'categories' ); - (new ConnectionPool())->getConnectionForTable('sys_category_record_mm')->insert( - 'sys_category_record_mm', - $values - ); + $this->getConnectionPool() + ->getConnectionForTable('sys_category_record_mm') + ->insert('sys_category_record_mm', $values); } } @@ -278,14 +288,23 @@ class CategoryCollectionTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase */ private function createDummyTable() { - $sql = 'CREATE TABLE ' . $this->tableName . ' (' . LF . TAB . - 'uid int(11) auto_increment,' . LF . TAB . - 'pid int(11) unsigned DEFAULT \'0\' NOT NULL,' . LF . TAB . - 'title tinytext,' . LF . TAB . - 'tcategories int(11) unsigned DEFAULT \'0\' NOT NULL,' . LF . TAB . - 'sys_category_is_dummy_record int(11) unsigned DEFAULT \'0\' NOT NULL,' . LF . LF . TAB . - 'PRIMARY KEY (uid)' . LF . ');'; - $this->database->sql_query($sql); + $connection = $this->getConnectionPool() + ->getConnectionForTable($this->tableName); + $currentSchema = $connection->getSchemaManager()->createSchema(); + $targetSchema = clone $currentSchema; + + $table = $targetSchema->createTable($this->tableName); + $table->addColumn('uid', Type::INTEGER, ['length' => 11, 'unsigned' => true, 'autoincrement' => true]); + $table->addColumn('pid', Type::INTEGER, ['length' => 11, 'notnull' => true, 'default' => 0]); + $table->addColumn('title', Type::STRING); + $table->addColumn('tcategories', Type::INTEGER, ['length' => 11, 'unsigned' => true, 'notnull' => true, 'default' => 0]); + $table->addColumn('sys_category_is_dummy_record', Type::INTEGER, ['length' => 11, 'unsigned' => true, 'notnull' => true, 'default' => 0]); + $table->setPrimaryKey(['uid']); + + $queries = $currentSchema->getMigrateToSql($targetSchema, $connection->getDatabasePlatform()); + foreach ($queries as $query) { + $connection->query($query); + } } /** @@ -295,8 +314,17 @@ class CategoryCollectionTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase */ private function dropDummyTable() { - $sql = 'DROP TABLE ' . $this->tableName . ';'; - $this->database->sql_query($sql); + $connection = $this->getConnectionPool() + ->getConnectionForTable($this->tableName); + $currentSchema = $connection->getSchemaManager()->createSchema(); + $targetSchema = clone $currentSchema; + + $targetSchema->dropTable($this->tableName); + + $queries = $currentSchema->getMigrateToSql($targetSchema, $connection->getDatabasePlatform()); + foreach ($queries as $query) { + $connection->query($query); + } } /** @@ -306,22 +334,55 @@ class CategoryCollectionTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase */ private function prepareTables() { - $sql = 'ALTER TABLE %s ADD is_dummy_record tinyint(1) unsigned DEFAULT \'0\' NOT NULL'; + $connection = $this->getConnectionPool() + ->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME); + $currentSchema = $connection->getSchemaManager()->createSchema(); + $targetSchema = clone $currentSchema; + + $columnOptions = ['length' => 1, 'unsigned' => true, 'notnull' => true, 'default' => 0]; foreach ($this->tables as $table) { - $_sql = sprintf($sql, $table); - $this->database->sql_query($_sql); + $targetSchema + ->getTable($table) + ->addColumn('is_dummy_record', Type::SMALLINT, $columnOptions); + } + + $queries = $currentSchema->getMigrateToSql($targetSchema, $connection->getDatabasePlatform()); + foreach ($queries as $query) { + $connection->query($query); } + $values = array( 'title' => $this->getUniqueId('title'), 'l10n_diffsource' => '', 'description' => '', 'is_dummy_record' => 1 ); - $connection = (new ConnectionPool())->getConnectionForTable('sys_category'); - $connection->insert( - 'sys_category', - $values - ); + + $connection->insert('sys_category', $values); $this->categoryUid = $connection->lastInsertId(); } + + /** + * Drops previously added dummy columns from core tables. + * + * @throws \Doctrine\DBAL\DBALException + * @throws \Doctrine\DBAL\Schema\SchemaException + * @see prepareTables() + */ + private function purgePreparedTables() + { + $connection = $this->getConnectionPool() + ->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME); + $currentSchema = $connection->getSchemaManager()->createSchema(); + $targetSchema = clone $currentSchema; + + foreach ($this->tables as $table) { + $targetSchema->getTable($table)->dropColumn('is_dummy_record'); + } + + $queries = $currentSchema->getMigrateToSql($targetSchema, $connection->getDatabasePlatform()); + foreach ($queries as $query) { + $connection->query($query); + } + } } diff --git a/typo3/sysext/core/Tests/Functional/DataHandling/AbstractDataHandlerActionTestCase.php b/typo3/sysext/core/Tests/Functional/DataHandling/AbstractDataHandlerActionTestCase.php index aaa99d3a743e..4a5e9a452aef 100644 --- a/typo3/sysext/core/Tests/Functional/DataHandling/AbstractDataHandlerActionTestCase.php +++ b/typo3/sysext/core/Tests/Functional/DataHandling/AbstractDataHandlerActionTestCase.php @@ -15,7 +15,6 @@ namespace TYPO3\CMS\Core\Tests\Functional\DataHandling; */ use Doctrine\DBAL\DBALException; -use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Tests\Functional\DataHandling\Framework\DataSet; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -115,12 +114,10 @@ abstract class AbstractDataHandlerActionTestCase extends \TYPO3\CMS\Core\Tests\F foreach ($dataSet->getTableNames() as $tableName) { foreach ($dataSet->getElements($tableName) as $element) { - $connection = (new ConnectionPool())->getConnectionForTable($tableName); + $connection = $this->getConnectionPool() + ->getConnectionForTable($tableName); try { - $connection->insert( - $tableName, - $element - ); + $connection->insert($tableName, $element); } catch (DBALException $e) { $this->fail('SQL Error for table "' . $tableName . '": ' . LF . $e->getMessage()); } @@ -204,13 +201,22 @@ abstract class AbstractDataHandlerActionTestCase extends \TYPO3\CMS\Core\Tests\F if ($this->expectedErrorLogEntries === null) { return; } - $errorLogEntries = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'sys_log', 'error IN (1,2)'); - $actualErrorLogEntries = count($errorLogEntries); + + $queryBuilder = $this->getConnectionPool() + ->getQueryBuilderForTable('sys_log'); + $queryBuilder->getRestrictions()->removeAll(); + $statement = $queryBuilder + ->select('*') + ->from('sys_log') + ->where($queryBuilder->expr()->in('error', [1, 2])) + ->execute(); + + $actualErrorLogEntries = $statement->rowCount(); if ($actualErrorLogEntries === $this->expectedErrorLogEntries) { $this->assertSame($this->expectedErrorLogEntries, $actualErrorLogEntries); } else { $failureMessage = 'Expected ' . $this->expectedErrorLogEntries . ' entries in sys_log, but got ' . $actualErrorLogEntries . LF; - foreach ($errorLogEntries as $entry) { + while ($entry = $statement->fetch()) { $entryData = unserialize($entry['log_data']); $entryMessage = vsprintf($entry['details'], $entryData); $failureMessage .= '* ' . $entryMessage . LF; @@ -226,20 +232,22 @@ abstract class AbstractDataHandlerActionTestCase extends \TYPO3\CMS\Core\Tests\F */ protected function getAllRecords($tableName, $hasUidField = false) { - $allRecords = array(); - - $records = $this->getDatabaseConnection()->exec_SELECTgetRows( - '*', - $tableName, - '1=1', - '', - '', - '', - ($hasUidField ? 'uid' : '') - ); + $queryBuilder = $this->getConnectionPool() + ->getQueryBuilderForTable($tableName); + $queryBuilder->getRestrictions()->removeAll(); + $statement = $queryBuilder + ->select('*') + ->from($tableName) + ->execute(); + + if (!$hasUidField) { + return $statement->fetchAll(); + } - if (!empty($records)) { - $allRecords = $records; + $allRecords = []; + while ($record = $statement->fetch()) { + $index = $record['uid']; + $allRecords[$index] = $record; } return $allRecords; diff --git a/typo3/sysext/core/Tests/Functional/DataHandling/FlexformIrre/ActionTestCase.php b/typo3/sysext/core/Tests/Functional/DataHandling/FlexformIrre/ActionTestCase.php index a5815a17389c..043a3b8c5427 100644 --- a/typo3/sysext/core/Tests/Functional/DataHandling/FlexformIrre/ActionTestCase.php +++ b/typo3/sysext/core/Tests/Functional/DataHandling/FlexformIrre/ActionTestCase.php @@ -51,6 +51,16 @@ class ActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\DataHandling\Abstr ]); // there should be one relation in the live WS and one in the draft WS pointing to the file field. - $this->assertEquals(2, $this->getDatabaseConnection()->exec_SELECTcountRows('uid', 'sys_file_reference', 'uid_local = 20')); + $queryBuilder = $this->getConnectionPool() + ->getQueryBuilderForTable('sys_file_reference'); + $queryBuilder->getRestrictions()->removeAll(); + $referenceCount = $queryBuilder + ->count('uid') + ->from('sys_file_reference') + ->where($queryBuilder->expr()->eq('uid_local', 20)) + ->execute() + ->fetchColumn(0); + + $this->assertEquals(2, $referenceCount); } } diff --git a/typo3/sysext/core/Tests/Functional/DataHandling/Framework/ActionService.php b/typo3/sysext/core/Tests/Functional/DataHandling/Framework/ActionService.php index 08345289459e..f3e5d03ababf 100644 --- a/typo3/sysext/core/Tests/Functional/DataHandling/Framework/ActionService.php +++ b/typo3/sysext/core/Tests/Functional/DataHandling/Framework/ActionService.php @@ -14,7 +14,9 @@ namespace TYPO3\CMS\Core\Tests\Functional\DataHandling\Framework; * The TYPO3 project - inspiring people to share! */ +use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\DataHandling\DataHandler; +use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\StringUtility; /** @@ -436,12 +438,21 @@ class ActionService $versionedId = null; $liveUid = (int)$liveUid; $workspaceId = (int)$this->getBackendUser()->workspace; - $row = $this->getDatabaseConnection()->exec_SELECTgetSingleRow( - 'uid', - $tableName, - 'pid=-1 AND t3ver_oid=' . $liveUid . ' AND t3ver_wsid=' . $workspaceId . - ($useDeleteClause ? \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($tableName) : '') - ); + + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable($tableName); + $queryBuilder->getRestrictions()->removeAll(); + $statement = $queryBuilder + ->select('uid') + ->from($tableName) + ->where( + $queryBuilder->expr()->eq('pid', -1), + $queryBuilder->expr()->eq('t3ver_oid', $liveUid), + $queryBuilder->expr()->eq('t3ver_wsid', $workspaceId) + ) + ->execute(); + + $row = $statement->fetch(); if (!empty($row['uid'])) { $versionedId = (int)$row['uid']; } @@ -453,7 +464,7 @@ class ActionService */ protected function createDataHandler() { - $this->dataHandler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(DataHandler::class); + $this->dataHandler = GeneralUtility::makeInstance(DataHandler::class); $backendUser = $this->getBackendUser(); if (isset($backendUser->uc['copyLevels'])) { $this->dataHandler->copyTree = $backendUser->uc['copyLevels']; @@ -466,7 +477,7 @@ class ActionService */ protected function getWorkspaceService() { - return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( + return GeneralUtility::makeInstance( \TYPO3\CMS\Workspaces\Service\WorkspaceService::class ); } @@ -478,12 +489,4 @@ class ActionService { return $GLOBALS['BE_USER']; } - - /** - * @return \TYPO3\CMS\Core\Database\DatabaseConnection - */ - protected function getDatabaseConnection() - { - return $GLOBALS['TYPO3_DB']; - } } diff --git a/typo3/sysext/core/Tests/Functional/DataHandling/IRRE/AbstractTestCase.php b/typo3/sysext/core/Tests/Functional/DataHandling/IRRE/AbstractTestCase.php deleted file mode 100644 index e22e34789b6f..000000000000 --- a/typo3/sysext/core/Tests/Functional/DataHandling/IRRE/AbstractTestCase.php +++ /dev/null @@ -1,449 +0,0 @@ -<?php -namespace TYPO3\CMS\Core\Tests\Functional\DataHandling\IRRE; - -/* - * This file is part of the TYPO3 CMS project. - * - * It is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, either version 2 - * of the License, or any later version. - * - * For the full copyright and license information, please read the - * LICENSE.txt file that was distributed with this source code. - * - * The TYPO3 project - inspiring people to share! - */ - -use TYPO3\CMS\Backend\Utility\BackendUtility; -use TYPO3\CMS\Core\Utility\GeneralUtility; - -/** - * Generic test helpers. - * - */ -abstract class AbstractTestCase extends \TYPO3\CMS\Core\Tests\FunctionalTestCase -{ - const VALUE_LanguageId = 2; - - const TABLE_Pages = 'pages'; - - const COMMAND_Copy = 'copy'; - const COMMAND_Localize = 'localize'; - const COMMAND_Delete = 'delete'; - - const PROPERTY_LocalizeReferencesAtParentLocalization = 'localizeReferencesAtParentLocalization'; - const BEHAVIOUR_LocalizeChildrenAtParentLocalization = 'localizeChildrenAtParentLocalization'; - const BEHAVIOUR_LocalizationMode = 'localizationMode'; - - protected $testExtensionsToLoad = array('typo3/sysext/core/Tests/Functional/Fixtures/Extensions/irre_tutorial'); - - /** - * @var int - */ - private $expectedLogEntries = 0; - - /** - * Sets up this test case. - * - * @return void - */ - protected function setUp() - { - parent::setUp(); - - $this->setUpBackendUserFromFixture(1); - \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->initializeLanguageObject(); - - $this->expectedLogEntries = 0; - - $GLOBALS['TYPO3_CONF_VARS']['SYS']['sqlDebug'] = 1; - - $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Fixtures/pages.xml'); - $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Fixtures/sys_language.xml'); - } - - /** - * Tears down this test case. - * - * @return void - */ - protected function tearDown() - { - $this->assertNoLogEntries(); - - $this->expectedLogEntries = 0; - - parent::tearDown(); - } - - /** - * Sets the number of expected log entries. - * - * @param int $count - * @return void - */ - protected function setExpectedLogEntries($count) - { - $count = (int)$count; - - if ($count > 0) { - $this->expectedLogEntries = $count; - } - } - - /** - * @param string $command - * @param mixed $value - * @param array $tables Table names with list of ids to be edited - * @return array - */ - protected function getElementStructureForCommands($command, $value, array $tables) - { - $commandStructure = array(); - - foreach ($tables as $tableName => $idList) { - $ids = GeneralUtility::trimExplode(',', $idList, true); - foreach ($ids as $id) { - $commandStructure[$tableName][$id] = array( - $command => $value - ); - } - } - - return $commandStructure; - } - - /** - * Simulates executing commands by using DataHandler. - * - * @param array $elements The cmdmap to be delivered to DataHandler - * @return \TYPO3\CMS\Core\DataHandling\DataHandler - */ - protected function simulateCommandByStructure(array $elements) - { - $tceMain = $this->getTceMain(); - $tceMain->start(array(), $elements); - $tceMain->process_cmdmap(); - - return $tceMain; - } - - /** - * @param string $command - * @param mixed $value - * @param array $tables Table names with list of ids to be edited - * @return \TYPO3\CMS\Core\DataHandling\DataHandler - */ - protected function simulateCommand($command, $value, array $tables) - { - return $this->simulateCommandByStructure( - $this->getElementStructureForCommands($command, $value, $tables) - ); - } - - /** - * Gets the last log entry. - * - * @return array - */ - protected function getLastLogEntryMessage() - { - $message = ''; - - $logEntries = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'sys_log', 'error IN (1,2)', '', '', 1); - - if (is_array($logEntries) && !empty($logEntries)) { - $message = $logEntries[0]['details']; - } - - return $message; - } - - /** - * @param array $itemArray - * @return array - */ - protected function getElementsByItemArray(array $itemArray) - { - $elements = array(); - - foreach ($itemArray as $item) { - $elements[$item['table']][$item['id']] = BackendUtility::getRecord($item['table'], $item['id']); - } - - return $elements; - } - - /** - * Gets all records of a table. - * - * @param string $table Name of the table - * @param string $indexField - * @return array - */ - protected function getAllRecords($table, $indexField = 'uid') - { - return $this->getDatabaseConnection()->exec_SELECTgetRows('*', $table, '1=1', '', '', '', $indexField); - } - - /** - * Gets the TCE configuration of a field. - * - * @param $tableName - * @param $fieldName - * @return array - */ - protected function getTcaFieldConfiguration($tableName, $fieldName) - { - if (!isset($GLOBALS['TCA'][$tableName]['columns'][$fieldName]['config'])) { - $this->fail('TCA definition for field ' . $tableName . '.' . $fieldName . ' not available'); - } - - return $GLOBALS['TCA'][$tableName]['columns'][$fieldName]['config']; - } - - /** - * @param string $tableName - * @param string $fieldName - * @param string $propertyName - * @param mixed $value - * @return void - */ - protected function setTcaFieldConfiguration($tableName, $fieldName, $propertyName, $value) - { - if (isset($GLOBALS['TCA'][$tableName]['columns'][$fieldName]['config'])) { - $GLOBALS['TCA'][$tableName]['columns'][$fieldName]['config'][$propertyName] = $value; - } - } - - /** - * @param string $tableName - * @param string $fieldName - * @param string $behaviourName - * @param mixed $value - * @return void - */ - protected function setTcaFieldConfigurationBehaviour($tableName, $fieldName, $behaviourName, $value) - { - if (isset($GLOBALS['TCA'][$tableName]['columns'][$fieldName]['config'])) { - if (!isset($GLOBALS['TCA'][$tableName]['columns'][$fieldName]['config']['behaviour'])) { - $GLOBALS['TCA'][$tableName]['columns'][$fieldName]['config']['behaviour'] = array(); - } - - $GLOBALS['TCA'][$tableName]['columns'][$fieldName]['config']['behaviour'][$behaviourName] = $value; - } - } - - /** - * Gets the field value of a record. - * - * @param $tableName - * @param $id - * @param $fieldName - * @return string - */ - protected function getFieldValue($tableName, $id, $fieldName) - { - $record = BackendUtility::getRecord($tableName, $id, $fieldName); - - if (!is_array($record)) { - $this->fail('Record ' . $tableName . ':' . $id . ' not available'); - } - - return $record[$fieldName]; - } - - /** - * Gets instance of \TYPO3\CMS\Core\Database\RelationHandler. - * - * @return \TYPO3\CMS\Core\Database\RelationHandler - */ - protected function getLoadDbGroup() - { - $loadDbGroup = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\RelationHandler::class); - - return $loadDbGroup; - } - - /** - * Gets an instance of \TYPO3\CMS\Core\DataHandling\DataHandler. - * - * @return \TYPO3\CMS\Core\DataHandling\DataHandler - */ - protected function getTceMain() - { - $tceMain = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class); - return $tceMain; - } - - /** - * Assert that no sys_log entries had been written. - * - * @return void - */ - protected function assertNoLogEntries() - { - $logEntries = $this->getLogEntries(); - - if (count($logEntries) > $this->expectedLogEntries) { - var_dump(array_values($logEntries)); - ob_flush(); - $this->fail('The sys_log table contains unexpected entries.'); - } elseif (count($logEntries) < $this->expectedLogEntries) { - $this->fail('Expected count of sys_log entries no reached.'); - } - } - - /** - * Asserts the correct order of elements. - * - * @param string $table - * @param string $field - * @param array $expectedOrderOfIds - * @param string $message - * @return void - */ - protected function assertSortingOrder($table, $field, $expectedOrderOfIds, $message) - { - $expectedOrderOfIdsCount = count($expectedOrderOfIds); - $elements = $this->getAllRecords($table); - - for ($i = 0; $i < $expectedOrderOfIdsCount-1; $i++) { - $this->assertLessThan( - $elements[$expectedOrderOfIds[$i+1]][$field], - $elements[$expectedOrderOfIds[$i]][$field], - $message - ); - } - } - - /** - * Asserts reference index elements. - * - * @param array $assertions - * @param bool $expected - */ - protected function assertReferenceIndex(array $assertions, $expected = true) - { - $references = $this->getAllRecords('sys_refindex', 'hash'); - - foreach ($assertions as $parent => $children) { - foreach ($children as $child) { - $parentItems = explode(':', $parent); - $childItems = explode(':', $child); - - $assertion = array( - 'tablename' => $parentItems[0], - 'recuid' => $parentItems[1], - 'field' => $parentItems[2], - 'ref_table' => $childItems[0], - 'ref_uid' => $childItems[1], - ); - - $this->assertTrue( - ($expected === $this->executeAssertionOnElements($assertion, $references)), - 'Expected reference index element for ' . $parent . ' -> ' . $child - ); - } - } - } - - /** - * @param string $parentTableName - * @param int $parentId - * @param string $parentFieldName - * @param array $assertions - * @param string $mmTable - * @param bool $expected - * @return void - */ - protected function assertChildren($parentTableName, $parentId, $parentFieldName, array $assertions, $mmTable = '', $expected = true) - { - $tcaFieldConfiguration = $this->getTcaFieldConfiguration($parentTableName, $parentFieldName); - - $loadDbGroup = $this->getLoadDbGroup(); - $loadDbGroup->start( - $this->getFieldValue($parentTableName, $parentId, $parentFieldName), - $tcaFieldConfiguration['foreign_table'], - $mmTable, - $parentId, - $parentTableName, - $tcaFieldConfiguration - ); - - $elements = $this->getElementsByItemArray($loadDbGroup->itemArray); - - foreach ($assertions as $index => $assertion) { - $this->assertTrue( - ($expected === $this->executeAssertionOnElements($assertion, $elements)), - 'Assertion #' . $index . ' failed' - ); - } - } - - /** - * Gets log entries from the sys_log - * - * @return array - */ - protected function getLogEntries() - { - return $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'sys_log', 'error IN (1,2)'); - } - - /** - * @param array $assertion - * @param array $elements - * @return bool - */ - protected function executeAssertionOnElements(array $assertion, array $elements) - { - if (!empty($assertion['tableName'])) { - $tableName = $assertion['tableName']; - unset($assertion['tableName']); - $elements = (array)$elements[$tableName]; - } - - foreach ($elements as $element) { - $result = false; - - foreach ($assertion as $field => $value) { - if ($element[$field] == $value) { - $result = true; - } else { - $result = false; - break; - } - } - - if ($result === true) { - return true; - } - } - - return false; - } - - /** - * @param mixed $element - * @return string - */ - protected function elementToString($element) - { - $result = preg_replace( - '#\n+#', - ' ', - var_export($element, true) - ); - - return $result; - } - - /** - * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication - */ - protected function getBackendUser() - { - return $GLOBALS['BE_USER']; - } -} diff --git a/typo3/sysext/core/Tests/Functional/Framework/Frontend/Hook/BackendUserHandler.php b/typo3/sysext/core/Tests/Functional/Framework/Frontend/Hook/BackendUserHandler.php index c398f95d1b64..33101955d0d1 100644 --- a/typo3/sysext/core/Tests/Functional/Framework/Frontend/Hook/BackendUserHandler.php +++ b/typo3/sysext/core/Tests/Functional/Framework/Frontend/Hook/BackendUserHandler.php @@ -14,6 +14,7 @@ namespace TYPO3\CMS\Core\Tests\Functional\Framework\Frontend\Hook; * The TYPO3 project - inspiring people to share! */ +use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Utility\GeneralUtility; /** @@ -35,7 +36,10 @@ class BackendUserHandler implements \TYPO3\CMS\Core\SingletonInterface } $backendUser = $this->createBackendUser(); - $backendUser->user = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', 'be_users', 'uid=' . $backendUserId); + $backendUser->user = GeneralUtility::makeInstance(ConnectionPool::class) + ->getConnectionForTable('be_users') + ->select(['*'], 'be_users', ['uid' => $backendUserId]) + ->fetch(); $backendUser->setTemporaryWorkspace($workspaceId); $frontendController->beUserLogin = true; @@ -52,12 +56,4 @@ class BackendUserHandler implements \TYPO3\CMS\Core\SingletonInterface \TYPO3\CMS\Backend\FrontendBackendUserAuthentication::class ); } - - /** - * @return \TYPO3\CMS\Core\Database\DatabaseConnection - */ - protected function getDatabaseConnection() - { - return $GLOBALS['TYPO3_DB']; - } } diff --git a/typo3/sysext/core/Tests/Functional/Framework/Frontend/Hook/FrontendUserHandler.php b/typo3/sysext/core/Tests/Functional/Framework/Frontend/Hook/FrontendUserHandler.php index 781706f0024b..39b32404421c 100644 --- a/typo3/sysext/core/Tests/Functional/Framework/Frontend/Hook/FrontendUserHandler.php +++ b/typo3/sysext/core/Tests/Functional/Framework/Frontend/Hook/FrontendUserHandler.php @@ -14,6 +14,7 @@ namespace TYPO3\CMS\Core\Tests\Functional\Framework\Frontend\Hook; * The TYPO3 project - inspiring people to share! */ +use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Utility\GeneralUtility; /** @@ -32,7 +33,10 @@ class FrontendUserHandler implements \TYPO3\CMS\Core\SingletonInterface $frontendUserId = (int)GeneralUtility::_GP('frontendUserId'); $frontendController->fe_user->checkPid = 0; - $frontendUser = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', 'fe_users', 'uid =' . $frontendUserId); + $frontendUser = GeneralUtility::makeInstance(ConnectionPool::class) + ->getConnectionForTable('fe_users') + ->select(['*'], 'fe_users', ['uid' => $frontendUserId]) + ->fetch(); if (is_array($frontendUser)) { $frontendController->loginUser = 1; $frontendController->fe_user->createUserSession($frontendUser); @@ -40,12 +44,4 @@ class FrontendUserHandler implements \TYPO3\CMS\Core\SingletonInterface $frontendController->initUserGroups(); } } - - /** - * @return \TYPO3\CMS\Core\Database\DatabaseConnection - */ - protected function getDatabaseConnection() - { - return $GLOBALS['TYPO3_DB']; - } } diff --git a/typo3/sysext/impexp/Tests/Functional/Import/IrreTutorialRecords/DataSet/Assertion/importIrreRecords.csv b/typo3/sysext/impexp/Tests/Functional/Import/IrreTutorialRecords/DataSet/Assertion/importIrreRecords.csv index e935836a05c6..18f742872f18 100644 --- a/typo3/sysext/impexp/Tests/Functional/Import/IrreTutorialRecords/DataSet/Assertion/importIrreRecords.csv +++ b/typo3/sysext/impexp/Tests/Functional/Import/IrreTutorialRecords/DataSet/Assertion/importIrreRecords.csv @@ -15,9 +15,9 @@ tx_irretutorial_1ncsv_offer ,3,1,1,0,0,64,0,0,"Offer 2.2 (csv)",3 tx_irretutorial_1ncsv_price ,uid,pid,cruser_id,sys_language_uid,l18n_parent,sorting,deleted,hidden,title,price -,1,1,1,0,0,256,0,0,"Price 1.1.1 (csv)",567.00 -,2,1,1,0,0,128,0,0,"Price 1.2.1 (csv)",90.00 -,3,1,1,0,0,64,0,0,"Price 2.2.1 (csv)",112.00 +,1,1,1,0,0,256,0,0,"Price 1.1.1 (csv)",567 +,2,1,1,0,0,128,0,0,"Price 1.2.1 (csv)",90 +,3,1,1,0,0,64,0,0,"Price 2.2.1 (csv)",112 tx_irretutorial_1nff_hotel ,uid,pid,cruser_id,sys_language_uid,l18n_parent,sorting,deleted,hidden,parentid,parenttable,parentidentifier,title,offers ,1,1,1,0,0,2,0,0,1,tt_content,,"Hotel 2 (nff)",1 @@ -29,10 +29,10 @@ tx_irretutorial_1nff_offer ,3,1,1,0,0,1,0,0,2,tx_irretutorial_1nff_hotel,,"Offer 1.1 (nff)",2 tx_irretutorial_1nff_price ,uid,pid,cruser_id,sys_language_uid,l18n_parent,sorting,deleted,hidden,parentid,parenttable,parentidentifier,title,price -,1,1,1,0,0,2,0,0,3,tx_irretutorial_1nff_offer,,"Price 1.1.2 (nff)",869.00 -,2,1,1,0,0,1,0,0,2,tx_irretutorial_1nff_offer,,"Price 2.1.1 (nff)",5467567.00 -,3,1,1,0,0,1,0,0,1,tx_irretutorial_1nff_offer,,"Price 1.2.1 (nff)",678.00 -,4,1,1,0,0,1,0,0,3,tx_irretutorial_1nff_offer,,"Price 1.1.1 (nff)",4.00 +,1,1,1,0,0,2,0,0,3,tx_irretutorial_1nff_offer,,"Price 1.1.2 (nff)",869 +,2,1,1,0,0,1,0,0,2,tx_irretutorial_1nff_offer,,"Price 2.1.1 (nff)",5467567 +,3,1,1,0,0,1,0,0,1,tx_irretutorial_1nff_offer,,"Price 1.2.1 (nff)",678 +,4,1,1,0,0,1,0,0,3,tx_irretutorial_1nff_offer,,"Price 1.1.1 (nff)",4 tx_irretutorial_mnasym_hotel ,uid,pid,cruser_id,sys_language_uid,l18n_parent,sorting,deleted,hidden,title,offers ,1,1,1,0,0,256,0,0,"Hotel 1 (m:n ASym)",2 @@ -46,8 +46,8 @@ tx_irretutorial_mnasym_offer ,2,1,1,0,0,128,0,0,"Offer 2 (m:n ASym)",1 tx_irretutorial_mnasym_price ,uid,pid,cruser_id,sys_language_uid,l18n_parent,sorting,deleted,hidden,parentid,title,price -,1,1,1,0,0,1,0,0,1,"Price 2 1:1 (m:n ASym)",45.00 -,2,1,1,0,0,1,0,0,2,"Price 1 1:2 (m:n ASym)",678.00 +,1,1,1,0,0,1,0,0,1,"Price 2 1:1 (m:n ASym)",45 +,2,1,1,0,0,1,0,0,2,"Price 1 1:2 (m:n ASym)",678 tx_irretutorial_mnattr_hotel ,uid,pid,cruser_id,sys_language_uid,l18n_parent,sorting,deleted,hidden,title,offers ,1,1,1,0,0,256,0,0,"Hotel 2 (m:n Attr)",1 @@ -71,9 +71,9 @@ tx_irretutorial_mnmmasym_offer ,3,1,1,0,0,64,0,0,"Offer 2.1 (m:n (MM) ASym)",0,1 tx_irretutorial_mnmmasym_price ,uid,pid,cruser_id,sys_language_uid,l18n_parent,sorting,deleted,hidden,title,price,offers -,1,1,1,0,0,256,0,0,"Price 1.1.1 (m:n (MM) ASym)",567.00,0 -,2,1,1,0,0,128,0,0,"Price 1.2.2 (m:n (MM) ASym)",567.00,0 -,3,1,1,0,0,64,0,0,"Price (m:n (MM) ASym)",223.00,0 +,1,1,1,0,0,256,0,0,"Price 1.1.1 (m:n (MM) ASym)",567,0 +,2,1,1,0,0,128,0,0,"Price 1.2.2 (m:n (MM) ASym)",567,0 +,3,1,1,0,0,64,0,0,"Price (m:n (MM) ASym)",223,0 tx_irretutorial_mnsym_hotel ,uid,pid,cruser_id,sys_language_uid,l18n_parent,sorting,deleted,hidden,title,branches ,1,1,1,0,0,256,0,0,"Hotel 1 (mm sym)",2 -- GitLab