Complete coverage of Xml::DateMenu()
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiTestCase.php
index 0134b3f..da02fe7 100644 (file)
@@ -9,20 +9,22 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
        protected $dbClone;
        protected $oldTablePrefix;
        protected $useTemporaryTables = true;
+
+       /**
+        * Table name prefixes. Oracle likes it shorter.
+        */
+       const DB_PREFIX = 'unittest_';
+       const ORA_DB_PREFIX = 'ut_';
        
        protected $supportedDBs = array(
                'mysql',
-               'sqlite'
+               'sqlite',
+               'oracle'
        );
 
        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;
        }
@@ -66,11 +68,17 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                $rc = new ReflectionClass( $this );
                return strpos( $rc->getDocComment(), '@group Database' ) !== false;
        }
-       
+
+       /**
+        * Stub. If a test needs to add additional data to the database, it should
+        * implement this method and do so
+        */
        function addDBData() {}
        
        private function addCoreDBData() {
-               
+
+               User::resetIdByNameCache();
+
                //Make sysop user
                $user = User::newFromName( 'UTSysop' );
                
@@ -98,13 +106,13 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
 
                $dbType = $this->db->getType();
                
-               if ( $wgDBprefix === 'unittest_' || ( $dbType == 'oracle' && $wgDBprefix === 'ut_' ) ) {
+               if ( $wgDBprefix === self::DB_PREFIX || ( $dbType == 'oracle' && $wgDBprefix === self::ORA_DB_PREFIX ) ) {
                        throw new MWException( 'Cannot run unit tests, the database prefix is already "unittest_"' );
                }
 
                $tables = $this->listTables();
                
-               $prefix = $dbType != 'oracle' ? 'unittest_' : 'ut_';
+               $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
@@ -125,7 +133,6 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
        }
        
        protected function destroyDB() {
-               global $wgDBprefix;
                
                if ( $this->useTemporaryTables ) {
                        # Don't need to do anything
@@ -138,15 +145,15 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                }
                
                if( $this->db->getType() == 'oracle' ) {
-                       $tables = $this->db->listTables( 'ut_', __METHOD__ );
+                       $tables = $this->db->listTables( self::ORA_DB_PREFIX, __METHOD__ );
                }
                else {
-                       $tables = $this->db->listTables( 'unittest_', __METHOD__ );
+                       $tables = $this->db->listTables( self::DB_PREFIX, __METHOD__ );
                }
                
                foreach ( $tables as $table ) {
                        try {
-                               $sql = $this->db->getType() == 'oracle' ? "DROP TABLE $table DROP CONSTRAINTS" : "DROP TABLE `$table`";
+                               $sql = $this->db->getType() == 'oracle' ? "DROP TABLE $table CASCADE CONSTRAINTS PURGE" : "DROP TABLE `$table`";
                                $this->db->query( $sql, __METHOD__ );
                        } catch( Exception $e ) {
                        }