+
+ /**
+ * @covers MWDebug::appendDebugInfoToApiResult
+ */
+ public function testAppendDebugInfoToApiResultXmlFormat() {
+ $request = $this->newApiRequest(
+ array( 'action' => 'help', 'format' => 'xml' ),
+ '/api.php?action=help&format=xml'
+ );
+
+ $context = new RequestContext();
+ $context->setRequest( $request );
+
+ $apiMain = new ApiMain( $context );
+
+ $result = new ApiResult( $apiMain );
+ $result->setRawMode( true );
+
+ MWDebug::appendDebugInfoToApiResult( $context, $result );
+
+ $this->assertInstanceOf( 'ApiResult', $result );
+ $data = $result->getData();
+
+ $expectedKeys = array( 'mwVersion', 'phpVersion', 'gitRevision', 'gitBranch',
+ 'gitViewUrl', 'time', 'log', 'debugLog', 'queries', 'request', 'memory',
+ 'memoryPeak', 'includes', 'profile', '_element' );
+
+ foreach( $expectedKeys as $expectedKey ) {
+ $this->assertArrayHasKey( $expectedKey, $data['debuginfo'], "debuginfo has $expectedKey" );
+ }
+
+ $xml = ApiFormatXml::recXmlPrint( 'help', $data );
+
+ // exception not thrown
+ $this->assertInternalType( 'string', $xml );
+ }
+
+ /**
+ * @param string[] $params
+ * @param string $requestUrl
+ *
+ * @return FauxRequest
+ */
+ private function newApiRequest( array $params, $requestUrl ) {
+ $request = $this->getMockBuilder( 'FauxRequest' )
+ ->setMethods( array( 'getRequestURL' ) )
+ ->setConstructorArgs( array(
+ $params
+ ) )
+ ->getMock();
+
+ $request->expects( $this->any() )
+ ->method( 'getRequestURL' )
+ ->will( $this->returnValue( $requestUrl ) );
+
+ return $request;
+ }
+