Fix unit tests
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
609b8aff12
commit
fd0c1a3bb2
|
@ -31,6 +31,7 @@ use OCA\DAV\CalDAV\WebcalCaching\RefreshWebcalService;
|
||||||
use OCP\Http\Client\IClient;
|
use OCP\Http\Client\IClient;
|
||||||
use OCP\Http\Client\IClientService;
|
use OCP\Http\Client\IClientService;
|
||||||
use OCP\Http\Client\IResponse;
|
use OCP\Http\Client\IResponse;
|
||||||
|
use OCP\Http\Client\LocalServerException;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
|
@ -170,8 +171,12 @@ class RefreshWebcalServiceTest extends TestCase {
|
||||||
* @param string $source
|
* @param string $source
|
||||||
*/
|
*/
|
||||||
public function testRunLocalURL($source) {
|
public function testRunLocalURL($source) {
|
||||||
$refreshWebcalService = new RefreshWebcalService($this->caldavBackend,
|
$refreshWebcalService = new RefreshWebcalService(
|
||||||
$this->clientService, $this->config, $this->logger);
|
$this->caldavBackend,
|
||||||
|
$this->clientService,
|
||||||
|
$this->config,
|
||||||
|
$this->logger
|
||||||
|
);
|
||||||
|
|
||||||
$this->caldavBackend->expects($this->once())
|
$this->caldavBackend->expects($this->once())
|
||||||
->method('getSubscriptionsForUser')
|
->method('getSubscriptionsForUser')
|
||||||
|
@ -199,8 +204,13 @@ class RefreshWebcalServiceTest extends TestCase {
|
||||||
->with('dav', 'webcalAllowLocalAccess', 'no')
|
->with('dav', 'webcalAllowLocalAccess', 'no')
|
||||||
->willReturn('no');
|
->willReturn('no');
|
||||||
|
|
||||||
$client->expects($this->never())
|
$client->expects($this->once())
|
||||||
->method('get');
|
->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');
|
$refreshWebcalService->refreshSubscription('principals/users/testuser', 'sub123');
|
||||||
}
|
}
|
||||||
|
@ -221,7 +231,42 @@ class RefreshWebcalServiceTest extends TestCase {
|
||||||
['10.0.0.1'],
|
['10.0.0.1'],
|
||||||
['another-host.local'],
|
['another-host.local'],
|
||||||
['service.localhost'],
|
['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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ use OC\Http\Client\Client;
|
||||||
use OC\Http\Client\ClientService;
|
use OC\Http\Client\ClientService;
|
||||||
use OCP\ICertificateManager;
|
use OCP\ICertificateManager;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
|
use OCP\ILogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ClientServiceTest
|
* Class ClientServiceTest
|
||||||
|
@ -23,10 +24,11 @@ class ClientServiceTest extends \Test\TestCase {
|
||||||
$config = $this->createMock(IConfig::class);
|
$config = $this->createMock(IConfig::class);
|
||||||
/** @var ICertificateManager $certificateManager */
|
/** @var ICertificateManager $certificateManager */
|
||||||
$certificateManager = $this->createMock(ICertificateManager::class);
|
$certificateManager = $this->createMock(ICertificateManager::class);
|
||||||
|
$logger = $this->createMock(ILogger::class);
|
||||||
|
|
||||||
$clientService = new ClientService($config, $certificateManager);
|
$clientService = new ClientService($config, $logger, $certificateManager);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
new Client($config, $certificateManager, new GuzzleClient()),
|
new Client($config, $logger, $certificateManager, new GuzzleClient()),
|
||||||
$clientService->newClient()
|
$clientService->newClient()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue