summaryrefslogtreecommitdiff
path: root/tests/phpunit/MediaWikiTestCase.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit/MediaWikiTestCase.php')
-rw-r--r--tests/phpunit/MediaWikiTestCase.php113
1 files changed, 76 insertions, 37 deletions
diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php
index 64cb486b..6ec8bdc7 100644
--- a/tests/phpunit/MediaWikiTestCase.php
+++ b/tests/phpunit/MediaWikiTestCase.php
@@ -11,6 +11,9 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
protected $db;
protected $oldTablePrefix;
protected $useTemporaryTables = true;
+ protected $reuseDB = false;
+ protected $tablesUsed = array(); // tables with data
+
private static $dbSetup = false;
/**
@@ -22,6 +25,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
protected $supportedDBs = array(
'mysql',
'sqlite',
+ 'postgres',
'oracle'
);
@@ -40,8 +44,10 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
ObjectCache::$instances[CACHE_DB] = new HashBagOStuff;
if( $this->needsDB() ) {
-
global $wgDBprefix;
+
+ $this->useTemporaryTables = !$this->getCliArg( 'use-normal-tables' );
+ $this->reuseDB = $this->getCliArg('reuse-db');
$this->db = wfGetDB( DB_MASTER );
@@ -81,6 +87,34 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
function addDBData() {}
private function addCoreDBData() {
+ # disabled for performance
+ #$this->tablesUsed[] = 'page';
+ #$this->tablesUsed[] = 'revision';
+
+ if ( $this->db->getType() == 'oracle' ) {
+
+ # Insert 0 user to prevent FK violations
+ # Anonymous user
+ $this->db->insert( 'user', array(
+ 'user_id' => 0,
+ 'user_name' => 'Anonymous' ), __METHOD__, array( 'IGNORE' ) );
+
+ # Insert 0 page to prevent FK violations
+ # Blank page
+ $this->db->insert( 'page', array(
+ 'page_id' => 0,
+ 'page_namespace' => 0,
+ 'page_title' => ' ',
+ 'page_restrictions' => NULL,
+ 'page_counter' => 0,
+ 'page_is_redirect' => 0,
+ 'page_is_new' => 0,
+ 'page_random' => 0,
+ 'page_touched' => $this->db->timestamp(),
+ 'page_latest' => 0,
+ 'page_len' => 0 ), __METHOD__, array( 'IGNORE' ) );
+
+ }
User::resetIdByNameCache();
@@ -98,12 +132,14 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
//Make 1 page with 1 revision
- $article = new Article( Title::newFromText( 'UTPage' ) );
- $article->doEdit( 'UTContent',
+ $page = WikiPage::factory( Title::newFromText( 'UTPage' ) );
+ if ( !$page->getId() == 0 ) {
+ $page->doEdit( 'UTContent',
'UTPageSummary',
EDIT_NEW,
false,
User::newFromName( 'UTSysop' ) );
+ }
}
private function initDB() {
@@ -112,18 +148,20 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
throw new MWException( 'Cannot run unit tests, the database prefix is already "unittest_"' );
}
- $dbClone = new CloneDatabase( $this->db, $this->listTables(), $this->dbPrefix() );
+ $tablesCloned = $this->listTables();
+ $dbClone = new CloneDatabase( $this->db, $tablesCloned, $this->dbPrefix() );
$dbClone->useTemporaryTables( $this->useTemporaryTables );
- $dbClone->cloneTableStructure();
+
+ if ( ( $this->db->getType() == 'oracle' || !$this->useTemporaryTables ) && $this->reuseDB ) {
+ CloneDatabase::changePrefix( $this->dbPrefix() );
+ $this->resetDB();
+ return;
+ } else {
+ $dbClone->cloneTableStructure();
+ }
if ( $this->db->getType() == 'oracle' ) {
$this->db->query( 'BEGIN FILL_WIKI_INFO; END;' );
-
- # Insert 0 user to prevent FK violations
- # Anonymous user
- $this->db->insert( 'user', array(
- 'user_id' => 0,
- 'user_name' => 'Anonymous' ) );
}
}
@@ -132,35 +170,25 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
*/
private function resetDB() {
if( $this->db ) {
- foreach( $this->listTables() as $tbl ) {
- if( $tbl == 'interwiki' || $tbl == 'user' ) continue;
- $this->db->delete( $tbl, '*', __METHOD__ );
+ if ( $this->db->getType() == 'oracle' ) {
+ if ( $this->useTemporaryTables ) {
+ wfGetLB()->closeAll();
+ $this->db = wfGetDB( DB_MASTER );
+ } else {
+ foreach( $this->tablesUsed as $tbl ) {
+ if( $tbl == 'interwiki') continue;
+ $this->db->query( 'TRUNCATE TABLE '.$this->db->tableName($tbl), __METHOD__ );
+ }
+ }
+ } else {
+ foreach( $this->tablesUsed as $tbl ) {
+ if( $tbl == 'interwiki' || $tbl == 'user' ) continue;
+ $this->db->delete( $tbl, '*', __METHOD__ );
+ }
}
}
}
- protected function destroyDB() {
- if ( $this->useTemporaryTables || is_null( $this->db ) ) {
- # Don't need to do anything
- return;
- }
-
- $tables = $this->db->listTables( $this->dbPrefix(), __METHOD__ );
-
- foreach ( $tables as $table ) {
- try {
- $sql = $this->db->getType() == 'oracle' ? "DROP TABLE $table CASCADE CONSTRAINTS PURGE" : "DROP TABLE `$table`";
- $this->db->query( $sql, __METHOD__ );
- } catch( MWException $mwe ) {}
- }
-
- if ( $this->db->getType() == 'oracle' )
- $this->db->query( 'BEGIN FILL_WIKI_INFO; END;', __METHOD__ );
-
- CloneDatabase::changePrefix( $this->oldTablePrefix );
- }
-
-
function __call( $func, $args ) {
static $compatibility = array(
'assertInternalType' => 'assertType',
@@ -235,5 +263,16 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
public static function disableInterwikis( $prefix, &$data ) {
return false;
}
-}
+ /**
+ * Don't throw a warning if $function is deprecated and called later
+ *
+ * @param $function String
+ * @return null
+ */
+ function hideDeprecated( $function ) {
+ wfSuppressWarnings();
+ wfDeprecated( $function );
+ wfRestoreWarnings();
+ }
+}