wiki.techinc.nl/tests/phpunit/includes/api/ApiOpenSearchTest.php
Erik Bernhardson 5da2c4197d Push common search api parameters into SearchApi class
We have a number of parameters that are pretty much the same between
these different search api's. Lets make them actually the same by
sharing the definitions, and then letting individual classes tweak them
as needed by removing the offset, or adjusting the max limits as
necessary.

Change-Id: I6f987db8ecb63dc943b4d2518bfe3703c677448e
2016-07-26 08:56:00 -07:00

66 lines
1.8 KiB
PHP

<?php
use MediaWiki\MediaWikiServices;
class ApiOpenSearchTest extends MediaWikiTestCase {
public function testGetAllowedParams() {
$config = $this->replaceSearchEngineConfig();
$config->expects( $this->any() )
->method( 'getSearchTypes' )
->will( $this->returnValue( [ 'the one ring' ] ) );
$engine = $this->replaceSearchEngine();
$engine->expects( $this->any() )
->method( 'getProfiles' )
->will( $this->returnValueMap( [
[ SearchEngine::COMPLETION_PROFILE_TYPE, [
[
'name' => 'normal',
'desc-message' => 'normal-message',
'default' => true,
],
[
'name' => 'strict',
'desc-message' => 'strict-message',
],
] ],
] ) );
$api = $this->createApi();
$params = $api->getAllowedParams();
$this->assertArrayNotHasKey( 'offset', $params );
$this->assertArrayHasKey( 'qiprofile', $params, print_r( $params, true ) );
$this->assertEquals( 'normal', $params['qiprofile'][ApiBase::PARAM_DFLT] );
}
private function replaceSearchEngineConfig() {
$config = $this->getMockBuilder( 'SearchEngineConfig' )
->disableOriginalConstructor()
->getMock();
$this->setService( 'SearchEngineConfig', $config );
return $config;
}
private function replaceSearchEngine() {
$engine = $this->getMockBuilder( 'SearchEngine' )
->disableOriginalConstructor()
->getMock();
$engineFactory = $this->getMockBuilder( 'SearchEngineFactory' )
->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', '' );
}
}