3 class ApiOpenSearchTest
extends MediaWikiTestCase
{
4 public function testGetAllowedParams() {
5 $config = $this->replaceSearchEngineConfig();
6 $config->expects( $this->any() )
7 ->method( 'getSearchTypes' )
8 ->will( $this->returnValue( [ 'the one ring' ] ) );
10 $api = $this->createApi();
11 $engine = $this->replaceSearchEngine();
12 $engine->expects( $this->any() )
13 ->method( 'getProfiles' )
14 ->will( $this->returnValueMap( [
15 [ SearchEngine
::COMPLETION_PROFILE_TYPE
, $api->getUser(), [
18 'desc-message' => 'normal-message',
23 'desc-message' => 'strict-message',
28 $params = $api->getAllowedParams();
30 $this->assertArrayNotHasKey( 'offset', $params );
31 $this->assertArrayHasKey( 'profile', $params, print_r( $params, true ) );
32 $this->assertEquals( 'normal', $params['profile'][ApiBase
::PARAM_DFLT
] );
35 private function replaceSearchEngineConfig() {
36 $config = $this->getMockBuilder( 'SearchEngineConfig' )
37 ->disableOriginalConstructor()
39 $this->setService( 'SearchEngineConfig', $config );
44 private function replaceSearchEngine() {
45 $engine = $this->getMockBuilder( 'SearchEngine' )
46 ->disableOriginalConstructor()
48 $engineFactory = $this->getMockBuilder( 'SearchEngineFactory' )
49 ->disableOriginalConstructor()
51 $engineFactory->expects( $this->any() )
53 ->will( $this->returnValue( $engine ) );
54 $this->setService( 'SearchEngineFactory', $engineFactory );
59 private function createApi() {
60 $ctx = new RequestContext();
61 $apiMain = new ApiMain( $ctx );
62 return new ApiOpenSearch( $apiMain, 'opensearch', '' );