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 $check = "NULL"; 00012 if ( $this->db->getType() === 'sqlite' ) { 00013 $check = "''"; 00014 } 00015 $this->assertEquals( $check, $this->db->addQuotes( null ) ); 00016 } 00017 00018 function testAddQuotesInt() { 00019 # returning just "1234" should be ok too, though... 00020 # maybe 00021 $this->assertEquals( 00022 "'1234'", 00023 $this->db->addQuotes( 1234 ) ); 00024 } 00025 00026 function testAddQuotesFloat() { 00027 # returning just "1234.5678" would be ok too, though 00028 $this->assertEquals( 00029 "'1234.5678'", 00030 $this->db->addQuotes( 1234.5678 ) ); 00031 } 00032 00033 function testAddQuotesString() { 00034 $this->assertEquals( 00035 "'string'", 00036 $this->db->addQuotes( 'string' ) ); 00037 } 00038 00039 function testAddQuotesStringQuote() { 00040 $check = "'string''s cause trouble'"; 00041 if ( $this->db->getType() === 'mysql' ) { 00042 $check = "'string\'s cause trouble'"; 00043 } 00044 $this->assertEquals( 00045 $check, 00046 $this->db->addQuotes( "string's cause trouble" ) ); 00047 } 00048 00049 function testFillPreparedEmpty() { 00050 $sql = $this->db->fillPrepared( 00051 'SELECT * FROM interwiki', array() ); 00052 $this->assertEquals( 00053 "SELECT * FROM interwiki", 00054 $sql); 00055 } 00056 00057 function testFillPreparedQuestion() { 00058 $sql = $this->db->fillPrepared( 00059 'SELECT * FROM cur WHERE cur_namespace=? AND cur_title=?', 00060 array( 4, "Snicker's_paradox" ) ); 00061 00062 $check = "SELECT * FROM cur WHERE cur_namespace='4' AND cur_title='Snicker''s_paradox'"; 00063 if ( $this->db->getType() === 'mysql' ) { 00064 $check = "SELECT * FROM cur WHERE cur_namespace='4' AND cur_title='Snicker\'s_paradox'"; 00065 } 00066 $this->assertEquals( $check, $sql ); 00067 } 00068 00069 function testFillPreparedBang() { 00070 $sql = $this->db->fillPrepared( 00071 'SELECT user_id FROM ! WHERE user_name=?', 00072 array( '"user"', "Slash's Dot" ) ); 00073 00074 $check = "SELECT user_id FROM \"user\" WHERE user_name='Slash''s Dot'"; 00075 if ( $this->db->getType() === 'mysql' ) { 00076 $check = "SELECT user_id FROM \"user\" WHERE user_name='Slash\'s Dot'"; 00077 } 00078 $this->assertEquals( $check, $sql ); 00079 } 00080 00081 function testFillPreparedRaw() { 00082 $sql = $this->db->fillPrepared( 00083 "SELECT * FROM cur WHERE cur_title='This_\\&_that,_WTF\\?\\!'", 00084 array( '"user"', "Slash's Dot" ) ); 00085 $this->assertEquals( 00086 "SELECT * FROM cur WHERE cur_title='This_&_that,_WTF?!'", 00087 $sql); 00088 } 00089 00090 } 00091 00092