From aabf9345f05401c33aa6123cc8c5732c5b8bdf3d Mon Sep 17 00:00:00 2001 From: aude Date: Sat, 28 Jun 2014 20:35:52 +0200 Subject: [PATCH] Fix uncaught ApiFormatXml exception with api debuginfo Also added tests to cover this. Bug: 67246 Change-Id: Ifb2e392d3277a4702832727f70c77b170d4b2bf5 --- includes/debug/Debug.php | 1 + tests/phpunit/includes/debug/MWDebugTest.php | 58 ++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/includes/debug/Debug.php b/includes/debug/Debug.php index 21170109f2..0cea658908 100644 --- a/includes/debug/Debug.php +++ b/includes/debug/Debug.php @@ -513,6 +513,7 @@ class MWDebug { $result->setIndexedTagName( $debugInfo['debugLog'], 'msg' ); $result->setIndexedTagName( $debugInfo['queries'], 'query' ); $result->setIndexedTagName( $debugInfo['includes'], 'queries' ); + $result->setIndexedTagName( $debugInfo['profile'], 'function' ); $result->addValue( null, 'debuginfo', $debugInfo ); } diff --git a/tests/phpunit/includes/debug/MWDebugTest.php b/tests/phpunit/includes/debug/MWDebugTest.php index 91399beee0..e642177f33 100644 --- a/tests/phpunit/includes/debug/MWDebugTest.php +++ b/tests/phpunit/includes/debug/MWDebugTest.php @@ -80,4 +80,62 @@ class MWDebugTest extends MediaWikiTestCase { "Only one deprecated warning per function should be kept" ); } + + /** + * @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; + } + } -- 2.20.1