wiki.techinc.nl/tests/phpunit/includes/api/ApiOpenSearchTest.php
addshore 959bc315f2 MediaWikiTestCase to MediaWikiIntegrationTestCase
The name change happened some time ago, and I think its
about time to start using the name name!
(Done with a find and replace)

My personal motivation for doing this is that I have started
trying out vscode as an IDE for mediawiki development, and
right now it doesn't appear to handle php aliases very well
or at all.

Change-Id: I412235d91ae26e4c1c6a62e0dbb7e7cf3c5ed4a6
2020-06-30 17:02:22 +01:00

67 lines
1.8 KiB
PHP

<?php
/**
* @covers ApiOpenSearch
*/
class ApiOpenSearchTest extends MediaWikiIntegrationTestCase {
public function testGetAllowedParams() {
$config = $this->replaceSearchEngineConfig();
$config->expects( $this->any() )
->method( 'getSearchTypes' )
->will( $this->returnValue( [ 'the one ring' ] ) );
$api = $this->createApi();
$engine = $this->replaceSearchEngine();
$engine->expects( $this->any() )
->method( 'getProfiles' )
->will( $this->returnValueMap( [
[ SearchEngine::COMPLETION_PROFILE_TYPE, $api->getUser(), [
[
'name' => 'normal',
'desc-message' => 'normal-message',
'default' => true,
],
[
'name' => 'strict',
'desc-message' => 'strict-message',
],
] ],
] ) );
$params = $api->getAllowedParams();
$this->assertArrayNotHasKey( 'offset', $params );
$this->assertArrayHasKey( 'profile', $params, print_r( $params, true ) );
$this->assertEquals( 'normal', $params['profile'][ApiBase::PARAM_DFLT] );
}
private function replaceSearchEngineConfig() {
$config = $this->getMockBuilder( SearchEngineConfig::class )
->disableOriginalConstructor()
->getMock();
$this->setService( 'SearchEngineConfig', $config );
return $config;
}
private function replaceSearchEngine() {
$engine = $this->getMockBuilder( SearchEngine::class )
->disableOriginalConstructor()
->getMock();
$engineFactory = $this->getMockBuilder( SearchEngineFactory::class )
->disableOriginalConstructor()
->getMock();
$engineFactory->expects( $this->any() )
->method( 'create' )
->will( $this->returnValue( $engine ) );
$this->setService( 'SearchEngineFactory', $engineFactory );
return $engine;
}
private function createApi() {
$ctx = new RequestContext();
$apiMain = new ApiMain( $ctx );
return new ApiOpenSearch( $apiMain, 'opensearch', '' );
}
}