1
0

CachedSubscriptionImplTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\DAV\Tests\unit\CalDAV;
  8. use OCA\DAV\CalDAV\CachedSubscription;
  9. use OCA\DAV\CalDAV\CachedSubscriptionImpl;
  10. use OCA\DAV\CalDAV\CalDavBackend;
  11. use Test\TestCase;
  12. class CachedSubscriptionImplTest extends TestCase {
  13. private CachedSubscription $cachedSubscription;
  14. private array $cachedSubscriptionInfo;
  15. private CachedSubscriptionImpl $cachedSubscriptionImpl;
  16. private CalDavBackend $backend;
  17. protected function setUp(): void {
  18. parent::setUp();
  19. $this->cachedSubscription = $this->createMock(CachedSubscription::class);
  20. $this->cachedSubscriptionInfo = [
  21. 'id' => 'fancy_id_123',
  22. '{DAV:}displayname' => 'user readable name 123',
  23. '{http://apple.com/ns/ical/}calendar-color' => '#AABBCC',
  24. 'uri' => '/this/is/a/uri',
  25. 'source' => 'https://test.localhost/calendar1',
  26. ];
  27. $this->backend = $this->createMock(CalDavBackend::class);
  28. $this->cachedSubscriptionImpl = new CachedSubscriptionImpl(
  29. $this->cachedSubscription,
  30. $this->cachedSubscriptionInfo,
  31. $this->backend
  32. );
  33. }
  34. public function testGetKey(): void {
  35. $this->assertEquals($this->cachedSubscriptionImpl->getKey(), 'fancy_id_123');
  36. }
  37. public function testGetDisplayname(): void {
  38. $this->assertEquals($this->cachedSubscriptionImpl->getDisplayName(), 'user readable name 123');
  39. }
  40. public function testGetDisplayColor(): void {
  41. $this->assertEquals($this->cachedSubscriptionImpl->getDisplayColor(), '#AABBCC');
  42. }
  43. public function testGetSource(): void {
  44. $this->assertEquals($this->cachedSubscriptionImpl->getSource(), 'https://test.localhost/calendar1');
  45. }
  46. public function testSearch(): void {
  47. $this->backend->expects($this->once())
  48. ->method('search')
  49. ->with($this->cachedSubscriptionInfo, 'abc', ['def'], ['ghi'], 42, 1337)
  50. ->willReturn(['SEARCHRESULTS']);
  51. $result = $this->cachedSubscriptionImpl->search('abc', ['def'], ['ghi'], 42, 1337);
  52. $this->assertEquals($result, ['SEARCHRESULTS']);
  53. }
  54. public function testGetPermissionRead(): void {
  55. $this->cachedSubscription->expects($this->once())
  56. ->method('getACL')
  57. ->with()
  58. ->willReturn([
  59. ['privilege' => '{DAV:}read']
  60. ]);
  61. $this->assertEquals(1, $this->cachedSubscriptionImpl->getPermissions());
  62. }
  63. }