aboutsummaryrefslogtreecommitdiffstats
path: root/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php')
-rw-r--r--apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php173
1 files changed, 55 insertions, 118 deletions
diff --git a/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php b/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php
index 77f7fde70fa..81c67a29254 100644
--- a/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php
+++ b/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php
@@ -1,45 +1,30 @@
<?php
+
+declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Bjoern Schiessle <bjoern@schiessle.org>
- * @author Björn Schießle <bjoern@schiessle.org>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @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/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\FederatedFileSharing\Tests;
+use OCA\FederatedFileSharing\AddressHandler;
use OCA\FederatedFileSharing\Controller\RequestHandlerController;
+use OCA\FederatedFileSharing\FederatedShareProvider;
+use OCA\FederatedFileSharing\Notifications;
use OCP\AppFramework\Http\DataResponse;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Federation\ICloudFederationFactory;
use OCP\Federation\ICloudFederationProvider;
use OCP\Federation\ICloudFederationProviderManager;
use OCP\Federation\ICloudFederationShare;
use OCP\Federation\ICloudIdManager;
-use OCP\EventDispatcher\IEventDispatcher;
use OCP\IDBConnection;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\Share;
use OCP\Share\IShare;
+use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
/**
@@ -49,65 +34,32 @@ use Psr\Log\LoggerInterface;
* @group DB
*/
class RequestHandlerControllerTest extends \Test\TestCase {
- private $owner = 'owner';
- private $user1 = 'user1';
- private $user2 = 'user2';
- private $ownerCloudId = 'owner@server0.org';
- private $user1CloudId = 'user1@server1.org';
- private $user2CloudId = 'user2@server2.org';
-
- /** @var RequestHandlerController */
- private $requestHandler;
-
- /** @var \OCA\FederatedFileSharing\FederatedShareProvider|\PHPUnit\Framework\MockObject\MockObject */
- private $federatedShareProvider;
-
- /** @var \OCA\FederatedFileSharing\Notifications|\PHPUnit\Framework\MockObject\MockObject */
- private $notifications;
-
- /** @var \OCA\FederatedFileSharing\AddressHandler|\PHPUnit\Framework\MockObject\MockObject */
- private $addressHandler;
-
- /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
- private $userManager;
-
- /** @var IShare|\PHPUnit\Framework\MockObject\MockObject */
- private $share;
-
- /** @var ICloudIdManager|\PHPUnit\Framework\MockObject\MockObject */
- private $cloudIdManager;
-
- /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
- private $logger;
-
- /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
- private $request;
-
- /** @var IDBConnection|\PHPUnit\Framework\MockObject\MockObject */
- private $connection;
-
- /** @var Share\IManager|\PHPUnit\Framework\MockObject\MockObject */
- private $shareManager;
-
- /** @var ICloudFederationFactory|\PHPUnit\Framework\MockObject\MockObject */
- private $cloudFederationFactory;
-
- /** @var ICloudFederationProviderManager|\PHPUnit\Framework\MockObject\MockObject */
- private $cloudFederationProviderManager;
-
- /** @var ICloudFederationProvider|\PHPUnit\Framework\MockObject\MockObject */
- private $cloudFederationProvider;
-
- /** @var ICloudFederationShare|\PHPUnit\Framework\MockObject\MockObject */
- private $cloudFederationShare;
-
- /** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
- private $eventDispatcher;
+ private string $owner = 'owner';
+ private string $user1 = 'user1';
+ private string $user2 = 'user2';
+ private string $ownerCloudId = 'owner@server0.org';
+ private string $user1CloudId = 'user1@server1.org';
+
+ private RequestHandlerController $requestHandler;
+ private FederatedShareProvider&MockObject $federatedShareProvider;
+ private Notifications&MockObject $notifications;
+ private AddressHandler&MockObject $addressHandler;
+ private IUserManager&MockObject $userManager;
+ private IShare&MockObject $share;
+ private ICloudIdManager&MockObject $cloudIdManager;
+ private LoggerInterface&MockObject $logger;
+ private IRequest&MockObject $request;
+ private IDBConnection&MockObject $connection;
+ private Share\IManager&MockObject $shareManager;
+ private ICloudFederationFactory&MockObject $cloudFederationFactory;
+ private ICloudFederationProviderManager&MockObject $cloudFederationProviderManager;
+ private ICloudFederationProvider&MockObject $cloudFederationProvider;
+ private ICloudFederationShare&MockObject $cloudFederationShare;
+ private IEventDispatcher&MockObject $eventDispatcher;
protected function setUp(): void {
- $this->share = $this->getMockBuilder(IShare::class)->getMock();
- $this->federatedShareProvider = $this->getMockBuilder('OCA\FederatedFileSharing\FederatedShareProvider')
- ->disableOriginalConstructor()->getMock();
+ $this->share = $this->createMock(IShare::class);
+ $this->federatedShareProvider = $this->createMock(FederatedShareProvider::class);
$this->federatedShareProvider->expects($this->any())
->method('isOutgoingServer2serverShareEnabled')->willReturn(true);
$this->federatedShareProvider->expects($this->any())
@@ -115,11 +67,9 @@ class RequestHandlerControllerTest extends \Test\TestCase {
$this->federatedShareProvider->expects($this->any())->method('getShareById')
->willReturn($this->share);
- $this->notifications = $this->getMockBuilder('OCA\FederatedFileSharing\Notifications')
- ->disableOriginalConstructor()->getMock();
- $this->addressHandler = $this->getMockBuilder('OCA\FederatedFileSharing\AddressHandler')
- ->disableOriginalConstructor()->getMock();
- $this->userManager = $this->getMockBuilder(IUserManager::class)->getMock();
+ $this->notifications = $this->createMock(Notifications::class);
+ $this->addressHandler = $this->createMock(AddressHandler::class);
+ $this->userManager = $this->createMock(IUserManager::class);
$this->cloudIdManager = $this->createMock(ICloudIdManager::class);
$this->request = $this->createMock(IRequest::class);
$this->connection = $this->createMock(IDBConnection::class);
@@ -150,34 +100,23 @@ class RequestHandlerControllerTest extends \Test\TestCase {
);
}
- public function testCreateShare() {
- // simulate a post request
- $_POST['remote'] = 'localhost';
- $_POST['token'] = 'token';
- $_POST['name'] = 'name';
- $_POST['owner'] = $this->owner;
- $_POST['sharedBy'] = $this->user1;
- $_POST['shareWith'] = $this->user2;
- $_POST['remoteId'] = 1;
- $_POST['sharedByFederatedId'] = $this->user1CloudId;
- $_POST['ownerFederatedId'] = $this->ownerCloudId;
-
+ public function testCreateShare(): void {
$this->cloudFederationFactory->expects($this->once())->method('getCloudFederationShare')
->with(
- $this->user2,
- 'name',
- '',
- 1,
- $this->ownerCloudId,
- $this->owner,
- $this->user1CloudId,
- $this->user1,
- 'token',
- 'user',
- 'file'
+ $this->user2,
+ 'name',
+ '',
+ 1,
+ $this->ownerCloudId,
+ $this->owner,
+ $this->user1CloudId,
+ $this->user1,
+ 'token',
+ 'user',
+ 'file'
)->willReturn($this->cloudFederationShare);
- /** @var ICloudFederationProvider|\PHPUnit\Framework\MockObject\MockObject $provider */
+ /** @var ICloudFederationProvider&MockObject $provider */
$this->cloudFederationProviderManager->expects($this->once())
->method('getCloudFederationProvider')
->with('file')
@@ -186,14 +125,13 @@ class RequestHandlerControllerTest extends \Test\TestCase {
$this->cloudFederationProvider->expects($this->once())->method('shareReceived')
->with($this->cloudFederationShare);
- $result = $this->requestHandler->createShare();
+ $result = $this->requestHandler->createShare('localhost', 'token', 'name', $this->owner, $this->user1, $this->user2, 1, $this->user1CloudId, $this->ownerCloudId);
$this->assertInstanceOf(DataResponse::class, $result);
}
- public function testDeclineShare() {
+ public function testDeclineShare(): void {
$id = 42;
- $_POST['token'] = 'token';
$notification = [
'sharedSecret' => 'token',
@@ -209,15 +147,14 @@ class RequestHandlerControllerTest extends \Test\TestCase {
->method('notificationReceived')
->with('SHARE_DECLINED', $id, $notification);
- $result = $this->requestHandler->declineShare($id);
+ $result = $this->requestHandler->declineShare($id, 'token');
$this->assertInstanceOf(DataResponse::class, $result);
}
- public function testAcceptShare() {
+ public function testAcceptShare(): void {
$id = 42;
- $_POST['token'] = 'token';
$notification = [
'sharedSecret' => 'token',
@@ -233,7 +170,7 @@ class RequestHandlerControllerTest extends \Test\TestCase {
->method('notificationReceived')
->with('SHARE_ACCEPTED', $id, $notification);
- $result = $this->requestHandler->acceptShare($id);
+ $result = $this->requestHandler->acceptShare($id, 'token');
$this->assertInstanceOf(DataResponse::class, $result);
}