Skip to content

Commit

Permalink
fixup! fix(caldav): add missing handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
miaulalala committed Oct 1, 2024
1 parent 5469384 commit f164841
Showing 1 changed file with 17 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@
*/
namespace OCA\DAV\Tests\unit\CalDAV\WebcalCaching;

use GuzzleHttp\HandlerStack;
use OCA\DAV\CalDAV\CalDavBackend;
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\IAppConfig;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Exception\BadRequest;
Expand All @@ -50,7 +49,7 @@ class RefreshWebcalServiceTest extends TestCase {
/** @var IClientService | MockObject */
private $clientService;

/** @var IConfig | MockObject */
/** @var IAppConfig | MockObject */
private $config;

/** @var LoggerInterface | MockObject */
Expand All @@ -61,7 +60,7 @@ protected function setUp(): void {

$this->caldavBackend = $this->createMock(CalDavBackend::class);
$this->clientService = $this->createMock(IClientService::class);
$this->config = $this->createMock(IConfig::class);
$this->config = $this->createMock(IAppConfig::class);
$this->logger = $this->createMock(LoggerInterface::class);
}

Expand Down Expand Up @@ -114,15 +113,13 @@ public function testRun(string $body, string $contentType, string $result): void
->willReturn($client);

$this->config->expects($this->once())
->method('getAppValue')
->method('getValueString')
->with('dav', 'webcalAllowLocalAccess', 'no')
->willReturn('no');

$client->expects($this->once())
->method('get')
->with('https://foo.bar/bla2', $this->callback(function ($obj) {
return $obj['allow_redirects']['redirects'] === 10 && $obj['handler'] instanceof HandlerStack;
}))
->with('https://foo.bar/bla2')
->willReturn($response);

$response->expects($this->once())
Expand Down Expand Up @@ -182,15 +179,13 @@ public function testRunCreateCalendarNoException(string $body, string $contentTy
->willReturn($client);

$this->config->expects($this->once())
->method('getAppValue')
->method('getValueString')
->with('dav', 'webcalAllowLocalAccess', 'no')
->willReturn('no');

$client->expects($this->once())
->method('get')
->with('https://foo.bar/bla2', $this->callback(function ($obj) {
return $obj['allow_redirects']['redirects'] === 10 && $obj['handler'] instanceof HandlerStack;
}))
->with('https://foo.bar/bla2')
->willReturn($response);

$response->expects($this->once())
Expand All @@ -212,7 +207,7 @@ public function testRunCreateCalendarNoException(string $body, string $contentTy

$noInstanceException = new NoInstancesException("can't add calendar object");
$this->caldavBackend->expects($this->once())
->method("createCalendarObject")
->method('createCalendarObject')
->willThrowException($noInstanceException);

$this->logger->expects($this->once())
Expand Down Expand Up @@ -259,15 +254,13 @@ public function testRunCreateCalendarBadRequest(string $body, string $contentTyp
->willReturn($client);

$this->config->expects($this->once())
->method('getAppValue')
->method('getValueString')
->with('dav', 'webcalAllowLocalAccess', 'no')
->willReturn('no');

$client->expects($this->once())
->method('get')
->with('https://foo.bar/bla2', $this->callback(function ($obj) {
return $obj['allow_redirects']['redirects'] === 10 && $obj['handler'] instanceof HandlerStack;
}))
->with('https://foo.bar/bla2')
->willReturn($response);

$response->expects($this->once())
Expand All @@ -289,7 +282,7 @@ public function testRunCreateCalendarBadRequest(string $body, string $contentTyp

$badRequestException = new BadRequest("can't add reach calendar url");
$this->caldavBackend->expects($this->once())
->method("createCalendarObject")
->method('createCalendarObject')
->willThrowException($badRequestException);

$this->logger->expects($this->once())
Expand Down Expand Up @@ -355,7 +348,7 @@ public function testRunLocalURL(string $source): void {
->willReturn($client);

$this->config->expects($this->once())
->method('getAppValue')
->method('getValueString')
->with('dav', 'webcalAllowLocalAccess', 'no')
->willReturn('no');

Expand All @@ -367,7 +360,7 @@ public function testRunLocalURL(string $source): void {

$this->logger->expects($this->once())
->method('warning')
->with("Subscription 42 was not refreshed because it violates local access rules", ['exception' => $localServerException]);
->with('Subscription 42 was not refreshed because it violates local access rules', ['exception' => $localServerException]);

$refreshWebcalService->refreshSubscription('principals/users/testuser', 'sub123');
}
Expand Down Expand Up @@ -411,15 +404,11 @@ public function testInvalidUrl(): void {
]);

$client = $this->createMock(IClient::class);
$this->clientService->expects($this->once())
->method('newClient')
->with()
->willReturn($client);
$this->clientService->expects($this->never())
->method('newClient');

$this->config->expects($this->once())
->method('getAppValue')
->with('dav', 'webcalAllowLocalAccess', 'no')
->willReturn('no');
$this->config->expects($this->never())
->method('getValueString');

$client->expects($this->never())
->method('get');
Expand Down

0 comments on commit f164841

Please sign in to comment.