0df5a460804eba6aa46d6c6c62d5fc991be50bfc
4 * Test the abstract database layer
5 * Using Mysql for the sql at the moment TODO
9 class DatabaseSQLTest
extends MediaWikiTestCase
{
11 public function setUp() {
12 // TODO support other DBMS or find another way to do it
13 if( $this->db
->getType() !== 'mysql' ) {
14 $this->markTestSkipped( 'No mysql database' );
19 * @dataProvider dataSelectSQLText
21 function testSelectSQLText( $sql, $sqlText ) {
22 $this->assertEquals( trim( $this->db
->selectSQLText(
23 isset( $sql['tables'] ) ?
$sql['tables'] : array(),
24 isset( $sql['fields'] ) ?
$sql['fields'] : array(),
25 isset( $sql['conds'] ) ?
$sql['conds'] : array(),
27 isset( $sql['options'] ) ?
$sql['options'] : array(),
28 isset( $sql['join_conds'] ) ?
$sql['join_conds'] : array()
32 function dataSelectSQLText() {
37 'fields' => array( 'field', 'alias' => 'field2' ),
38 'conds' => array( 'alias' => 'text' ),
40 "SELECT field,field2 AS alias " .
41 "FROM `unittest_table` " .
42 "WHERE alias = 'text'"
47 'fields' => array( 'field', 'alias' => 'field2' ),
48 'conds' => array( 'alias' => 'text' ),
49 'options' => array( 'LIMIT' => 1, 'ORDER BY' => 'field' ),
51 "SELECT field,field2 AS alias " .
52 "FROM `unittest_table` " .
53 "WHERE alias = 'text' " .
59 'tables' => array( 'table', 't2' => 'table2' ),
60 'fields' => array( 'tid', 'field', 'alias' => 'field2', 't2.id' ),
61 'conds' => array( 'alias' => 'text' ),
62 'options' => array( 'LIMIT' => 1, 'ORDER BY' => 'field' ),
63 'join_conds' => array( 't2' => array(
64 'LEFT JOIN', 'tid = t2.id'
67 "SELECT tid,field,field2 AS alias,t2.id " .
68 "FROM `unittest_table` LEFT JOIN `unittest_table2` `t2` ON ((tid = t2.id)) " .
69 "WHERE alias = 'text' " .
77 * @dataProvider dataConditional
79 function testConditional( $sql, $sqlText ) {
80 $this->assertEquals( trim( $this->db
->conditional(
87 function dataConditional() {
91 'conds' => array( 'field' => 'text' ),
95 "(CASE WHEN field = 'text' THEN 1 ELSE NULL END)"
103 "(CASE WHEN field=1 THEN 1 ELSE NULL END)"