w/s changes.
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiTestCase.php
index deea8a0..a88c357 100644 (file)
@@ -12,14 +12,13 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
        protected $oldTablePrefix;
        protected $useTemporaryTables = true;
        private static $dbSetup = false;
-       private static $dbTables = null;
 
        /**
         * Table name prefixes. Oracle likes it shorter.
         */
        const DB_PREFIX = 'unittest_';
        const ORA_DB_PREFIX = 'ut_';
-       
+
        protected $supportedDBs = array(
                'mysql',
                'sqlite',
@@ -32,7 +31,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                $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.
@@ -41,11 +40,11 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                ObjectCache::$instances[CACHE_DB] = new HashBagOStuff;
 
                if( $this->needsDB() ) {
-               
+
                        global $wgDBprefix;
-                       
+
                        $this->db = wfGetDB( DB_MASTER );
-                       
+
                        $this->checkDbIsSupported();
 
                        $this->oldTablePrefix = $wgDBprefix;
@@ -57,7 +56,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
 
                        $this->addCoreDBData();
                        $this->addDBData();
-                       
+
                        parent::run( $result );
 
                        $this->resetDB();
@@ -69,7 +68,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
        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;
@@ -80,14 +79,14 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
         * 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' );
@@ -97,7 +96,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                        $user->saveSettings();
                }
 
-               
+
                //Make 1 page with 1 revision
                $article = new Article( Title::newFromText( 'UTPage' ) );
                $article->doEdit( 'UTContent',
@@ -106,7 +105,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                                                        false,
                                                        User::newFromName( 'UTSysop' ) );
        }
-       
+
        private function initDB() {
                global $wgDBprefix;
                if ( $wgDBprefix === $this->dbPrefix() ) {
@@ -183,51 +182,54 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
        private function assertEmpty2( $value, $msg ) {
                return $this->assertTrue( $value == '', $msg );
        }
-       
+
        static private function unprefixTable( $tableName ) {
                global $wgDBprefix;
                return substr( $tableName, strlen( $wgDBprefix ) );
        }
 
+       static private function isNotUnittest( $table ) {
+               return strpos( $table, 'unittest_' ) !== 0;
+       }
+
        protected function listTables() {
                global $wgDBprefix;
 
-               if( is_null( self::$dbTables ) ) {
-                       $tables = $this->db->listTables( $wgDBprefix, __METHOD__ );
-                       $tables = array_map( array( __CLASS__, 'unprefixTable' ), $tables );
-
-                       if ( $this->db->getType() == 'sqlite' ) {
-                               $tables = array_flip( $tables );
-                               // these are subtables of searchindex and don't need to be duped/dropped separately
-                               unset( $tables['searchindex_content'] );
-                               unset( $tables['searchindex_segdir'] );
-                               unset( $tables['searchindex_segments'] );
-                               $tables = array_flip( $tables );
-                       }
-                       self::$dbTables = $tables;
+               $tables = $this->db->listTables( $wgDBprefix, __METHOD__ );
+               $tables = array_map( array( __CLASS__, 'unprefixTable' ), $tables );
+
+               // Don't duplicate test tables from the previous fataled run
+               $tables = array_filter( $tables, array( __CLASS__, 'isNotUnittest' ) );
+
+               if ( $this->db->getType() == 'sqlite' ) {
+                       $tables = array_flip( $tables );
+                       // these are subtables of searchindex and don't need to be duped/dropped separately
+                       unset( $tables['searchindex_content'] );
+                       unset( $tables['searchindex_segdir'] );
+                       unset( $tables['searchindex_segments'] );
+                       $tables = array_flip( $tables );
                }
-               return self::$dbTables;
-               
+               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;
-               
+
        }
 }