From b257385ff2267075d8b389e9103eeabdf09a6578 Mon Sep 17 00:00:00 2001 From: Matthew Flaschen Date: Thu, 3 Mar 2016 02:16:53 -0500 Subject: [PATCH] PrefixSearchTest, SearchEnginePrefixTest: ignore ext. special pages It was attempting to do this before, but it didn't handle special pages registered by hook, and was not clearing the list properly (so it was too late when wgSpecialPages was cleared). This would cause the test to fail if certain extensions were installed (e.g. AbuseFilter). Change-Id: I9affac5ad00e97326ebf9961bbf709ac22aef498 --- tests/phpunit/includes/PrefixSearchTest.php | 19 +++++++++++++++++- .../search/SearchEnginePrefixTest.php | 20 ++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/includes/PrefixSearchTest.php b/tests/phpunit/includes/PrefixSearchTest.php index 6d5154f418..0ec200c163 100644 --- a/tests/phpunit/includes/PrefixSearchTest.php +++ b/tests/phpunit/includes/PrefixSearchTest.php @@ -4,6 +4,7 @@ * @group Database */ class PrefixSearchTest extends MediaWikiLangTestCase { + private $originalHandlers; public function addDBDataOnce() { if ( !$this->isWikitextNS( NS_MAIN ) ) { @@ -40,7 +41,23 @@ class PrefixSearchTest extends MediaWikiLangTestCase { } // Avoid special pages from extensions interferring with the tests - $this->setMwGlobals( 'wgSpecialPages', [] ); + $this->setMwGlobals( [ + 'wgSpecialPages' => [], + 'wgHooks' => [], + ] ); + + $this->originalHandlers = TestingAccessWrapper::newFromClass( 'Hooks' )->handlers; + TestingAccessWrapper::newFromClass( 'Hooks' )->handlers = []; + + SpecialPageFactory::resetList(); + } + + public function tearDown() { + parent::tearDown(); + + TestingAccessWrapper::newFromClass( 'Hooks' )->handlers = $this->originalHandlers; + + SpecialPageFactory::resetList(); } protected function searchProvision( array $results = null ) { diff --git a/tests/phpunit/includes/search/SearchEnginePrefixTest.php b/tests/phpunit/includes/search/SearchEnginePrefixTest.php index 9ed52444ea..e0de58866f 100644 --- a/tests/phpunit/includes/search/SearchEnginePrefixTest.php +++ b/tests/phpunit/includes/search/SearchEnginePrefixTest.php @@ -6,6 +6,7 @@ use MediaWiki\MediaWikiServices; * @group Database */ class SearchEnginePrefixTest extends MediaWikiLangTestCase { + private $originalHandlers; /** * @var SearchEngine @@ -47,9 +48,26 @@ class SearchEnginePrefixTest extends MediaWikiLangTestCase { } // Avoid special pages from extensions interferring with the tests - $this->setMwGlobals( 'wgSpecialPages', [] ); + $this->setMwGlobals( [ + 'wgSpecialPages' => [], + 'wgHooks' => [], + ] ); + $this->search = MediaWikiServices::getInstance()->newSearchEngine(); $this->search->setNamespaces( [] ); + + $this->originalHandlers = TestingAccessWrapper::newFromClass( 'Hooks' )->handlers; + TestingAccessWrapper::newFromClass( 'Hooks' )->handlers = []; + + SpecialPageFactory::resetList(); + } + + public function tearDown() { + parent::tearDown(); + + TestingAccessWrapper::newFromClass( 'Hooks' )->handlers = $this->originalHandlers; + + SpecialPageFactory::resetList(); } protected function searchProvision( array $results = null ) { -- 2.20.1