}
public function testLBFactorySimpleServer() {
- global $wgDBserver, $wgDBname, $wgDBuser, $wgDBpassword, $wgDBtype;
+ global $wgDBserver, $wgDBname, $wgDBuser, $wgDBpassword, $wgDBtype, $wgSQLiteDataDir;
$servers = [
[
- 'host' => $wgDBserver,
- 'dbname' => $wgDBname,
- 'user' => $wgDBuser,
- 'password' => $wgDBpassword,
- 'type' => $wgDBtype,
- 'load' => 0,
- 'flags' => DBO_TRX // REPEATABLE-READ for consistency
+ 'host' => $wgDBserver,
+ 'dbname' => $wgDBname,
+ 'user' => $wgDBuser,
+ 'password' => $wgDBpassword,
+ 'type' => $wgDBtype,
+ 'dbDirectory' => $wgSQLiteDataDir,
+ 'load' => 0,
+ 'flags' => DBO_TRX // REPEATABLE-READ for consistency
],
];
}
public function testLBFactorySimpleServers() {
- global $wgDBserver, $wgDBname, $wgDBuser, $wgDBpassword, $wgDBtype;
+ global $wgDBserver, $wgDBname, $wgDBuser, $wgDBpassword, $wgDBtype, $wgSQLiteDataDir;
$servers = [
[ // master
- 'host' => $wgDBserver,
- 'dbname' => $wgDBname,
- 'user' => $wgDBuser,
- 'password' => $wgDBpassword,
- 'type' => $wgDBtype,
- 'load' => 0,
- 'flags' => DBO_TRX // REPEATABLE-READ for consistency
+ 'host' => $wgDBserver,
+ 'dbname' => $wgDBname,
+ 'user' => $wgDBuser,
+ 'password' => $wgDBpassword,
+ 'type' => $wgDBtype,
+ 'dbDirectory' => $wgSQLiteDataDir,
+ 'load' => 0,
+ 'flags' => DBO_TRX // REPEATABLE-READ for consistency
],
[ // emulated slave
- 'host' => $wgDBserver,
- 'dbname' => $wgDBname,
- 'user' => $wgDBuser,
- 'password' => $wgDBpassword,
- 'type' => $wgDBtype,
- 'load' => 100,
- 'flags' => DBO_TRX // REPEATABLE-READ for consistency
+ 'host' => $wgDBserver,
+ 'dbname' => $wgDBname,
+ 'user' => $wgDBuser,
+ 'password' => $wgDBpassword,
+ 'type' => $wgDBtype,
+ 'dbDirectory' => $wgSQLiteDataDir,
+ 'load' => 100,
+ 'flags' => DBO_TRX // REPEATABLE-READ for consistency
]
];
$dbw = $lb->getConnection( DB_MASTER );
$this->assertTrue( $dbw->getLBInfo( 'master' ), 'master shows as master' );
$this->assertEquals(
- $wgDBserver, $dbw->getLBInfo( 'clusterMasterHost' ), 'cluster master set' );
+ ( $wgDBserver != '' ) ? $wgDBserver : 'localhost',
+ $dbw->getLBInfo( 'clusterMasterHost' ),
+ 'cluster master set' );
$dbr = $lb->getConnection( DB_SLAVE );
$this->assertTrue( $dbr->getLBInfo( 'replica' ), 'slave shows as slave' );
$this->assertEquals(
- $wgDBserver, $dbr->getLBInfo( 'clusterMasterHost' ), 'cluster master set' );
+ ( $wgDBserver != '' ) ? $wgDBserver : 'localhost',
+ $dbr->getLBInfo( 'clusterMasterHost' ),
+ 'cluster master set' );
$factory->shutdown();
$lb->closeAll();
}
public function testLBFactoryMulti() {
- global $wgDBserver, $wgDBname, $wgDBuser, $wgDBpassword, $wgDBtype;
+ global $wgDBserver, $wgDBname, $wgDBuser, $wgDBpassword, $wgDBtype, $wgSQLiteDataDir;
$factory = new LBFactoryMulti( [
'sectionsByDB' => [],
'user' => $wgDBuser,
'password' => $wgDBpassword,
'type' => $wgDBtype,
+ 'dbDirectory' => $wgSQLiteDataDir,
'flags' => DBO_DEFAULT
],
'hostsByName' => [
}
private function newLBFactoryMulti( array $baseOverride = [], array $serverOverride = [] ) {
- global $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, $wgDBtype;
+ global $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname, $wgDBtype, $wgSQLiteDataDir;
return new LBFactoryMulti( $baseOverride + [
'sectionsByDB' => [],
'user' => $wgDBuser,
'password' => $wgDBpassword,
'type' => $wgDBtype,
+ 'dbDirectory' => $wgSQLiteDataDir,
'flags' => DBO_DEFAULT
],
'hostsByName' => [
}
public function testNiceDomains() {
- global $wgDBname;
+ global $wgDBname, $wgDBtype;
+
+ if ( $wgDBtype === 'sqlite' ) {
+ $tmpDir = $this->getNewTempDirectory();
+ $dbPath = "$tmpDir/unit_test_db.sqlite";
+ file_put_contents( $dbPath, '' );
+ $tempFsFile = new TempFSFile( $dbPath );
+ $tempFsFile->autocollect();
+ } else {
+ $dbPath = null;
+ }
- $factory = $this->newLBFactoryMulti();
+ $factory = $this->newLBFactoryMulti(
+ [],
+ [ 'dbFilePath' => $dbPath ]
+ );
$lb = $factory->getMainLB();
- $db = $lb->getConnectionRef( DB_MASTER );
- $this->assertEquals(
- $wgDBname,
- $db->getDomainID()
- );
- unset( $db );
+ if ( $wgDBtype !== 'sqlite' ) {
+ $db = $lb->getConnectionRef( DB_MASTER );
+ $this->assertEquals(
+ $wgDBname,
+ $db->getDomainID()
+ );
+ unset( $db );
+ }
/** @var Database $db */
$db = $lb->getConnection( DB_MASTER, [], '' );
);
$this->assertEquals(
- $db->addIdentifierQuotes( 'page' ),
+ $this->quoteTable( $db, 'page' ),
$db->tableName( 'page' ),
"Correct full table name"
);
$this->assertEquals(
- $db->addIdentifierQuotes( $wgDBname ) . '.' . $db->addIdentifierQuotes( 'page' ),
+ $this->quoteTable( $db, $wgDBname ) . '.' . $this->quoteTable( $db, 'page' ),
$db->tableName( "$wgDBname.page" ),
"Correct full table name"
);
$this->assertEquals(
- $db->addIdentifierQuotes( 'nice_db' ) . '.' . $db->addIdentifierQuotes( 'page' ),
+ $this->quoteTable( $db, 'nice_db' ) . '.' . $this->quoteTable( $db, 'page' ),
$db->tableName( 'nice_db.page' ),
"Correct full table name"
);
$db->getDomainID()
);
$this->assertEquals(
- $db->addIdentifierQuotes( 'my_page' ),
+ $this->quoteTable( $db, 'my_page' ),
$db->tableName( 'page' ),
"Correct full table name"
);
$this->assertEquals(
- $db->addIdentifierQuotes( 'other_nice_db' ) . '.' . $db->addIdentifierQuotes( 'page' ),
+ $this->quoteTable( $db, 'other_nice_db' ) . '.' . $this->quoteTable( $db, 'page' ),
$db->tableName( 'other_nice_db.page' ),
"Correct full table name"
);
}
public function testTrickyDomain() {
+ global $wgDBtype;
+
+ if ( $wgDBtype === 'sqlite' ) {
+ $tmpDir = $this->getNewTempDirectory();
+ $dbPath = "$tmpDir/unit_test_db.sqlite";
+ file_put_contents( $dbPath, '' );
+ $tempFsFile = new TempFSFile( $dbPath );
+ $tempFsFile->autocollect();
+ } else {
+ $dbPath = null;
+ }
+
$dbname = 'unittest-domain';
$factory = $this->newLBFactoryMulti(
- [ 'localDomain' => $dbname ], [ 'dbname' => $dbname ] );
+ [ 'localDomain' => $dbname ],
+ [ 'dbname' => $dbname, 'dbFilePath' => $dbPath ]
+ );
$lb = $factory->getMainLB();
/** @var Database $db */
$db = $lb->getConnection( DB_MASTER, [], '' );
);
$this->assertEquals(
- $db->addIdentifierQuotes( 'page' ),
+ $this->quoteTable( $db, 'page' ),
$db->tableName( 'page' ),
"Correct full table name"
);
$this->assertEquals(
- $db->addIdentifierQuotes( $dbname ) . '.' . $db->addIdentifierQuotes( 'page' ),
+ $this->quoteTable( $db, $dbname ) . '.' . $this->quoteTable( $db, 'page' ),
$db->tableName( "$dbname.page" ),
"Correct full table name"
);
$this->assertEquals(
- $db->addIdentifierQuotes( 'nice_db' ) . '.' . $db->addIdentifierQuotes( 'page' ),
+ $this->quoteTable( $db, 'nice_db' ) . '.' . $this->quoteTable( $db, 'page' ),
$db->tableName( 'nice_db.page' ),
"Correct full table name"
);
$factory->setDomainPrefix( 'my_' );
$this->assertEquals(
- $db->addIdentifierQuotes( 'my_page' ),
+ $this->quoteTable( $db, 'my_page' ),
$db->tableName( 'page' ),
"Correct full table name"
);
$this->assertEquals(
- $db->addIdentifierQuotes( 'other_nice_db' ) . '.' . $db->addIdentifierQuotes( 'page' ),
+ $this->quoteTable( $db, 'other_nice_db' ) . '.' . $this->quoteTable( $db, 'page' ),
$db->tableName( 'other_nice_db.page' ),
"Correct full table name"
);
\MediaWiki\restoreWarnings();
$this->assertEquals(
- $db->addIdentifierQuotes( 'garbage-db' ) . '.' . $db->addIdentifierQuotes( 'page' ),
+ $this->quoteTable( $db, 'garbage-db' ) . '.' . $this->quoteTable( $db, 'page' ),
$db->tableName( 'garbage-db.page' ),
"Correct full table name"
);
$factory->closeAll();
$factory->destroy();
}
+
+ private function quoteTable( Database $db, $table ) {
+ if ( $db->getType() === 'sqlite' ) {
+ return $table;
+ } else {
+ return $db->addIdentifierQuotes( $table );
+ }
+ }
}