From: aude Date: Mon, 15 Aug 2016 16:37:00 +0000 (-0400) Subject: Call parent::getFieldsForSearchIndex in ContentHandlers X-Git-Tag: 1.31.0-rc.0~5989^2~1 X-Git-Url: http://git.cyclocoop.org/wiki/Target_page?a=commitdiff_plain;h=c67536716d62b3095ac58106ad6d723e778a97bb;p=lhc%2Fweb%2Fwiklou.git Call parent::getFieldsForSearchIndex in ContentHandlers ContentHandler implementations were not including fields defined by their parent ContentHandler classes. merge method is added to the SearchIndexFieldDefinition mock in SearchEngineTest, to allow merges of fields in the way that SearchIndexFieldDefition implementation does. Change-Id: Id04a51528f566da2666bad0394a2f61c949c69b4 --- diff --git a/includes/content/CodeContentHandler.php b/includes/content/CodeContentHandler.php index 2bbf6ca7b2..20893bb0e7 100644 --- a/includes/content/CodeContentHandler.php +++ b/includes/content/CodeContentHandler.php @@ -64,11 +64,4 @@ abstract class CodeContentHandler extends TextContentHandler { throw new MWException( 'Subclass must override' ); } - /** - * @param SearchEngine $engine - * @return array - */ - public function getFieldsForSearchIndex( SearchEngine $engine ) { - return []; - } } diff --git a/includes/content/TextContentHandler.php b/includes/content/TextContentHandler.php index 74cbd16965..09cdcee143 100644 --- a/includes/content/TextContentHandler.php +++ b/includes/content/TextContentHandler.php @@ -143,9 +143,10 @@ class TextContentHandler extends ContentHandler { } public function getFieldsForSearchIndex( SearchEngine $engine ) { - $fields = []; + $fields = parent::getFieldsForSearchIndex( $engine ); $fields['language'] = $engine->makeSearchFieldMapping( 'language', SearchIndexField::INDEX_TYPE_KEYWORD ); + return $fields; } diff --git a/includes/content/WikitextContentHandler.php b/includes/content/WikitextContentHandler.php index d9f1e8639d..9baf64331d 100644 --- a/includes/content/WikitextContentHandler.php +++ b/includes/content/WikitextContentHandler.php @@ -109,7 +109,7 @@ class WikitextContentHandler extends TextContentHandler { } public function getFieldsForSearchIndex( SearchEngine $engine ) { - $fields = []; + $fields = parent::getFieldsForSearchIndex( $engine ); $fields['category'] = $engine->makeSearchFieldMapping( 'category', SearchIndexField::INDEX_TYPE_TEXT ); diff --git a/tests/phpunit/includes/search/SearchEngineTest.php b/tests/phpunit/includes/search/SearchEngineTest.php index 081cb38830..0b34b6f9b5 100644 --- a/tests/phpunit/includes/search/SearchEngineTest.php +++ b/tests/phpunit/includes/search/SearchEngineTest.php @@ -172,11 +172,17 @@ class SearchEngineTest extends MediaWikiLangTestCase { $name, $type ] )->getMock(); + $mockField->expects( $this->any() )->method( 'getMapping' )->willReturn( [ 'testData' => 'test', 'name' => $name, 'type' => $type, ] ); + + $mockField->expects( $this->any() ) + ->method( 'merge' ) + ->willReturn( $mockField ); + return $mockField; };