DefaultCalendarValidatorTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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\Calendar;
  9. use OCA\DAV\CalDAV\DefaultCalendarValidator;
  10. use Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet;
  11. use Test\TestCase;
  12. class DefaultCalendarValidatorTest extends TestCase {
  13. private DefaultCalendarValidator $validator;
  14. protected function setUp(): void {
  15. parent::setUp();
  16. $this->validator = new DefaultCalendarValidator();
  17. }
  18. public function testValidateScheduleDefaultCalendar(): void {
  19. $node = $this->createMock(Calendar::class);
  20. $node->expects(self::once())
  21. ->method('isSubscription')
  22. ->willReturn(false);
  23. $node->expects(self::once())
  24. ->method('canWrite')
  25. ->willReturn(true);
  26. $node->expects(self::once())
  27. ->method('isShared')
  28. ->willReturn(false);
  29. $node->expects(self::once())
  30. ->method('isDeleted')
  31. ->willReturn(false);
  32. $node->expects(self::once())
  33. ->method('getProperties')
  34. ->willReturn([
  35. '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VEVENT']),
  36. ]);
  37. $this->validator->validateScheduleDefaultCalendar($node);
  38. }
  39. public function testValidateScheduleDefaultCalendarWithEmptyProperties(): void {
  40. $node = $this->createMock(Calendar::class);
  41. $node->expects(self::once())
  42. ->method('isSubscription')
  43. ->willReturn(false);
  44. $node->expects(self::once())
  45. ->method('canWrite')
  46. ->willReturn(true);
  47. $node->expects(self::once())
  48. ->method('isShared')
  49. ->willReturn(false);
  50. $node->expects(self::once())
  51. ->method('isDeleted')
  52. ->willReturn(false);
  53. $node->expects(self::once())
  54. ->method('getProperties')
  55. ->willReturn([]);
  56. $this->validator->validateScheduleDefaultCalendar($node);
  57. }
  58. public function testValidateScheduleDefaultCalendarWithSubscription(): void {
  59. $node = $this->createMock(Calendar::class);
  60. $node->expects(self::once())
  61. ->method('isSubscription')
  62. ->willReturn(true);
  63. $node->expects(self::never())
  64. ->method('canWrite');
  65. $node->expects(self::never())
  66. ->method('isShared');
  67. $node->expects(self::never())
  68. ->method('isDeleted');
  69. $node->expects(self::never())
  70. ->method('getProperties');
  71. $this->expectException(\Sabre\DAV\Exception::class);
  72. $this->validator->validateScheduleDefaultCalendar($node);
  73. }
  74. public function testValidateScheduleDefaultCalendarWithoutWrite(): void {
  75. $node = $this->createMock(Calendar::class);
  76. $node->expects(self::once())
  77. ->method('isSubscription')
  78. ->willReturn(false);
  79. $node->expects(self::once())
  80. ->method('canWrite')
  81. ->willReturn(false);
  82. $node->expects(self::never())
  83. ->method('isShared');
  84. $node->expects(self::never())
  85. ->method('isDeleted');
  86. $node->expects(self::never())
  87. ->method('getProperties');
  88. $this->expectException(\Sabre\DAV\Exception::class);
  89. $this->validator->validateScheduleDefaultCalendar($node);
  90. }
  91. public function testValidateScheduleDefaultCalendarWithShared(): void {
  92. $node = $this->createMock(Calendar::class);
  93. $node->expects(self::once())
  94. ->method('isSubscription')
  95. ->willReturn(false);
  96. $node->expects(self::once())
  97. ->method('canWrite')
  98. ->willReturn(true);
  99. $node->expects(self::once())
  100. ->method('isShared')
  101. ->willReturn(true);
  102. $node->expects(self::never())
  103. ->method('isDeleted');
  104. $node->expects(self::never())
  105. ->method('getProperties');
  106. $this->expectException(\Sabre\DAV\Exception::class);
  107. $this->validator->validateScheduleDefaultCalendar($node);
  108. }
  109. public function testValidateScheduleDefaultCalendarWithDeleted(): void {
  110. $node = $this->createMock(Calendar::class);
  111. $node->expects(self::once())
  112. ->method('isSubscription')
  113. ->willReturn(false);
  114. $node->expects(self::once())
  115. ->method('canWrite')
  116. ->willReturn(true);
  117. $node->expects(self::once())
  118. ->method('isShared')
  119. ->willReturn(false);
  120. $node->expects(self::once())
  121. ->method('isDeleted')
  122. ->willReturn(true);
  123. $node->expects(self::never())
  124. ->method('getProperties');
  125. $this->expectException(\Sabre\DAV\Exception::class);
  126. $this->validator->validateScheduleDefaultCalendar($node);
  127. }
  128. public function testValidateScheduleDefaultCalendarWithoutVeventSupport(): void {
  129. $node = $this->createMock(Calendar::class);
  130. $node->expects(self::once())
  131. ->method('isSubscription')
  132. ->willReturn(false);
  133. $node->expects(self::once())
  134. ->method('canWrite')
  135. ->willReturn(true);
  136. $node->expects(self::once())
  137. ->method('isShared')
  138. ->willReturn(false);
  139. $node->expects(self::once())
  140. ->method('isDeleted')
  141. ->willReturn(false);
  142. $node->expects(self::once())
  143. ->method('getProperties')
  144. ->willReturn([
  145. '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO']),
  146. ]);
  147. $this->expectException(\Sabre\DAV\Exception::class);
  148. $this->validator->validateScheduleDefaultCalendar($node);
  149. }
  150. }