3 namespace MediaWiki\Tests\Rest\Handler
;
6 use GuzzleHttp\Psr7\Uri
;
7 use MediaWiki\Rest\BasicAccess\StaticBasicAuthorizer
;
8 use MediaWiki\Rest\RequestData
;
9 use MediaWiki\Rest\ResponseFactory
;
10 use MediaWiki\Rest\Router
;
13 * @covers \MediaWiki\Rest\Handler\HelloHandler
15 class HelloHandlerTest
extends \MediaWikiUnitTestCase
{
16 public static function provideTestViaRouter() {
21 'uri' => self
::makeUri( '/user/Tim/hello' ),
25 'reasonPhrase' => 'OK',
26 'protocolVersion' => '1.1',
27 'body' => '{"message":"Hello, Tim!"}',
30 'method not allowed' => [
33 'uri' => self
::makeUri( '/user/Tim/hello' ),
37 'reasonPhrase' => 'Method Not Allowed',
38 'protocolVersion' => '1.1',
39 'body' => '{"httpCode":405,"httpReason":"Method Not Allowed"}',
45 private static function makeUri( $path ) {
46 return new Uri( "http://www.example.com/rest$path" );
49 /** @dataProvider provideTestViaRouter */
50 public function testViaRouter( $requestInfo, $responseInfo ) {
52 [ __DIR__
. '/../testRoutes.json' ],
56 new ResponseFactory(),
57 new StaticBasicAuthorizer() );
58 $request = new RequestData( $requestInfo );
59 $response = $router->execute( $request );
60 if ( isset( $responseInfo['statusCode'] ) ) {
61 $this->assertSame( $responseInfo['statusCode'], $response->getStatusCode() );
63 if ( isset( $responseInfo['reasonPhrase'] ) ) {
64 $this->assertSame( $responseInfo['reasonPhrase'], $response->getReasonPhrase() );
66 if ( isset( $responseInfo['protocolVersion'] ) ) {
67 $this->assertSame( $responseInfo['protocolVersion'], $response->getProtocolVersion() );
69 if ( isset( $responseInfo['body'] ) ) {
70 $this->assertSame( $responseInfo['body'], $response->getBody()->getContents() );
74 array_diff( array_keys( $responseInfo ), [
80 '$responseInfo may not contain unknown keys' );