CachedSubscriptionProviderTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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\CachedSubscriptionImpl;
  9. use OCA\DAV\CalDAV\CachedSubscriptionProvider;
  10. use OCA\DAV\CalDAV\CalDavBackend;
  11. use Test\TestCase;
  12. class CachedSubscriptionProviderTest extends TestCase {
  13. private CalDavBackend $backend;
  14. private CachedSubscriptionProvider $provider;
  15. protected function setUp(): void {
  16. parent::setUp();
  17. $this->backend = $this->createMock(CalDavBackend::class);
  18. $this->backend
  19. ->expects(self::once())
  20. ->method('getSubscriptionsForUser')
  21. ->with('user-principal-123')
  22. ->willReturn([
  23. [
  24. 'id' => 'subscription-1',
  25. 'uri' => 'subscription-1',
  26. 'principaluris' => 'user-principal-123',
  27. 'source' => 'https://localhost/subscription-1',
  28. // A subscription array has actually more properties.
  29. ],
  30. [
  31. 'id' => 'subscription-2',
  32. 'uri' => 'subscription-2',
  33. 'principaluri' => 'user-principal-123',
  34. 'source' => 'https://localhost/subscription-2',
  35. // A subscription array has actually more properties.
  36. ]
  37. ]);
  38. $this->provider = new CachedSubscriptionProvider($this->backend);
  39. }
  40. public function testGetCalendars(): void {
  41. $calendars = $this->provider->getCalendars(
  42. 'user-principal-123',
  43. []
  44. );
  45. $this->assertCount(2, $calendars);
  46. $this->assertInstanceOf(CachedSubscriptionImpl::class, $calendars[0]);
  47. $this->assertInstanceOf(CachedSubscriptionImpl::class, $calendars[1]);
  48. }
  49. public function testGetCalendarsFilterByUri(): void {
  50. $calendars = $this->provider->getCalendars(
  51. 'user-principal-123',
  52. ['subscription-1']
  53. );
  54. $this->assertCount(1, $calendars);
  55. $this->assertInstanceOf(CachedSubscriptionImpl::class, $calendars[0]);
  56. $this->assertEquals('subscription-1', $calendars[0]->getUri());
  57. }
  58. }