Mass convert NULL -> null. Left strings and comments alone, obviously.
[lhc/web/wiklou.git] / tests / DatabaseTest.php
1 <?php
2
3 class DatabaseTest extends PHPUnit_Framework_TestCase {
4 var $db;
5
6 function setUp() {
7 $this->db = wfGetDB( DB_SLAVE );
8 }
9
10 function testAddQuotesNull() {
11 $this->assertEquals(
12 'NULL',
13 $this->db->addQuotes( null ) );
14 }
15
16 function testAddQuotesInt() {
17 # returning just "1234" should be ok too, though...
18 # maybe
19 $this->assertEquals(
20 "'1234'",
21 $this->db->addQuotes( 1234 ) );
22 }
23
24 function testAddQuotesFloat() {
25 # returning just "1234.5678" would be ok too, though
26 $this->assertEquals(
27 "'1234.5678'",
28 $this->db->addQuotes( 1234.5678 ) );
29 }
30
31 function testAddQuotesString() {
32 $this->assertEquals(
33 "'string'",
34 $this->db->addQuotes( 'string' ) );
35 }
36
37 function testAddQuotesStringQuote() {
38 $this->assertEquals(
39 "'string\'s cause trouble'",
40 $this->db->addQuotes( "string's cause trouble" ) );
41 }
42
43 function testFillPreparedEmpty() {
44 $sql = $this->db->fillPrepared(
45 'SELECT * FROM interwiki', array() );
46 $this->assertEquals(
47 "SELECT * FROM interwiki",
48 $sql);
49 }
50
51 function testFillPreparedQuestion() {
52 $sql = $this->db->fillPrepared(
53 'SELECT * FROM cur WHERE cur_namespace=? AND cur_title=?',
54 array( 4, "Snicker's_paradox" ) );
55 $this->assertEquals(
56 "SELECT * FROM cur WHERE cur_namespace='4' AND cur_title='Snicker\'s_paradox'",
57 $sql);
58 }
59
60 function testFillPreparedBang() {
61 $sql = $this->db->fillPrepared(
62 'SELECT user_id FROM ! WHERE user_name=?',
63 array( '"user"', "Slash's Dot" ) );
64 $this->assertEquals(
65 "SELECT user_id FROM \"user\" WHERE user_name='Slash\'s Dot'",
66 $sql);
67 }
68
69 function testFillPreparedRaw() {
70 $sql = $this->db->fillPrepared(
71 "SELECT * FROM cur WHERE cur_title='This_\\&_that,_WTF\\?\\!'",
72 array( '"user"', "Slash's Dot" ) );
73 $this->assertEquals(
74 "SELECT * FROM cur WHERE cur_title='This_&_that,_WTF?!'",
75 $sql);
76 }
77
78 }
79
80