diff --git a/lib/public/AppFramework/OCSController.php b/lib/public/AppFramework/OCSController.php index 2da914d33996..e2e810108a6a 100644 --- a/lib/public/AppFramework/OCSController.php +++ b/lib/public/AppFramework/OCSController.php @@ -80,8 +80,10 @@ public function __construct($appName, private function buildOCSResponse($format, $data) { if ($data instanceof Result) { $headers = $data->getHeaders(); + $d = $data->getData(); $data = $data->getMeta(); $data['headers'] = $headers; + $data['data'] = $d; } if ($data instanceof DataResponse) { $data = $data->getData(); diff --git a/tests/lib/AppFramework/Controller/OCSControllerTest.php b/tests/lib/AppFramework/Controller/OCSControllerTest.php index f69740d44966..189a4d5a1e6a 100644 --- a/tests/lib/AppFramework/Controller/OCSControllerTest.php +++ b/tests/lib/AppFramework/Controller/OCSControllerTest.php @@ -25,6 +25,7 @@ namespace Test\AppFramework\Controller; use OC\AppFramework\Http\Request; +use OC\OCS\Result; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCSController; @@ -124,8 +125,11 @@ public function testXMLDataResponse() { $this->assertEquals($expected, $out); } - - public function testJSON() { + /** + * @dataProvider providesData + * @param $params + */ + public function testJSON($params) { $controller = new ChildOCSController('app', new Request( [], $this->getMock('\OCP\Security\ISecureRandom'), @@ -133,16 +137,23 @@ public function testJSON() { )); $expected = '{"ocs":{"meta":{"status":"failure","statuscode":400,"message":"OK",' . '"totalitems":"","itemsperpage":""},"data":{"test":"hi"}}}'; - $params = [ - 'data' => [ - 'test' => 'hi' - ], - 'statuscode' => 400 - ]; $out = $controller->buildResponse($params, 'json')->render(); $this->assertEquals($expected, $out); } + public function providesData() { + return [ + 'array' => [[ + 'data' => [ + 'test' => 'hi' + ], + 'statuscode' => 400] + ], + 'ocs-resuls' => [new Result([ + 'test' => 'hi' + ], 400, 'OK')] + ]; + } }