6 class DatabaseTest
extends MediaWikiTestCase
{
10 $this->db
= wfGetDB( DB_SLAVE
);
13 function testAddQuotesNull() {
15 if ( $this->db
->getType() === 'sqlite' ) {
18 $this->assertEquals( $check, $this->db
->addQuotes( null ) );
21 function testAddQuotesInt() {
22 # returning just "1234" should be ok too, though...
26 $this->db
->addQuotes( 1234 ) );
29 function testAddQuotesFloat() {
30 # returning just "1234.5678" would be ok too, though
33 $this->db
->addQuotes( 1234.5678 ) );
36 function testAddQuotesString() {
39 $this->db
->addQuotes( 'string' ) );
42 function testAddQuotesStringQuote() {
43 $check = "'string''s cause trouble'";
44 if ( $this->db
->getType() === 'mysql' ) {
45 $check = "'string\'s cause trouble'";
49 $this->db
->addQuotes( "string's cause trouble" ) );
52 function testFillPreparedEmpty() {
53 $sql = $this->db
->fillPrepared(
54 'SELECT * FROM interwiki', array() );
56 "SELECT * FROM interwiki",
60 function testFillPreparedQuestion() {
61 $sql = $this->db
->fillPrepared(
62 'SELECT * FROM cur WHERE cur_namespace=? AND cur_title=?',
63 array( 4, "Snicker's_paradox" ) );
65 $check = "SELECT * FROM cur WHERE cur_namespace='4' AND cur_title='Snicker''s_paradox'";
66 if ( $this->db
->getType() === 'mysql' ) {
67 $check = "SELECT * FROM cur WHERE cur_namespace='4' AND cur_title='Snicker\'s_paradox'";
69 $this->assertEquals( $check, $sql );
72 function testFillPreparedBang() {
73 $sql = $this->db
->fillPrepared(
74 'SELECT user_id FROM ! WHERE user_name=?',
75 array( '"user"', "Slash's Dot" ) );
77 $check = "SELECT user_id FROM \"user\" WHERE user_name='Slash''s Dot'";
78 if ( $this->db
->getType() === 'mysql' ) {
79 $check = "SELECT user_id FROM \"user\" WHERE user_name='Slash\'s Dot'";
81 $this->assertEquals( $check, $sql );
84 function testFillPreparedRaw() {
85 $sql = $this->db
->fillPrepared(
86 "SELECT * FROM cur WHERE cur_title='This_\\&_that,_WTF\\?\\!'",
87 array( '"user"', "Slash's Dot" ) );
89 "SELECT * FROM cur WHERE cur_title='This_&_that,_WTF?!'",
93 function testMakeNotInList() {
96 $this->db
->makeList( array(
97 'field' => array( 0, 1 )
101 "field NOT IN ('0','1')",
102 $this->db
->makeList( array(
103 'field!' => array( 0, 1 )
107 // make sure an array with only one value use = or !=
110 $this->db
->makeList( array(
111 'field' => array( 777 )
116 $this->db
->makeList( array(
117 'field!' => array( 888 )