MediaWiki REL1_31
ApiOpenSearchTest.php
Go to the documentation of this file.
1<?php
2
7 public function testGetAllowedParams() {
8 $config = $this->replaceSearchEngineConfig();
9 $config->expects( $this->any() )
10 ->method( 'getSearchTypes' )
11 ->will( $this->returnValue( [ 'the one ring' ] ) );
12
13 $api = $this->createApi();
15 $engine->expects( $this->any() )
16 ->method( 'getProfiles' )
17 ->will( $this->returnValueMap( [
18 [ SearchEngine::COMPLETION_PROFILE_TYPE, $api->getUser(), [
19 [
20 'name' => 'normal',
21 'desc-message' => 'normal-message',
22 'default' => true,
23 ],
24 [
25 'name' => 'strict',
26 'desc-message' => 'strict-message',
27 ],
28 ] ],
29 ] ) );
30
31 $params = $api->getAllowedParams();
32
33 $this->assertArrayNotHasKey( 'offset', $params );
34 $this->assertArrayHasKey( 'profile', $params, print_r( $params, true ) );
35 $this->assertEquals( 'normal', $params['profile'][ApiBase::PARAM_DFLT] );
36 }
37
38 private function replaceSearchEngineConfig() {
39 $config = $this->getMockBuilder( SearchEngineConfig::class )
40 ->disableOriginalConstructor()
41 ->getMock();
42 $this->setService( 'SearchEngineConfig', $config );
43
44 return $config;
45 }
46
47 private function replaceSearchEngine() {
48 $engine = $this->getMockBuilder( SearchEngine::class )
49 ->disableOriginalConstructor()
50 ->getMock();
51 $engineFactory = $this->getMockBuilder( SearchEngineFactory::class )
52 ->disableOriginalConstructor()
53 ->getMock();
54 $engineFactory->expects( $this->any() )
55 ->method( 'create' )
56 ->will( $this->returnValue( $engine ) );
57 $this->setService( 'SearchEngineFactory', $engineFactory );
58
59 return $engine;
60 }
61
62 private function createApi() {
63 $ctx = new RequestContext();
64 $apiMain = new ApiMain( $ctx );
65 return new ApiOpenSearch( $apiMain, 'opensearch', '' );
66 }
67}
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
Definition COPYING.txt:326
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition ApiBase.php:48
This is the main API class, used for both external and internal processing.
Definition ApiMain.php:43
setService( $name, $object)
Sets a service, maintaining a stashed version of the previous service to be restored in tearDown.
Group all the pieces relevant to the context of a request into one instance.
the value to return A Title object or null for latest all implement SearchIndexField $engine
Definition hooks.txt:2881
$params