Merge "Remove use of BagOStuff TTL constants from unrelated code"
[mediawiki.git] / tests / phpunit / includes / api / query / ApiQueryPrefixSearchTest.php
blob0e4e37c57f5b46b308f7b1a2cb4bd8e70eaa26ef
1 <?php
3 namespace MediaWiki\Tests\Api\Query;
5 use MediaWiki\MainConfigNames;
6 use MediaWiki\Tests\Api\ApiTestCase;
7 use MockCompletionSearchEngine;
9 /**
10 * @group API
11 * @group medium
12 * @group Database
14 * @covers \MediaWiki\Api\ApiQueryPrefixSearch
16 class ApiQueryPrefixSearchTest extends ApiTestCase {
17 private const TEST_QUERY = 'unittest';
19 protected function setUp(): void {
20 parent::setUp();
21 $this->overrideConfigValue( MainConfigNames::SearchType, MockCompletionSearchEngine::class );
22 MockCompletionSearchEngine::clearMockResults();
23 $results = [];
24 foreach ( range( 0, 10 ) as $i ) {
25 $title = "Search_Result_$i";
26 $results[] = $title;
27 $this->editPage( $title, 'hi there' );
29 MockCompletionSearchEngine::addMockResults( self::TEST_QUERY, $results );
32 public static function offsetContinueProvider() {
33 return [
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 ],
41 /**
42 * @dataProvider offsetContinueProvider
44 public function testOffsetContinue( $expectedOffset, $expectedResults, $offset, $limit ) {
45 $this->overrideConfigValue( MainConfigNames::UsePigLatinVariant, false );
46 $response = $this->doApiRequest( [
47 'action' => 'query',
48 'list' => 'prefixsearch',
49 'pssearch' => self::TEST_QUERY,
50 'psoffset' => $offset,
51 'pslimit' => $limit,
52 ] );
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 );
59 } else {
60 $this->assertArrayHasKey( 'continue', $result );
61 $this->assertEquals( $expectedOffset, $result['continue']['psoffset'] );