[TASK] Implement getDatabase to FunctionalTestCase 87/23187/2
authorChristian Kuhn <lolli@schwarzbu.ch>
Sun, 18 Aug 2013 23:24:02 +0000 (01:24 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sun, 18 Aug 2013 23:29:19 +0000 (01:29 +0200)
Fiddling with database records is a common use case in
functional tests. The patch implements a getDatabase()
method to FunctionalTestCase for easy IDE auto completion
and uses it in activated test cases.

Change-Id: I8900457ff1c31e1f1d731337be17431ccf89b379
Resolves: #51167
Releases: 6.2
Reviewed-on: https://review.typo3.org/23187
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/core/Tests/Functional/DataHandling/DataHandlerTest.php
typo3/sysext/core/Tests/FunctionalTestCase.php
typo3/sysext/workspaces/Tests/Functional/DataHandling/DataHandlerTest.php

index 66de152..ad785d0 100644 (file)
@@ -66,8 +66,7 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase {
 
                $this->assertGreaterThanOrEqual(1, $uid);
 
-               /** @var DatabaseConnection $database */
-               $database = $GLOBALS['TYPO3_DB'];
+               $database = $this->getDatabase();
                $row = $database->exec_SELECTgetSingleRow('*', 'tt_content', 'uid = ' . $uid);
                $this->assertNotEmpty($row);
 
@@ -101,8 +100,7 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase {
                $uid = $dataHandler->copyMappingArray_merged['tt_content'][$originalRecordId];
                $this->assertGreaterThanOrEqual(2, $uid);
 
-               /** @var DatabaseConnection $database */
-               $database = $GLOBALS['TYPO3_DB'];
+               $database = $this->getDatabase();
                $row = $database->exec_SELECTgetSingleRow('*', 'tt_content', 'uid = ' . $uid);
                $this->assertNotEmpty($row);
 
index 27e95fe..0a33d2b 100644 (file)
@@ -139,6 +139,18 @@ abstract class FunctionalTestCase extends BaseTestCase {
        }
 
        /**
+        * Get DatabaseConnection instance - $GLOBALS['TYPO3_DB']
+        *
+        * This method should be used instead of direct access to
+        * $GLOBALS['TYPO3_DB'] for easy IDE auto completion.
+        *
+        * @return \TYPO3\CMS\Core\Database\DatabaseConnection
+        */
+       protected function getDatabase() {
+               return $GLOBALS['TYPO3_DB'];
+       }
+
+       /**
         * Imports a data set represented as XML into the test database,
         *
         * @param string $path Absolute path to the XML file containing the data set to load
@@ -153,8 +165,7 @@ abstract class FunctionalTestCase extends BaseTestCase {
                        );
                }
 
-               /** @var \TYPO3\CMS\Core\Database\DatabaseConnection $database */
-               $database = $GLOBALS['TYPO3_DB'];
+               $database = $this->getDatabase();
 
                $xml = simplexml_load_file($path);
                $foreignKeys = array();
index b4036b4..1cd2edb 100644 (file)
@@ -73,8 +73,7 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase {
 
                $versionedId = $dataHandler->getAutoVersionId('tt_content', $uid);
 
-               /** @var \TYPO3\CMS\Core\Database\DatabaseConnection $database */
-               $database = $GLOBALS['TYPO3_DB'];
+               $database = $this->getDatabase();
                $row = $database->exec_SELECTgetSingleRow('*', 'tt_content', 'uid = ' . $versionedId);
                $this->assertNotEmpty($row);