Added release notes for 'ContentHandler::runLegacyHooks' removal
[mediawiki.git] / tests / phpunit / includes / api / ApiOpenSearchTest.php
blob23fa7bcb25fda5b64098254dd18d8f4cc3ea99f8
1 <?php
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(), [
17 'name' => 'normal',
18 'desc-message' => 'normal-message',
19 'default' => true,
22 'name' => 'strict',
23 'desc-message' => 'strict-message',
25 ] ],
26 ] ) );
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()
38 ->getMock();
39 $this->setService( 'SearchEngineConfig', $config );
41 return $config;
44 private function replaceSearchEngine() {
45 $engine = $this->getMockBuilder( 'SearchEngine' )
46 ->disableOriginalConstructor()
47 ->getMock();
48 $engineFactory = $this->getMockBuilder( 'SearchEngineFactory' )
49 ->disableOriginalConstructor()
50 ->getMock();
51 $engineFactory->expects( $this->any() )
52 ->method( 'create' )
53 ->will( $this->returnValue( $engine ) );
54 $this->setService( 'SearchEngineFactory', $engineFactory );
56 return $engine;
59 private function createApi() {
60 $ctx = new RequestContext();
61 $apiMain = new ApiMain( $ctx );
62 return new ApiOpenSearch( $apiMain, 'opensearch', '' );