wiki.techinc.nl/tests/phpunit/includes/api/ApiQueryPrefixSearchTest.php
Erik Bernhardson 2a43939ffb Push pagination decision for search into SearchEngine
Various code using the search engine shouldn't need to implement it's
own methods, such as over-fetching, to determine if there are more
results available. This should be knowledge internal to search that is
exposed by a boolean.

Change-Id: Ica094428700637dfdedb723b03f6aeadfe12b9f4
2018-06-11 13:35:44 -07:00

48 lines
1.3 KiB
PHP

<?php
/**
* @group API
* @group medium
*
* @covers ApiQueryPrefixSearch
*/
class ApiQueryPrefixSearchTest extends ApiTestCase {
public function offsetContinueProvider() {
return [
'no offset' => [ 2, 2, 0, 2 ],
'with offset' => [ 7, 2, 5, 2 ],
'past end, no offset' => [ null, 11, 0, 20 ],
'past end, with offset' => [ null, 5, 6, 10 ],
];
}
/**
* @dataProvider offsetContinueProvider
*/
public function testOffsetContinue( $expectedOffset, $expectedResults, $offset, $limit ) {
$this->registerMockSearchEngine();
$response = $this->doApiRequest( [
'action' => 'query',
'list' => 'prefixsearch',
'pssearch' => 'example query terms',
'psoffset' => $offset,
'pslimit' => $limit,
] );
$result = $response[0];
$this->assertArrayNotHasKey( 'warnings', $result );
$suggestions = $result['query']['prefixsearch'];
$this->assertCount( $expectedResults, $suggestions );
if ( $expectedOffset == null ) {
$this->assertArrayNotHasKey( 'continue', $result );
} else {
$this->assertArrayHasKey( 'continue', $result );
$this->assertEquals( $expectedOffset, $result['continue']['psoffset'] );
}
}
private function registerMockSearchEngine() {
$this->setMwGlobals( [
'wgSearchType' => MockCompletionSearchEngine::class,
] );
}
}