/**
* @group sqlite
+ * @group Database
*/
class DatabaseSqliteTest extends MediaWikiTestCase {
var $db;
return preg_replace( '/\s+/', ' ', $this->db->replaceVars( $sql ) );
}
+ private function assertResultIs( $expected, $res ) {
+ $this->assertNotNull( $res );
+ $i = 0;
+ foreach( $res as $row ) {
+ foreach( $expected[$i] as $key => $value ) {
+ $this->assertTrue( isset( $row->$key ) );
+ $this->assertEquals( $value, $row->$key );
+ }
+ $i++;
+ }
+ $this->assertEquals( count( $expected ), $i, 'Unexpected number of rows' );
+ }
+
public function testReplaceVars() {
$this->assertEquals( 'foo', $this->replaceVars( 'foo' ), "Don't break anything accidentally" );
$this->assertEquals( 'sqlite_master', $db->tableName( 'sqlite_master' ) );
$this->assertEquals( 'foobar', $db->tableName( 'bar' ) );
}
-
+
public function testDuplicateTableStructure() {
$db = new DatabaseSqliteStandalone( ':memory:' );
$db->query( 'CREATE TABLE foo(foo, barfoo)' );
'Create a temporary duplicate only'
);
}
-
+
public function testDuplicateTableStructureVirtual() {
$db = new DatabaseSqliteStandalone( ':memory:' );
if ( $db->getFulltextSearchModule() != 'FTS3' ) {
);
}
+ public function testDeleteJoin() {
+ $db = new DatabaseSqliteStandalone( ':memory:' );
+ $db->query( 'CREATE TABLE a (a_1)', __METHOD__ );
+ $db->query( 'CREATE TABLE b (b_1, b_2)', __METHOD__ );
+ $db->insert( 'a', array(
+ array( 'a_1' => 1 ),
+ array( 'a_1' => 2 ),
+ array( 'a_1' => 3 ),
+ ),
+ __METHOD__
+ );
+ $db->insert( 'b', array(
+ array( 'b_1' => 2, 'b_2' => 'a' ),
+ array( 'b_1' => 3, 'b_2' => 'b' ),
+ ),
+ __METHOD__
+ );
+ $db->deleteJoin( 'a', 'b', 'a_1', 'b_1', array( 'b_2' => 'a' ), __METHOD__ );
+ $res = $db->query( "SELECT * FROM a", __METHOD__ );
+ $this->assertResultIs( array(
+ array( 'a_1' => 1 ),
+ array( 'a_1' => 3 ),
+ ),
+ $res
+ );
+ }
+
public function testEntireSchema() {
global $IP;
'1.15',
'1.16',
'1.17',
+ '1.18',
);
// Mismatches for these columns we can safely ignore
$ignoredColumns = array(
'user_newtalk.user_last_timestamp', // r84185
);
-
+
$currentDB = new DatabaseSqliteStandalone( ':memory:' );
$currentDB->sourceFile( "$IP/maintenance/tables.sql" );
$currentTables = $this->getTables( $currentDB );
}
}
+ public function testInsertIdType() {
+ $db = new DatabaseSqliteStandalone( ':memory:' );
+ $this->assertInstanceOf( 'ResultWrapper',
+ $db->query( 'CREATE TABLE a ( a_1 )', __METHOD__ ), "Database creationg" );
+ $this->assertTrue( $db->insert( 'a', array( 'a_1' => 10 ), __METHOD__ ),
+ "Insertion worked" );
+ $this->assertEquals( "integer", gettype( $db->insertId() ), "Actual typecheck" );
+ $this->assertTrue( $db->close(), "closing database" );
+ }
+
private function prepareDB( $version ) {
static $maint = null;
if ( $maint === null ) {
$maint = new FakeMaintenance();
$maint->loadParamsAndArgs( null, array( 'quiet' => 1 ) );
}
-
+
+ global $IP;
$db = new DatabaseSqliteStandalone( ':memory:' );
- $db->sourceFile( dirname( __FILE__ ) . "/sqlite/tables-$version.sql" );
+ $db->sourceFile( "$IP/tests/phpunit/data/db/sqlite/tables-$version.sql" );
$updater = DatabaseUpdater::newForDB( $db, false, $maint );
$updater->doUpdates( array( 'core' ) );
return $db;
$list = array_flip( $db->listTables() );
$excluded = array(
'math', // moved out of core in 1.18
+ 'trackbacks', // removed from core in 1.19
'searchindex',
'searchindex_content',
'searchindex_segments',