Modified the tests so that a database is not unnecessarily required.
authorPlatonides <platonides@users.mediawiki.org>
Mon, 1 Nov 2010 18:23:33 +0000 (18:23 +0000)
committerPlatonides <platonides@users.mediawiki.org>
Mon, 1 Nov 2010 18:23:33 +0000 (18:23 +0000)
Database group for tests needing a db. The other tests should be runnable without a server running!
Destructive group for tests which modify the db.

Added two more actions to the makefile: safe and databaseless

maintenance/tests/phpunit/Makefile
maintenance/tests/phpunit/bootstrap.php
maintenance/tests/phpunit/includes/LanguageConverterTest.php
maintenance/tests/phpunit/includes/MessageTest.php
maintenance/tests/phpunit/includes/TitlePermissionTest.php
maintenance/tests/phpunit/includes/api/ApiTest.php
maintenance/tests/phpunit/includes/api/ApiWatchTest.php
maintenance/tests/phpunit/includes/db/DatabaseTest.php
maintenance/tests/phpunit/includes/search/SearchDbTest.php
maintenance/tests/phpunit/includes/search/SearchEngineTest.php
maintenance/tests/phpunit/includes/search/SearchUpdateTest.php

index dd3399c..e14c5b1 100644 (file)
@@ -1,4 +1,4 @@
-.PHONY: help test phpunit install coverage warning destructive parser noparser list-groups
+.PHONY: help test phpunit install coverage warning destructive parser noparser safe databaseless list-groups
 .DEFAULT: warning
 
 SHELL = /bin/sh
@@ -10,14 +10,21 @@ all test: warning
 
 warning:
        # Use 'make help' to get usage
-       @echo "WARNING -- these tests are DESTRUCTIVE and will alter your wiki."
+       @echo "WARNING -- some tests are DESTRUCTIVE and will alter your wiki."
        @echo "DO NOT RUN THESE TESTS on a production wiki."
        @echo ""
        @echo "Until the default suites are made non-destructive, you can run"
        @echo "the destructive tests like so:"
-       @echo ""
        @echo "  make destructive"
        @echo ""
+       @echo "Some tests are expected to be safe, you can run them with"
+       @echo "  make safe"
+       @echo ""
+       @echo "You are recommended to run them with read-only credentials, though."
+       @echo ""
+       @echo "If you don't have a database running, you can still run"
+       @echo "  make databaseless"
+       @echo ""
 
 destructive: phpunit
 
@@ -39,6 +46,12 @@ parser:
 noparser:
        ${PU} --exclude-group Parser,Broken
 
+safe:
+       ${PU} --exclude-group Broken,Destructive
+
+databaseless:
+       ${PU} --exclude-group Broken,Destructive,Database
+
 list-groups:
        ${PU} --list-groups
 
index d38652c..81beb2b 100644 (file)
@@ -28,6 +28,18 @@ dependencies.
 EOF;
 }
 
+global $wgLocalisationCacheConf, $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType;
+global $wgMessageCache, $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry;
+$wgLocalisationCacheConf['storeClass'] =  'LCStore_Null';
+$wgMainCacheType = CACHE_NONE;
+$wgMessageCacheType = CACHE_NONE;
+$wgParserCacheType = CACHE_NONE;
+$wgUseDatabaseMessages = false; # Set for future resets
+
+# The message cache was already created in Setup.php
+$wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
+       array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry ) );
+
 /* Classes */
 
 abstract class MediaWikiTestSetup extends PHPUnit_Framework_TestCase {
index 3eb83c9..f22bfc6 100644 (file)
@@ -62,6 +62,7 @@ class LanguageConverterTest extends PHPUnit_Framework_TestCase {
                $wgUser = new User;
                $wgUser->setId( 1 );
                $wgUser->mDataLoaded = true;
+               $wgUser->mOptionsLoaded = true;
                $wgUser->setOption( 'variant', 'tg-latn' );
 
                $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant() );
@@ -74,6 +75,8 @@ class LanguageConverterTest extends PHPUnit_Framework_TestCase {
                $wgRequest->setVal( 'variant', 'tg' );
                $wgUser = User::newFromId( "admin" );
                $wgUser->setId( 1 );
+               $wgUser->mDataLoaded = true;
+               $wgUser->mOptionsLoaded = true;
                $wgUser->setOption( 'variant', 'tg-latn' ); // The user's data is ignored
                                                                                                  // because the variant is set in the URL.
                $this->assertEquals( 'tg', $this->lc->getPreferredVariant() );
index 0c01144..65c368a 100644 (file)
@@ -8,7 +8,7 @@ class MessageTest extends PHPUnit_Framework_TestCase {
                $wgLanguageCode = 'en'; # For mainpage to be 'Main Page'
                //Note that a Stub Object is not enough for this test
                $wgContLang = $wgLang = Language::factory( $wgLanguageCode );
-               $wgMessageCache = new MessageCache( false, true, 3600 );
+               $wgMessageCache = new MessageCache( false, false, 3600 );
        }
 
        function testExists() {
index 4e910dd..d24359f 100644 (file)
@@ -1,5 +1,9 @@
 <?php
 
+/**
+ * @group Database
+ * @group Destructive
+ */
 class TitlePermissionTest extends PHPUnit_Framework_TestCase {
        static $title;
        static $user;
index 389fa40..2f1deec 100644 (file)
@@ -18,6 +18,7 @@ class MockApi extends ApiBase {
 }
 
 /**
+ * @group Database
  * @group Destructive
  */
 class ApiTest extends ApiTestSetup {
index 08595d8..e16ea31 100644 (file)
@@ -3,6 +3,7 @@
 require_once dirname( __FILE__ ) . '/ApiSetup.php';
 
 /**
+ * @group Database
  * @group Destructive
  */
 class ApiWatchTest extends ApiTestSetup {
index 96a1c1a..b184331 100644 (file)
@@ -1,5 +1,8 @@
 <?php
 
+/**
+ * @group Database
+ */
 class DatabaseTest extends PHPUnit_Framework_TestCase {
        var $db;
 
index f35e8b3..fb2bcc1 100644 (file)
@@ -2,6 +2,10 @@
 
 require_once( dirname( __FILE__ ) . '/SearchEngineTest.php' );
 
+/**
+ * @group Database
+ * @group Destructive
+ */
 class SearchDbTest extends SearchEngineTest {
        var $db;
 
index 88a3787..22a1d9d 100644 (file)
@@ -5,6 +5,7 @@ require_once dirname(dirname(dirname(__FILE__))). '/bootstrap.php';
 /**
  * This class is not directly tested. Instead it is extended by SearchDbTest.
  * @group Stub
+ * @group Destructive
  */
 class SearchEngineTest extends MediaWikiTestSetup {
        var $db, $search, $pageList;
index 58af596..fd2d70f 100644 (file)
@@ -73,6 +73,9 @@ class SearchUpdateTest extends PHPUnit_Framework_TestCase {
                $wgDBtype = 'mock';
                $wgLBFactoryConf['class'] = 'LBFactory_Simple';
                $wgDBservers = null;
+
+               # We need to reset the LoadBalancer in order to bypass its cache and get the mock db
+               wfGetLBFactory()->destroyInstance();
                $wgContLang = Language::factory( 'en' );
        }