25 $dbType = $this->db->getType();
26 $dbSupported = ( $dbType ===
'mysql' )
27 || ( $dbType ===
'sqlite' && $this->db->getFulltextSearchModule() ==
'FTS3' );
29 if ( !$dbSupported ) {
30 $this->markTestSkipped(
"MySQL or SQLite with FTS3 only" );
33 $searchType = SearchEngineFactory::getSearchEngineClass( $this->db );
35 'wgSearchType' => $searchType,
36 'wgCapitalLinks' =>
true,
37 'wgCapitalLinkOverrides' => [
42 $this->search =
new $searchType( $this->db );
46 unset( $this->search );
60 'wgSearchType' =>
null,
61 'wgCapitalLinks' =>
true,
62 'wgCapitalLinkOverrides' => [
67 $this->
insertPage(
'Not_Main_Page',
'This is not a main page' );
70 'This is not a talk page to the main page, see [[smithee]]'
72 $this->
insertPage(
'Smithee',
'A smithee is one who smiths. See also [[Alan Smithee]]' );
73 $this->
insertPage(
'Talk:Smithee',
'This article sucks.' );
74 $this->
insertPage(
'Unrelated_page',
'Nothing in this page is about the S word.' );
75 $this->
insertPage(
'Another_page',
'This page also is unrelated.' );
84 $this->
insertPage(
'HalfNumbers',
'1234567890' );
85 $this->
insertPage(
'FullNumbers',
'1234567890' );
86 $this->
insertPage(
'DomainName',
'example.com' );
87 $this->
insertPage(
'DomainName',
'example.com' );
88 $this->
insertPage(
'Category:search is not Search',
'' );
89 $this->
insertPage(
'Category:Search is not search',
'' );
94 $this->markTestIncomplete( __CLASS__ .
" does no yet support non-wikitext content "
95 .
"in the main namespace" );
97 $this->assertTrue( is_object( $results ) );
100 $row = $results->next();
102 $matches[] = $row->getTitle()->getPrefixedText();
103 $row = $results->next();
106 # Search is not guaranteed to return results in a certain order;
107 # sort them numerically so we will compare simply that we received
108 # the expected matches.
116 [
'FullOneUp',
'FullTwoLow',
'HalfOneUp',
'HalfTwoLow' ],
117 $this->
fetchIds( $this->search->searchText(
'AZ' ) ),
118 "Search for normalized from Half-width Upper" );
120 [
'FullOneUp',
'FullTwoLow',
'HalfOneUp',
'HalfTwoLow' ],
121 $this->
fetchIds( $this->search->searchText(
'az' ) ),
122 "Search for normalized from Half-width Lower" );
124 [
'FullOneUp',
'FullTwoLow',
'HalfOneUp',
'HalfTwoLow' ],
125 $this->
fetchIds( $this->search->searchText(
'AZ' ) ),
126 "Search for normalized from Full-width Upper" );
128 [
'FullOneUp',
'FullTwoLow',
'HalfOneUp',
'HalfTwoLow' ],
129 $this->
fetchIds( $this->search->searchText(
'az' ) ),
130 "Search for normalized from Full-width Lower" );
136 $this->
fetchIds( $this->search->searchText(
'smithee' ) ),
141 $res = $this->search->searchText(
'smith*' );
145 "Search with wildcards" );
147 $res = $this->search->searchText(
'smithson*' );
151 "Search with wildcards must not find unrelated articles" );
153 $res = $this->search->searchText(
'smith* smithee' );
157 "Search with wildcards can be combined with simple terms" );
159 $res = $this->search->searchText(
'smith* "one who smiths"' );
163 "Search with wildcards can be combined with phrase search" );
167 $res = $this->search->searchText(
'"smithee is one who smiths"' );
173 $res = $this->search->searchText(
'"smithee is who smiths"' );
177 "Phrase search is not sloppy, search terms must be adjacent" );
179 $res = $this->search->searchText(
'"is smithee one who smiths"' );
183 "Phrase search is ordered" );
187 $phrase =
"smithee is one who smiths";
188 $res = $this->search->searchText(
"\"$phrase\"" );
189 $match =
$res->next();
190 $snippet =
"A <span class='searchmatch'>" . $phrase .
"</span>";
191 $this->assertStringStartsWith( $snippet,
192 $match->getTextSnippet(
$res->termMatches() ),
193 "Highlight a phrase search" );
197 $this->search->setNamespaces( [ 0, 1, 4 ] );
201 'Talk:Not Main Page',
203 $this->
fetchIds( $this->search->searchText(
'smithee' ) ),
213 $this->
fetchIds( $this->search->searchTitle(
'smithee' ) ),
218 $this->search->setNamespaces( [ 0, 1, 4 ] );
225 $this->
fetchIds( $this->search->searchTitle(
'smithee' ) ),
226 "Title power search" );
231 'Searching for "smithee" finds Smithee on NS_MAIN' => [
236 'Searching for "search is" will finds "search is not Search" on NS_CATEGORY' => [
238 'Category:search is not Search',
241 'Searching for "Search is" will finds "search is not Search" on NS_CATEGORY' => [
243 'Category:Search is not search',
266 $results = $this->search->completionSearch(
$search );
267 $this->assertEquals( 1, $results->getSize() );
268 $this->assertEquals( $expectedSuggestion, $results->getSuggestions()[0]->getText() );
278 $mockEngine = $this->getMockBuilder( SearchEngine::class )
279 ->setMethods( [
'makeSearchFieldMapping' ] )->getMock();
281 $mockFieldBuilder =
function (
$name,
$type ) {
283 $this->getMockBuilder( SearchIndexFieldDefinition::class )->setConstructorArgs( [
288 $mockField->expects( $this->
any() )->method(
'getMapping' )->willReturn( [
289 'testData' =>
'test',
294 $mockField->expects( $this->
any() )
296 ->willReturn( $mockField );
301 $mockEngine->expects( $this->atLeastOnce() )
302 ->method(
'makeSearchFieldMapping' )
303 ->willReturnCallback( $mockFieldBuilder );
308 $fields[
'testField'] =
313 $fields = $mockEngine->getSearchIndexFields();
314 $this->assertArrayHasKey(
'language', $fields );
315 $this->assertArrayHasKey(
'category', $fields );
316 $this->assertInstanceOf( SearchIndexField::class, $fields[
'testField'] );
318 $mapping = $fields[
'testField']->getMapping( $mockEngine );
319 $this->assertArrayHasKey(
'testData', $mapping );
320 $this->assertEquals(
'test', $mapping[
'testData'] );
329 $this->search->setNamespaces( [ 0, 1, 4 ] );
330 $resultSet = $this->search->searchText(
'smithee' );
333 [
'SearchResultsAugment' => [ [ $this,
'addAugmentors' ] ] ] );
334 $this->search->augmentSearchResults( $resultSet );
335 for ( $result = $resultSet->next();
$result; $result = $resultSet->next() ) {
336 $id = $result->getTitle()->getArticleID();
337 $augmentData =
"Result:$id:" . $result->getTitle()->getText();
338 $augmentData2 =
"Result2:$id:" . $result->getTitle()->getText();
339 $this->assertEquals( [
'testSet' => $augmentData,
'testRow' => $augmentData2 ],
340 $result->getExtensionData() );
345 $setAugmentor = $this->createMock( ResultSetAugmentor::class );
346 $setAugmentor->expects( $this->once() )
347 ->method(
'augmentAll' )
350 for ( $result = $resultSet->
next();
$result; $result = $resultSet->
next() ) {
351 $id = $result->getTitle()->getArticleID();
352 $data[$id] =
"Result:$id:" . $result->getTitle()->getText();
357 $setAugmentors[
'testSet'] = $setAugmentor;
359 $rowAugmentor = $this->createMock( ResultAugmentor::class );
360 $rowAugmentor->expects( $this->exactly( 2 ) )
361 ->method(
'augment' )
362 ->willReturnCallback(
function (
SearchResult $result ) {
363 $id = $result->getTitle()->getArticleID();
364 return "Result2:$id:" . $result->getTitle()->getText();
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
testCompletionSearchMustRespectCapitalLinkOverrides( $search, $expectedSuggestion, array $namespaces)
Test that the search query is not munged using wrong CapitalLinks setup (in other test that the defau...
testPhraseSearchHighlight()
provideCompletionSearchMustRespectCapitalLinkOverrides()
hookSearchIndexFields( $mockFieldBuilder, &$fields, SearchEngine $engine)
addAugmentors(&$setAugmentors, &$rowAugmentors)
setUp()
Checks for database type & version.
testSearchIndexFields()
SearchEngine::getSearchIndexFields.
testTextTitlePowerSearch()
Contain a class for special pages.
rewind()
Rewind result set back to beginning.
next()
Fetches next search result, or false.
namespace being checked & $result
namespace and then decline to actually register it & $namespaces
the value to return A Title object or null for latest all implement SearchIndexField must implement ResultSetAugmentor & $rowAugmentors
Allows to change the fields on the form that will be generated $name
the value to return A Title object or null for latest all implement SearchIndexField $engine
const INDEX_TYPE_TEXT
Field types.