MediaWiki REL1_32
ApiQueryPrefixSearchTest.php
Go to the documentation of this file.
1<?php
2
11 const TEST_QUERY = 'unittest';
12
13 public function setUp() {
14 parent::setUp();
15 $this->setMwGlobals( [
16 'wgSearchType' => MockCompletionSearchEngine::class,
17 ] );
19 $results = [];
20 foreach ( range( 0, 10 ) as $i ) {
21 $title = "Search_Result_$i";
22 $results[] = $title;
23 $this->editPage( $title, 'hi there' );
24 }
25 MockCompletionSearchEngine::addMockResults( self::TEST_QUERY, $results );
26 }
27
28 public function offsetContinueProvider() {
29 return [
30 'no offset' => [ 2, 2, 0, 2 ],
31 'with offset' => [ 7, 2, 5, 2 ],
32 'past end, no offset' => [ null, 11, 0, 20 ],
33 'past end, with offset' => [ null, 5, 6, 10 ],
34 ];
35 }
36
40 public function testOffsetContinue( $expectedOffset, $expectedResults, $offset, $limit ) {
41 $response = $this->doApiRequest( [
42 'action' => 'query',
43 'list' => 'prefixsearch',
44 'pssearch' => self::TEST_QUERY,
45 'psoffset' => $offset,
46 'pslimit' => $limit,
47 ] );
48 $result = $response[0];
49 $this->assertArrayNotHasKey( 'warnings', $result );
50 $suggestions = $result['query']['prefixsearch'];
51 $this->assertCount( $expectedResults, $suggestions );
52 if ( $expectedOffset == null ) {
53 $this->assertArrayNotHasKey( 'continue', $result );
54 } else {
55 $this->assertArrayHasKey( 'continue', $result );
56 $this->assertEquals( $expectedOffset, $result['continue']['psoffset'] );
57 }
58 }
59}
testOffsetContinue( $expectedOffset, $expectedResults, $offset, $limit)
offsetContinueProvider
doApiRequest(array $params, array $session=null, $appendModule=false, User $user=null, $tokenType=null)
Does the API request and returns the result.
editPage( $pageName, $text, $summary='', $defaultNs=NS_MAIN)
Edits or creates a page/revision.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
static addMockResults( $query, array $result)
Allows returning arbitrary lists of titles for completion search.
static clearMockResults()
Reset any mocked results.
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:994
this hook is for auditing only $response
Definition hooks.txt:813