Debian Codegraph @

tests/phpunit/integration/includes/Rest/Handler/OpenSearchDescriptionHandlerTest.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Tests\Rest\Handler;
4
5 use MediaWiki\Config\HashConfig;
6 use MediaWiki\MainConfigNames;
7 use MediaWiki\MainConfigSchema;
8 use MediaWiki\Rest\Handler\OpenSearchDescriptionHandler;
9 use MediaWiki\Rest\RequestData;
10 use MediaWikiIntegrationTestCase;
11
12 /**
13 * @covers \MediaWiki\Rest\Handler\OpenSearchDescriptionHandler
14 */
15 class OpenSearchDescriptionHandlerTest extends MediaWikiIntegrationTestCase {
16
17 use HandlerTestTrait;
18
19 private function newHandler() {
20 $config = new HashConfig( [
21 MainConfigNames::Favicon => MainConfigSchema::getDefaultValue(
22 MainConfigNames::Favicon
23 ),
24 MainConfigNames::OpenSearchTemplates => MainConfigSchema::getDefaultValue(
25 MainConfigNames::OpenSearchTemplates
26 ),
27 ] );
28 $urlUtils = $this->getServiceContainer()->getUrlUtils();
29
30 $handler = new OpenSearchDescriptionHandler( $config, $urlUtils );
31 return $handler;
32 }
33
34 public function testOpenSearchDescription() {
35 $req = new RequestData( [] );
36 $handler = $this->newHandler( $req );
37
38 $resp = $this->executeHandler( $handler, $req );
39 $this->assertSame(
40 'application/opensearchdescription+xml',
41 $resp->getHeaderLine( 'content-type' )
42 );
43
44 $xml = (string)$resp->getBody();
45 $this->assertMatchesRegularExpression( '!^<\?xml!', $xml );
46 $this->assertMatchesRegularExpression( '!<OpenSearchDescription!', $xml );
47 $this->assertMatchesRegularExpression( '!<Url type="text/html" method="get" template=!', $xml );
48 }
49
50 // TODO: write tests for wgOpenSearchTemplates and the OpenSearchUrls hook.
51 }