share = $this->getMockBuilder(IShare::class)->getMock(); $this->federatedShareProvider = $this->getMockBuilder('OCA\FederatedFileSharing\FederatedShareProvider') ->disableOriginalConstructor()->getMock(); $this->federatedShareProvider->expects($this->any()) ->method('isOutgoingServer2serverShareEnabled')->willReturn(true); $this->federatedShareProvider->expects($this->any()) ->method('isIncomingServer2serverShareEnabled')->willReturn(true); $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->cloudIdManager = $this->createMock(ICloudIdManager::class); $this->request = $this->createMock(IRequest::class); $this->connection = $this->createMock(IDBConnection::class); $this->shareManager = $this->createMock(Share\IManager::class); $this->cloudFederationFactory = $this->createMock(ICloudFederationFactory::class); $this->cloudFederationProviderManager = $this->createMock(ICloudFederationProviderManager::class); $this->cloudFederationProvider = $this->createMock(ICloudFederationProvider::class); $this->cloudFederationShare = $this->createMock(ICloudFederationShare::class); $this->eventDispatcher = $this->createMock(IEventDispatcher::class); $this->eventDispatcher->expects($this->any())->method('dispatchTyped'); $this->logger = $this->createMock(LoggerInterface::class); $this->requestHandler = new RequestHandlerController( 'federatedfilesharing', $this->request, $this->federatedShareProvider, $this->connection, $this->shareManager, $this->notifications, $this->addressHandler, $this->userManager, $this->cloudIdManager, $this->logger, $this->cloudFederationFactory, $this->cloudFederationProviderManager, $this->eventDispatcher ); } public function testCreateShare() { $this->cloudFederationFactory->expects($this->once())->method('getCloudFederationShare') ->with( $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 */ $this->cloudFederationProviderManager->expects($this->once()) ->method('getCloudFederationProvider') ->with('file') ->willReturn($this->cloudFederationProvider); $this->cloudFederationProvider->expects($this->once())->method('shareReceived') ->with($this->cloudFederationShare); $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() { $id = 42; $notification = [ 'sharedSecret' => 'token', 'message' => 'Recipient declined the share' ]; $this->cloudFederationProviderManager->expects($this->once()) ->method('getCloudFederationProvider') ->with('file') ->willReturn($this->cloudFederationProvider); $this->cloudFederationProvider->expects($this->once()) ->method('notificationReceived') ->with('SHARE_DECLINED', $id, $notification); $result = $this->requestHandler->declineShare($id, 'token'); $this->assertInstanceOf(DataResponse::class, $result); } public function testAcceptShare() { $id = 42; $notification = [ 'sharedSecret' => 'token', 'message' => 'Recipient accept the share' ]; $this->cloudFederationProviderManager->expects($this->once()) ->method('getCloudFederationProvider') ->with('file') ->willReturn($this->cloudFederationProvider); $this->cloudFederationProvider->expects($this->once()) ->method('notificationReceived') ->with('SHARE_ACCEPTED', $id, $notification); $result = $this->requestHandler->acceptShare($id, 'token'); $this->assertInstanceOf(DataResponse::class, $result); } }