00001 <?php
00002
00003 class MockDatabaseSqlite extends DatabaseSqliteStandalone {
00004 var $lastQuery;
00005
00006 function __construct( ) {
00007 parent::__construct( '' );
00008 }
00009
00010 function query( $sql, $fname = '', $tempIgnore = false ) {
00011 $this->lastQuery = $sql;
00012 return true;
00013 }
00014
00015 function replaceVars( $s ) {
00016 return parent::replaceVars( $s );
00017 }
00018 }
00019
00020 class DatabaseSqliteTest extends PHPUnit_Framework_TestCase {
00021 var $db;
00022
00023 function setup() {
00024 if ( !extension_loaded( 'pdo_sqlite' ) ) {
00025 $this->markTestIncomplete( 'No SQLite support detected' );
00026 }
00027 $this->db = new MockDatabaseSqlite();
00028 }
00029
00030 function replaceVars( $sql ) {
00031
00032 return preg_replace( '/\s+/', ' ', $this->db->replaceVars( $sql ) );
00033 }
00034
00035 function testReplaceVars() {
00036 $this->assertEquals( 'foo', $this->replaceVars( 'foo' ), "Don't break anything accidentally" );
00037
00038 $this->assertEquals( "CREATE TABLE /**/foo (foo_key INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "
00039 . "foo_name TEXT NOT NULL DEFAULT '', foo_int INTEGER, foo_int2 INTEGER );",
00040 $this->replaceVars( "CREATE TABLE /**/foo (foo_key int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
00041 foo_name varchar(255) binary NOT NULL DEFAULT '', foo_int tinyint( 8 ), foo_int2 int(16) ) ENGINE=MyISAM;" )
00042 );
00043
00044 $this->assertEquals( "CREATE TABLE foo ( foo_binary1 BLOB, foo_binary2 BLOB );",
00045 $this->replaceVars( "CREATE TABLE foo ( foo_binary1 binary(16), foo_binary2 varbinary(32) );" )
00046 );
00047
00048 $this->assertEquals( "CREATE TABLE text ( text_foo TEXT );",
00049 $this->replaceVars( "CREATE TABLE text ( text_foo tinytext );" ),
00050 'Table name changed'
00051 );
00052
00053 $this->assertEquals( "ALTER TABLE foo ADD COLUMN foo_bar INTEGER DEFAULT 42",
00054 $this->replaceVars( "ALTER TABLE foo\nADD COLUMN foo_bar int(10) unsigned DEFAULT 42")
00055 );
00056 }
00057 }