aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorCôme Chilliet <91878298+come-nc@users.noreply.github.com>2024-09-12 14:34:07 +0200
committerGitHub <noreply@github.com>2024-09-12 14:34:07 +0200
commitb6c286640f3fe4ab9eef8817e093a0403189f40c (patch)
treee3b1c31da302ef36d7a80805db6b038a0586f101 /tests
parenta2ac1d8be05a482aa649d902b47b4ed688f21f8d (diff)
parent90a948506bad93c4ebdbf4dfdbdd97a91a847c12 (diff)
downloadnextcloud-server-b6c286640f3fe4ab9eef8817e093a0403189f40c.tar.gz
nextcloud-server-b6c286640f3fe4ab9eef8817e093a0403189f40c.zip
Merge pull request #47685 from nextcloud/fix/move-apihelper-to-oc-namespace
fix: Move OC_API into \OC\ApiHelper in standard namespace
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/APITest.php84
-rw-r--r--tests/lib/AppFramework/OCS/BaseResponseTest.php2
-rw-r--r--tests/lib/AppFramework/OCS/V2ResponseTest.php38
-rw-r--r--tests/lib/OCS/ApiHelperTest.php54
-rw-r--r--tests/lib/OCS/MapStatusCodeTest.php29
5 files changed, 93 insertions, 114 deletions
diff --git a/tests/lib/APITest.php b/tests/lib/APITest.php
deleted file mode 100644
index cc255b929ad..00000000000
--- a/tests/lib/APITest.php
+++ /dev/null
@@ -1,84 +0,0 @@
-<?php
-/**
- * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
- * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-
-namespace Test;
-
-use OCP\IRequest;
-
-class APITest extends \Test\TestCase {
- // Helps build a response variable
-
- /**
- * @param string $message
- */
- public function buildResponse($shipped, $data, $code, $message = null) {
- $resp = new \OC\OCS\Result($data, $code, $message);
- $resp->addHeader('KEY', 'VALUE');
- return [
- 'shipped' => $shipped,
- 'response' => $resp,
- 'app' => $this->getUniqueID('testapp_'),
- ];
- }
-
- // Validate details of the result
-
- /**
- * @param \OC\OCS\Result $result
- */
- public function checkResult($result, $success) {
- // Check response is of correct type
- $this->assertInstanceOf(\OC\OCS\Result::class, $result);
- // Check if it succeeded
- /** @var \OC\OCS\Result $result */
- $this->assertEquals($success, $result->succeeded());
- }
-
- /**
- * @return array
- */
- public function versionDataScriptNameProvider() {
- return [
- // Valid script name
- [
- '/master/ocs/v2.php',
- true,
- ],
-
- // Invalid script names
- [
- '/master/ocs/v2.php/someInvalidPathName',
- false,
- ],
- [
- '/master/ocs/v1.php',
- false,
- ],
- [
- '',
- false,
- ],
- ];
- }
-
- /**
- * @dataProvider versionDataScriptNameProvider
- * @param string $scriptName
- * @param bool $expected
- */
- public function testIsV2($scriptName, $expected) {
- $request = $this->getMockBuilder(IRequest::class)
- ->disableOriginalConstructor()
- ->getMock();
- $request
- ->expects($this->once())
- ->method('getScriptName')
- ->willReturn($scriptName);
-
- $this->assertEquals($expected, $this->invokePrivate(new \OC_API, 'isV2', [$request]));
- }
-}
diff --git a/tests/lib/AppFramework/OCS/BaseResponseTest.php b/tests/lib/AppFramework/OCS/BaseResponseTest.php
index aaa107ef013..159459a4aec 100644
--- a/tests/lib/AppFramework/OCS/BaseResponseTest.php
+++ b/tests/lib/AppFramework/OCS/BaseResponseTest.php
@@ -7,7 +7,7 @@ declare(strict_types=1);
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
-namespace Test\AppFramework\Middleware;
+namespace Test\AppFramework\OCS;
use OC\AppFramework\OCS\BaseResponse;
diff --git a/tests/lib/AppFramework/OCS/V2ResponseTest.php b/tests/lib/AppFramework/OCS/V2ResponseTest.php
new file mode 100644
index 00000000000..97a227418f3
--- /dev/null
+++ b/tests/lib/AppFramework/OCS/V2ResponseTest.php
@@ -0,0 +1,38 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace Test\AppFramework\OCS;
+
+use OC\AppFramework\OCS\V2Response;
+use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\DataResponse;
+use OCP\AppFramework\OCSController;
+
+class V2ResponseTest extends \Test\TestCase {
+ /**
+ * @dataProvider providesStatusCodes
+ */
+ public function testStatusCodeMapper(int $expected, int $sc): void {
+ $response = new V2Response(new DataResponse([], $sc));
+ $this->assertEquals($expected, $response->getStatus());
+ }
+
+ public function providesStatusCodes(): array {
+ return [
+ [Http::STATUS_OK, 200],
+ [Http::STATUS_BAD_REQUEST, 104],
+ [Http::STATUS_BAD_REQUEST, 1000],
+ [201, 201],
+ [Http::STATUS_UNAUTHORIZED, OCSController::RESPOND_UNAUTHORISED],
+ [Http::STATUS_INTERNAL_SERVER_ERROR, OCSController::RESPOND_SERVER_ERROR],
+ [Http::STATUS_NOT_FOUND, OCSController::RESPOND_NOT_FOUND],
+ [Http::STATUS_INTERNAL_SERVER_ERROR, OCSController::RESPOND_UNKNOWN_ERROR],
+ ];
+ }
+}
diff --git a/tests/lib/OCS/ApiHelperTest.php b/tests/lib/OCS/ApiHelperTest.php
new file mode 100644
index 00000000000..fdbc1f4c538
--- /dev/null
+++ b/tests/lib/OCS/ApiHelperTest.php
@@ -0,0 +1,54 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace Test\OCS;
+
+use OC\OCS\ApiHelper;
+use OCP\IRequest;
+
+class ApiHelperTest extends \Test\TestCase {
+ /**
+ * @return array
+ */
+ public function versionDataScriptNameProvider(): array {
+ return [
+ // Valid script name
+ [
+ '/master/ocs/v2.php', true,
+ ],
+
+ // Invalid script names
+ [
+ '/master/ocs/v2.php/someInvalidPathName', false,
+ ],
+ [
+ '/master/ocs/v1.php', false,
+ ],
+ [
+ '', false,
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider versionDataScriptNameProvider
+ */
+ public function testIsV2(string $scriptName, bool $expected): void {
+ $request = $this->getMockBuilder(IRequest::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $request
+ ->expects($this->once())
+ ->method('getScriptName')
+ ->willReturn($scriptName);
+
+ $this->assertEquals($expected, $this->invokePrivate(new ApiHelper, 'isV2', [$request]));
+ }
+}
diff --git a/tests/lib/OCS/MapStatusCodeTest.php b/tests/lib/OCS/MapStatusCodeTest.php
deleted file mode 100644
index c6d6d5edd06..00000000000
--- a/tests/lib/OCS/MapStatusCodeTest.php
+++ /dev/null
@@ -1,29 +0,0 @@
-<?php
-/**
- * SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors
- * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
- * SPDX-License-Identifier: AGPL-3.0-only
- */
-
-namespace Test\OCS;
-
-use OCP\AppFramework\Http;
-
-class MapStatusCodeTest 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_BAD_REQUEST, 1000],
- [201, 201],
- ];
- }
-}