X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fdb%2FDatabaseSQLTest.php;h=0c9f7495a77cbc0734cf63fde5886b4c4aaa8ee1;hb=329d5b3516daa2a338101a6625f2f8513cf443fa;hp=0df5a460804eba6aa46d6c6c62d5fc991be50bfc;hpb=cddcb353fb67171fefe4cd4277b4e138d78fcdcd;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/db/DatabaseSQLTest.php b/tests/phpunit/includes/db/DatabaseSQLTest.php index 0df5a46080..0c9f7495a7 100644 --- a/tests/phpunit/includes/db/DatabaseSQLTest.php +++ b/tests/phpunit/includes/db/DatabaseSQLTest.php @@ -8,15 +8,15 @@ */ class DatabaseSQLTest extends MediaWikiTestCase { - public function setUp() { + protected function setUp() { // TODO support other DBMS or find another way to do it - if( $this->db->getType() !== 'mysql' ) { + if ( $this->db->getType() !== 'mysql' ) { $this->markTestSkipped( 'No mysql database' ); } } /** - * @dataProvider dataSelectSQLText + * @dataProvider provideSelectSQLText */ function testSelectSQLText( $sql, $sqlText ) { $this->assertEquals( trim( $this->db->selectSQLText( @@ -29,7 +29,7 @@ class DatabaseSQLTest extends MediaWikiTestCase { ) ), $sqlText ); } - function dataSelectSQLText() { + public static function provideSelectSQLText() { return array( array( array( @@ -70,11 +70,43 @@ 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 + * @dataProvider provideConditional */ function testConditional( $sql, $sqlText ) { $this->assertEquals( trim( $this->db->conditional( @@ -84,7 +116,7 @@ class DatabaseSQLTest extends MediaWikiTestCase { ) ), $sqlText ); } - function dataConditional() { + public static function provideConditional() { return array( array( array( @@ -94,6 +126,14 @@ class DatabaseSQLTest extends MediaWikiTestCase { ), "(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',