summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBernhard Posselt <Raydiation@users.noreply.github.com>2015-08-05 17:28:08 +0200
committerBernhard Posselt <Raydiation@users.noreply.github.com>2015-08-05 17:28:08 +0200
commit7cb0934fa27a512b2e409361fe283d9c15560327 (patch)
tree1e2f9fcb7433e53e8c072aab6f3d0c81713c01f7 /tests
parent314fc11e1beb37e683cfa874e74ae3103632d803 (diff)
parent6c46430cdb6edf411142d0a73fb888391ea86fd7 (diff)
downloadnextcloud-server-7cb0934fa27a512b2e409361fe283d9c15560327.tar.gz
nextcloud-server-7cb0934fa27a512b2e409361fe283d9c15560327.zip
Merge pull request #18035 from owncloud/ocs-2.0
Adding ocs/v2.php with status code mapper
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/appframework/controller/OCSControllerTest.php12
-rw-r--r--tests/lib/appframework/http/OCSResponseTest.php5
-rw-r--r--tests/ocs/response.php42
3 files changed, 52 insertions, 7 deletions
diff --git a/tests/lib/appframework/controller/OCSControllerTest.php b/tests/lib/appframework/controller/OCSControllerTest.php
index 11a9d45eb92..92b092cf0e9 100644
--- a/tests/lib/appframework/controller/OCSControllerTest.php
+++ b/tests/lib/appframework/controller/OCSControllerTest.php
@@ -69,9 +69,11 @@ class OCSControllerTest extends \Test\TestCase {
$expected = "<?xml version=\"1.0\"?>\n" .
"<ocs>\n" .
" <meta>\n" .
- " <status>OK</status>\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" .
@@ -99,9 +101,11 @@ class OCSControllerTest extends \Test\TestCase {
$expected = "<?xml version=\"1.0\"?>\n" .
"<ocs>\n" .
" <meta>\n" .
- " <status>OK</status>\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" .
@@ -126,8 +130,8 @@ class OCSControllerTest extends \Test\TestCase {
$this->getMock('\OCP\Security\ISecureRandom'),
$this->getMock('\OCP\IConfig')
));
- $expected = '{"status":"OK","statuscode":400,"message":"OK",' .
- '"totalitems":"","itemsperpage":"","data":{"test":"hi"}}';
+ $expected = '{"ocs":{"meta":{"status":"failure","statuscode":400,"message":"OK",' .
+ '"totalitems":"","itemsperpage":""},"data":{"test":"hi"}}}';
$params = [
'data' => [
'test' => 'hi'
diff --git a/tests/lib/appframework/http/OCSResponseTest.php b/tests/lib/appframework/http/OCSResponseTest.php
index 111dc7ad0a3..1ca3e330bad 100644
--- a/tests/lib/appframework/http/OCSResponseTest.php
+++ b/tests/lib/appframework/http/OCSResponseTest.php
@@ -47,14 +47,13 @@ class OCSResponseTest extends \Test\TestCase {
public function testRender() {
$response = new OCSResponse(
- 'xml', 'status', 2, 'message', ['test' => 'hi'], 'tag', 'abc',
- 'dynamic', 3, 4
+ 'xml', 2, 'message', ['test' => 'hi'], 3, 4
);
$out = $response->render();
$expected = "<?xml version=\"1.0\"?>\n" .
"<ocs>\n" .
" <meta>\n" .
- " <status>status</status>\n" .
+ " <status>failure</status>\n" .
" <statuscode>2</statuscode>\n" .
" <message>message</message>\n" .
" <totalitems>3</totalitems>\n" .
diff --git a/tests/ocs/response.php b/tests/ocs/response.php
new file mode 100644
index 00000000000..0d5883fa4cc
--- /dev/null
+++ b/tests/ocs/response.php
@@ -0,0 +1,42 @@
+<?php
+use OCP\AppFramework\Http;
+
+/**
+ * @author Thomas Müller <thomas.mueller@tmit.eu>
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+class OcsResponseTest extends \Test\TestCase {
+
+ /**
+ * @dataProvider providesStatusCodes
+ */
+ public function testStatusCodeMapper($expected, $sc) {
+ $result = OC_API::mapStatusCodes($sc);
+ $this->assertEquals($expected, $result);
+ }
+
+ public function providesStatusCodes() {
+ return [
+ [Http::STATUS_OK, 100],
+ [Http::STATUS_BAD_REQUEST, 104],
+ [Http::STATUS_OK, 1000],
+ [201, 201],
+ ];
+ }
+}