wiki.techinc.nl/tests/phpunit/includes/api/ApiOpenSearchTest.php
Erik Bernhardson 1b13cc1236 Rename OpenSearch qiprofile parameter back to profile
In I6f987db this parameter was inadvertantly renamed to qiprofile. The
qiprofile is something different, and is also a BC break. The BC break is
pretty minor, for a randomly chosen day this looks to be used 157 times
out of 28.7M requests, but since this really isn't a qiprofile rename
it back to what it was.

Change-Id: I1cc07945888c15ea4b4c9596eea447b706606fae
2016-07-28 10:25:33 -07:00

66 lines
1.8 KiB
PHP

<?php
use MediaWiki\MediaWikiServices;
class ApiOpenSearchTest extends MediaWikiTestCase {
public function testGetAllowedParams() {
$config = $this->replaceSearchEngineConfig();
$config->expects( $this->any() )
->method( 'getSearchTypes' )
->will( $this->returnValue( [ 'the one ring' ] ) );
$engine = $this->replaceSearchEngine();
$engine->expects( $this->any() )
->method( 'getProfiles' )
->will( $this->returnValueMap( [
[ SearchEngine::COMPLETION_PROFILE_TYPE, [
[
'name' => 'normal',
'desc-message' => 'normal-message',
'default' => true,
],
[
'name' => 'strict',
'desc-message' => 'strict-message',
],
] ],
] ) );
$api = $this->createApi();
$params = $api->getAllowedParams();
$this->assertArrayNotHasKey( 'offset', $params );
$this->assertArrayHasKey( 'profile', $params, print_r( $params, true ) );
$this->assertEquals( 'normal', $params['profile'][ApiBase::PARAM_DFLT] );
}
private function replaceSearchEngineConfig() {
$config = $this->getMockBuilder( 'SearchEngineConfig' )
->disableOriginalConstructor()
->getMock();
$this->setService( 'SearchEngineConfig', $config );
return $config;
}
private function replaceSearchEngine() {
$engine = $this->getMockBuilder( 'SearchEngine' )
->disableOriginalConstructor()
->getMock();
$engineFactory = $this->getMockBuilder( 'SearchEngineFactory' )
->disableOriginalConstructor()
->getMock();
$engineFactory->expects( $this->any() )
->method( 'create' )
->will( $this->returnValue( $engine ) );
$this->setService( 'SearchEngineFactory', $engineFactory );
return $engine;
}
private function createApi() {
$ctx = new RequestContext();
$apiMain = new ApiMain( $ctx );
return new ApiOpenSearch( $apiMain, 'opensearch', '' );
}
}