From: aude Date: Fri, 3 Jan 2014 01:23:16 +0000 (+0100) Subject: Fix SearchEngineTest when $wgSearchType is set to non-default X-Git-Tag: 1.31.0-rc.0~17399^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_aide%28?a=commitdiff_plain;h=73bc21bb1cb1fc9e242686f2abbb7a302bf36823;p=lhc%2Fweb%2Fwiklou.git Fix SearchEngineTest when $wgSearchType is set to non-default $wgSearchType needs to be controlled for at time the pages get created. This patch sets the $wgSearchType global. Also, the 'singleton' is removed from SearchEngine::getSearchTypes, which appears to provide little or no benefit while binding all tests to the global variable. SearchEngine::getSearchTypes() gets called in SearchUpdate which is run on page edits. This means the first page edit in the entire test suite causes the global variable to be set and subsequent tests cannot override it. These changes allow SearchEngineTest to pass, even if one has CirrusSearch or other such extensions enabled. Change-Id: I39050da8659dc69db31125f469f494a5fb4b8fca --- diff --git a/includes/search/SearchEngine.php b/includes/search/SearchEngine.php index 71c05d8b03..15569612aa 100644 --- a/includes/search/SearchEngine.php +++ b/includes/search/SearchEngine.php @@ -485,11 +485,10 @@ class SearchEngine { */ public static function getSearchTypes() { global $wgSearchType, $wgSearchTypeAlternatives; - static $alternatives = null; - if ( $alternatives === null ) { - $alternatives = $wgSearchTypeAlternatives ?: array(); - array_unshift( $alternatives, $wgSearchType ); - } + + $alternatives = $wgSearchTypeAlternatives ?: array(); + array_unshift( $alternatives, $wgSearchType ); + return $alternatives; } diff --git a/tests/phpunit/includes/search/SearchEngineTest.php b/tests/phpunit/includes/search/SearchEngineTest.php index e4605911f0..ff360e99bb 100644 --- a/tests/phpunit/includes/search/SearchEngineTest.php +++ b/tests/phpunit/includes/search/SearchEngineTest.php @@ -8,10 +8,12 @@ * @note Coverage will only ever show one of on of the Search* classes */ class SearchEngineTest extends MediaWikiLangTestCase { + /** * @var SearchEngine */ protected $search; + protected $pageList; /** @@ -22,17 +24,23 @@ class SearchEngineTest extends MediaWikiLangTestCase { parent::setUp(); // Search tests require MySQL or SQLite with FTS - # Get database type and version $dbType = $this->db->getType(); - $dbSupported = - ( $dbType === 'mysql' ) - || ( $dbType === 'sqlite' && $this->db->getFulltextSearchModule() == 'FTS3' ); + $dbSupported = ( $dbType === 'mysql' ) + || ( $dbType === 'sqlite' && $this->db->getFulltextSearchModule() == 'FTS3' ); if ( !$dbSupported ) { $this->markTestSkipped( "MySQL or SQLite with FTS3 only" ); } $searchType = $this->db->getSearchEngine(); + $this->setMwGlobals( array( + 'wgSearchType' => $searchType + ) ); + + if ( !isset( self::$pageList ) ) { + $this->addPages(); + } + $this->search = new $searchType( $this->db ); } @@ -42,15 +50,7 @@ class SearchEngineTest extends MediaWikiLangTestCase { parent::tearDown(); } - function pageExists( $title ) { - return false; - } - - function addDBData() { - if ( $this->pageExists( 'Not_Main_Page' ) ) { - return; - } - + protected function addPages() { if ( !$this->isWikitextNS( NS_MAIN ) ) { // @todo cover the case of non-wikitext content in the main namespace return; @@ -75,12 +75,11 @@ class SearchEngineTest extends MediaWikiLangTestCase { $this->insertPage( 'DomainName', 'example.com', 0 ); } - function fetchIds( $results ) { + protected function fetchIds( $results ) { if ( !$this->isWikitextNS( NS_MAIN ) ) { $this->markTestIncomplete( __CLASS__ . " does no yet support non-wikitext content " . "in the main namespace" ); } - $this->assertTrue( is_object( $results ) ); $matches = array(); @@ -105,7 +104,7 @@ class SearchEngineTest extends MediaWikiLangTestCase { * @param $text String: page's content * @param $n Integer: unused */ - function insertPage( $pageName, $text, $ns ) { + protected function insertPage( $pageName, $text, $ns ) { $title = Title::newFromText( $pageName, $ns ); $user = User::newFromName( 'WikiSysop' ); @@ -180,4 +179,5 @@ class SearchEngineTest extends MediaWikiLangTestCase { $this->fetchIds( $this->search->searchTitle( 'smithee' ) ), "Title power search failed" ); } + }