Follow up r85922 moving the </caption> to another line, fixing one of the tests added...
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiTestCase.php
index 48b6212..8e3d215 100644 (file)
@@ -23,19 +23,19 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
        );
 
        function  __construct( $name = null, array $data = array(), $dataName = '' ) {
-               if ($name !== null) {
-                       $this->setName($name);
-               }
+               parent::__construct( $name, $data, $dataName );
 
-               $this->data = $data;
-               $this->dataName = $dataName;
-               
                $this->backupGlobals = false;
-        $this->backupStaticAttributes = 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.
+                * Replace with a HashBag. They would not be going to persist anyway.
+                */
+               ObjectCache::$instances[CACHE_DB] = new HashBagOStuff;
+                  
                if( $this->needsDB() ) {
                
                        global $wgDBprefix;
@@ -68,6 +68,10 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                        $this->destroyDB();
                }
        }
+
+       function dbPrefix() {
+               return $this->db->getType() == 'oracle' ? self::ORA_DB_PREFIX : self::DB_PREFIX;
+       }
        
        function needsDB() {
                $rc = new ReflectionClass( $this );
@@ -111,16 +115,14 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
 
                $dbType = $this->db->getType();
                
-               if ( $wgDBprefix === self::DB_PREFIX || ( $dbType == 'oracle' && $wgDBprefix === self::ORA_DB_PREFIX ) ) {
+               if ( $wgDBprefix === $this->dbPrefix() ) {
                        throw new MWException( 'Cannot run unit tests, the database prefix is already "unittest_"' );
                }
 
                $tables = $this->listTables();
                
-               $prefix = $dbType != 'oracle' ? self::DB_PREFIX : self::ORA_DB_PREFIX;
-               
-               $this->dbClone = new CloneDatabase( $this->db, $tables, $prefix );
-               $this->dbClone->useTemporaryTables( false ); //reported problems with temp tables, disabling until fixed
+               $this->dbClone = new CloneDatabase( $this->db, $tables, $this->dbPrefix() );
+               $this->dbClone->useTemporaryTables( $this->useTemporaryTables );
                $this->dbClone->cloneTableStructure();
                
                if ( $dbType == 'oracle' )
@@ -149,12 +151,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                        return;
                }
                
-               if( $this->db->getType() == 'oracle' ) {
-                       $tables = $this->db->listTables( self::ORA_DB_PREFIX, __METHOD__ );
-               }
-               else {
-                       $tables = $this->db->listTables( self::DB_PREFIX, __METHOD__ );
-               }
+               $tables = $this->db->listTables( $this->dbPrefix(), __METHOD__ );
                
                foreach ( $tables as $table ) {
                        try {
@@ -175,6 +172,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                        'assertInternalType' => 'assertType',
                        'assertNotInternalType' => 'assertNotType',
                        'assertInstanceOf' => 'assertType',
+                       'assertEmpty' => 'assertEmpty2',
                );
 
                if ( method_exists( $this->suite, $func ) ) {
@@ -186,6 +184,10 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                                . get_class( $this ) );
                }
        }
+
+       private function assertEmpty2( $value, $msg ) {
+               return $this->assertTrue( $value == '', $msg );
+       }
        
        static private function unprefixTable( $tableName ) {
                global $wgDBprefix;
@@ -197,6 +199,15 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                
                $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 );
+               }
                return $tables;
                
        }