|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors |
| 7 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 8 | + */ |
| 9 | + |
| 10 | +namespace OCA\DAV\Tests\unit\CalDAV; |
| 11 | + |
| 12 | +use OCA\DAV\CalDAV\Calendar; |
| 13 | +use OCA\DAV\CalDAV\DefaultCalendarValidator; |
| 14 | +use Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet; |
| 15 | +use Test\TestCase; |
| 16 | + |
| 17 | +class DefaultCalendarValidatorTest extends TestCase { |
| 18 | + private DefaultCalendarValidator $validator; |
| 19 | + |
| 20 | + protected function setUp(): void { |
| 21 | + parent::setUp(); |
| 22 | + |
| 23 | + $this->validator = new DefaultCalendarValidator(); |
| 24 | + } |
| 25 | + |
| 26 | + public function testValidateScheduleDefaultCalendar(): void { |
| 27 | + $node = $this->createMock(Calendar::class); |
| 28 | + $node->expects(self::once()) |
| 29 | + ->method('isSubscription') |
| 30 | + ->willReturn(false); |
| 31 | + $node->expects(self::once()) |
| 32 | + ->method('canWrite') |
| 33 | + ->willReturn(true); |
| 34 | + $node->expects(self::once()) |
| 35 | + ->method('isShared') |
| 36 | + ->willReturn(false); |
| 37 | + $node->expects(self::once()) |
| 38 | + ->method('isDeleted') |
| 39 | + ->willReturn(false); |
| 40 | + $node->expects(self::once()) |
| 41 | + ->method('getProperties') |
| 42 | + ->willReturn([ |
| 43 | + '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VEVENT']), |
| 44 | + ]); |
| 45 | + |
| 46 | + $this->validator->validateScheduleDefaultCalendar($node); |
| 47 | + } |
| 48 | + |
| 49 | + public function testValidateScheduleDefaultCalendarWithEmptyProperties(): void { |
| 50 | + $node = $this->createMock(Calendar::class); |
| 51 | + $node->expects(self::once()) |
| 52 | + ->method('isSubscription') |
| 53 | + ->willReturn(false); |
| 54 | + $node->expects(self::once()) |
| 55 | + ->method('canWrite') |
| 56 | + ->willReturn(true); |
| 57 | + $node->expects(self::once()) |
| 58 | + ->method('isShared') |
| 59 | + ->willReturn(false); |
| 60 | + $node->expects(self::once()) |
| 61 | + ->method('isDeleted') |
| 62 | + ->willReturn(false); |
| 63 | + $node->expects(self::once()) |
| 64 | + ->method('getProperties') |
| 65 | + ->willReturn([]); |
| 66 | + |
| 67 | + $this->validator->validateScheduleDefaultCalendar($node); |
| 68 | + } |
| 69 | + |
| 70 | + public function testValidateScheduleDefaultCalendarWithSubscription(): void { |
| 71 | + $node = $this->createMock(Calendar::class); |
| 72 | + $node->expects(self::once()) |
| 73 | + ->method('isSubscription') |
| 74 | + ->willReturn(true); |
| 75 | + $node->expects(self::never()) |
| 76 | + ->method('canWrite'); |
| 77 | + $node->expects(self::never()) |
| 78 | + ->method('isShared'); |
| 79 | + $node->expects(self::never()) |
| 80 | + ->method('isDeleted'); |
| 81 | + $node->expects(self::never()) |
| 82 | + ->method('getProperties'); |
| 83 | + |
| 84 | + $this->expectException(\Sabre\DAV\Exception::class); |
| 85 | + $this->validator->validateScheduleDefaultCalendar($node); |
| 86 | + } |
| 87 | + |
| 88 | + public function testValidateScheduleDefaultCalendarWithoutWrite(): void { |
| 89 | + $node = $this->createMock(Calendar::class); |
| 90 | + $node->expects(self::once()) |
| 91 | + ->method('isSubscription') |
| 92 | + ->willReturn(false); |
| 93 | + $node->expects(self::once()) |
| 94 | + ->method('canWrite') |
| 95 | + ->willReturn(false); |
| 96 | + $node->expects(self::never()) |
| 97 | + ->method('isShared'); |
| 98 | + $node->expects(self::never()) |
| 99 | + ->method('isDeleted'); |
| 100 | + $node->expects(self::never()) |
| 101 | + ->method('getProperties'); |
| 102 | + |
| 103 | + $this->expectException(\Sabre\DAV\Exception::class); |
| 104 | + $this->validator->validateScheduleDefaultCalendar($node); |
| 105 | + } |
| 106 | + |
| 107 | + public function testValidateScheduleDefaultCalendarWithShared(): void { |
| 108 | + $node = $this->createMock(Calendar::class); |
| 109 | + $node->expects(self::once()) |
| 110 | + ->method('isSubscription') |
| 111 | + ->willReturn(false); |
| 112 | + $node->expects(self::once()) |
| 113 | + ->method('canWrite') |
| 114 | + ->willReturn(true); |
| 115 | + $node->expects(self::once()) |
| 116 | + ->method('isShared') |
| 117 | + ->willReturn(true); |
| 118 | + $node->expects(self::never()) |
| 119 | + ->method('isDeleted'); |
| 120 | + $node->expects(self::never()) |
| 121 | + ->method('getProperties'); |
| 122 | + |
| 123 | + $this->expectException(\Sabre\DAV\Exception::class); |
| 124 | + $this->validator->validateScheduleDefaultCalendar($node); |
| 125 | + } |
| 126 | + |
| 127 | + public function testValidateScheduleDefaultCalendarWithDeleted(): void { |
| 128 | + $node = $this->createMock(Calendar::class); |
| 129 | + $node->expects(self::once()) |
| 130 | + ->method('isSubscription') |
| 131 | + ->willReturn(false); |
| 132 | + $node->expects(self::once()) |
| 133 | + ->method('canWrite') |
| 134 | + ->willReturn(true); |
| 135 | + $node->expects(self::once()) |
| 136 | + ->method('isShared') |
| 137 | + ->willReturn(false); |
| 138 | + $node->expects(self::once()) |
| 139 | + ->method('isDeleted') |
| 140 | + ->willReturn(true); |
| 141 | + $node->expects(self::never()) |
| 142 | + ->method('getProperties'); |
| 143 | + |
| 144 | + $this->expectException(\Sabre\DAV\Exception::class); |
| 145 | + $this->validator->validateScheduleDefaultCalendar($node); |
| 146 | + } |
| 147 | + |
| 148 | + public function testValidateScheduleDefaultCalendarWithoutVeventSupport(): void { |
| 149 | + $node = $this->createMock(Calendar::class); |
| 150 | + $node->expects(self::once()) |
| 151 | + ->method('isSubscription') |
| 152 | + ->willReturn(false); |
| 153 | + $node->expects(self::once()) |
| 154 | + ->method('canWrite') |
| 155 | + ->willReturn(true); |
| 156 | + $node->expects(self::once()) |
| 157 | + ->method('isShared') |
| 158 | + ->willReturn(false); |
| 159 | + $node->expects(self::once()) |
| 160 | + ->method('isDeleted') |
| 161 | + ->willReturn(false); |
| 162 | + $node->expects(self::once()) |
| 163 | + ->method('getProperties') |
| 164 | + ->willReturn([ |
| 165 | + '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO']), |
| 166 | + ]); |
| 167 | + |
| 168 | + $this->expectException(\Sabre\DAV\Exception::class); |
| 169 | + $this->validator->validateScheduleDefaultCalendar($node); |
| 170 | + } |
| 171 | +} |
0 commit comments