CachedSubscriptionProviderTest.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2024 Daniel Kesselberg <mail@danielkesselberg.de>
  5. *
  6. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\DAV\Tests\unit\CalDAV;
  25. use OCA\DAV\CalDAV\CachedSubscriptionImpl;
  26. use OCA\DAV\CalDAV\CachedSubscriptionProvider;
  27. use OCA\DAV\CalDAV\CalDavBackend;
  28. use Test\TestCase;
  29. class CachedSubscriptionProviderTest extends TestCase {
  30. private CalDavBackend $backend;
  31. private CachedSubscriptionProvider $provider;
  32. protected function setUp(): void {
  33. parent::setUp();
  34. $this->backend = $this->createMock(CalDavBackend::class);
  35. $this->backend
  36. ->expects(self::once())
  37. ->method('getSubscriptionsForUser')
  38. ->with('user-principal-123')
  39. ->willReturn([
  40. [
  41. 'id' => 'subscription-1',
  42. 'uri' => 'subscription-1',
  43. 'principaluris' => 'user-principal-123',
  44. 'source' => 'https://localhost/subscription-1',
  45. // A subscription array has actually more properties.
  46. ],
  47. [
  48. 'id' => 'subscription-2',
  49. 'uri' => 'subscription-2',
  50. 'principaluri' => 'user-principal-123',
  51. 'source' => 'https://localhost/subscription-2',
  52. // A subscription array has actually more properties.
  53. ]
  54. ]);
  55. $this->provider = new CachedSubscriptionProvider($this->backend);
  56. }
  57. public function testGetCalendars() {
  58. $calendars = $this->provider->getCalendars(
  59. 'user-principal-123',
  60. []
  61. );
  62. $this->assertCount(2, $calendars);
  63. $this->assertInstanceOf(CachedSubscriptionImpl::class, $calendars[0]);
  64. $this->assertInstanceOf(CachedSubscriptionImpl::class, $calendars[1]);
  65. }
  66. public function testGetCalendarsFilterByUri() {
  67. $calendars = $this->provider->getCalendars(
  68. 'user-principal-123',
  69. ['subscription-1']
  70. );
  71. $this->assertCount(1, $calendars);
  72. $this->assertInstanceOf(CachedSubscriptionImpl::class, $calendars[0]);
  73. $this->assertEquals('subscription-1', $calendars[0]->getUri());
  74. }
  75. }