Added unit test for RFC #6953: Mapping of fieldnames in SQL-functions like MIN()...
authorXavier Perseguers <typo3@perseguers.ch>
Sat, 7 Nov 2009 09:56:45 +0000 (09:56 +0000)
committerXavier Perseguers <typo3@perseguers.ch>
Sat, 7 Nov 2009 09:56:45 +0000 (09:56 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/dbal/trunk@26284 735d13b6-9817-0410-8766-e36946ffe9aa

typo3/sysext/dbal/ChangeLog
typo3/sysext/dbal/tests/db_oracle_testcase.php
typo3/sysext/dbal/tests/fixtures/oci8.config.php

index 7d18653..3f5f5c3 100644 (file)
@@ -1,6 +1,7 @@
 2009-11-07  Xavier Perseguers  <typo3@perseguers.ch>
 
        * Added unit test for RFC #6198: Problem with strings in IN
+       * Added unit test for RFC #6953: Mapping of fieldnames in SQL-functions like MIN(), MAX() or SUM() does not work
 
 2009-11-06  Xavier Perseguers  <typo3@perseguers.ch>
 
index a58189e..5a725b2 100644 (file)
@@ -172,10 +172,10 @@ class db_oracle_testcase extends BaseTestCase {
         */
        public function tablesAndFieldsAreRemappedInMultipleJoins() {
                $selectFields = '*';
-               $fromTables = 'tt_news_cat INNER JOIN tt_news_cat_mm ON tt_news_cat.uid = tt_news_cat_mm.uid_foreign INNER JOIN tt_news ON tt_news.uid = tt_news_cat_mm.uid_local';
-               $whereClause = '1=1';
-               $groupBy = '';
-               $orderBy = '';
+               $fromTables   = 'tt_news_cat INNER JOIN tt_news_cat_mm ON tt_news_cat.uid = tt_news_cat_mm.uid_foreign INNER JOIN tt_news ON tt_news.uid = tt_news_cat_mm.uid_local';
+               $whereClause  = '1=1';
+               $groupBy      = '';
+               $orderBy      = '';
 
                $this->fixture->_callRef('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
                $query = $this->cleanSql($this->fixture->SELECTquery($selectFields, $fromTables, $whereClause, $groupBy, $orderBy));
@@ -199,6 +199,44 @@ class db_oracle_testcase extends BaseTestCase {
                ));
                $expected = 'SELECT COUNT(DISTINCT "tx_dam"."uid") AS "count" FROM "tx_dam"';
                $expected .= ' WHERE "tx_dam"."pid" IN (1) AND "tx_dam"."file_type" IN (\'gif\',\'png\',\'jpg\',\'jpeg\') AND "tx_dam"."deleted" = 0';
-               $this->assertEquals($query, $expected);
+               $this->assertEquals($expected, $query);
+       }
+
+       /**
+        * @test
+        * @see http://bugs.typo3.org/view.php?id=6953
+        */
+       public function fieldWithinSqlFunctionIsRemapped() {
+               $selectFields = 'tstamp, script, SUM(exec_time) AS calc_sum, COUNT(*) AS qrycount, MAX(errorFlag) AS error';
+               $fromTables   = 'tx_dbal_debuglog';
+               $whereClause  = '1=1';
+               $groupBy      = '';
+               $orderBy      = '';
+
+               $this->fixture->_callRef('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
+               $query = $this->cleanSql($this->fixture->SELECTquery($selectFields, $fromTables, $whereClause, $groupBy, $orderBy));
+
+               $expected = 'SELECT "tstamp", "script", SUM("exec_time") AS "calc_sum", COUNT(*) AS "qrycount", MAX("errorflag") AS "error" FROM "tx_dbal_debuglog" WHERE 1 = 1';
+               $this->assertEquals($expected, $query);
+       }
+
+       /**
+        * @test
+        * @see http://bugs.typo3.org/view.php?id=6953
+        */
+       public function tableAndfieldWithinSqlFunctionIsRemapped() {
+               $selectFields = 'MAX(tt_news_cat.uid) AS biggest_id';
+               $fromTables   = 'tt_news_cat INNER JOIN tt_news_cat_mm ON tt_news_cat.uid = tt_news_cat_mm.uid_foreign';
+               $whereClause  = 'tt_news_cat_mm.uid_local > 50';
+               $groupBy      = '';
+               $orderBy      = '';
+
+               $this->fixture->_callRef('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
+               $query = $this->cleanSql($this->fixture->SELECTquery($selectFields, $fromTables, $whereClause, $groupBy, $orderBy));
+
+               $expected = 'SELECT MAX("ext_tt_news_cat"."cat_uid") AS "biggest_id" FROM "ext_tt_news_cat"';
+               $expected .= ' INNER JOIN "ext_tt_news_cat_mm" ON "ext_tt_news_cat"."cat_uid"="ext_tt_news_cat_mm"."uid_foreign"';
+               $expected .= ' WHERE "ext_tt_news_cat_mm"."local_uid" > 50';
+               $this->assertEquals($expected, $query);
        }
 }
\ No newline at end of file
index 2d50593..242df01 100644 (file)
@@ -42,6 +42,11 @@ $TYPO3_CONF_VARS['EXTCONF']['dbal']['mapping'] = array(
                        'uid_local' => 'local_uid',
                ),
        ),
+       'tx_dbal_debuglog' => array(
+               'mapFieldNames' => array(
+                       'errorFlag' => 'errorflag',
+               ),
+       ),
        'tx_templavoila_datastructure' => array(
                'mapTableName' => 'tx_templavoila_ds',
        ),