]> source.dussan.org Git - nextcloud-server.git/commitdiff
OCSController requires DataResponse
authorRoeland Jago Douma <roeland@famdouma.nl>
Tue, 9 Aug 2016 08:03:16 +0000 (10:03 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Wed, 10 Aug 2016 10:40:26 +0000 (12:40 +0200)
The OCS Controller requires a DataResponse object to be returned.
This means that all error handling will have to be done via exceptions
thrown and handling in the middleware.

lib/public/AppFramework/OCSController.php
tests/lib/AppFramework/Controller/OCSControllerTest.php

index bd50f0a4017a0fde02e3669f9738b4623fbd16f6..6036fc6a5a87a8f0e4e705b5cba190ebbc8f6a8f 100644 (file)
@@ -88,26 +88,19 @@ abstract class OCSController extends ApiController {
        /**
         * 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'],
index 7dcbd189cd5852a16c8c1665ee4634ed9aae60ef..9c9214181a4f4577586393dff965c00cb1ee6756 100644 (file)
@@ -75,8 +75,8 @@ class OCSControllerTest extends \Test\TestCase {
                $expected = "<?xml version=\"1.0\"?>\n" .
                "<ocs>\n" .
                " <meta>\n" .
-               "  <status>failure</status>\n" .
-               "  <statuscode>400</statuscode>\n" .
+               "  <status>ok</status>\n" .
+               "  <statuscode>100</statuscode>\n" .
                "  <message>OK</message>\n" .
                "  <totalitems></totalitems>\n" .
                "  <itemsperpage></itemsperpage>\n" .
@@ -86,54 +86,12 @@ class OCSControllerTest extends \Test\TestCase {
                " </data>\n" .
                "</ocs>\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 = "<?xml version=\"1.0\"?>\n" .
-               "<ocs>\n" .
-               " <meta>\n" .
-               "  <status>failure</status>\n" .
-               "  <statuscode>400</statuscode>\n" .
-               "  <message>OK</message>\n" .
-               "  <totalitems></totalitems>\n" .
-               "  <itemsperpage></itemsperpage>\n" .
-               " </meta>\n" .
-               " <data>\n" .
-               "  <test>hi</test>\n" .
-               " </data>\n" .
-               "</ocs>\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 @@ class OCSControllerTest extends \Test\TestCase {
                                ->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);