Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / includes / api / ApiOpenSearchTest.php
blobaba7117b8e497ff80897de874c08e76205d749c5
1 <?php
3 namespace MediaWiki\Tests\Api;
5 use MediaWiki\Api\ApiMain;
6 use MediaWiki\Api\ApiOpenSearch;
7 use MediaWiki\Context\RequestContext;
8 use MediaWikiIntegrationTestCase;
9 use SearchEngine;
10 use SearchEngineConfig;
11 use SearchEngineFactory;
12 use Wikimedia\ParamValidator\ParamValidator;
14 /**
15 * TODO convert to unit test, no integration is needed
17 * @covers \MediaWiki\Api\ApiOpenSearch
19 class ApiOpenSearchTest extends MediaWikiIntegrationTestCase {
20 public function testGetAllowedParams() {
21 $config = $this->replaceSearchEngineConfig();
22 $config->method( 'getSearchTypes' )
23 ->willReturn( [ 'the one ring' ] );
25 [ $engine, $engineFactory ] = $this->replaceSearchEngine();
27 $ctx = new RequestContext();
28 $apiMain = new ApiMain( $ctx );
29 $api = new ApiOpenSearch(
30 $apiMain,
31 'opensearch',
32 $this->getServiceContainer()->getLinkBatchFactory(),
33 $config,
34 $engineFactory,
35 $this->getServiceContainer()->getUrlUtils()
38 $engine->method( 'getProfiles' )
39 ->willReturnMap( [
40 [ SearchEngine::COMPLETION_PROFILE_TYPE, $api->getUser(), [
42 'name' => 'normal',
43 'desc-message' => 'normal-message',
44 'default' => true,
47 'name' => 'strict',
48 'desc-message' => 'strict-message',
50 ] ],
51 ] );
53 $params = $api->getAllowedParams();
55 $this->assertArrayNotHasKey( 'offset', $params );
56 $this->assertArrayHasKey( 'profile', $params, print_r( $params, true ) );
57 $this->assertEquals( 'normal', $params['profile'][ParamValidator::PARAM_DEFAULT] );
60 private function replaceSearchEngineConfig() {
61 $config = $this->createMock( SearchEngineConfig::class );
62 $this->setService( 'SearchEngineConfig', $config );
64 return $config;
67 private function replaceSearchEngine() {
68 $engine = $this->createMock( SearchEngine::class );
69 $engineFactory = $this->createMock( SearchEngineFactory::class );
70 $engineFactory->method( 'create' )
71 ->willReturn( $engine );
72 $this->setService( 'SearchEngineFactory', $engineFactory );
74 return [ $engine, $engineFactory ];