MediaWiki  1.28.1
ApiOpenSearchTest.php
Go to the documentation of this file.
1 <?php
2 
4 
6  public function testGetAllowedParams() {
7  $config = $this->replaceSearchEngineConfig();
8  $config->expects( $this->any() )
9  ->method( 'getSearchTypes' )
10  ->will( $this->returnValue( [ 'the one ring' ] ) );
11 
12  $api = $this->createApi();
13  $engine = $this->replaceSearchEngine();
14  $engine->expects( $this->any() )
15  ->method( 'getProfiles' )
16  ->will( $this->returnValueMap( [
17  [ SearchEngine::COMPLETION_PROFILE_TYPE, $api->getUser(), [
18  [
19  'name' => 'normal',
20  'desc-message' => 'normal-message',
21  'default' => true,
22  ],
23  [
24  'name' => 'strict',
25  'desc-message' => 'strict-message',
26  ],
27  ] ],
28  ] ) );
29 
30  $params = $api->getAllowedParams();
31 
32  $this->assertArrayNotHasKey( 'offset', $params );
33  $this->assertArrayHasKey( 'profile', $params, print_r( $params, true ) );
34  $this->assertEquals( 'normal', $params['profile'][ApiBase::PARAM_DFLT] );
35  }
36 
37  private function replaceSearchEngineConfig() {
38  $config = $this->getMockBuilder( 'SearchEngineConfig' )
39  ->disableOriginalConstructor()
40  ->getMock();
41  $this->setService( 'SearchEngineConfig', $config );
42 
43  return $config;
44  }
45 
46  private function replaceSearchEngine() {
47  $engine = $this->getMockBuilder( 'SearchEngine' )
48  ->disableOriginalConstructor()
49  ->getMock();
50  $engineFactory = $this->getMockBuilder( 'SearchEngineFactory' )
51  ->disableOriginalConstructor()
52  ->getMock();
53  $engineFactory->expects( $this->any() )
54  ->method( 'create' )
55  ->will( $this->returnValue( $engine ) );
56  $this->setService( 'SearchEngineFactory', $engineFactory );
57 
58  return $engine;
59  }
60 
61  private function createApi() {
62  $ctx = new RequestContext();
63  $apiMain = new ApiMain( $ctx );
64  return new ApiOpenSearch( $apiMain, 'opensearch', '' );
65  }
66 }
Group all the pieces relevant to the context of a request into one instance.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition: ApiBase.php:50
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
setService($name, $object)
Sets a service, maintaining a stashed version of the previous service to be restored in tearDown...
$params
This is the main API class, used for both external and internal processing.
Definition: ApiMain.php:43
const COMPLETION_PROFILE_TYPE
string profile type for completionSearch
the value to return A Title object or null for latest all implement SearchIndexField $engine
Definition: hooks.txt:2736
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35