*/
const DB_PREFIX = 'unittest_';
const ORA_DB_PREFIX = 'ut_';
-
+
protected $supportedDBs = array(
'mysql',
'sqlite',
$this->backupGlobals = false;
$this->backupStaticAttributes = false;
}
-
+
function run( PHPUnit_Framework_TestResult $result = NULL ) {
/* Some functions require some kind of caching, and will end up using the db,
* which we can't allow, as that would open a new connection for mysql.
ObjectCache::$instances[CACHE_DB] = new HashBagOStuff;
if( $this->needsDB() ) {
-
+
global $wgDBprefix;
-
+
$this->db = wfGetDB( DB_MASTER );
-
+
$this->checkDbIsSupported();
$this->oldTablePrefix = $wgDBprefix;
$this->addCoreDBData();
$this->addDBData();
-
+
parent::run( $result );
$this->resetDB();
function dbPrefix() {
return $this->db->getType() == 'oracle' ? self::ORA_DB_PREFIX : self::DB_PREFIX;
}
-
+
function needsDB() {
$rc = new ReflectionClass( $this );
return strpos( $rc->getDocComment(), '@group Database' ) !== false;
* implement this method and do so
*/
function addDBData() {}
-
+
private function addCoreDBData() {
User::resetIdByNameCache();
//Make sysop user
$user = User::newFromName( 'UTSysop' );
-
+
if ( $user->idForName() == 0 ) {
$user->addToDatabase();
$user->setPassword( 'UTSysopPassword' );
$user->saveSettings();
}
-
+
//Make 1 page with 1 revision
$article = new Article( Title::newFromText( 'UTPage' ) );
$article->doEdit( 'UTContent',
false,
User::newFromName( 'UTSysop' ) );
}
-
+
private function initDB() {
global $wgDBprefix;
if ( $wgDBprefix === $this->dbPrefix() ) {
private function assertEmpty2( $value, $msg ) {
return $this->assertTrue( $value == '', $msg );
}
-
+
static private function unprefixTable( $tableName ) {
global $wgDBprefix;
return substr( $tableName, strlen( $wgDBprefix ) );
}
return $tables;
}
-
+
protected function checkDbIsSupported() {
if( !in_array( $this->db->getType(), $this->supportedDBs ) ) {
throw new MWException( $this->db->getType() . " is not currently supported for unit testing." );
}
}
-
+
public function getCliArg( $offset ) {
-
+
if( isset( MediaWikiPHPUnitCommand::$additionalOptions[$offset] ) ) {
return MediaWikiPHPUnitCommand::$additionalOptions[$offset];
}
-
+
}
-
+
public function setCliArg( $offset, $value ) {
-
+
MediaWikiPHPUnitCommand::$additionalOptions[$offset] = $value;
-
+
}
}