7 * @covers ApiQueryPrefixSearch
9 class ApiQueryPrefixSearchTest
extends ApiTestCase
{
10 const TEST_QUERY
= 'unittest';
12 public function setUp() {
14 $this->setMwGlobals( [
15 'wgSearchType' => MockCompletionSearchEngine
::class,
17 MockCompletionSearchEngine
::clearMockResults();
19 foreach ( range( 0, 10 ) as $i ) {
20 $title = "Search_Result_$i";
22 $this->editPage( $title, 'hi there' );
24 MockCompletionSearchEngine
::addMockResults( self
::TEST_QUERY
, $results );
27 public function offsetContinueProvider() {
29 'no offset' => [ 2, 2, 0, 2 ],
30 'with offset' => [ 7, 2, 5, 2 ],
31 'past end, no offset' => [ null, 11, 0, 20 ],
32 'past end, with offset' => [ null, 5, 6, 10 ],
37 * @dataProvider offsetContinueProvider
39 public function testOffsetContinue( $expectedOffset, $expectedResults, $offset, $limit ) {
40 $response = $this->doApiRequest( [
42 'list' => 'prefixsearch',
43 'pssearch' => self
::TEST_QUERY
,
44 'psoffset' => $offset,
47 $result = $response[0];
48 $this->assertArrayNotHasKey( 'warnings', $result );
49 $suggestions = $result['query']['prefixsearch'];
50 $this->assertCount( $expectedResults, $suggestions );
51 if ( $expectedOffset == null ) {
52 $this->assertArrayNotHasKey( 'continue', $result );
54 $this->assertArrayHasKey( 'continue', $result );
55 $this->assertEquals( $expectedOffset, $result['continue']['psoffset'] );