federationFactory = $this->createMock(ICloudFederationFactory::class); $this->federationManager = $this->createMock(ICloudFederationProviderManager::class); $this->url = $this->createMock(IURLGenerator::class); $this->calendarFederationNotifier = new CalendarFederationNotifier( $this->federationFactory, $this->federationManager, $this->url, ); } public function testNotifySyncCalendar(): void { $cloudId = $this->createMock(ICloudId::class); $cloudId->method('getId') ->willReturn('remote1@nextcloud.remote'); $cloudId->method('getRemote') ->willReturn('nextcloud.remote'); $this->url->expects(self::once()) ->method('linkTo') ->with('', 'remote.php') ->willReturn('/remote.php'); $this->url->expects(self::once()) ->method('getAbsoluteURL') ->with('/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1') ->willReturn('https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1'); $notification = $this->createMock(ICloudFederationNotification::class); $notification->expects(self::once()) ->method('setMessage') ->with( 'SYNC_CALENDAR', 'calendar', 'calendar', [ 'sharedSecret' => 'token', 'shareWith' => 'remote1@nextcloud.remote', 'calendarUrl' => 'https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1', ], ); $this->federationFactory->expects(self::once()) ->method('getCloudFederationNotification') ->willReturn($notification); $response = $this->createMock(IResponse::class); $this->federationManager->expects(self::once()) ->method('sendCloudNotification') ->with('nextcloud.remote', $notification) ->willReturn($response); $this->calendarFederationNotifier->notifySyncCalendar($cloudId, 'host1', 'cal1', 'token'); } public function testNotifySyncCalendarShouldRethrowOcmException(): void { $cloudId = $this->createMock(ICloudId::class); $cloudId->method('getId') ->willReturn('remote1@nextcloud.remote'); $cloudId->method('getRemote') ->willReturn('nextcloud.remote'); $this->url->expects(self::once()) ->method('linkTo') ->with('', 'remote.php') ->willReturn('/remote.php'); $this->url->expects(self::once()) ->method('getAbsoluteURL') ->with('/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1') ->willReturn('https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1'); $notification = $this->createMock(ICloudFederationNotification::class); $notification->expects(self::once()) ->method('setMessage') ->with( 'SYNC_CALENDAR', 'calendar', 'calendar', [ 'sharedSecret' => 'token', 'shareWith' => 'remote1@nextcloud.remote', 'calendarUrl' => 'https://nextcloud.host/remote.php/dav/remote-calendars/cmVtb3RlMUBuZXh0Y2xvdWQucmVtb3Rl/cal1_shared_by_host1', ], ); $this->federationFactory->expects(self::once()) ->method('getCloudFederationNotification') ->willReturn($notification); $this->federationManager->expects(self::once()) ->method('sendCloudNotification') ->with('nextcloud.remote', $notification) ->willThrowException(new OCMProviderException('I threw this')); $this->expectException(OCMProviderException::class); $this->expectExceptionMessage('I threw this'); $this->calendarFederationNotifier->notifySyncCalendar($cloudId, 'host1', 'cal1', 'token'); } }