aa50de2ec8ddde24a6e9c45b48a38be27afa2486
[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 $check = "NULL";
12 if ( $this->db->getType() === 'sqlite' ) {
13 $check = "''";
14 }
15 $this->assertEquals( $check, $this->db->addQuotes( null ) );
16 }
17
18 function testAddQuotesInt() {
19 # returning just "1234" should be ok too, though...
20 # maybe
21 $this->assertEquals(
22 "'1234'",
23 $this->db->addQuotes( 1234 ) );
24 }
25
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 ) );
31 }
32
33 function testAddQuotesString() {
34 $this->assertEquals(
35 "'string'",
36 $this->db->addQuotes( 'string' ) );
37 }
38
39 function testAddQuotesStringQuote() {
40 $check = "'string''s cause trouble'";
41 if ( $this->db->getType() === 'mysql' ) {
42 $check = "'string\'s cause trouble'";
43 }
44 $this->assertEquals(
45 $check,
46 $this->db->addQuotes( "string's cause trouble" ) );
47 }
48
49 function testFillPreparedEmpty() {
50 $sql = $this->db->fillPrepared(
51 'SELECT * FROM interwiki', array() );
52 $this->assertEquals(
53 "SELECT * FROM interwiki",
54 $sql);
55 }
56
57 function testFillPreparedQuestion() {
58 $sql = $this->db->fillPrepared(
59 'SELECT * FROM cur WHERE cur_namespace=? AND cur_title=?',
60 array( 4, "Snicker's_paradox" ) );
61
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'";
65 }
66 $this->assertEquals( $check, $sql );
67 }
68
69 function testFillPreparedBang() {
70 $sql = $this->db->fillPrepared(
71 'SELECT user_id FROM ! WHERE user_name=?',
72 array( '"user"', "Slash's Dot" ) );
73
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'";
77 }
78 $this->assertEquals( $check, $sql );
79 }
80
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);
88 }
89
90 }
91
92