summaryrefslogtreecommitdiffstats
path: root/apps/dav/tests/unit/CalDAV
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2020-04-14 18:55:41 +0200
committerJoas Schilling <coding@schilljs.com>2020-04-15 08:06:51 +0200
commitfd0c1a3bb234fdfeb01bb5f36b2c1183ef01bc9c (patch)
treeb8447650d1fab0925a38777395d3b94fe7df1921 /apps/dav/tests/unit/CalDAV
parent609b8aff12935ac158d60491fe7211946ed28838 (diff)
downloadnextcloud-server-fd0c1a3bb234fdfeb01bb5f36b2c1183ef01bc9c.tar.gz
nextcloud-server-fd0c1a3bb234fdfeb01bb5f36b2c1183ef01bc9c.zip
Fix unit tests
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/dav/tests/unit/CalDAV')
-rw-r--r--apps/dav/tests/unit/CalDAV/WebcalCaching/RefreshWebcalServiceTest.php55
1 files changed, 50 insertions, 5 deletions
diff --git a/apps/dav/tests/unit/CalDAV/WebcalCaching/RefreshWebcalServiceTest.php b/apps/dav/tests/unit/CalDAV/WebcalCaching/RefreshWebcalServiceTest.php
index 8de32ad8c35..e662f4651a0 100644
--- a/apps/dav/tests/unit/CalDAV/WebcalCaching/RefreshWebcalServiceTest.php
+++ b/apps/dav/tests/unit/CalDAV/WebcalCaching/RefreshWebcalServiceTest.php
@@ -31,6 +31,7 @@ use OCA\DAV\CalDAV\WebcalCaching\RefreshWebcalService;
use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
use OCP\Http\Client\IResponse;
+use OCP\Http\Client\LocalServerException;
use OCP\IConfig;
use OCP\ILogger;
use PHPUnit\Framework\MockObject\MockObject;
@@ -170,8 +171,12 @@ class RefreshWebcalServiceTest extends TestCase {
* @param string $source
*/
public function testRunLocalURL($source) {
- $refreshWebcalService = new RefreshWebcalService($this->caldavBackend,
- $this->clientService, $this->config, $this->logger);
+ $refreshWebcalService = new RefreshWebcalService(
+ $this->caldavBackend,
+ $this->clientService,
+ $this->config,
+ $this->logger
+ );
$this->caldavBackend->expects($this->once())
->method('getSubscriptionsForUser')
@@ -199,8 +204,13 @@ class RefreshWebcalServiceTest extends TestCase {
->with('dav', 'webcalAllowLocalAccess', 'no')
->willReturn('no');
- $client->expects($this->never())
- ->method('get');
+ $client->expects($this->once())
+ ->method('get')
+ ->willThrowException(new LocalServerException());
+
+ $this->logger->expects($this->once())
+ ->method('logException')
+ ->with($this->isInstanceOf(LocalServerException::class), $this->anything());
$refreshWebcalService->refreshSubscription('principals/users/testuser', 'sub123');
}
@@ -221,7 +231,42 @@ class RefreshWebcalServiceTest extends TestCase {
['10.0.0.1'],
['another-host.local'],
['service.localhost'],
- ['!@#$'], // test invalid url
];
}
+
+ public function testInvalidUrl() {
+ $refreshWebcalService = new RefreshWebcalService($this->caldavBackend,
+ $this->clientService, $this->config, $this->logger);
+
+ $this->caldavBackend->expects($this->once())
+ ->method('getSubscriptionsForUser')
+ ->with('principals/users/testuser')
+ ->willReturn([
+ [
+ 'id' => 42,
+ 'uri' => 'sub123',
+ 'refreshreate' => 'P1H',
+ 'striptodos' => 1,
+ 'stripalarms' => 1,
+ 'stripattachments' => 1,
+ 'source' => '!@#$'
+ ],
+ ]);
+
+ $client = $this->createMock(IClient::class);
+ $this->clientService->expects($this->once())
+ ->method('newClient')
+ ->with()
+ ->willReturn($client);
+
+ $this->config->expects($this->once())
+ ->method('getAppValue')
+ ->with('dav', 'webcalAllowLocalAccess', 'no')
+ ->willReturn('no');
+
+ $client->expects($this->never())
+ ->method('get');
+
+ $refreshWebcalService->refreshSubscription('principals/users/testuser', 'sub123');
+ }
}