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();
14  $engine = $this->replaceSearchEngine();
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 }
ApiMain
This is the main API class, used for both external and internal processing.
Definition: ApiMain.php:43
ApiOpenSearchTest\createApi
createApi()
Definition: ApiOpenSearchTest.php:62
ApiOpenSearch
Definition: ApiOpenSearch.php:30
$params
$params
Definition: styleTest.css.php:40
ApiOpenSearchTest
ApiOpenSearch.
Definition: ApiOpenSearchTest.php:6
php
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:37
SearchEngine\COMPLETION_PROFILE_TYPE
const COMPLETION_PROFILE_TYPE
@const string profile type for completionSearch
Definition: SearchEngine.php:58
MediaWikiTestCase
Definition: MediaWikiTestCase.php:17
RequestContext
Group all the pieces relevant to the context of a request into one instance.
Definition: RequestContext.php:32
ApiOpenSearchTest\replaceSearchEngineConfig
replaceSearchEngineConfig()
Definition: ApiOpenSearchTest.php:38
$engine
the value to return A Title object or null for latest all implement SearchIndexField $engine
Definition: hooks.txt:2881
ApiOpenSearchTest\replaceSearchEngine
replaceSearchEngine()
Definition: ApiOpenSearchTest.php:47
ApiOpenSearchTest\testGetAllowedParams
testGetAllowedParams()
Definition: ApiOpenSearchTest.php:7
ApiBase\PARAM_DFLT
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition: ApiBase.php:48
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:56
MediaWikiTestCase\setService
setService( $name, $object)
Sets a service, maintaining a stashed version of the previous service to be restored in tearDown.
Definition: MediaWikiTestCase.php:628