$this->assertTrue( is_object( $results ) );
$matches = [];
- $row = $results->next();
- while ( $row ) {
+ foreach ( $results as $row ) {
$matches[] = $row->getTitle()->getPrefixedText();
- $row = $results->next();
}
$results->free();
# Search is not guaranteed to return results in a certain order;
public function testPhraseSearchHighlight() {
$phrase = "smithee is one who smiths";
$res = $this->search->searchText( "\"$phrase\"" );
- $match = $res->next();
+ $match = $res->getIterator()->current();
$snippet = "A <span class='searchmatch'>" . $phrase . "</span>";
$this->assertStringStartsWith( $snippet,
$match->getTextSnippet( $res->termMatches() ),
/**
* @var $mockEngine SearchEngine
*/
- $mockEngine = $this->getMockBuilder( 'SearchEngine' )
+ $mockEngine = $this->getMockBuilder( SearchEngine::class )
->setMethods( [ 'makeSearchFieldMapping' ] )->getMock();
$mockFieldBuilder = function ( $name, $type ) {
$mockField =
- $this->getMockBuilder( 'SearchIndexFieldDefinition' )->setConstructorArgs( [
+ $this->getMockBuilder( SearchIndexFieldDefinition::class )->setConstructorArgs( [
$name,
$type
] )->getMock();
$fields = $mockEngine->getSearchIndexFields();
$this->assertArrayHasKey( 'language', $fields );
$this->assertArrayHasKey( 'category', $fields );
- $this->assertInstanceOf( 'SearchIndexField', $fields['testField'] );
+ $this->assertInstanceOf( SearchIndexField::class, $fields['testField'] );
$mapping = $fields['testField']->getMapping( $mockEngine );
$this->assertArrayHasKey( 'testData', $mapping );
$this->mergeMwGlobalArrayValue( 'wgHooks',
[ 'SearchResultsAugment' => [ [ $this, 'addAugmentors' ] ] ] );
$this->search->augmentSearchResults( $resultSet );
- for ( $result = $resultSet->next(); $result; $result = $resultSet->next() ) {
+ foreach ( $resultSet as $result ) {
$id = $result->getTitle()->getArticleID();
$augmentData = "Result:$id:" . $result->getTitle()->getText();
$augmentData2 = "Result2:$id:" . $result->getTitle()->getText();
}
public function addAugmentors( &$setAugmentors, &$rowAugmentors ) {
- $setAugmentor = $this->createMock( 'ResultSetAugmentor' );
+ $setAugmentor = $this->createMock( ResultSetAugmentor::class );
$setAugmentor->expects( $this->once() )
->method( 'augmentAll' )
->willReturnCallback( function ( SearchResultSet $resultSet ) {
$data = [];
- for ( $result = $resultSet->next(); $result; $result = $resultSet->next() ) {
+ foreach ( $resultSet as $result ) {
$id = $result->getTitle()->getArticleID();
$data[$id] = "Result:$id:" . $result->getTitle()->getText();
}
- $resultSet->rewind();
return $data;
} );
$setAugmentors['testSet'] = $setAugmentor;
- $rowAugmentor = $this->createMock( 'ResultAugmentor' );
+ $rowAugmentor = $this->createMock( ResultAugmentor::class );
$rowAugmentor->expects( $this->exactly( 2 ) )
->method( 'augment' )
->willReturnCallback( function ( SearchResult $result ) {
} );
$rowAugmentors['testRow'] = $rowAugmentor;
}
+
+ public function testFiltersMissing() {
+ $availableResults = [];
+ foreach ( range( 0, 11 ) as $i ) {
+ $title = "Search_Result_$i";
+ $availableResults[] = $title;
+ // pages not created must be filtered
+ if ( $i % 2 == 0 ) {
+ $this->editPage( $title );
+ }
+ }
+ MockCompletionSearchEngine::addMockResults( 'foo', $availableResults );
+
+ $engine = new MockCompletionSearchEngine();
+ $engine->setLimitOffset( 10, 0 );
+ $results = $engine->completionSearch( 'foo' );
+ $this->assertEquals( 5, $results->getSize() );
+ $this->assertTrue( $results->hasMoreResults() );
+
+ $engine->setLimitOffset( 10, 10 );
+ $results = $engine->completionSearch( 'foo' );
+ $this->assertEquals( 1, $results->getSize() );
+ $this->assertFalse( $results->hasMoreResults() );
+ }
+
+ private function editPage( $title ) {
+ $page = WikiPage::factory( Title::newFromText( $title ) );
+ $page->doEditContent(
+ new WikitextContent( 'UTContent' ),
+ 'UTPageSummary',
+ EDIT_NEW | EDIT_SUPPRESS_RC
+ );
+ }
}