3 namespace MediaWiki\Tests\Api\Query
;
5 use MediaWiki\MainConfigNames
;
6 use MediaWiki\Tests\Api\ApiTestCase
;
7 use MockCompletionSearchEngine
;
14 * @covers \MediaWiki\Api\ApiQueryPrefixSearch
16 class ApiQueryPrefixSearchTest
extends ApiTestCase
{
17 private const TEST_QUERY
= 'unittest';
19 protected function setUp(): void
{
21 $this->overrideConfigValue( MainConfigNames
::SearchType
, MockCompletionSearchEngine
::class );
22 MockCompletionSearchEngine
::clearMockResults();
24 foreach ( range( 0, 10 ) as $i ) {
25 $title = "Search_Result_$i";
27 $this->editPage( $title, 'hi there' );
29 MockCompletionSearchEngine
::addMockResults( self
::TEST_QUERY
, $results );
32 public static function offsetContinueProvider() {
34 'no offset' => [ 2, 2, 0, 2 ],
35 'with offset' => [ 7, 2, 5, 2 ],
36 'past end, no offset' => [ null, 11, 0, 20 ],
37 'past end, with offset' => [ null, 5, 6, 10 ],
42 * @dataProvider offsetContinueProvider
44 public function testOffsetContinue( $expectedOffset, $expectedResults, $offset, $limit ) {
45 $this->overrideConfigValue( MainConfigNames
::UsePigLatinVariant
, false );
46 $response = $this->doApiRequest( [
48 'list' => 'prefixsearch',
49 'pssearch' => self
::TEST_QUERY
,
50 'psoffset' => $offset,
53 $result = $response[0];
54 $this->assertArrayNotHasKey( 'warnings', $result );
55 $suggestions = $result['query']['prefixsearch'];
56 $this->assertCount( $expectedResults, $suggestions );
57 if ( $expectedOffset == null ) {
58 $this->assertArrayNotHasKey( 'continue', $result );
60 $this->assertArrayHasKey( 'continue', $result );
61 $this->assertEquals( $expectedOffset, $result['continue']['psoffset'] );