http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89301
Revision: 89301
Author: demon
Date: 2011-06-01 22:43:19 +0000 (Wed, 01 Jun 2011)
Log Message:
-----------
Test db cleanup
* Fix Oracle stuff per CR on r88755
* Don't expect tests to clean up after themselves, do it in
MediaWikiTestCase::run() (skipping user and interwiki, also per CR)
** Also don't do it from the destructor, phpunit calls this more often than
you'd think
* Need to find: way to detect "is this the last test?" so we can drop our
tables on completion
Modified Paths:
--------------
trunk/phase3/tests/phpunit/MediaWikiTestCase.php
trunk/phase3/tests/phpunit/includes/api/ApiBlockTest.php
Modified: trunk/phase3/tests/phpunit/MediaWikiTestCase.php
===================================================================
--- trunk/phase3/tests/phpunit/MediaWikiTestCase.php 2011-06-01 22:35:03 UTC
(rev 89300)
+++ trunk/phase3/tests/phpunit/MediaWikiTestCase.php 2011-06-01 22:43:19 UTC
(rev 89301)
@@ -46,7 +46,7 @@
$this->db = wfGetDB( DB_MASTER );
$this->checkDbIsSupported();
-
+
$this->oldTablePrefix = $wgDBprefix;
if( !self::$dbSetup ) {
@@ -54,24 +54,16 @@
self::$dbSetup = true;
}
- $this->resetDB();
$this->addCoreDBData();
$this->addDBData();
parent::run( $result );
- $this->removeDBData();
-
+ $this->resetDB();
} else {
parent::run( $result );
}
}
-
- function __destruct() {
- if( $this->needsDB() ) {
- $this->destroyDB();
- }
- }
function dbPrefix() {
return $this->db->getType() == 'oracle' ? self::ORA_DB_PREFIX :
self::DB_PREFIX;
@@ -87,12 +79,6 @@
* implement this method and do so
*/
function addDBData() {}
-
- /**
- * Stub. If a test needs to remove data from the database. Called after
- * test run.
- */
- function removeDBData() {}
private function addCoreDBData() {
@@ -129,6 +115,16 @@
$dbClone = new CloneDatabase( $this->db, $this->listTables(),
$this->dbPrefix() );
$dbClone->useTemporaryTables( $this->useTemporaryTables );
$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' ) );
+ }
}
/**
@@ -137,49 +133,34 @@
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' ) {
- $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' ) );
- }
}
}
-
+
protected function destroyDB() {
-
- if ( $this->useTemporaryTables ) {
+ if ( $this->useTemporaryTables || is_null( $this->db ) ) {
# Don't need to do anything
- //return;
- //Temporary tables seem to be broken ATM, delete anyway
- }
-
- if( is_null( $this->db ) ) {
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( Exception $e ) {
- }
+ } 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',
@@ -209,7 +190,7 @@
protected function listTables() {
global $wgDBprefix;
-
+
$tables = $this->db->listTables( $wgDBprefix, __METHOD__ );
$tables = array_map( array( __CLASS__, 'unprefixTable' ),
$tables );
Modified: trunk/phase3/tests/phpunit/includes/api/ApiBlockTest.php
===================================================================
--- trunk/phase3/tests/phpunit/includes/api/ApiBlockTest.php 2011-06-01
22:35:03 UTC (rev 89300)
+++ trunk/phase3/tests/phpunit/includes/api/ApiBlockTest.php 2011-06-01
22:43:19 UTC (rev 89301)
@@ -28,14 +28,6 @@
}
}
- function removeDBData() {
- $block = Block::newFromTarget('UTBlockee');
- if( $block ) {
- $block->delete();
- }
- }
-
-
function testMakeNormalBlock() {
$data = $this->getTokens();
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs