From: daniel Date: Mon, 7 Mar 2016 17:26:25 +0000 (+0100) Subject: Avoid rebuilding database fixtures for every test run X-Git-Tag: 1.31.0-rc.0~7655^2 X-Git-Url: https://git.heureux-cyclage.org/index.php?a=commitdiff_plain;h=a8995619c1bc0c0880962a266a0398bc87d1b7ae;p=lhc%2Fweb%2Fwiklou.git Avoid rebuilding database fixtures for every test run This reduces the runtime of database-bound tests by about 40% (on my system, from 4:55 to 2:47; results from Jenkins are inconclusive). The basic idea is to call addCoreDBData() only once, and have a addDBDataOnce() that is called once per test class, not for every test method lie addDBData() is. Most tests could be trivially be changed to implement addDBDataOnce() instead of addDBData(). The ones for which this did not work immediately were left out for now. A closer look at the tests that still implement addDBData() may reveal additional potential for improvement. TODO: Once this is merged, try to change addDBData() to addDBDataOnce() where possible in extensions. Change-Id: Iec4ed4c8419fb4ad87e6710de808863ede9998b7 --- diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index 3bd5ed852b..b9cf51d17a 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -134,12 +134,20 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { if ( !self::$dbSetup ) { // switch to a temporary clone of the database self::setupTestDB( $this->db, $this->dbPrefix() ); + $this->addCoreDBData(); if ( ( $this->db->getType() == 'oracle' || !self::$useTemporaryTables ) && self::$reuseDB ) { $this->resetDB(); } } - $this->addCoreDBData(); + + // TODO: the DB setup should be done in setUpBeforeClass(), so the test DB + // is available in subclasse's setUpBeforeClass() and setUp() methods. + // This would also remove the need for the HACK that is oncePerClass(). + if ( $this->oncePerClass() ) { + $this->addDBDataOnce(); + } + $this->addDBData(); $needsResetDB = true; } @@ -151,6 +159,22 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { } } + /** + * @return boolean + */ + private function oncePerClass() { + // Remember current test class in the database connection, + // so we know when we need to run addData. + + $class = static::class; + + $first = !isset( $this->db->_hasDataForTestClass ) + || $this->db->_hasDataForTestClass !== $class; + + $this->db->_hasDataForTestClass = $class; + return $first; + } + /** * @since 1.21 * @@ -554,8 +578,29 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { } /** - * Stub. If a test needs to add additional data to the database, it should - * implement this method and do so + * Stub. If a test suite needs to add additional data to the database, it should + * implement this method and do so. This method is called once per test suite + * (i.e. once per class). + * + * Note data added by this method may be removed by resetDB() depending on + * the contents of $tablesUsed. + * + * To add additional data between test function runs, override prepareDB(). + * + * @see addDBData() + * @see resetDB() + * + * @since 1.27 + */ + public function addDBDataOnce() { + } + + /** + * Stub. Subclasses may override this to prepare the database. + * Called before every test run (test function or data set). + * + * @see addDBDataOnce() + * @see resetDB() * * @since 1.18 */ @@ -702,23 +747,16 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { */ private function resetDB() { if ( $this->db ) { - if ( $this->db->getType() == 'oracle' ) { - if ( self::$useTemporaryTables ) { - wfGetLB()->closeAll(); - $this->db = wfGetDB( DB_MASTER ); - } else { - foreach ( $this->tablesUsed as $tbl ) { - if ( $tbl == 'interwiki' ) { - continue; - } - $this->db->query( 'TRUNCATE TABLE ' . $this->db->tableName( $tbl ), __METHOD__ ); - } + $truncate = in_array( $this->db->getType(), [ 'oracle', 'mysql' ] ); + foreach ( $this->tablesUsed as $tbl ) { + // TODO: reset interwiki and user tables to their original content. + if ( $tbl == 'interwiki' || $tbl == 'user' ) { + continue; } - } else { - foreach ( $this->tablesUsed as $tbl ) { - if ( $tbl == 'interwiki' || $tbl == 'user' ) { - continue; - } + + if ( $truncate ) { + $this->db->query( 'TRUNCATE TABLE ' . $this->db->tableName( $tbl ), __METHOD__ ); + } else { $this->db->delete( $tbl, '*', __METHOD__ ); } } @@ -1310,4 +1348,5 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { public static function wfResetOutputBuffersBarrier( $buffer ) { return $buffer; } + } diff --git a/tests/phpunit/includes/BlockTest.php b/tests/phpunit/includes/BlockTest.php index e14960ab03..35ebf42c26 100644 --- a/tests/phpunit/includes/BlockTest.php +++ b/tests/phpunit/includes/BlockTest.php @@ -14,7 +14,6 @@ class BlockTest extends MediaWikiLangTestCase { private $blockId; function addDBData() { - $user = User::newFromName( 'UTBlockee' ); if ( $user->getID() == 0 ) { $user->addToDatabase(); diff --git a/tests/phpunit/includes/MergeHistoryTest.php b/tests/phpunit/includes/MergeHistoryTest.php index 951cf8d64e..5ea0cdf2d6 100644 --- a/tests/phpunit/includes/MergeHistoryTest.php +++ b/tests/phpunit/includes/MergeHistoryTest.php @@ -8,7 +8,7 @@ class MergeHistoryTest extends MediaWikiTestCase { /** * Make some pages to work with */ - public function addDBData() { + public function addDBDataOnce() { // Pages that won't actually be merged $this->insertPage( 'Test' ); $this->insertPage( 'Test2' ); diff --git a/tests/phpunit/includes/PrefixSearchTest.php b/tests/phpunit/includes/PrefixSearchTest.php index 6f4c300a4c..6d5154f418 100644 --- a/tests/phpunit/includes/PrefixSearchTest.php +++ b/tests/phpunit/includes/PrefixSearchTest.php @@ -5,7 +5,7 @@ */ class PrefixSearchTest extends MediaWikiLangTestCase { - public function addDBData() { + public function addDBDataOnce() { if ( !$this->isWikitextNS( NS_MAIN ) ) { // tests are skipped if NS_MAIN is not wikitext return; diff --git a/tests/phpunit/includes/RevisionStorageTest.php b/tests/phpunit/includes/RevisionStorageTest.php index 16d8c97435..440495b216 100644 --- a/tests/phpunit/includes/RevisionStorageTest.php +++ b/tests/phpunit/includes/RevisionStorageTest.php @@ -57,6 +57,8 @@ class RevisionStorageTest extends MediaWikiTestCase { CONTENT_MODEL_WIKITEXT ); } + + $this->tablesUsed[] = 'archive'; } protected function tearDown() { diff --git a/tests/phpunit/includes/api/ApiBlockTest.php b/tests/phpunit/includes/api/ApiBlockTest.php index f51997c916..d2dccf997d 100644 --- a/tests/phpunit/includes/api/ApiBlockTest.php +++ b/tests/phpunit/includes/api/ApiBlockTest.php @@ -17,7 +17,7 @@ class ApiBlockTest extends ApiTestCase { return $this->getTokenList( self::$users['sysop'] ); } - function addDBData() { + function addDBDataOnce() { $user = User::newFromName( 'UTApiBlockee' ); if ( $user->getId() == 0 ) { diff --git a/tests/phpunit/includes/api/query/ApiQueryBasicTest.php b/tests/phpunit/includes/api/query/ApiQueryBasicTest.php index 9ba4587b5d..e5971b4418 100644 --- a/tests/phpunit/includes/api/query/ApiQueryBasicTest.php +++ b/tests/phpunit/includes/api/query/ApiQueryBasicTest.php @@ -36,9 +36,10 @@ class ApiQueryBasicTest extends ApiQueryTestBase { /** * Create a set of pages. These must not change, otherwise the tests might give wrong results. - * @see MediaWikiTestCase::addDBData() + * +*@see MediaWikiTestCase::addDBDataOnce() */ - function addDBData() { + function addDBDataOnce() { try { if ( Title::newFromText( 'AQBT-All' )->exists() ) { return; diff --git a/tests/phpunit/includes/api/query/ApiQueryContinue2Test.php b/tests/phpunit/includes/api/query/ApiQueryContinue2Test.php index 8f11a51168..944d31c824 100644 --- a/tests/phpunit/includes/api/query/ApiQueryContinue2Test.php +++ b/tests/phpunit/includes/api/query/ApiQueryContinue2Test.php @@ -29,9 +29,10 @@ class ApiQueryContinue2Test extends ApiQueryContinueTestBase { /** * Create a set of pages. These must not change, otherwise the tests might give wrong results. - * @see MediaWikiTestCase::addDBData() + * +*@see MediaWikiTestCase::addDBDataOnce() */ - function addDBData() { + function addDBDataOnce() { try { $this->editPage( 'AQCT73462-A', '**AQCT73462-A** [[AQCT73462-B]] [[AQCT73462-C]]' ); $this->editPage( 'AQCT73462-B', '[[AQCT73462-A]] **AQCT73462-B** [[AQCT73462-C]]' ); diff --git a/tests/phpunit/includes/api/query/ApiQueryContinueTest.php b/tests/phpunit/includes/api/query/ApiQueryContinueTest.php index a6269ed265..b31627b4d4 100644 --- a/tests/phpunit/includes/api/query/ApiQueryContinueTest.php +++ b/tests/phpunit/includes/api/query/ApiQueryContinueTest.php @@ -33,9 +33,10 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase { /** * Create a set of pages. These must not change, otherwise the tests might give wrong results. - * @see MediaWikiTestCase::addDBData() + * +*@see MediaWikiTestCase::addDBDataOnce() */ - function addDBData() { + function addDBDataOnce() { try { $this->editPage( 'Template:AQCT-T1', '**Template:AQCT-T1**' ); $this->editPage( 'Template:AQCT-T2', '**Template:AQCT-T2**' ); diff --git a/tests/phpunit/includes/cache/GenderCacheTest.php b/tests/phpunit/includes/cache/GenderCacheTest.php index a441b3d441..40994da037 100644 --- a/tests/phpunit/includes/cache/GenderCacheTest.php +++ b/tests/phpunit/includes/cache/GenderCacheTest.php @@ -6,7 +6,7 @@ */ class GenderCacheTest extends MediaWikiLangTestCase { - function addDBData() { + function addDBDataOnce() { // ensure the correct default gender $this->mergeMwGlobalArrayValue( 'wgDefaultUserOptions', [ 'gender' => 'unknown' ] ); diff --git a/tests/phpunit/includes/cache/MessageCacheTest.php b/tests/phpunit/includes/cache/MessageCacheTest.php index 38cc863a4b..bd744c01ca 100644 --- a/tests/phpunit/includes/cache/MessageCacheTest.php +++ b/tests/phpunit/includes/cache/MessageCacheTest.php @@ -23,7 +23,7 @@ class MessageCacheTest extends MediaWikiLangTestCase { $this->setContentLang( 'de' ); } - function addDBData() { + function addDBDataOnce() { $this->configureLanguages(); // Set up messages and fallbacks ab -> ru -> de diff --git a/tests/phpunit/includes/changes/CategoryMembershipChangeTest.php b/tests/phpunit/includes/changes/CategoryMembershipChangeTest.php index 70da12e2db..6369b33430 100644 --- a/tests/phpunit/includes/changes/CategoryMembershipChangeTest.php +++ b/tests/phpunit/includes/changes/CategoryMembershipChangeTest.php @@ -24,6 +24,16 @@ class CategoryMembershipChangeTest extends MediaWikiLangTestCase { */ private static $mockRecentChange; + /** + * @var Revision + */ + private static $pageRev = null; + + /** + * @var string + */ + private static $pageName = 'CategoryMembershipChangeTestPage'; + public static function newForCategorizationCallback() { self::$lastNotifyArgs = func_get_args(); self::$notifyCallCounter += 1; @@ -34,10 +44,20 @@ class CategoryMembershipChangeTest extends MediaWikiLangTestCase { parent::setUp(); self::$notifyCallCounter = 0; self::$mockRecentChange = self::getMock( 'RecentChange' ); + + $this->setContentLang( 'qqx' ); + } + + public function addDBDataOnce() { + $info = $this->insertPage( self::$pageName ); + $title = $info['title']; + + $page = WikiPage::factory( $title ); + self::$pageRev = $page->getRevision(); } private function newChange( Revision $revision = null ) { - $change = new CategoryMembershipChange( Title::newFromText( 'UTPage' ), $revision ); + $change = new CategoryMembershipChange( Title::newFromText( self::$pageName ), $revision ); $change->overrideNewForCategorizationCallback( 'CategoryMembershipChangeTest::newForCategorizationCallback' ); @@ -53,9 +73,10 @@ class CategoryMembershipChangeTest extends MediaWikiLangTestCase { $this->assertTrue( strlen( self::$lastNotifyArgs[0] ) === 14 ); $this->assertEquals( 'Category:CategoryName', self::$lastNotifyArgs[1]->getPrefixedText() ); - $this->assertEquals( 'MediaWiki automatic change', self::$lastNotifyArgs[2]->getName() ); - $this->assertEquals( '[[:UTPage]] added to category', self::$lastNotifyArgs[3] ); - $this->assertEquals( 'UTPage', self::$lastNotifyArgs[4]->getPrefixedText() ); + $this->assertEquals( '(autochange-username)', self::$lastNotifyArgs[2]->getName() ); + $this->assertEquals( '(recentchanges-page-added-to-category: ' . self::$pageName . ', 0)', + self::$lastNotifyArgs[3] ); + $this->assertEquals( self::$pageName, self::$lastNotifyArgs[4]->getPrefixedText() ); $this->assertEquals( 0, self::$lastNotifyArgs[5] ); $this->assertEquals( 0, self::$lastNotifyArgs[6] ); $this->assertEquals( null, self::$lastNotifyArgs[7] ); @@ -72,9 +93,10 @@ class CategoryMembershipChangeTest extends MediaWikiLangTestCase { $this->assertTrue( strlen( self::$lastNotifyArgs[0] ) === 14 ); $this->assertEquals( 'Category:CategoryName', self::$lastNotifyArgs[1]->getPrefixedText() ); - $this->assertEquals( 'MediaWiki automatic change', self::$lastNotifyArgs[2]->getName() ); - $this->assertEquals( '[[:UTPage]] removed from category', self::$lastNotifyArgs[3] ); - $this->assertEquals( 'UTPage', self::$lastNotifyArgs[4]->getPrefixedText() ); + $this->assertEquals( '(autochange-username)', self::$lastNotifyArgs[2]->getName() ); + $this->assertEquals( '(recentchanges-page-removed-from-category: ' . self::$pageName . ', 0)', + self::$lastNotifyArgs[3] ); + $this->assertEquals( self::$pageName, self::$lastNotifyArgs[4]->getPrefixedText() ); $this->assertEquals( 0, self::$lastNotifyArgs[5] ); $this->assertEquals( 0, self::$lastNotifyArgs[6] ); $this->assertEquals( null, self::$lastNotifyArgs[7] ); @@ -84,7 +106,7 @@ class CategoryMembershipChangeTest extends MediaWikiLangTestCase { } public function testChangeAddedWithRev() { - $revision = Revision::newFromId( Title::newFromText( 'UTPage' )->getLatestRevID() ); + $revision = Revision::newFromId( Title::newFromText( self::$pageName )->getLatestRevID() ); $change = $this->newChange( $revision ); $change->triggerCategoryAddedNotification( Title::newFromText( 'CategoryName', NS_CATEGORY ) ); @@ -93,9 +115,10 @@ class CategoryMembershipChangeTest extends MediaWikiLangTestCase { $this->assertTrue( strlen( self::$lastNotifyArgs[0] ) === 14 ); $this->assertEquals( 'Category:CategoryName', self::$lastNotifyArgs[1]->getPrefixedText() ); $this->assertEquals( 'UTSysop', self::$lastNotifyArgs[2]->getName() ); - $this->assertEquals( '[[:UTPage]] added to category', self::$lastNotifyArgs[3] ); - $this->assertEquals( 'UTPage', self::$lastNotifyArgs[4]->getPrefixedText() ); - $this->assertEquals( 0, self::$lastNotifyArgs[5] ); + $this->assertEquals( '(recentchanges-page-added-to-category: ' . self::$pageName . ', 0)', + self::$lastNotifyArgs[3] ); + $this->assertEquals( self::$pageName, self::$lastNotifyArgs[4]->getPrefixedText() ); + $this->assertEquals( self::$pageRev->getParentId(), self::$lastNotifyArgs[5] ); $this->assertEquals( $revision->getId(), self::$lastNotifyArgs[6] ); $this->assertEquals( null, self::$lastNotifyArgs[7] ); $this->assertEquals( 0, self::$lastNotifyArgs[8] ); @@ -104,7 +127,7 @@ class CategoryMembershipChangeTest extends MediaWikiLangTestCase { } public function testChangeRemovedWithRev() { - $revision = Revision::newFromId( Title::newFromText( 'UTPage' )->getLatestRevID() ); + $revision = Revision::newFromId( Title::newFromText( self::$pageName )->getLatestRevID() ); $change = $this->newChange( $revision ); $change->triggerCategoryRemovedNotification( Title::newFromText( 'CategoryName', NS_CATEGORY ) ); @@ -113,9 +136,10 @@ class CategoryMembershipChangeTest extends MediaWikiLangTestCase { $this->assertTrue( strlen( self::$lastNotifyArgs[0] ) === 14 ); $this->assertEquals( 'Category:CategoryName', self::$lastNotifyArgs[1]->getPrefixedText() ); $this->assertEquals( 'UTSysop', self::$lastNotifyArgs[2]->getName() ); - $this->assertEquals( '[[:UTPage]] removed from category', self::$lastNotifyArgs[3] ); - $this->assertEquals( 'UTPage', self::$lastNotifyArgs[4]->getPrefixedText() ); - $this->assertEquals( 0, self::$lastNotifyArgs[5] ); + $this->assertEquals( '(recentchanges-page-removed-from-category: ' . self::$pageName . ', 0)', + self::$lastNotifyArgs[3] ); + $this->assertEquals( self::$pageName, self::$lastNotifyArgs[4]->getPrefixedText() ); + $this->assertEquals( self::$pageRev->getParentId(), self::$lastNotifyArgs[5] ); $this->assertEquals( $revision->getId(), self::$lastNotifyArgs[6] ); $this->assertEquals( null, self::$lastNotifyArgs[7] ); $this->assertEquals( 0, self::$lastNotifyArgs[8] ); diff --git a/tests/phpunit/includes/db/DatabaseSqliteTest.php b/tests/phpunit/includes/db/DatabaseSqliteTest.php index 18de9be049..80fb826bf3 100644 --- a/tests/phpunit/includes/db/DatabaseSqliteTest.php +++ b/tests/phpunit/includes/db/DatabaseSqliteTest.php @@ -330,7 +330,7 @@ class DatabaseSqliteTest extends MediaWikiTestCase { foreach ( $versions as $version ) { $versions = "upgrading from $version to $wgVersion"; - $db = $this->prepareDB( $version ); + $db = $this->prepareTestDB( $version ); $tables = $this->getTables( $db ); $this->assertEquals( $currentTables, $tables, "Different tables $versions" ); foreach ( $tables as $table ) { @@ -389,7 +389,7 @@ class DatabaseSqliteTest extends MediaWikiTestCase { $this->assertTrue( $db->close(), "closing database" ); } - private function prepareDB( $version ) { + private function prepareTestDB( $version ) { static $maint = null; if ( $maint === null ) { $maint = new FakeMaintenance(); diff --git a/tests/phpunit/includes/deferred/LinksUpdateTest.php b/tests/phpunit/includes/deferred/LinksUpdateTest.php index 75af87e6d5..9609f74a14 100644 --- a/tests/phpunit/includes/deferred/LinksUpdateTest.php +++ b/tests/phpunit/includes/deferred/LinksUpdateTest.php @@ -6,7 +6,7 @@ * ^--- make sure temporary tables are used. */ class LinksUpdateTest extends MediaWikiLangTestCase { - protected $testingPageId; + protected static $testingPageId; function __construct( $name = null, array $data = [], $dataName = '' ) { parent::__construct( $name, $data, $dataName ); @@ -45,9 +45,9 @@ class LinksUpdateTest extends MediaWikiLangTestCase { $this->setMwGlobals( 'wgRCWatchCategoryMembership', true ); } - public function addDBData() { + public function addDBDataOnce() { $res = $this->insertPage( 'Testing' ); - $this->testingPageId = $res['id']; + self::$testingPageId = $res['id']; $this->insertPage( 'Some_other_page' ); $this->insertPage( 'Template:TestingTemplate' ); } @@ -68,7 +68,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase { public function testUpdate_pagelinks() { /** @var Title $t */ /** @var ParserOutput $po */ - list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", $this->testingPageId ); + list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", self::$testingPageId ); $po->addLink( Title::newFromText( "Foo" ) ); $po->addLink( Title::newFromText( "Special:Foo" ) ); // special namespace should be ignored @@ -81,7 +81,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase { 'pagelinks', 'pl_namespace, pl_title', - 'pl_from = ' . $this->testingPageId, + 'pl_from = ' . self::$testingPageId, [ [ NS_MAIN, 'Foo' ] ] ); $this->assertArrayEquals( [ @@ -100,7 +100,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase { 'pagelinks', 'pl_namespace, pl_title', - 'pl_from = ' . $this->testingPageId, + 'pl_from = ' . self::$testingPageId, [ [ NS_MAIN, 'Bar' ], [ NS_TALK, 'Bar' ], @@ -120,7 +120,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase { */ public function testUpdate_externallinks() { /** @var ParserOutput $po */ - list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", $this->testingPageId ); + list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", self::$testingPageId ); $po->addExternalLink( "http://testing.com/wiki/Foo" ); @@ -129,7 +129,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase { $po, 'externallinks', 'el_to, el_index', - 'el_from = ' . $this->testingPageId, + 'el_from = ' . self::$testingPageId, [ [ 'http://testing.com/wiki/Foo', 'http://com.testing./wiki/Foo' ], ] @@ -143,7 +143,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase { /** @var ParserOutput $po */ $this->setMwGlobals( 'wgCategoryCollation', 'uppercase' ); - list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", $this->testingPageId ); + list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", self::$testingPageId ); $po->addCategory( "Foo", "FOO" ); @@ -152,7 +152,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase { $po, 'categorylinks', 'cl_to, cl_sortkey', - 'cl_from = ' . $this->testingPageId, + 'cl_from = ' . self::$testingPageId, [ [ 'Foo', "FOO\nTESTING" ] ] ); } @@ -232,7 +232,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase { */ public function testUpdate_iwlinks() { /** @var ParserOutput $po */ - list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", $this->testingPageId ); + list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", self::$testingPageId ); $target = Title::makeTitleSafe( NS_MAIN, "Foo", '', 'linksupdatetest' ); $po->addInterwikiLink( $target ); @@ -242,7 +242,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase { $po, 'iwlinks', 'iwl_prefix, iwl_title', - 'iwl_from = ' . $this->testingPageId, + 'iwl_from = ' . self::$testingPageId, [ [ 'linksupdatetest', 'Foo' ] ] ); } @@ -252,7 +252,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase { */ public function testUpdate_templatelinks() { /** @var ParserOutput $po */ - list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", $this->testingPageId ); + list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", self::$testingPageId ); $po->addTemplate( Title::newFromText( "Template:Foo" ), 23, 42 ); @@ -262,7 +262,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase { 'templatelinks', 'tl_namespace, tl_title', - 'tl_from = ' . $this->testingPageId, + 'tl_from = ' . self::$testingPageId, [ [ NS_TEMPLATE, 'Foo' ] ] ); } @@ -272,7 +272,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase { */ public function testUpdate_imagelinks() { /** @var ParserOutput $po */ - list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", $this->testingPageId ); + list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", self::$testingPageId ); $po->addImage( "Foo.png" ); @@ -281,7 +281,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase { $po, 'imagelinks', 'il_to', - 'il_from = ' . $this->testingPageId, + 'il_from = ' . self::$testingPageId, [ [ 'Foo.png' ] ] ); } @@ -295,7 +295,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase { ] ); /** @var ParserOutput $po */ - list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", $this->testingPageId ); + list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", self::$testingPageId ); $po->addLanguageLink( Title::newFromText( "en:Foo" )->getFullText() ); @@ -304,7 +304,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase { $po, 'langlinks', 'll_lang, ll_title', - 'll_from = ' . $this->testingPageId, + 'll_from = ' . self::$testingPageId, [ [ 'En', 'Foo' ] ] ); } @@ -316,7 +316,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase { global $wgPagePropsHaveSortkey; /** @var ParserOutput $po */ - list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", $this->testingPageId ); + list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", self::$testingPageId ); $fields = [ 'pp_propname', 'pp_value' ]; $expected = []; @@ -349,7 +349,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase { } $this->assertLinksUpdate( - $t, $po, 'page_props', $fields, 'pp_page = ' . $this->testingPageId, $expected ); + $t, $po, 'page_props', $fields, 'pp_page = ' . self::$testingPageId, $expected ); } public function testUpdate_page_props_without_sortkey() { diff --git a/tests/phpunit/includes/jobqueue/jobs/CategoryMembershipChangeJobTest.php b/tests/phpunit/includes/jobqueue/jobs/CategoryMembershipChangeJobTest.php index 50a24ada24..54178fe2af 100644 --- a/tests/phpunit/includes/jobqueue/jobs/CategoryMembershipChangeJobTest.php +++ b/tests/phpunit/includes/jobqueue/jobs/CategoryMembershipChangeJobTest.php @@ -21,10 +21,11 @@ class CategoryMembershipChangeJobTest extends MediaWikiTestCase { public function setUp() { parent::setUp(); $this->setMwGlobals( 'wgRCWatchCategoryMembership', true ); + $this->setContentLang( 'qqx' ); } - public function addDBData() { - parent::addDBData(); + public function addDBDataOnce() { + parent::addDBDataOnce(); $insertResult = $this->insertPage( self::TITLE_STRING, 'UT Content' ); $this->title = $insertResult['title']; } @@ -74,11 +75,11 @@ class CategoryMembershipChangeJobTest extends MediaWikiTestCase { $removedRevId = $this->editPageText( 'Blank' ); $this->assertEquals( - '[[:' . self::TITLE_STRING . ']] added to category', + '(recentchanges-page-added-to-category: ' . self::TITLE_STRING . ', 0)', $this->getCategorizeRecentChangeForRevId( $addedRevId )->getAttribute( 'rc_comment' ) ); $this->assertEquals( - '[[:' . self::TITLE_STRING . ']] removed from category', + '(recentchanges-page-removed-from-category: ' . self::TITLE_STRING . ', 0)', $this->getCategorizeRecentChangeForRevId( $removedRevId )->getAttribute( 'rc_comment' ) ); } diff --git a/tests/phpunit/includes/parser/NewParserTest.php b/tests/phpunit/includes/parser/NewParserTest.php index 04d606782a..4eb480d4ef 100644 --- a/tests/phpunit/includes/parser/NewParserTest.php +++ b/tests/phpunit/includes/parser/NewParserTest.php @@ -211,15 +211,15 @@ class NewParserTest extends MediaWikiTestCase { parent::tearDownAfterClass(); } - function addDBData() { - $this->tablesUsed[] = 'site_stats'; + function addDBDataOnce() { # disabled for performance # $this->tablesUsed[] = 'image'; # Update certain things in site_stats $this->db->insert( 'site_stats', [ 'ss_row_id' => 1, 'ss_images' => 2, 'ss_good_articles' => 1 ], - __METHOD__ + __METHOD__, + [ 'IGNORE' ] ); $user = User::newFromId( 0 ); diff --git a/tests/phpunit/includes/search/SearchEnginePrefixTest.php b/tests/phpunit/includes/search/SearchEnginePrefixTest.php index 2a3a5fe9cf..6a3f95bb22 100644 --- a/tests/phpunit/includes/search/SearchEnginePrefixTest.php +++ b/tests/phpunit/includes/search/SearchEnginePrefixTest.php @@ -10,7 +10,7 @@ class SearchEnginePrefixTest extends MediaWikiLangTestCase { */ private $search; - public function addDBData() { + public function addDBDataOnce() { if ( !$this->isWikitextNS( NS_MAIN ) ) { // tests are skipped if NS_MAIN is not wikitext return; diff --git a/tests/phpunit/includes/search/SearchEngineTest.php b/tests/phpunit/includes/search/SearchEngineTest.php index b680d5e014..055e982377 100644 --- a/tests/phpunit/includes/search/SearchEngineTest.php +++ b/tests/phpunit/includes/search/SearchEngineTest.php @@ -44,7 +44,7 @@ class SearchEngineTest extends MediaWikiLangTestCase { parent::tearDown(); } - public function addDBData() { + public function addDBDataOnce() { if ( !$this->isWikitextNS( NS_MAIN ) ) { // @todo cover the case of non-wikitext content in the main namespace return; diff --git a/tests/phpunit/includes/session/BotPasswordSessionProviderTest.php b/tests/phpunit/includes/session/BotPasswordSessionProviderTest.php index 590f2878ba..5126a42138 100644 --- a/tests/phpunit/includes/session/BotPasswordSessionProviderTest.php +++ b/tests/phpunit/includes/session/BotPasswordSessionProviderTest.php @@ -62,7 +62,7 @@ class BotPasswordSessionProviderTest extends MediaWikiTestCase { ] ); } - public function addDBData() { + public function addDBDataOnce() { $passwordFactory = new \PasswordFactory(); $passwordFactory->init( \RequestContext::getMain()->getConfig() ); // A is unsalted MD5 (thus fast) ... we don't care about security here, this is test only diff --git a/tests/phpunit/includes/specials/SpecialMyLanguageTest.php b/tests/phpunit/includes/specials/SpecialMyLanguageTest.php index 548b75bec3..89fd1b0696 100644 --- a/tests/phpunit/includes/specials/SpecialMyLanguageTest.php +++ b/tests/phpunit/includes/specials/SpecialMyLanguageTest.php @@ -5,7 +5,7 @@ * @covers SpecialMyLanguage */ class SpecialMyLanguageTest extends MediaWikiTestCase { - public function addDBData() { + public function addDBDataOnce() { $titles = [ 'Page/Another', 'Page/Another/ru',