follow up r60832 and follow up r60763
[mediawiki.git] / tests / DatabaseTest.php
blobaa50de2ec8ddde24a6e9c45b48a38be27afa2486
1 <?php
3 class DatabaseTest extends PHPUnit_Framework_TestCase {
4 var $db;
6 function setUp() {
7 $this->db = wfGetDB( DB_SLAVE );
10 function testAddQuotesNull() {
11 $check = "NULL";
12 if ( $this->db->getType() === 'sqlite' ) {
13 $check = "''";
15 $this->assertEquals( $check, $this->db->addQuotes( null ) );
18 function testAddQuotesInt() {
19 # returning just "1234" should be ok too, though...
20 # maybe
21 $this->assertEquals(
22 "'1234'",
23 $this->db->addQuotes( 1234 ) );
26 function testAddQuotesFloat() {
27 # returning just "1234.5678" would be ok too, though
28 $this->assertEquals(
29 "'1234.5678'",
30 $this->db->addQuotes( 1234.5678 ) );
33 function testAddQuotesString() {
34 $this->assertEquals(
35 "'string'",
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'";
44 $this->assertEquals(
45 $check,
46 $this->db->addQuotes( "string's cause trouble" ) );
49 function testFillPreparedEmpty() {
50 $sql = $this->db->fillPrepared(
51 'SELECT * FROM interwiki', array() );
52 $this->assertEquals(
53 "SELECT * FROM interwiki",
54 $sql);
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" ) );
85 $this->assertEquals(
86 "SELECT * FROM cur WHERE cur_title='This_&_that,_WTF?!'",
87 $sql);