Merge "Add parameter to API modules to apply change tags to log entries"
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiOpenSearchTest.php
1 <?php
2
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' ] ) );
9
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(), [
16 [
17 'name' => 'normal',
18 'desc-message' => 'normal-message',
19 'default' => true,
20 ],
21 [
22 'name' => 'strict',
23 'desc-message' => 'strict-message',
24 ],
25 ] ],
26 ] ) );
27
28 $params = $api->getAllowedParams();
29
30 $this->assertArrayNotHasKey( 'offset', $params );
31 $this->assertArrayHasKey( 'profile', $params, print_r( $params, true ) );
32 $this->assertEquals( 'normal', $params['profile'][ApiBase::PARAM_DFLT] );
33 }
34
35 private function replaceSearchEngineConfig() {
36 $config = $this->getMockBuilder( 'SearchEngineConfig' )
37 ->disableOriginalConstructor()
38 ->getMock();
39 $this->setService( 'SearchEngineConfig', $config );
40
41 return $config;
42 }
43
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 );
55
56 return $engine;
57 }
58
59 private function createApi() {
60 $ctx = new RequestContext();
61 $apiMain = new ApiMain( $ctx );
62 return new ApiOpenSearch( $apiMain, 'opensearch', '' );
63 }
64 }