note to self: think before commit
[lhc/web/wiklou.git] / tests / DatabaseTest.php
1 <?php
2
3 require_once( 'PHPUnit.php' );
4 require_once( '../includes/Defines.php' );
5 require_once( '../includes/Database.php' );
6 require_once( '../includes/GlobalFunctions.php' );
7
8 class DatabaseTest extends PHPUnit_TestCase {
9 var $db;
10
11 function DatabaseTest( $name ) {
12 $this->PHPUnit_TestCase( $name );
13 }
14
15 function setUp() {
16 $this->db =& new Database();
17 }
18
19 function tearDown() {
20 unset( $this->db );
21 }
22
23 function testAddQuotesNull() {
24 $this->assertEquals(
25 'NULL',
26 $this->db->addQuotes( NULL ) );
27 }
28
29 function testAddQuotesInt() {
30 # returning just "1234" should be ok too, though...
31 # maybe
32 $this->assertEquals(
33 "'1234'",
34 $this->db->addQuotes( 1234 ) );
35 }
36
37 function testAddQuotesFloat() {
38 # returning just "1234.5678" would be ok too, though
39 $this->assertEquals(
40 "'1234.5678'",
41 $this->db->addQuotes( 1234.5678 ) );
42 }
43
44 function testAddQuotesString() {
45 $this->assertEquals(
46 "'string'",
47 $this->db->addQuotes( 'string' ) );
48 }
49
50 function testAddQuotesStringQuote() {
51 $this->assertEquals(
52 "'string\'s cause trouble'",
53 $this->db->addQuotes( "string's cause trouble" ) );
54 }
55
56 function testFillPreparedEmpty() {
57 $sql = $this->db->fillPrepared(
58 'SELECT * FROM interwiki', array() );
59 $this->assertEquals(
60 "SELECT * FROM interwiki",
61 $sql);
62 }
63
64 function testFillPreparedQuestion() {
65 $sql = $this->db->fillPrepared(
66 'SELECT * FROM cur WHERE cur_namespace=? AND cur_title=?',
67 array( 4, "Snicker's_paradox" ) );
68 $this->assertEquals(
69 "SELECT * FROM cur WHERE cur_namespace='4' AND cur_title='Snicker\'s_paradox'",
70 $sql);
71 }
72
73 function testFillPreparedBang() {
74 $sql = $this->db->fillPrepared(
75 'SELECT user_id FROM ! WHERE user_name=?',
76 array( '"user"', "Slash's Dot" ) );
77 $this->assertEquals(
78 "SELECT user_id FROM \"user\" WHERE user_name='Slash\'s Dot'",
79 $sql);
80 }
81
82 function testFillPreparedRaw() {
83 $sql = $this->db->fillPrepared(
84 "SELECT * FROM cur WHERE cur_title='This_\\&_that,_WTF\\?\\!'",
85 array( '"user"', "Slash's Dot" ) );
86 $this->assertEquals(
87 "SELECT * FROM cur WHERE cur_title='This_&_that,_WTF?!'",
88 $sql);
89 }
90
91 }
92
93 ?>