PrefixSearchTest, SearchEnginePrefixTest: ignore ext. special pages
authorMatthew Flaschen <mflaschen@wikimedia.org>
Thu, 3 Mar 2016 07:16:53 +0000 (02:16 -0500)
committerMatthew Flaschen <mflaschen@wikimedia.org>
Fri, 29 Apr 2016 19:53:37 +0000 (15:53 -0400)
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
tests/phpunit/includes/search/SearchEnginePrefixTest.php

index 6d5154f..0ec200c 100644 (file)
@@ -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 ) {
index 9ed5244..e0de588 100644 (file)
@@ -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 ) {