* Modified MediaWiki_Setup to use the normal mechanism to get a database connection
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sun, 7 Feb 2010 16:42:50 +0000 (16:42 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sun, 7 Feb 2010 16:42:50 +0000 (16:42 +0000)
* Include commandLine.inc from bootstrap.php to get admin credentials
* Marked SearchEngineTest as stub and exclude it

maintenance/tests/MediaWiki_Setup.php
maintenance/tests/SearchEngineTest.php
maintenance/tests/SearchMySQL4Test.php
maintenance/tests/bootstrap.php
maintenance/tests/phpunit.xml

index da42893..c0fba27 100644 (file)
@@ -1,45 +1,40 @@
 <?php
 
 abstract class MediaWiki_Setup extends PHPUnit_Framework_TestCase {
-       /**
-        * @param string $serverType
-        * @param array $tables
-        */
+
        protected function buildTestDatabase( $tables ) {
-               global $testOptions, $wgDBprefix, $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname;
-               $this->markTestIncomplete("This test requires DB admin user credentials.");
-               $wgDBprefix = 'parsertest_';
+               global $wgDBprefix;
+
+               $db = wfGetDB( DB_MASTER );
+               $oldTableNames = array();
+               foreach( $tables as $table )
+                       $oldTableNames[$table] = $db->tableName( $table );
+               $db->tablePrefix( 'parsertest_' );
 
-               $db = new DatabaseMysql(
-                       $wgDBserver,
-                       $wgDBadminuser,
-                       $wgDBadminpassword,
-                       $wgDBname );
                if( $db->isOpen() ) {
-                       if (!(strcmp($db->getServerVersion(), '4.1') < 0 and stristr($db->getSoftwareLink(), 'MySQL'))) {
+                       if ( !( strcmp( $db->getServerVersion(), '4.1' ) < 0 and $db->getType() == 'mysql' ) ) {
                                # Database that supports CREATE TABLE ... LIKE
-                               foreach ($tables as $tbl) {
+                               foreach ( $tables as $tbl ) {
                                        $newTableName = $db->tableName( $tbl );
-                                       #$tableName = $this->oldTableNames[$tbl];
-                                       $tableName = $tbl;
-                                       $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName)");
+                                       $tableName = $oldTableNames[$tbl];
+                                       $db->query( "CREATE TEMPORARY TABLE $newTableName (LIKE $tableName)" );
                                }
                        } else {
                                # Hack for MySQL versions < 4.1, which don't support
                                # "CREATE TABLE ... LIKE". Note that
                                # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
                                # would not create the indexes we need....
-                               foreach ($tables as $tbl) {
-                                       $res = $db->query("SHOW CREATE TABLE $tbl");
+                               foreach ( $tables as $tbl ) {
+                                       $res = $db->query( "SHOW CREATE TABLE $tbl" );
                                        $row = $db->fetchRow($res);
                                        $create = $row[1];
-                                       $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `'
-                                               . $wgDBprefix . '\\1`', $create);
+                                       $create_tmp = preg_replace( '/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `'
+                                               . $wgDBprefix . '\\1`', $create );
                                        if ($create === $create_tmp) {
                                                # Couldn't do replacement
                                                wfDie( "could not create temporary table $tbl" );
                                        }
-                                       $db->query($create_tmp);
+                                       $db->query( $create_tmp );
                                }
 
                        }
index dd3367a..0cae2d4 100644 (file)
@@ -2,9 +2,9 @@
 
 require_once( 'MediaWiki_Setup.php' );
 
-/** @todo document
+/**
+ * @group Stub
  */
-
 class SearchEngineTest extends MediaWiki_Setup {
        var $db, $search;
 
index 4fe4d54..e3bee86 100644 (file)
@@ -16,7 +16,7 @@ class SearchMySQL4Test extends SearchEngineTest {
 
        function tearDown() {
                if( !is_null( $this->db ) ) {
-                       $this->db->close();
+                       wfGetLB()->closeConnecton( $this->db );
                }
                unset( $this->db );
                unset( $this->search );
index 91ffdbe..019bee0 100644 (file)
@@ -7,20 +7,9 @@
  * @file
  */
 
-global $wgCommandLineMode, $IP;
-$wgCommandLineMode = true;
+global $wgCommandLineMode, $IP, $optionsWithArgs;
 $IP = dirname( dirname( dirname( __FILE__ ) ) );
-
-define( 'MEDIAWIKI', true );
 define( 'MW_PHPUNIT_TEST', true );
 
-require_once( "$IP/includes/Defines.php" );
-require_once( "$IP/includes/AutoLoader.php" );
-require_once( "$IP/LocalSettings.php" );
-require_once( "$IP/includes/ProfilerStub.php" );
-require_once( "$IP/includes/GlobalFunctions.php" );
-require_once( "$IP/includes/Hooks.php" );
-$self = __FILE__;
-require_once( "$IP/includes/Setup.php" );
-
+require_once( "$IP/maintenance/commandLine.inc" );
 
index 58e50e6..ce7d44f 100644 (file)
@@ -11,6 +11,7 @@
   <groups>
     <exclude>
       <group>Broken</group>
+      <group>Stub</group>
     </exclude>
   </groups>
 </phpunit>
\ No newline at end of file