diff --git a/lib/public/AppFramework/OCSController.php b/lib/public/AppFramework/OCSController.php
index bd50f0a4017a0..6036fc6a5a87a 100644
--- a/lib/public/AppFramework/OCSController.php
+++ b/lib/public/AppFramework/OCSController.php
@@ -88,26 +88,19 @@ public function buildResponse($response, $format = 'xml') {
/**
* Unwrap data and build ocs response
* @param string $format json or xml
- * @param array|DataResponse $data the data which should be transformed
+ * @param DataResponse $data the data which should be transformed
* @since 8.1.0
+ * @return OCSResponse
*/
- private function buildOCSResponse($format, $data) {
- if ($data instanceof DataResponse) {
- $data = $data->getData();
- }
-
+ private function buildOCSResponse($format, DataResponse $data) {
$params = [
'statuscode' => 100,
'message' => 'OK',
- 'data' => [],
+ 'data' => $data->getData(),
'itemscount' => '',
'itemsperpage' => ''
];
- foreach ($data as $key => $value) {
- $params[$key] = $value;
- }
-
return new OCSResponse(
$format, $params['statuscode'],
$params['message'], $params['data'],
diff --git a/tests/lib/AppFramework/Controller/OCSControllerTest.php b/tests/lib/AppFramework/Controller/OCSControllerTest.php
index 7dcbd189cd585..9c9214181a4f4 100644
--- a/tests/lib/AppFramework/Controller/OCSControllerTest.php
+++ b/tests/lib/AppFramework/Controller/OCSControllerTest.php
@@ -75,8 +75,8 @@ public function testXML() {
$expected = "\n" .
"\n" .
" \n" .
- " failure\n" .
- " 400\n" .
+ " ok\n" .
+ " 100\n" .
" OK\n" .
" \n" .
" \n" .
@@ -86,54 +86,12 @@ public function testXML() {
" \n" .
"\n";
- $params = [
- 'data' => [
- 'test' => 'hi'
- ],
- 'statuscode' => 400
- ];
+ $params = new DataResponse(['test' => 'hi']);
$out = $controller->buildResponse($params, 'xml')->render();
$this->assertEquals($expected, $out);
}
-
- public function testXMLDataResponse() {
- $controller = new ChildOCSController('app', new Request(
- [],
- $this->getMockBuilder('\OCP\Security\ISecureRandom')
- ->disableOriginalConstructor()
- ->getMock(),
- $this->getMockBuilder('\OCP\IConfig')
- ->disableOriginalConstructor()
- ->getMock()
- ));
- $expected = "\n" .
- "\n" .
- " \n" .
- " failure\n" .
- " 400\n" .
- " OK\n" .
- " \n" .
- " \n" .
- " \n" .
- " \n" .
- " hi\n" .
- " \n" .
- "\n";
-
- $params = new DataResponse([
- 'data' => [
- 'test' => 'hi'
- ],
- 'statuscode' => 400
- ]);
-
- $out = $controller->buildResponse($params, 'xml')->render();
- $this->assertEquals($expected, $out);
- }
-
-
public function testJSON() {
$controller = new ChildOCSController('app', new Request(
[],
@@ -144,14 +102,9 @@ public function testJSON() {
->disableOriginalConstructor()
->getMock()
));
- $expected = '{"ocs":{"meta":{"status":"failure","statuscode":400,"message":"OK",' .
+ $expected = '{"ocs":{"meta":{"status":"ok","statuscode":100,"message":"OK",' .
'"totalitems":"","itemsperpage":""},"data":{"test":"hi"}}}';
- $params = [
- 'data' => [
- 'test' => 'hi'
- ],
- 'statuscode' => 400
- ];
+ $params = new DataResponse(['test' => 'hi']);
$out = $controller->buildResponse($params, 'json')->render();
$this->assertEquals($expected, $out);