00001 <?php
00002
00003 class DatabaseTest extends PHPUnit_Framework_TestCase {
00004 var $db;
00005
00006 function setUp() {
00007 $this->db = wfGetDB( DB_SLAVE );
00008 }
00009
00010 function testAddQuotesNull() {
00011 $this->assertEquals(
00012 'NULL',
00013 $this->db->addQuotes( NULL ) );
00014 }
00015
00016 function testAddQuotesInt() {
00017 # returning just "1234" should be ok too, though...
00018 # maybe
00019 $this->assertEquals(
00020 "'1234'",
00021 $this->db->addQuotes( 1234 ) );
00022 }
00023
00024 function testAddQuotesFloat() {
00025 # returning just "1234.5678" would be ok too, though
00026 $this->assertEquals(
00027 "'1234.5678'",
00028 $this->db->addQuotes( 1234.5678 ) );
00029 }
00030
00031 function testAddQuotesString() {
00032 $this->assertEquals(
00033 "'string'",
00034 $this->db->addQuotes( 'string' ) );
00035 }
00036
00037 function testAddQuotesStringQuote() {
00038 $this->assertEquals(
00039 "'string\'s cause trouble'",
00040 $this->db->addQuotes( "string's cause trouble" ) );
00041 }
00042
00043 function testFillPreparedEmpty() {
00044 $sql = $this->db->fillPrepared(
00045 'SELECT * FROM interwiki', array() );
00046 $this->assertEquals(
00047 "SELECT * FROM interwiki",
00048 $sql);
00049 }
00050
00051 function testFillPreparedQuestion() {
00052 $sql = $this->db->fillPrepared(
00053 'SELECT * FROM cur WHERE cur_namespace=? AND cur_title=?',
00054 array( 4, "Snicker's_paradox" ) );
00055 $this->assertEquals(
00056 "SELECT * FROM cur WHERE cur_namespace='4' AND cur_title='Snicker\'s_paradox'",
00057 $sql);
00058 }
00059
00060 function testFillPreparedBang() {
00061 $sql = $this->db->fillPrepared(
00062 'SELECT user_id FROM ! WHERE user_name=?',
00063 array( '"user"', "Slash's Dot" ) );
00064 $this->assertEquals(
00065 "SELECT user_id FROM \"user\" WHERE user_name='Slash\'s Dot'",
00066 $sql);
00067 }
00068
00069 function testFillPreparedRaw() {
00070 $sql = $this->db->fillPrepared(
00071 "SELECT * FROM cur WHERE cur_title='This_\\&_that,_WTF\\?\\!'",
00072 array( '"user"', "Slash's Dot" ) );
00073 $this->assertEquals(
00074 "SELECT * FROM cur WHERE cur_title='This_&_that,_WTF?!'",
00075 $sql);
00076 }
00077
00078 }
00079
00080