MediaWiki
REL1_31
ApiOpenSearchTest.php
Go to the documentation of this file.
1
<?php
2
6
class
ApiOpenSearchTest
extends
MediaWikiTestCase
{
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
}
any
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
Definition
COPYING.txt:326
ApiBase\PARAM_DFLT
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition
ApiBase.php:48
ApiMain
This is the main API class, used for both external and internal processing.
Definition
ApiMain.php:43
ApiOpenSearchTest
ApiOpenSearch.
Definition
ApiOpenSearchTest.php:6
ApiOpenSearchTest\replaceSearchEngine
replaceSearchEngine()
Definition
ApiOpenSearchTest.php:47
ApiOpenSearchTest\createApi
createApi()
Definition
ApiOpenSearchTest.php:62
ApiOpenSearchTest\replaceSearchEngineConfig
replaceSearchEngineConfig()
Definition
ApiOpenSearchTest.php:38
ApiOpenSearchTest\testGetAllowedParams
testGetAllowedParams()
Definition
ApiOpenSearchTest.php:7
ApiOpenSearch
Definition
ApiOpenSearch.php:30
MediaWikiTestCase
Definition
MediaWikiTestCase.php:17
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
RequestContext
Group all the pieces relevant to the context of a request into one instance.
Definition
RequestContext.php:32
$engine
the value to return A Title object or null for latest all implement SearchIndexField $engine
Definition
hooks.txt:2881
$params
$params
Definition
styleTest.css.php:40
tests
phpunit
includes
api
ApiOpenSearchTest.php
Generated on Mon Nov 25 2024 15:36:14 for MediaWiki by
1.10.0