Merge "(bug 29898) Set cookie to force HTTPS from HTTP"
[lhc/web/wiklou.git] / tests / phpunit / includes / db / DatabaseSQLTest.php
index d56e632..e37cd44 100644 (file)
@@ -16,9 +16,9 @@ class DatabaseSQLTest extends MediaWikiTestCase {
        }
 
        /**
-        * @dataProvider dataSQL
+        * @dataProvider dataSelectSQLText
         */
-       function testSQL( $sql, $sqlText ) {
+       function testSelectSQLText( $sql, $sqlText ) {
                $this->assertEquals( trim( $this->db->selectSQLText(
                        isset( $sql['tables'] ) ? $sql['tables'] : array(),
                        isset( $sql['fields'] ) ? $sql['fields'] : array(),
@@ -29,7 +29,7 @@ class DatabaseSQLTest extends MediaWikiTestCase {
                ) ), $sqlText );
        }
 
-       function dataSQL() {
+       function dataSelectSQLText() {
                return array(
                        array(
                                array(
@@ -70,6 +70,78 @@ class DatabaseSQLTest extends MediaWikiTestCase {
                                "ORDER BY field " .
                                "LIMIT 1"
                        ),
+                       array(
+                               array(
+                                       'tables' => array( 'table', 't2' => 'table2' ),
+                                       'fields' => array( 'tid', 'field', 'alias' => 'field2', 't2.id' ),
+                                       'conds' => array( 'alias' => 'text' ),
+                                       'options' => array( 'LIMIT' => 1, 'GROUP BY' => 'field', 'HAVING' => 'COUNT(*) > 1' ),
+                                       'join_conds' => array( 't2' => array(
+                                               'LEFT JOIN', 'tid = t2.id'
+                                       )),
+                               ),
+                               "SELECT  tid,field,field2 AS alias,t2.id  " .
+                               "FROM `unittest_table` LEFT JOIN `unittest_table2` `t2` ON ((tid = t2.id))  " .
+                               "WHERE alias = 'text'  " .
+                               "GROUP BY field HAVING COUNT(*) > 1 " .
+                               "LIMIT 1"
+                       ),
+                       array(
+                               array(
+                                       'tables' => array( 'table', 't2' => 'table2' ),
+                                       'fields' => array( 'tid', 'field', 'alias' => 'field2', 't2.id' ),
+                                       'conds' => array( 'alias' => 'text' ),
+                                       'options' => array( 'LIMIT' => 1, 'GROUP BY' => array( 'field', 'field2' ), 'HAVING' => array( 'COUNT(*) > 1', 'field' => 1 ) ),
+                                       'join_conds' => array( 't2' => array(
+                                               'LEFT JOIN', 'tid = t2.id'
+                                       )),
+                               ),
+                               "SELECT  tid,field,field2 AS alias,t2.id  " .
+                               "FROM `unittest_table` LEFT JOIN `unittest_table2` `t2` ON ((tid = t2.id))  " .
+                               "WHERE alias = 'text'  " .
+                               "GROUP BY field,field2 HAVING (COUNT(*) > 1) AND field = '1' " .
+                               "LIMIT 1"
+                       ),
+               );
+       }
+
+       /**
+        * @dataProvider dataConditional
+        */
+       function testConditional( $sql, $sqlText ) {
+               $this->assertEquals( trim( $this->db->conditional(
+                       $sql['conds'],
+                       $sql['true'],
+                       $sql['false']
+               ) ), $sqlText );
+       }
+
+       function dataConditional() {
+               return array(
+                       array(
+                               array(
+                                       'conds' => array( 'field' => 'text' ),
+                                       'true' => 1,
+                                       'false' => 'NULL',
+                               ),
+                               "(CASE WHEN field = 'text' THEN 1 ELSE NULL END)"
+                       ),
+                       array(
+                               array(
+                                       'conds' => array( 'field' => 'text', 'field2' => 'anothertext' ),
+                                       'true' => 1,
+                                       'false' => 'NULL',
+                               ),
+                               "(CASE WHEN field = 'text' AND field2 = 'anothertext' THEN 1 ELSE NULL END)"
+                       ),
+                       array(
+                               array(
+                                       'conds' => 'field=1',
+                                       'true' => 1,
+                                       'false' => 'NULL',
+                               ),
+                               "(CASE WHEN field=1 THEN 1 ELSE NULL END)"
+                       ),
                );
        }
 }
\ No newline at end of file