Revert "Revert "jQuery 1.8""
[lhc/web/wiklou.git] / tests / phpunit / includes / db / DatabaseSQLTest.php
1 <?php
2
3 /**
4 * Test the abstract database layer
5 * Using Mysql for the sql at the moment TODO
6 *
7 * @group Database
8 */
9 class DatabaseSQLTest extends MediaWikiTestCase {
10
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' );
15 }
16 }
17
18 /**
19 * @dataProvider dataSQL
20 */
21 function testSQL( $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(),
26 __METHOD__,
27 isset( $sql['options'] ) ? $sql['options'] : array(),
28 isset( $sql['join_conds'] ) ? $sql['join_conds'] : array()
29 ) ), $sqlText );
30 }
31
32 function dataSQL() {
33 return array(
34 array(
35 array(
36 'tables' => 'table',
37 'fields' => array( 'field', 'alias' => 'field2' ),
38 'conds' => array( 'alias' => 'text' ),
39 ),
40 "SELECT field,field2 AS alias " .
41 "FROM `unittest_table` " .
42 "WHERE alias = 'text'"
43 ),
44 array(
45 array(
46 'tables' => 'table',
47 'fields' => array( 'field', 'alias' => 'field2' ),
48 'conds' => array( 'alias' => 'text' ),
49 'options' => array( 'LIMIT' => 1, 'ORDER BY' => 'field' ),
50 ),
51 "SELECT field,field2 AS alias " .
52 "FROM `unittest_table` " .
53 "WHERE alias = 'text' " .
54 "ORDER BY field " .
55 "LIMIT 1"
56 ),
57 array(
58 array(
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'
65 )),
66 ),
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' " .
70 "ORDER BY field " .
71 "LIMIT 1"
72 ),
73 );
74 }
75 }