1
0

CachedSubscriptionObjectTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\DAV\Tests\unit\CalDAV;
  7. use OCA\DAV\CalDAV\CachedSubscriptionObject;
  8. use OCA\DAV\CalDAV\CalDavBackend;
  9. class CachedSubscriptionObjectTest extends \Test\TestCase {
  10. public function testGet(): void {
  11. $backend = $this->createMock(CalDavBackend::class);
  12. $calendarInfo = [
  13. '{http://owncloud.org/ns}owner-principal' => 'user1',
  14. 'principaluri' => 'user2',
  15. 'id' => 666,
  16. 'uri' => 'cal',
  17. ];
  18. $objectData = [
  19. 'uri' => 'foo123'
  20. ];
  21. $backend->expects($this->once())
  22. ->method('getCalendarObject')
  23. ->with(666, 'foo123', 1)
  24. ->willReturn([
  25. 'calendardata' => 'BEGIN...',
  26. ]);
  27. $calendarObject = new CachedSubscriptionObject($backend, $calendarInfo, $objectData);
  28. $this->assertEquals('BEGIN...', $calendarObject->get());
  29. }
  30. public function testPut(): void {
  31. $this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class);
  32. $this->expectExceptionMessage('Creating objects in a cached subscription is not allowed');
  33. $backend = $this->createMock(CalDavBackend::class);
  34. $calendarInfo = [
  35. '{http://owncloud.org/ns}owner-principal' => 'user1',
  36. 'principaluri' => 'user2',
  37. 'id' => 666,
  38. 'uri' => 'cal',
  39. ];
  40. $objectData = [
  41. 'uri' => 'foo123'
  42. ];
  43. $calendarObject = new CachedSubscriptionObject($backend, $calendarInfo, $objectData);
  44. $calendarObject->put('');
  45. }
  46. public function testDelete(): void {
  47. $this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class);
  48. $this->expectExceptionMessage('Deleting objects in a cached subscription is not allowed');
  49. $backend = $this->createMock(CalDavBackend::class);
  50. $calendarInfo = [
  51. '{http://owncloud.org/ns}owner-principal' => 'user1',
  52. 'principaluri' => 'user2',
  53. 'id' => 666,
  54. 'uri' => 'cal',
  55. ];
  56. $objectData = [
  57. 'uri' => 'foo123'
  58. ];
  59. $calendarObject = new CachedSubscriptionObject($backend, $calendarInfo, $objectData);
  60. $calendarObject->delete();
  61. }
  62. }