wiki.techinc.nl/tests/phpunit/includes/api/query/ApiQueryPrefixSearchTest.php
daniel 8c1c1ae35a Enable pig-latin variant for testing
Having pig-latin enabled per default in dev environments is convenient
for manual testing. More importantly, it will allow us to write
end-to-end tests for variant conversion.

Depends-On: I9dc2f743ac487b0f7cfb667150c0f6950d5e7fce
Depends-On: I85b66c85be3959d48a048733af17197bc4cf70af
Change-Id: Ia80ad33cbf5e311fa8b84bd765a8df8d156f4c38
2022-11-08 17:45:51 +05:30

60 lines
1.7 KiB
PHP

<?php
use MediaWiki\MainConfigNames;
/**
* @group API
* @group medium
* @group Database
*
* @covers ApiQueryPrefixSearch
*/
class ApiQueryPrefixSearchTest extends ApiTestCase {
private const TEST_QUERY = 'unittest';
protected function setUp(): void {
parent::setUp();
$this->overrideConfigValue( MainConfigNames::SearchType, MockCompletionSearchEngine::class );
MockCompletionSearchEngine::clearMockResults();
$results = [];
foreach ( range( 0, 10 ) as $i ) {
$title = "Search_Result_$i";
$results[] = $title;
$this->editPage( $title, 'hi there' );
}
MockCompletionSearchEngine::addMockResults( self::TEST_QUERY, $results );
}
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->overrideConfigValue( MainConfigNames::UsePigLatinVariant, false );
$response = $this->doApiRequest( [
'action' => 'query',
'list' => 'prefixsearch',
'pssearch' => self::TEST_QUERY,
'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'] );
}
}
}