3 class DatabaseTest
extends PHPUnit_Framework_TestCase
{
7 $this->db
= wfGetDB( DB_SLAVE
);
10 function testAddQuotesNull() {
12 if ( $this->db
->getType() === 'sqlite' ) {
15 $this->assertEquals( $check, $this->db
->addQuotes( null ) );
18 function testAddQuotesInt() {
19 # returning just "1234" should be ok too, though...
23 $this->db
->addQuotes( 1234 ) );
26 function testAddQuotesFloat() {
27 # returning just "1234.5678" would be ok too, though
30 $this->db
->addQuotes( 1234.5678 ) );
33 function testAddQuotesString() {
36 $this->db
->addQuotes( 'string' ) );
39 function testAddQuotesStringQuote() {
40 $check = "'string''s cause trouble'";
41 if ( $this->db
->getType() === 'mysql' ) {
42 $check = "'string\'s cause trouble'";
46 $this->db
->addQuotes( "string's cause trouble" ) );
49 function testFillPreparedEmpty() {
50 $sql = $this->db
->fillPrepared(
51 'SELECT * FROM interwiki', array() );
53 "SELECT * FROM interwiki",
57 function testFillPreparedQuestion() {
58 $sql = $this->db
->fillPrepared(
59 'SELECT * FROM cur WHERE cur_namespace=? AND cur_title=?',
60 array( 4, "Snicker's_paradox" ) );
62 $check = "SELECT * FROM cur WHERE cur_namespace='4' AND cur_title='Snicker''s_paradox'";
63 if ( $this->db
->getType() === 'mysql' ) {
64 $check = "SELECT * FROM cur WHERE cur_namespace='4' AND cur_title='Snicker\'s_paradox'";
66 $this->assertEquals( $check, $sql );
69 function testFillPreparedBang() {
70 $sql = $this->db
->fillPrepared(
71 'SELECT user_id FROM ! WHERE user_name=?',
72 array( '"user"', "Slash's Dot" ) );
74 $check = "SELECT user_id FROM \"user\" WHERE user_name='Slash''s Dot'";
75 if ( $this->db
->getType() === 'mysql' ) {
76 $check = "SELECT user_id FROM \"user\" WHERE user_name='Slash\'s Dot'";
78 $this->assertEquals( $check, $sql );
81 function testFillPreparedRaw() {
82 $sql = $this->db
->fillPrepared(
83 "SELECT * FROM cur WHERE cur_title='This_\\&_that,_WTF\\?\\!'",
84 array( '"user"', "Slash's Dot" ) );
86 "SELECT * FROM cur WHERE cur_title='This_&_that,_WTF?!'",