return;
}
+ // Reset the search type back to default - some extensions may have
+ // overridden it.
+ $this->setMwGlobals( [ 'wgSearchType' => null ] );
+
$this->insertPage( 'Not_Main_Page', 'This is not a main page' );
$this->insertPage(
'Talk:Not_Main_Page',
"Title power search failed" );
}
+ /**
+ * @covers SearchEngine::getSearchIndexFields
+ */
+ public function testSearchIndexFields() {
+ /**
+ * @var $mockEngine SearchEngine
+ */
+ $mockEngine = $this->getMock( 'SearchEngine', [ 'makeSearchFieldMapping' ] );
+
+ $mockFieldBuilder = function ( $name, $type ) {
+ $mockField =
+ $this->getMockBuilder( 'SearchIndexFieldDefinition' )->setConstructorArgs( [
+ $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;
+ };
+
+ $mockEngine->expects( $this->atLeastOnce() )
+ ->method( 'makeSearchFieldMapping' )
+ ->willReturnCallback( $mockFieldBuilder );
+
+ // Not using mock since PHPUnit mocks do not work properly with references in params
+ $this->setTemporaryHook( 'SearchIndexFields',
+ function ( &$fields, SearchEngine $engine ) use ( $mockFieldBuilder ) {
+ $fields['testField'] =
+ $mockFieldBuilder( "testField", SearchIndexField::INDEX_TYPE_TEXT );
+ return true;
+ } );
+
+ $fields = $mockEngine->getSearchIndexFields();
+ $this->assertArrayHasKey( 'language', $fields );
+ $this->assertArrayHasKey( 'category', $fields );
+ $this->assertInstanceOf( 'SearchIndexField', $fields['testField'] );
+
+ $mapping = $fields['testField']->getMapping( $mockEngine );
+ $this->assertArrayHasKey( 'testData', $mapping );
+ $this->assertEquals( 'test', $mapping['testData'] );
+ }
}