@@ -20,304 +20,304 @@ discard block |
||
20 | 20 | use Test\TestCase; |
21 | 21 | |
22 | 22 | class CalendarTest extends TestCase { |
23 | - protected IL10N&MockObject $l10n; |
|
24 | - protected IConfig&MockObject $config; |
|
25 | - protected LoggerInterface&MockObject $logger; |
|
26 | - |
|
27 | - protected function setUp(): void { |
|
28 | - parent::setUp(); |
|
29 | - $this->l10n = $this->createMock(IL10N::class); |
|
30 | - $this->config = $this->createMock(IConfig::class); |
|
31 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
32 | - $this->l10n |
|
33 | - ->expects($this->any()) |
|
34 | - ->method('t') |
|
35 | - ->willReturnCallback(function ($text, $parameters = []) { |
|
36 | - return vsprintf($text, $parameters); |
|
37 | - }); |
|
38 | - } |
|
39 | - |
|
40 | - public function testDelete(): void { |
|
41 | - /** @var CalDavBackend&MockObject $backend */ |
|
42 | - $backend = $this->createMock(CalDavBackend::class); |
|
43 | - $backend->expects($this->never()) |
|
44 | - ->method('updateShares'); |
|
45 | - $backend->expects($this->once()) |
|
46 | - ->method('unshare'); |
|
47 | - |
|
48 | - $calendarInfo = [ |
|
49 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
50 | - 'principaluri' => 'user2', |
|
51 | - 'id' => 666, |
|
52 | - 'uri' => 'cal', |
|
53 | - ]; |
|
54 | - $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
55 | - $c->delete(); |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - public function testDeleteFromGroup(): void { |
|
60 | - /** @var CalDavBackend&MockObject $backend */ |
|
61 | - $backend = $this->createMock(CalDavBackend::class); |
|
62 | - $backend->expects($this->never()) |
|
63 | - ->method('updateShares'); |
|
64 | - $backend->expects($this->once()) |
|
65 | - ->method('unshare'); |
|
66 | - |
|
67 | - $calendarInfo = [ |
|
68 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
69 | - 'principaluri' => 'user2', |
|
70 | - 'id' => 666, |
|
71 | - 'uri' => 'cal', |
|
72 | - ]; |
|
73 | - $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
74 | - $c->delete(); |
|
75 | - } |
|
76 | - |
|
77 | - public function testDeleteOwn(): void { |
|
78 | - /** @var CalDavBackend&MockObject $backend */ |
|
79 | - $backend = $this->createMock(CalDavBackend::class); |
|
80 | - $backend->expects($this->never())->method('updateShares'); |
|
81 | - $backend->expects($this->never())->method('getShares'); |
|
82 | - |
|
83 | - $this->config->expects($this->never())->method('setUserValue'); |
|
84 | - |
|
85 | - $backend->expects($this->once())->method('deleteCalendar') |
|
86 | - ->with(666); |
|
87 | - |
|
88 | - $calendarInfo = [ |
|
89 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
90 | - 'principaluri' => 'user1', |
|
91 | - 'id' => 666, |
|
92 | - 'uri' => 'cal', |
|
93 | - ]; |
|
94 | - $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
95 | - $c->delete(); |
|
96 | - } |
|
97 | - |
|
98 | - public function testDeleteBirthdayCalendar(): void { |
|
99 | - /** @var CalDavBackend&MockObject $backend */ |
|
100 | - $backend = $this->createMock(CalDavBackend::class); |
|
101 | - $backend->expects($this->once())->method('deleteCalendar') |
|
102 | - ->with(666); |
|
103 | - |
|
104 | - $this->config->expects($this->once()) |
|
105 | - ->method('setUserValue') |
|
106 | - ->with('user1', 'dav', 'generateBirthdayCalendar', 'no'); |
|
107 | - |
|
108 | - $calendarInfo = [ |
|
109 | - '{http://owncloud.org/ns}owner-principal' => 'principals/users/user1', |
|
110 | - 'principaluri' => 'principals/users/user1', |
|
111 | - 'id' => 666, |
|
112 | - 'uri' => 'contact_birthdays', |
|
113 | - '{DAV:}displayname' => 'Test', |
|
114 | - ]; |
|
115 | - |
|
116 | - $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
117 | - $c->delete(); |
|
118 | - } |
|
119 | - |
|
120 | - public static function dataPropPatch(): array { |
|
121 | - return [ |
|
122 | - ['user1', 'user2', [], true], |
|
123 | - ['user1', 'user2', [ |
|
124 | - '{http://owncloud.org/ns}calendar-enabled' => true, |
|
125 | - ], true], |
|
126 | - ['user1', 'user2', [ |
|
127 | - '{DAV:}displayname' => true, |
|
128 | - ], true], |
|
129 | - ['user1', 'user2', [ |
|
130 | - '{DAV:}displayname' => true, |
|
131 | - '{http://owncloud.org/ns}calendar-enabled' => true, |
|
132 | - ], true], |
|
133 | - ['user1', 'user1', [], false], |
|
134 | - ['user1', 'user1', [ |
|
135 | - '{http://owncloud.org/ns}calendar-enabled' => true, |
|
136 | - ], false], |
|
137 | - ['user1', 'user1', [ |
|
138 | - '{DAV:}displayname' => true, |
|
139 | - ], false], |
|
140 | - ['user1', 'user1', [ |
|
141 | - '{DAV:}displayname' => true, |
|
142 | - '{http://owncloud.org/ns}calendar-enabled' => true, |
|
143 | - ], false], |
|
144 | - ]; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @dataProvider dataPropPatch |
|
149 | - */ |
|
150 | - public function testPropPatch(string $ownerPrincipal, string $principalUri, array $mutations, bool $shared): void { |
|
151 | - /** @var CalDavBackend&MockObject $backend */ |
|
152 | - $backend = $this->createMock(CalDavBackend::class); |
|
153 | - $calendarInfo = [ |
|
154 | - '{http://owncloud.org/ns}owner-principal' => $ownerPrincipal, |
|
155 | - 'principaluri' => $principalUri, |
|
156 | - 'id' => 666, |
|
157 | - 'uri' => 'default' |
|
158 | - ]; |
|
159 | - $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
160 | - $propPatch = new PropPatch($mutations); |
|
161 | - |
|
162 | - if (!$shared) { |
|
163 | - $backend->expects($this->once()) |
|
164 | - ->method('updateCalendar') |
|
165 | - ->with(666, $propPatch); |
|
166 | - } |
|
167 | - $c->propPatch($propPatch); |
|
168 | - $this->addToAssertionCount(1); |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * @dataProvider providesReadOnlyInfo |
|
173 | - */ |
|
174 | - public function testAcl($expectsWrite, $readOnlyValue, $hasOwnerSet, $uri = 'default'): void { |
|
175 | - /** @var CalDavBackend&MockObject $backend */ |
|
176 | - $backend = $this->createMock(CalDavBackend::class); |
|
177 | - $backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1); |
|
178 | - $calendarInfo = [ |
|
179 | - 'principaluri' => 'user2', |
|
180 | - 'id' => 666, |
|
181 | - 'uri' => $uri |
|
182 | - ]; |
|
183 | - $calendarInfo['{DAV:}displayname'] = 'Test'; |
|
184 | - if (!is_null($readOnlyValue)) { |
|
185 | - $calendarInfo['{http://owncloud.org/ns}read-only'] = $readOnlyValue; |
|
186 | - } |
|
187 | - if ($hasOwnerSet) { |
|
188 | - $calendarInfo['{http://owncloud.org/ns}owner-principal'] = 'user1'; |
|
189 | - } |
|
190 | - $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
191 | - $acl = $c->getACL(); |
|
192 | - $childAcl = $c->getChildACL(); |
|
193 | - |
|
194 | - $expectedAcl = [[ |
|
195 | - 'privilege' => '{DAV:}read', |
|
196 | - 'principal' => $hasOwnerSet ? 'user1' : 'user2', |
|
197 | - 'protected' => true |
|
198 | - ], [ |
|
199 | - 'privilege' => '{DAV:}read', |
|
200 | - 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-write', |
|
201 | - 'protected' => true, |
|
202 | - ], [ |
|
203 | - 'privilege' => '{DAV:}read', |
|
204 | - 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-read', |
|
205 | - 'protected' => true, |
|
206 | - ]]; |
|
207 | - if ($uri === BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
208 | - $expectedAcl[] = [ |
|
209 | - 'privilege' => '{DAV:}write-properties', |
|
210 | - 'principal' => $hasOwnerSet ? 'user1' : 'user2', |
|
211 | - 'protected' => true |
|
212 | - ]; |
|
213 | - $expectedAcl[] = [ |
|
214 | - 'privilege' => '{DAV:}write-properties', |
|
215 | - 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-write', |
|
216 | - 'protected' => true |
|
217 | - ]; |
|
218 | - } else { |
|
219 | - $expectedAcl[] = [ |
|
220 | - 'privilege' => '{DAV:}write', |
|
221 | - 'principal' => $hasOwnerSet ? 'user1' : 'user2', |
|
222 | - 'protected' => true |
|
223 | - ]; |
|
224 | - $expectedAcl[] = [ |
|
225 | - 'privilege' => '{DAV:}write', |
|
226 | - 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-write', |
|
227 | - 'protected' => true |
|
228 | - ]; |
|
229 | - } |
|
230 | - |
|
231 | - $expectedAcl[] = [ |
|
232 | - 'privilege' => '{DAV:}write-properties', |
|
233 | - 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-read', |
|
234 | - 'protected' => true |
|
235 | - ]; |
|
236 | - |
|
237 | - if ($hasOwnerSet) { |
|
238 | - $expectedAcl[] = [ |
|
239 | - 'privilege' => '{DAV:}read', |
|
240 | - 'principal' => 'user2', |
|
241 | - 'protected' => true |
|
242 | - ]; |
|
243 | - if ($expectsWrite) { |
|
244 | - $expectedAcl[] = [ |
|
245 | - 'privilege' => '{DAV:}write', |
|
246 | - 'principal' => 'user2', |
|
247 | - 'protected' => true |
|
248 | - ]; |
|
249 | - } else { |
|
250 | - $expectedAcl[] = [ |
|
251 | - 'privilege' => '{DAV:}write-properties', |
|
252 | - 'principal' => 'user2', |
|
253 | - 'protected' => true |
|
254 | - ]; |
|
255 | - } |
|
256 | - } |
|
257 | - $this->assertEquals($expectedAcl, $acl); |
|
258 | - $this->assertEquals($expectedAcl, $childAcl); |
|
259 | - } |
|
260 | - |
|
261 | - public static function providesReadOnlyInfo(): array { |
|
262 | - return [ |
|
263 | - 'read-only property not set' => [true, null, true], |
|
264 | - 'read-only property is false' => [true, false, true], |
|
265 | - 'read-only property is true' => [false, true, true], |
|
266 | - 'read-only property not set and no owner' => [true, null, false], |
|
267 | - 'read-only property is false and no owner' => [true, false, false], |
|
268 | - 'read-only property is true and no owner' => [false, true, false], |
|
269 | - 'birthday calendar' => [false, false, false, BirthdayService::BIRTHDAY_CALENDAR_URI] |
|
270 | - ]; |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * @dataProvider providesConfidentialClassificationData |
|
275 | - */ |
|
276 | - public function testPrivateClassification(int $expectedChildren, bool $isShared): void { |
|
277 | - $calObject0 = ['uri' => 'event-0', 'classification' => CalDavBackend::CLASSIFICATION_PUBLIC]; |
|
278 | - $calObject1 = ['uri' => 'event-1', 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL]; |
|
279 | - $calObject2 = ['uri' => 'event-2', 'classification' => CalDavBackend::CLASSIFICATION_PRIVATE]; |
|
280 | - |
|
281 | - /** @var CalDavBackend&MockObject $backend */ |
|
282 | - $backend = $this->createMock(CalDavBackend::class); |
|
283 | - $backend->expects($this->any())->method('getCalendarObjects')->willReturn([ |
|
284 | - $calObject0, $calObject1, $calObject2 |
|
285 | - ]); |
|
286 | - $backend->expects($this->any())->method('getMultipleCalendarObjects') |
|
287 | - ->with(666, ['event-0', 'event-1', 'event-2']) |
|
288 | - ->willReturn([ |
|
289 | - $calObject0, $calObject1, $calObject2 |
|
290 | - ]); |
|
291 | - $backend->expects($this->any())->method('getCalendarObject') |
|
292 | - ->willReturn($calObject2)->with(666, 'event-2'); |
|
293 | - $backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1); |
|
294 | - |
|
295 | - $calendarInfo = [ |
|
296 | - 'principaluri' => 'user2', |
|
297 | - 'id' => 666, |
|
298 | - 'uri' => 'cal', |
|
299 | - ]; |
|
300 | - |
|
301 | - if ($isShared) { |
|
302 | - $calendarInfo['{http://owncloud.org/ns}owner-principal'] = 'user1'; |
|
303 | - } |
|
304 | - $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
305 | - $children = $c->getChildren(); |
|
306 | - $this->assertEquals($expectedChildren, count($children)); |
|
307 | - $children = $c->getMultipleChildren(['event-0', 'event-1', 'event-2']); |
|
308 | - $this->assertEquals($expectedChildren, count($children)); |
|
309 | - |
|
310 | - $this->assertEquals(!$isShared, $c->childExists('event-2')); |
|
311 | - } |
|
312 | - |
|
313 | - /** |
|
314 | - * @dataProvider providesConfidentialClassificationData |
|
315 | - */ |
|
316 | - public function testConfidentialClassification(int $expectedChildren, bool $isShared): void { |
|
317 | - $start = '20160609'; |
|
318 | - $end = '20160610'; |
|
319 | - |
|
320 | - $calData = <<<EOD |
|
23 | + protected IL10N&MockObject $l10n; |
|
24 | + protected IConfig&MockObject $config; |
|
25 | + protected LoggerInterface&MockObject $logger; |
|
26 | + |
|
27 | + protected function setUp(): void { |
|
28 | + parent::setUp(); |
|
29 | + $this->l10n = $this->createMock(IL10N::class); |
|
30 | + $this->config = $this->createMock(IConfig::class); |
|
31 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
32 | + $this->l10n |
|
33 | + ->expects($this->any()) |
|
34 | + ->method('t') |
|
35 | + ->willReturnCallback(function ($text, $parameters = []) { |
|
36 | + return vsprintf($text, $parameters); |
|
37 | + }); |
|
38 | + } |
|
39 | + |
|
40 | + public function testDelete(): void { |
|
41 | + /** @var CalDavBackend&MockObject $backend */ |
|
42 | + $backend = $this->createMock(CalDavBackend::class); |
|
43 | + $backend->expects($this->never()) |
|
44 | + ->method('updateShares'); |
|
45 | + $backend->expects($this->once()) |
|
46 | + ->method('unshare'); |
|
47 | + |
|
48 | + $calendarInfo = [ |
|
49 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
50 | + 'principaluri' => 'user2', |
|
51 | + 'id' => 666, |
|
52 | + 'uri' => 'cal', |
|
53 | + ]; |
|
54 | + $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
55 | + $c->delete(); |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + public function testDeleteFromGroup(): void { |
|
60 | + /** @var CalDavBackend&MockObject $backend */ |
|
61 | + $backend = $this->createMock(CalDavBackend::class); |
|
62 | + $backend->expects($this->never()) |
|
63 | + ->method('updateShares'); |
|
64 | + $backend->expects($this->once()) |
|
65 | + ->method('unshare'); |
|
66 | + |
|
67 | + $calendarInfo = [ |
|
68 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
69 | + 'principaluri' => 'user2', |
|
70 | + 'id' => 666, |
|
71 | + 'uri' => 'cal', |
|
72 | + ]; |
|
73 | + $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
74 | + $c->delete(); |
|
75 | + } |
|
76 | + |
|
77 | + public function testDeleteOwn(): void { |
|
78 | + /** @var CalDavBackend&MockObject $backend */ |
|
79 | + $backend = $this->createMock(CalDavBackend::class); |
|
80 | + $backend->expects($this->never())->method('updateShares'); |
|
81 | + $backend->expects($this->never())->method('getShares'); |
|
82 | + |
|
83 | + $this->config->expects($this->never())->method('setUserValue'); |
|
84 | + |
|
85 | + $backend->expects($this->once())->method('deleteCalendar') |
|
86 | + ->with(666); |
|
87 | + |
|
88 | + $calendarInfo = [ |
|
89 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
90 | + 'principaluri' => 'user1', |
|
91 | + 'id' => 666, |
|
92 | + 'uri' => 'cal', |
|
93 | + ]; |
|
94 | + $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
95 | + $c->delete(); |
|
96 | + } |
|
97 | + |
|
98 | + public function testDeleteBirthdayCalendar(): void { |
|
99 | + /** @var CalDavBackend&MockObject $backend */ |
|
100 | + $backend = $this->createMock(CalDavBackend::class); |
|
101 | + $backend->expects($this->once())->method('deleteCalendar') |
|
102 | + ->with(666); |
|
103 | + |
|
104 | + $this->config->expects($this->once()) |
|
105 | + ->method('setUserValue') |
|
106 | + ->with('user1', 'dav', 'generateBirthdayCalendar', 'no'); |
|
107 | + |
|
108 | + $calendarInfo = [ |
|
109 | + '{http://owncloud.org/ns}owner-principal' => 'principals/users/user1', |
|
110 | + 'principaluri' => 'principals/users/user1', |
|
111 | + 'id' => 666, |
|
112 | + 'uri' => 'contact_birthdays', |
|
113 | + '{DAV:}displayname' => 'Test', |
|
114 | + ]; |
|
115 | + |
|
116 | + $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
117 | + $c->delete(); |
|
118 | + } |
|
119 | + |
|
120 | + public static function dataPropPatch(): array { |
|
121 | + return [ |
|
122 | + ['user1', 'user2', [], true], |
|
123 | + ['user1', 'user2', [ |
|
124 | + '{http://owncloud.org/ns}calendar-enabled' => true, |
|
125 | + ], true], |
|
126 | + ['user1', 'user2', [ |
|
127 | + '{DAV:}displayname' => true, |
|
128 | + ], true], |
|
129 | + ['user1', 'user2', [ |
|
130 | + '{DAV:}displayname' => true, |
|
131 | + '{http://owncloud.org/ns}calendar-enabled' => true, |
|
132 | + ], true], |
|
133 | + ['user1', 'user1', [], false], |
|
134 | + ['user1', 'user1', [ |
|
135 | + '{http://owncloud.org/ns}calendar-enabled' => true, |
|
136 | + ], false], |
|
137 | + ['user1', 'user1', [ |
|
138 | + '{DAV:}displayname' => true, |
|
139 | + ], false], |
|
140 | + ['user1', 'user1', [ |
|
141 | + '{DAV:}displayname' => true, |
|
142 | + '{http://owncloud.org/ns}calendar-enabled' => true, |
|
143 | + ], false], |
|
144 | + ]; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @dataProvider dataPropPatch |
|
149 | + */ |
|
150 | + public function testPropPatch(string $ownerPrincipal, string $principalUri, array $mutations, bool $shared): void { |
|
151 | + /** @var CalDavBackend&MockObject $backend */ |
|
152 | + $backend = $this->createMock(CalDavBackend::class); |
|
153 | + $calendarInfo = [ |
|
154 | + '{http://owncloud.org/ns}owner-principal' => $ownerPrincipal, |
|
155 | + 'principaluri' => $principalUri, |
|
156 | + 'id' => 666, |
|
157 | + 'uri' => 'default' |
|
158 | + ]; |
|
159 | + $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
160 | + $propPatch = new PropPatch($mutations); |
|
161 | + |
|
162 | + if (!$shared) { |
|
163 | + $backend->expects($this->once()) |
|
164 | + ->method('updateCalendar') |
|
165 | + ->with(666, $propPatch); |
|
166 | + } |
|
167 | + $c->propPatch($propPatch); |
|
168 | + $this->addToAssertionCount(1); |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * @dataProvider providesReadOnlyInfo |
|
173 | + */ |
|
174 | + public function testAcl($expectsWrite, $readOnlyValue, $hasOwnerSet, $uri = 'default'): void { |
|
175 | + /** @var CalDavBackend&MockObject $backend */ |
|
176 | + $backend = $this->createMock(CalDavBackend::class); |
|
177 | + $backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1); |
|
178 | + $calendarInfo = [ |
|
179 | + 'principaluri' => 'user2', |
|
180 | + 'id' => 666, |
|
181 | + 'uri' => $uri |
|
182 | + ]; |
|
183 | + $calendarInfo['{DAV:}displayname'] = 'Test'; |
|
184 | + if (!is_null($readOnlyValue)) { |
|
185 | + $calendarInfo['{http://owncloud.org/ns}read-only'] = $readOnlyValue; |
|
186 | + } |
|
187 | + if ($hasOwnerSet) { |
|
188 | + $calendarInfo['{http://owncloud.org/ns}owner-principal'] = 'user1'; |
|
189 | + } |
|
190 | + $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
191 | + $acl = $c->getACL(); |
|
192 | + $childAcl = $c->getChildACL(); |
|
193 | + |
|
194 | + $expectedAcl = [[ |
|
195 | + 'privilege' => '{DAV:}read', |
|
196 | + 'principal' => $hasOwnerSet ? 'user1' : 'user2', |
|
197 | + 'protected' => true |
|
198 | + ], [ |
|
199 | + 'privilege' => '{DAV:}read', |
|
200 | + 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-write', |
|
201 | + 'protected' => true, |
|
202 | + ], [ |
|
203 | + 'privilege' => '{DAV:}read', |
|
204 | + 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-read', |
|
205 | + 'protected' => true, |
|
206 | + ]]; |
|
207 | + if ($uri === BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
208 | + $expectedAcl[] = [ |
|
209 | + 'privilege' => '{DAV:}write-properties', |
|
210 | + 'principal' => $hasOwnerSet ? 'user1' : 'user2', |
|
211 | + 'protected' => true |
|
212 | + ]; |
|
213 | + $expectedAcl[] = [ |
|
214 | + 'privilege' => '{DAV:}write-properties', |
|
215 | + 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-write', |
|
216 | + 'protected' => true |
|
217 | + ]; |
|
218 | + } else { |
|
219 | + $expectedAcl[] = [ |
|
220 | + 'privilege' => '{DAV:}write', |
|
221 | + 'principal' => $hasOwnerSet ? 'user1' : 'user2', |
|
222 | + 'protected' => true |
|
223 | + ]; |
|
224 | + $expectedAcl[] = [ |
|
225 | + 'privilege' => '{DAV:}write', |
|
226 | + 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-write', |
|
227 | + 'protected' => true |
|
228 | + ]; |
|
229 | + } |
|
230 | + |
|
231 | + $expectedAcl[] = [ |
|
232 | + 'privilege' => '{DAV:}write-properties', |
|
233 | + 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-read', |
|
234 | + 'protected' => true |
|
235 | + ]; |
|
236 | + |
|
237 | + if ($hasOwnerSet) { |
|
238 | + $expectedAcl[] = [ |
|
239 | + 'privilege' => '{DAV:}read', |
|
240 | + 'principal' => 'user2', |
|
241 | + 'protected' => true |
|
242 | + ]; |
|
243 | + if ($expectsWrite) { |
|
244 | + $expectedAcl[] = [ |
|
245 | + 'privilege' => '{DAV:}write', |
|
246 | + 'principal' => 'user2', |
|
247 | + 'protected' => true |
|
248 | + ]; |
|
249 | + } else { |
|
250 | + $expectedAcl[] = [ |
|
251 | + 'privilege' => '{DAV:}write-properties', |
|
252 | + 'principal' => 'user2', |
|
253 | + 'protected' => true |
|
254 | + ]; |
|
255 | + } |
|
256 | + } |
|
257 | + $this->assertEquals($expectedAcl, $acl); |
|
258 | + $this->assertEquals($expectedAcl, $childAcl); |
|
259 | + } |
|
260 | + |
|
261 | + public static function providesReadOnlyInfo(): array { |
|
262 | + return [ |
|
263 | + 'read-only property not set' => [true, null, true], |
|
264 | + 'read-only property is false' => [true, false, true], |
|
265 | + 'read-only property is true' => [false, true, true], |
|
266 | + 'read-only property not set and no owner' => [true, null, false], |
|
267 | + 'read-only property is false and no owner' => [true, false, false], |
|
268 | + 'read-only property is true and no owner' => [false, true, false], |
|
269 | + 'birthday calendar' => [false, false, false, BirthdayService::BIRTHDAY_CALENDAR_URI] |
|
270 | + ]; |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * @dataProvider providesConfidentialClassificationData |
|
275 | + */ |
|
276 | + public function testPrivateClassification(int $expectedChildren, bool $isShared): void { |
|
277 | + $calObject0 = ['uri' => 'event-0', 'classification' => CalDavBackend::CLASSIFICATION_PUBLIC]; |
|
278 | + $calObject1 = ['uri' => 'event-1', 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL]; |
|
279 | + $calObject2 = ['uri' => 'event-2', 'classification' => CalDavBackend::CLASSIFICATION_PRIVATE]; |
|
280 | + |
|
281 | + /** @var CalDavBackend&MockObject $backend */ |
|
282 | + $backend = $this->createMock(CalDavBackend::class); |
|
283 | + $backend->expects($this->any())->method('getCalendarObjects')->willReturn([ |
|
284 | + $calObject0, $calObject1, $calObject2 |
|
285 | + ]); |
|
286 | + $backend->expects($this->any())->method('getMultipleCalendarObjects') |
|
287 | + ->with(666, ['event-0', 'event-1', 'event-2']) |
|
288 | + ->willReturn([ |
|
289 | + $calObject0, $calObject1, $calObject2 |
|
290 | + ]); |
|
291 | + $backend->expects($this->any())->method('getCalendarObject') |
|
292 | + ->willReturn($calObject2)->with(666, 'event-2'); |
|
293 | + $backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1); |
|
294 | + |
|
295 | + $calendarInfo = [ |
|
296 | + 'principaluri' => 'user2', |
|
297 | + 'id' => 666, |
|
298 | + 'uri' => 'cal', |
|
299 | + ]; |
|
300 | + |
|
301 | + if ($isShared) { |
|
302 | + $calendarInfo['{http://owncloud.org/ns}owner-principal'] = 'user1'; |
|
303 | + } |
|
304 | + $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
305 | + $children = $c->getChildren(); |
|
306 | + $this->assertEquals($expectedChildren, count($children)); |
|
307 | + $children = $c->getMultipleChildren(['event-0', 'event-1', 'event-2']); |
|
308 | + $this->assertEquals($expectedChildren, count($children)); |
|
309 | + |
|
310 | + $this->assertEquals(!$isShared, $c->childExists('event-2')); |
|
311 | + } |
|
312 | + |
|
313 | + /** |
|
314 | + * @dataProvider providesConfidentialClassificationData |
|
315 | + */ |
|
316 | + public function testConfidentialClassification(int $expectedChildren, bool $isShared): void { |
|
317 | + $start = '20160609'; |
|
318 | + $end = '20160610'; |
|
319 | + |
|
320 | + $calData = <<<EOD |
|
321 | 321 | BEGIN:VCALENDAR |
322 | 322 | PRODID:-//ownCloud calendar v1.2.2 |
323 | 323 | BEGIN:VEVENT |
@@ -359,84 +359,84 @@ discard block |
||
359 | 359 | END:VCALENDAR |
360 | 360 | EOD; |
361 | 361 | |
362 | - $calObject0 = ['uri' => 'event-0', 'classification' => CalDavBackend::CLASSIFICATION_PUBLIC]; |
|
363 | - $calObject1 = ['uri' => 'event-1', 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL, 'calendardata' => $calData]; |
|
364 | - $calObject2 = ['uri' => 'event-2', 'classification' => CalDavBackend::CLASSIFICATION_PRIVATE]; |
|
365 | - |
|
366 | - /** @var CalDavBackend&MockObject $backend */ |
|
367 | - $backend = $this->createMock(CalDavBackend::class); |
|
368 | - $backend->expects($this->any())->method('getCalendarObjects')->willReturn([ |
|
369 | - $calObject0, $calObject1, $calObject2 |
|
370 | - ]); |
|
371 | - $backend->expects($this->any())->method('getMultipleCalendarObjects') |
|
372 | - ->with(666, ['event-0', 'event-1', 'event-2']) |
|
373 | - ->willReturn([ |
|
374 | - $calObject0, $calObject1, $calObject2 |
|
375 | - ]); |
|
376 | - $backend->expects($this->any())->method('getCalendarObject') |
|
377 | - ->willReturn($calObject1)->with(666, 'event-1'); |
|
378 | - $backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1); |
|
379 | - |
|
380 | - $calendarInfo = [ |
|
381 | - '{http://owncloud.org/ns}owner-principal' => $isShared ? 'user1' : 'user2', |
|
382 | - 'principaluri' => 'user2', |
|
383 | - 'id' => 666, |
|
384 | - 'uri' => 'cal', |
|
385 | - ]; |
|
386 | - $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
387 | - |
|
388 | - $this->assertEquals(count($c->getChildren()), $expectedChildren); |
|
389 | - |
|
390 | - // test private event |
|
391 | - $privateEvent = $c->getChild('event-1'); |
|
392 | - $calData = $privateEvent->get(); |
|
393 | - $event = Reader::read($calData); |
|
394 | - |
|
395 | - $this->assertEquals($start, $event->VEVENT->DTSTART->getValue()); |
|
396 | - $this->assertEquals($end, $event->VEVENT->DTEND->getValue()); |
|
397 | - |
|
398 | - if ($isShared) { |
|
399 | - $this->assertEquals('Busy', $event->VEVENT->SUMMARY->getValue()); |
|
400 | - $this->assertArrayNotHasKey('ATTENDEE', $event->VEVENT); |
|
401 | - $this->assertArrayNotHasKey('LOCATION', $event->VEVENT); |
|
402 | - $this->assertArrayNotHasKey('DESCRIPTION', $event->VEVENT); |
|
403 | - $this->assertArrayNotHasKey('ORGANIZER', $event->VEVENT); |
|
404 | - } else { |
|
405 | - $this->assertEquals('Test Event', $event->VEVENT->SUMMARY->getValue()); |
|
406 | - } |
|
407 | - |
|
408 | - // Test l10n |
|
409 | - $l10n = $this->createMock(IL10N::class); |
|
410 | - if ($isShared) { |
|
411 | - $l10n->expects($this->once()) |
|
412 | - ->method('t') |
|
413 | - ->with('Busy') |
|
414 | - ->willReturn('Translated busy'); |
|
415 | - } else { |
|
416 | - $l10n->expects($this->never()) |
|
417 | - ->method('t'); |
|
418 | - } |
|
419 | - $c = new Calendar($backend, $calendarInfo, $l10n, $this->config, $this->logger); |
|
420 | - |
|
421 | - $calData = $c->getChild('event-1')->get(); |
|
422 | - $event = Reader::read($calData); |
|
423 | - |
|
424 | - if ($isShared) { |
|
425 | - $this->assertEquals('Translated busy', $event->VEVENT->SUMMARY->getValue()); |
|
426 | - } else { |
|
427 | - $this->assertEquals('Test Event', $event->VEVENT->SUMMARY->getValue()); |
|
428 | - } |
|
429 | - } |
|
430 | - |
|
431 | - public static function providesConfidentialClassificationData(): array { |
|
432 | - return [ |
|
433 | - [3, false], |
|
434 | - [2, true] |
|
435 | - ]; |
|
436 | - } |
|
437 | - |
|
438 | - public function testRemoveVAlarms(): void { |
|
439 | - $publicObjectData = <<<EOD |
|
362 | + $calObject0 = ['uri' => 'event-0', 'classification' => CalDavBackend::CLASSIFICATION_PUBLIC]; |
|
363 | + $calObject1 = ['uri' => 'event-1', 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL, 'calendardata' => $calData]; |
|
364 | + $calObject2 = ['uri' => 'event-2', 'classification' => CalDavBackend::CLASSIFICATION_PRIVATE]; |
|
365 | + |
|
366 | + /** @var CalDavBackend&MockObject $backend */ |
|
367 | + $backend = $this->createMock(CalDavBackend::class); |
|
368 | + $backend->expects($this->any())->method('getCalendarObjects')->willReturn([ |
|
369 | + $calObject0, $calObject1, $calObject2 |
|
370 | + ]); |
|
371 | + $backend->expects($this->any())->method('getMultipleCalendarObjects') |
|
372 | + ->with(666, ['event-0', 'event-1', 'event-2']) |
|
373 | + ->willReturn([ |
|
374 | + $calObject0, $calObject1, $calObject2 |
|
375 | + ]); |
|
376 | + $backend->expects($this->any())->method('getCalendarObject') |
|
377 | + ->willReturn($calObject1)->with(666, 'event-1'); |
|
378 | + $backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1); |
|
379 | + |
|
380 | + $calendarInfo = [ |
|
381 | + '{http://owncloud.org/ns}owner-principal' => $isShared ? 'user1' : 'user2', |
|
382 | + 'principaluri' => 'user2', |
|
383 | + 'id' => 666, |
|
384 | + 'uri' => 'cal', |
|
385 | + ]; |
|
386 | + $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger); |
|
387 | + |
|
388 | + $this->assertEquals(count($c->getChildren()), $expectedChildren); |
|
389 | + |
|
390 | + // test private event |
|
391 | + $privateEvent = $c->getChild('event-1'); |
|
392 | + $calData = $privateEvent->get(); |
|
393 | + $event = Reader::read($calData); |
|
394 | + |
|
395 | + $this->assertEquals($start, $event->VEVENT->DTSTART->getValue()); |
|
396 | + $this->assertEquals($end, $event->VEVENT->DTEND->getValue()); |
|
397 | + |
|
398 | + if ($isShared) { |
|
399 | + $this->assertEquals('Busy', $event->VEVENT->SUMMARY->getValue()); |
|
400 | + $this->assertArrayNotHasKey('ATTENDEE', $event->VEVENT); |
|
401 | + $this->assertArrayNotHasKey('LOCATION', $event->VEVENT); |
|
402 | + $this->assertArrayNotHasKey('DESCRIPTION', $event->VEVENT); |
|
403 | + $this->assertArrayNotHasKey('ORGANIZER', $event->VEVENT); |
|
404 | + } else { |
|
405 | + $this->assertEquals('Test Event', $event->VEVENT->SUMMARY->getValue()); |
|
406 | + } |
|
407 | + |
|
408 | + // Test l10n |
|
409 | + $l10n = $this->createMock(IL10N::class); |
|
410 | + if ($isShared) { |
|
411 | + $l10n->expects($this->once()) |
|
412 | + ->method('t') |
|
413 | + ->with('Busy') |
|
414 | + ->willReturn('Translated busy'); |
|
415 | + } else { |
|
416 | + $l10n->expects($this->never()) |
|
417 | + ->method('t'); |
|
418 | + } |
|
419 | + $c = new Calendar($backend, $calendarInfo, $l10n, $this->config, $this->logger); |
|
420 | + |
|
421 | + $calData = $c->getChild('event-1')->get(); |
|
422 | + $event = Reader::read($calData); |
|
423 | + |
|
424 | + if ($isShared) { |
|
425 | + $this->assertEquals('Translated busy', $event->VEVENT->SUMMARY->getValue()); |
|
426 | + } else { |
|
427 | + $this->assertEquals('Test Event', $event->VEVENT->SUMMARY->getValue()); |
|
428 | + } |
|
429 | + } |
|
430 | + |
|
431 | + public static function providesConfidentialClassificationData(): array { |
|
432 | + return [ |
|
433 | + [3, false], |
|
434 | + [2, true] |
|
435 | + ]; |
|
436 | + } |
|
437 | + |
|
438 | + public function testRemoveVAlarms(): void { |
|
439 | + $publicObjectData = <<<EOD |
|
440 | 440 | BEGIN:VCALENDAR |
441 | 441 | VERSION:2.0 |
442 | 442 | PRODID:-//Nextcloud calendar v1.5.6 |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | |
461 | 461 | EOD; |
462 | 462 | |
463 | - $confidentialObjectData = <<<EOD |
|
463 | + $confidentialObjectData = <<<EOD |
|
464 | 464 | BEGIN:VCALENDAR |
465 | 465 | VERSION:2.0 |
466 | 466 | PRODID:-//Nextcloud calendar v1.5.6 |
@@ -484,7 +484,7 @@ discard block |
||
484 | 484 | |
485 | 485 | EOD; |
486 | 486 | |
487 | - $publicObjectDataWithoutVAlarm = <<<EOD |
|
487 | + $publicObjectDataWithoutVAlarm = <<<EOD |
|
488 | 488 | BEGIN:VCALENDAR |
489 | 489 | VERSION:2.0 |
490 | 490 | PRODID:-//Nextcloud calendar v1.5.6 |
@@ -504,7 +504,7 @@ discard block |
||
504 | 504 | |
505 | 505 | EOD; |
506 | 506 | |
507 | - $confidentialObjectCleaned = <<<EOD |
|
507 | + $confidentialObjectCleaned = <<<EOD |
|
508 | 508 | BEGIN:VCALENDAR |
509 | 509 | VERSION:2.0 |
510 | 510 | PRODID:-//Nextcloud calendar v1.5.6 |
@@ -523,94 +523,94 @@ discard block |
||
523 | 523 | |
524 | 524 | |
525 | 525 | |
526 | - $publicObject = ['uri' => 'event-0', |
|
527 | - 'classification' => CalDavBackend::CLASSIFICATION_PUBLIC, |
|
528 | - 'calendardata' => $publicObjectData]; |
|
529 | - |
|
530 | - $confidentialObject = ['uri' => 'event-1', |
|
531 | - 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL, |
|
532 | - 'calendardata' => $confidentialObjectData]; |
|
533 | - |
|
534 | - /** @var CalDavBackend&MockObject $backend */ |
|
535 | - $backend = $this->createMock(CalDavBackend::class); |
|
536 | - $backend->expects($this->any()) |
|
537 | - ->method('getCalendarObjects') |
|
538 | - ->willReturn([$publicObject, $confidentialObject]); |
|
539 | - |
|
540 | - $backend->expects($this->any()) |
|
541 | - ->method('getMultipleCalendarObjects') |
|
542 | - ->with(666, ['event-0', 'event-1']) |
|
543 | - ->willReturn([$publicObject, $confidentialObject]); |
|
544 | - |
|
545 | - $backend->expects($this->any()) |
|
546 | - ->method('getCalendarObject') |
|
547 | - ->willReturnCallback(function ($cId, $uri) use ($publicObject, $confidentialObject) { |
|
548 | - switch ($uri) { |
|
549 | - case 'event-0': |
|
550 | - return $publicObject; |
|
551 | - |
|
552 | - case 'event-1': |
|
553 | - return $confidentialObject; |
|
554 | - |
|
555 | - default: |
|
556 | - throw new \Exception('unexpected uri'); |
|
557 | - } |
|
558 | - }); |
|
559 | - |
|
560 | - $backend->expects($this->any()) |
|
561 | - ->method('applyShareAcl') |
|
562 | - ->willReturnArgument(1); |
|
563 | - |
|
564 | - $calendarInfoOwner = [ |
|
565 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
566 | - 'principaluri' => 'user1', |
|
567 | - 'id' => 666, |
|
568 | - 'uri' => 'cal', |
|
569 | - ]; |
|
570 | - $calendarInfoSharedRW = [ |
|
571 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
572 | - 'principaluri' => 'user2', |
|
573 | - 'id' => 666, |
|
574 | - 'uri' => 'cal', |
|
575 | - ]; |
|
576 | - $calendarInfoSharedRO = [ |
|
577 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
578 | - '{http://owncloud.org/ns}read-only' => true, |
|
579 | - 'principaluri' => 'user2', |
|
580 | - 'id' => 666, |
|
581 | - 'uri' => 'cal', |
|
582 | - ]; |
|
583 | - |
|
584 | - $ownerCalendar = new Calendar($backend, $calendarInfoOwner, $this->l10n, $this->config, $this->logger); |
|
585 | - $rwCalendar = new Calendar($backend, $calendarInfoSharedRW, $this->l10n, $this->config, $this->logger); |
|
586 | - $roCalendar = new Calendar($backend, $calendarInfoSharedRO, $this->l10n, $this->config, $this->logger); |
|
587 | - |
|
588 | - $this->assertCount(2, $ownerCalendar->getChildren()); |
|
589 | - $this->assertCount(2, $rwCalendar->getChildren()); |
|
590 | - $this->assertCount(2, $roCalendar->getChildren()); |
|
591 | - |
|
592 | - // calendar data shall not be altered for the owner |
|
593 | - $this->assertEquals($ownerCalendar->getChild('event-0')->get(), $publicObjectData); |
|
594 | - $this->assertEquals($ownerCalendar->getChild('event-1')->get(), $confidentialObjectData); |
|
595 | - |
|
596 | - // valarms shall not be removed for read-write shares |
|
597 | - $this->assertEquals( |
|
598 | - $this->fixLinebreak($rwCalendar->getChild('event-0')->get()), |
|
599 | - $this->fixLinebreak($publicObjectData)); |
|
600 | - $this->assertEquals( |
|
601 | - $this->fixLinebreak($rwCalendar->getChild('event-1')->get()), |
|
602 | - $this->fixLinebreak($confidentialObjectCleaned)); |
|
603 | - |
|
604 | - // valarms shall be removed for read-only shares |
|
605 | - $this->assertEquals( |
|
606 | - $this->fixLinebreak($roCalendar->getChild('event-0')->get()), |
|
607 | - $this->fixLinebreak($publicObjectDataWithoutVAlarm)); |
|
608 | - $this->assertEquals( |
|
609 | - $this->fixLinebreak($roCalendar->getChild('event-1')->get()), |
|
610 | - $this->fixLinebreak($confidentialObjectCleaned)); |
|
611 | - } |
|
612 | - |
|
613 | - private function fixLinebreak(string $str): string { |
|
614 | - return preg_replace('~(*BSR_ANYCRLF)\R~', "\r\n", $str); |
|
615 | - } |
|
526 | + $publicObject = ['uri' => 'event-0', |
|
527 | + 'classification' => CalDavBackend::CLASSIFICATION_PUBLIC, |
|
528 | + 'calendardata' => $publicObjectData]; |
|
529 | + |
|
530 | + $confidentialObject = ['uri' => 'event-1', |
|
531 | + 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL, |
|
532 | + 'calendardata' => $confidentialObjectData]; |
|
533 | + |
|
534 | + /** @var CalDavBackend&MockObject $backend */ |
|
535 | + $backend = $this->createMock(CalDavBackend::class); |
|
536 | + $backend->expects($this->any()) |
|
537 | + ->method('getCalendarObjects') |
|
538 | + ->willReturn([$publicObject, $confidentialObject]); |
|
539 | + |
|
540 | + $backend->expects($this->any()) |
|
541 | + ->method('getMultipleCalendarObjects') |
|
542 | + ->with(666, ['event-0', 'event-1']) |
|
543 | + ->willReturn([$publicObject, $confidentialObject]); |
|
544 | + |
|
545 | + $backend->expects($this->any()) |
|
546 | + ->method('getCalendarObject') |
|
547 | + ->willReturnCallback(function ($cId, $uri) use ($publicObject, $confidentialObject) { |
|
548 | + switch ($uri) { |
|
549 | + case 'event-0': |
|
550 | + return $publicObject; |
|
551 | + |
|
552 | + case 'event-1': |
|
553 | + return $confidentialObject; |
|
554 | + |
|
555 | + default: |
|
556 | + throw new \Exception('unexpected uri'); |
|
557 | + } |
|
558 | + }); |
|
559 | + |
|
560 | + $backend->expects($this->any()) |
|
561 | + ->method('applyShareAcl') |
|
562 | + ->willReturnArgument(1); |
|
563 | + |
|
564 | + $calendarInfoOwner = [ |
|
565 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
566 | + 'principaluri' => 'user1', |
|
567 | + 'id' => 666, |
|
568 | + 'uri' => 'cal', |
|
569 | + ]; |
|
570 | + $calendarInfoSharedRW = [ |
|
571 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
572 | + 'principaluri' => 'user2', |
|
573 | + 'id' => 666, |
|
574 | + 'uri' => 'cal', |
|
575 | + ]; |
|
576 | + $calendarInfoSharedRO = [ |
|
577 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
578 | + '{http://owncloud.org/ns}read-only' => true, |
|
579 | + 'principaluri' => 'user2', |
|
580 | + 'id' => 666, |
|
581 | + 'uri' => 'cal', |
|
582 | + ]; |
|
583 | + |
|
584 | + $ownerCalendar = new Calendar($backend, $calendarInfoOwner, $this->l10n, $this->config, $this->logger); |
|
585 | + $rwCalendar = new Calendar($backend, $calendarInfoSharedRW, $this->l10n, $this->config, $this->logger); |
|
586 | + $roCalendar = new Calendar($backend, $calendarInfoSharedRO, $this->l10n, $this->config, $this->logger); |
|
587 | + |
|
588 | + $this->assertCount(2, $ownerCalendar->getChildren()); |
|
589 | + $this->assertCount(2, $rwCalendar->getChildren()); |
|
590 | + $this->assertCount(2, $roCalendar->getChildren()); |
|
591 | + |
|
592 | + // calendar data shall not be altered for the owner |
|
593 | + $this->assertEquals($ownerCalendar->getChild('event-0')->get(), $publicObjectData); |
|
594 | + $this->assertEquals($ownerCalendar->getChild('event-1')->get(), $confidentialObjectData); |
|
595 | + |
|
596 | + // valarms shall not be removed for read-write shares |
|
597 | + $this->assertEquals( |
|
598 | + $this->fixLinebreak($rwCalendar->getChild('event-0')->get()), |
|
599 | + $this->fixLinebreak($publicObjectData)); |
|
600 | + $this->assertEquals( |
|
601 | + $this->fixLinebreak($rwCalendar->getChild('event-1')->get()), |
|
602 | + $this->fixLinebreak($confidentialObjectCleaned)); |
|
603 | + |
|
604 | + // valarms shall be removed for read-only shares |
|
605 | + $this->assertEquals( |
|
606 | + $this->fixLinebreak($roCalendar->getChild('event-0')->get()), |
|
607 | + $this->fixLinebreak($publicObjectDataWithoutVAlarm)); |
|
608 | + $this->assertEquals( |
|
609 | + $this->fixLinebreak($roCalendar->getChild('event-1')->get()), |
|
610 | + $this->fixLinebreak($confidentialObjectCleaned)); |
|
611 | + } |
|
612 | + |
|
613 | + private function fixLinebreak(string $str): string { |
|
614 | + return preg_replace('~(*BSR_ANYCRLF)\R~', "\r\n", $str); |
|
615 | + } |
|
616 | 616 | } |
@@ -12,13 +12,13 @@ discard block |
||
12 | 12 | use Test\TestCase; |
13 | 13 | |
14 | 14 | class CalendarSearchReportTest extends TestCase { |
15 | - private array $elementMap = [ |
|
16 | - '{http://nextcloud.com/ns}calendar-search' => |
|
17 | - 'OCA\\DAV\\CalDAV\\Search\\Xml\\Request\\CalendarSearchReport', |
|
18 | - ]; |
|
15 | + private array $elementMap = [ |
|
16 | + '{http://nextcloud.com/ns}calendar-search' => |
|
17 | + 'OCA\\DAV\\CalDAV\\Search\\Xml\\Request\\CalendarSearchReport', |
|
18 | + ]; |
|
19 | 19 | |
20 | - public function testFoo(): void { |
|
21 | - $xml = <<<XML |
|
20 | + public function testFoo(): void { |
|
21 | + $xml = <<<XML |
|
22 | 22 | <?xml version="1.0" encoding="UTF-8"?> |
23 | 23 | <nc:calendar-search xmlns:nc="http://nextcloud.com/ns" xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:"> |
24 | 24 | <d:prop> |
@@ -39,42 +39,42 @@ discard block |
||
39 | 39 | </nc:calendar-search> |
40 | 40 | XML; |
41 | 41 | |
42 | - $result = $this->parse($xml); |
|
43 | - |
|
44 | - $calendarSearchReport = new CalendarSearchReport(); |
|
45 | - $calendarSearchReport->properties = [ |
|
46 | - '{DAV:}getetag', |
|
47 | - '{urn:ietf:params:xml:ns:caldav}calendar-data', |
|
48 | - ]; |
|
49 | - $calendarSearchReport->filters = [ |
|
50 | - 'comps' => [ |
|
51 | - 'VEVENT', |
|
52 | - 'VTODO' |
|
53 | - ], |
|
54 | - 'props' => [ |
|
55 | - 'SUMMARY', |
|
56 | - 'LOCATION', |
|
57 | - 'ATTENDEE' |
|
58 | - ], |
|
59 | - 'params' => [ |
|
60 | - [ |
|
61 | - 'property' => 'ATTENDEE', |
|
62 | - 'parameter' => 'CN' |
|
63 | - ] |
|
64 | - ], |
|
65 | - 'search-term' => 'foo' |
|
66 | - ]; |
|
67 | - $calendarSearchReport->limit = 10; |
|
68 | - $calendarSearchReport->offset = 5; |
|
69 | - |
|
70 | - $this->assertEquals( |
|
71 | - $calendarSearchReport, |
|
72 | - $result['value'] |
|
73 | - ); |
|
74 | - } |
|
75 | - |
|
76 | - public function testNoLimitOffset(): void { |
|
77 | - $xml = <<<XML |
|
42 | + $result = $this->parse($xml); |
|
43 | + |
|
44 | + $calendarSearchReport = new CalendarSearchReport(); |
|
45 | + $calendarSearchReport->properties = [ |
|
46 | + '{DAV:}getetag', |
|
47 | + '{urn:ietf:params:xml:ns:caldav}calendar-data', |
|
48 | + ]; |
|
49 | + $calendarSearchReport->filters = [ |
|
50 | + 'comps' => [ |
|
51 | + 'VEVENT', |
|
52 | + 'VTODO' |
|
53 | + ], |
|
54 | + 'props' => [ |
|
55 | + 'SUMMARY', |
|
56 | + 'LOCATION', |
|
57 | + 'ATTENDEE' |
|
58 | + ], |
|
59 | + 'params' => [ |
|
60 | + [ |
|
61 | + 'property' => 'ATTENDEE', |
|
62 | + 'parameter' => 'CN' |
|
63 | + ] |
|
64 | + ], |
|
65 | + 'search-term' => 'foo' |
|
66 | + ]; |
|
67 | + $calendarSearchReport->limit = 10; |
|
68 | + $calendarSearchReport->offset = 5; |
|
69 | + |
|
70 | + $this->assertEquals( |
|
71 | + $calendarSearchReport, |
|
72 | + $result['value'] |
|
73 | + ); |
|
74 | + } |
|
75 | + |
|
76 | + public function testNoLimitOffset(): void { |
|
77 | + $xml = <<<XML |
|
78 | 78 | <?xml version="1.0" encoding="UTF-8"?> |
79 | 79 | <nc:calendar-search xmlns:nc="http://nextcloud.com/ns" xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:"> |
80 | 80 | <d:prop> |
@@ -89,37 +89,37 @@ discard block |
||
89 | 89 | </nc:calendar-search> |
90 | 90 | XML; |
91 | 91 | |
92 | - $result = $this->parse($xml); |
|
93 | - |
|
94 | - $calendarSearchReport = new CalendarSearchReport(); |
|
95 | - $calendarSearchReport->properties = [ |
|
96 | - '{DAV:}getetag', |
|
97 | - '{urn:ietf:params:xml:ns:caldav}calendar-data', |
|
98 | - ]; |
|
99 | - $calendarSearchReport->filters = [ |
|
100 | - 'comps' => [ |
|
101 | - 'VEVENT', |
|
102 | - ], |
|
103 | - 'props' => [ |
|
104 | - 'SUMMARY', |
|
105 | - ], |
|
106 | - 'search-term' => 'foo' |
|
107 | - ]; |
|
108 | - $calendarSearchReport->limit = null; |
|
109 | - $calendarSearchReport->offset = null; |
|
110 | - |
|
111 | - $this->assertEquals( |
|
112 | - $calendarSearchReport, |
|
113 | - $result['value'] |
|
114 | - ); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - public function testRequiresCompFilter(): void { |
|
119 | - $this->expectException(\Sabre\DAV\Exception\BadRequest::class); |
|
120 | - $this->expectExceptionMessage('{http://nextcloud.com/ns}prop-filter or {http://nextcloud.com/ns}param-filter given without any {http://nextcloud.com/ns}comp-filter'); |
|
121 | - |
|
122 | - $xml = <<<XML |
|
92 | + $result = $this->parse($xml); |
|
93 | + |
|
94 | + $calendarSearchReport = new CalendarSearchReport(); |
|
95 | + $calendarSearchReport->properties = [ |
|
96 | + '{DAV:}getetag', |
|
97 | + '{urn:ietf:params:xml:ns:caldav}calendar-data', |
|
98 | + ]; |
|
99 | + $calendarSearchReport->filters = [ |
|
100 | + 'comps' => [ |
|
101 | + 'VEVENT', |
|
102 | + ], |
|
103 | + 'props' => [ |
|
104 | + 'SUMMARY', |
|
105 | + ], |
|
106 | + 'search-term' => 'foo' |
|
107 | + ]; |
|
108 | + $calendarSearchReport->limit = null; |
|
109 | + $calendarSearchReport->offset = null; |
|
110 | + |
|
111 | + $this->assertEquals( |
|
112 | + $calendarSearchReport, |
|
113 | + $result['value'] |
|
114 | + ); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + public function testRequiresCompFilter(): void { |
|
119 | + $this->expectException(\Sabre\DAV\Exception\BadRequest::class); |
|
120 | + $this->expectExceptionMessage('{http://nextcloud.com/ns}prop-filter or {http://nextcloud.com/ns}param-filter given without any {http://nextcloud.com/ns}comp-filter'); |
|
121 | + |
|
122 | + $xml = <<<XML |
|
123 | 123 | <?xml version="1.0" encoding="UTF-8"?> |
124 | 124 | <nc:calendar-search xmlns:nc="http://nextcloud.com/ns" xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:"> |
125 | 125 | <d:prop> |
@@ -138,15 +138,15 @@ discard block |
||
138 | 138 | </nc:calendar-search> |
139 | 139 | XML; |
140 | 140 | |
141 | - $this->parse($xml); |
|
142 | - } |
|
141 | + $this->parse($xml); |
|
142 | + } |
|
143 | 143 | |
144 | 144 | |
145 | - public function testRequiresFilter(): void { |
|
146 | - $this->expectException(\Sabre\DAV\Exception\BadRequest::class); |
|
147 | - $this->expectExceptionMessage('The {http://nextcloud.com/ns}filter element is required for this request'); |
|
145 | + public function testRequiresFilter(): void { |
|
146 | + $this->expectException(\Sabre\DAV\Exception\BadRequest::class); |
|
147 | + $this->expectExceptionMessage('The {http://nextcloud.com/ns}filter element is required for this request'); |
|
148 | 148 | |
149 | - $xml = <<<XML |
|
149 | + $xml = <<<XML |
|
150 | 150 | <?xml version="1.0" encoding="UTF-8"?> |
151 | 151 | <nc:calendar-search xmlns:nc="http://nextcloud.com/ns" xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:"> |
152 | 152 | <d:prop> |
@@ -156,15 +156,15 @@ discard block |
||
156 | 156 | </nc:calendar-search> |
157 | 157 | XML; |
158 | 158 | |
159 | - $this->parse($xml); |
|
160 | - } |
|
159 | + $this->parse($xml); |
|
160 | + } |
|
161 | 161 | |
162 | 162 | |
163 | - public function testNoSearchTerm(): void { |
|
164 | - $this->expectException(\Sabre\DAV\Exception\BadRequest::class); |
|
165 | - $this->expectExceptionMessage('{http://nextcloud.com/ns}search-term is required for this request'); |
|
163 | + public function testNoSearchTerm(): void { |
|
164 | + $this->expectException(\Sabre\DAV\Exception\BadRequest::class); |
|
165 | + $this->expectExceptionMessage('{http://nextcloud.com/ns}search-term is required for this request'); |
|
166 | 166 | |
167 | - $xml = <<<XML |
|
167 | + $xml = <<<XML |
|
168 | 168 | <?xml version="1.0" encoding="UTF-8"?> |
169 | 169 | <nc:calendar-search xmlns:nc="http://nextcloud.com/ns" xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:"> |
170 | 170 | <d:prop> |
@@ -184,15 +184,15 @@ discard block |
||
184 | 184 | </nc:calendar-search> |
185 | 185 | XML; |
186 | 186 | |
187 | - $this->parse($xml); |
|
188 | - } |
|
187 | + $this->parse($xml); |
|
188 | + } |
|
189 | 189 | |
190 | 190 | |
191 | - public function testCompOnly(): void { |
|
192 | - $this->expectException(\Sabre\DAV\Exception\BadRequest::class); |
|
193 | - $this->expectExceptionMessage('At least one{http://nextcloud.com/ns}prop-filter or {http://nextcloud.com/ns}param-filter is required for this request'); |
|
191 | + public function testCompOnly(): void { |
|
192 | + $this->expectException(\Sabre\DAV\Exception\BadRequest::class); |
|
193 | + $this->expectExceptionMessage('At least one{http://nextcloud.com/ns}prop-filter or {http://nextcloud.com/ns}param-filter is required for this request'); |
|
194 | 194 | |
195 | - $xml = <<<XML |
|
195 | + $xml = <<<XML |
|
196 | 196 | <?xml version="1.0" encoding="UTF-8"?> |
197 | 197 | <nc:calendar-search xmlns:nc="http://nextcloud.com/ns" xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:"> |
198 | 198 | <d:prop> |
@@ -207,31 +207,31 @@ discard block |
||
207 | 207 | </nc:calendar-search> |
208 | 208 | XML; |
209 | 209 | |
210 | - $result = $this->parse($xml); |
|
211 | - |
|
212 | - $calendarSearchReport = new CalendarSearchReport(); |
|
213 | - $calendarSearchReport->properties = [ |
|
214 | - '{DAV:}getetag', |
|
215 | - '{urn:ietf:params:xml:ns:caldav}calendar-data', |
|
216 | - ]; |
|
217 | - $calendarSearchReport->filters = [ |
|
218 | - 'comps' => [ |
|
219 | - 'VEVENT', |
|
220 | - 'VTODO' |
|
221 | - ], |
|
222 | - 'search-term' => 'foo' |
|
223 | - ]; |
|
224 | - $calendarSearchReport->limit = null; |
|
225 | - $calendarSearchReport->offset = null; |
|
226 | - |
|
227 | - $this->assertEquals( |
|
228 | - $calendarSearchReport, |
|
229 | - $result['value'] |
|
230 | - ); |
|
231 | - } |
|
232 | - |
|
233 | - public function testPropOnly(): void { |
|
234 | - $xml = <<<XML |
|
210 | + $result = $this->parse($xml); |
|
211 | + |
|
212 | + $calendarSearchReport = new CalendarSearchReport(); |
|
213 | + $calendarSearchReport->properties = [ |
|
214 | + '{DAV:}getetag', |
|
215 | + '{urn:ietf:params:xml:ns:caldav}calendar-data', |
|
216 | + ]; |
|
217 | + $calendarSearchReport->filters = [ |
|
218 | + 'comps' => [ |
|
219 | + 'VEVENT', |
|
220 | + 'VTODO' |
|
221 | + ], |
|
222 | + 'search-term' => 'foo' |
|
223 | + ]; |
|
224 | + $calendarSearchReport->limit = null; |
|
225 | + $calendarSearchReport->offset = null; |
|
226 | + |
|
227 | + $this->assertEquals( |
|
228 | + $calendarSearchReport, |
|
229 | + $result['value'] |
|
230 | + ); |
|
231 | + } |
|
232 | + |
|
233 | + public function testPropOnly(): void { |
|
234 | + $xml = <<<XML |
|
235 | 235 | <?xml version="1.0" encoding="UTF-8"?> |
236 | 236 | <nc:calendar-search xmlns:nc="http://nextcloud.com/ns" xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:"> |
237 | 237 | <d:prop> |
@@ -246,33 +246,33 @@ discard block |
||
246 | 246 | </nc:calendar-search> |
247 | 247 | XML; |
248 | 248 | |
249 | - $result = $this->parse($xml); |
|
250 | - |
|
251 | - $calendarSearchReport = new CalendarSearchReport(); |
|
252 | - $calendarSearchReport->properties = [ |
|
253 | - '{DAV:}getetag', |
|
254 | - '{urn:ietf:params:xml:ns:caldav}calendar-data', |
|
255 | - ]; |
|
256 | - $calendarSearchReport->filters = [ |
|
257 | - 'comps' => [ |
|
258 | - 'VEVENT', |
|
259 | - ], |
|
260 | - 'props' => [ |
|
261 | - 'SUMMARY', |
|
262 | - ], |
|
263 | - 'search-term' => 'foo' |
|
264 | - ]; |
|
265 | - $calendarSearchReport->limit = null; |
|
266 | - $calendarSearchReport->offset = null; |
|
267 | - |
|
268 | - $this->assertEquals( |
|
269 | - $calendarSearchReport, |
|
270 | - $result['value'] |
|
271 | - ); |
|
272 | - } |
|
273 | - |
|
274 | - public function testParamOnly(): void { |
|
275 | - $xml = <<<XML |
|
249 | + $result = $this->parse($xml); |
|
250 | + |
|
251 | + $calendarSearchReport = new CalendarSearchReport(); |
|
252 | + $calendarSearchReport->properties = [ |
|
253 | + '{DAV:}getetag', |
|
254 | + '{urn:ietf:params:xml:ns:caldav}calendar-data', |
|
255 | + ]; |
|
256 | + $calendarSearchReport->filters = [ |
|
257 | + 'comps' => [ |
|
258 | + 'VEVENT', |
|
259 | + ], |
|
260 | + 'props' => [ |
|
261 | + 'SUMMARY', |
|
262 | + ], |
|
263 | + 'search-term' => 'foo' |
|
264 | + ]; |
|
265 | + $calendarSearchReport->limit = null; |
|
266 | + $calendarSearchReport->offset = null; |
|
267 | + |
|
268 | + $this->assertEquals( |
|
269 | + $calendarSearchReport, |
|
270 | + $result['value'] |
|
271 | + ); |
|
272 | + } |
|
273 | + |
|
274 | + public function testParamOnly(): void { |
|
275 | + $xml = <<<XML |
|
276 | 276 | <?xml version="1.0" encoding="UTF-8"?> |
277 | 277 | <nc:calendar-search xmlns:nc="http://nextcloud.com/ns" xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:"> |
278 | 278 | <d:prop> |
@@ -287,38 +287,38 @@ discard block |
||
287 | 287 | </nc:calendar-search> |
288 | 288 | XML; |
289 | 289 | |
290 | - $result = $this->parse($xml); |
|
291 | - |
|
292 | - $calendarSearchReport = new CalendarSearchReport(); |
|
293 | - $calendarSearchReport->properties = [ |
|
294 | - '{DAV:}getetag', |
|
295 | - '{urn:ietf:params:xml:ns:caldav}calendar-data', |
|
296 | - ]; |
|
297 | - $calendarSearchReport->filters = [ |
|
298 | - 'comps' => [ |
|
299 | - 'VEVENT', |
|
300 | - ], |
|
301 | - 'params' => [ |
|
302 | - [ |
|
303 | - 'property' => 'ATTENDEE', |
|
304 | - 'parameter' => 'CN' |
|
305 | - ] |
|
306 | - ], |
|
307 | - 'search-term' => 'foo' |
|
308 | - ]; |
|
309 | - $calendarSearchReport->limit = null; |
|
310 | - $calendarSearchReport->offset = null; |
|
311 | - |
|
312 | - $this->assertEquals( |
|
313 | - $calendarSearchReport, |
|
314 | - $result['value'] |
|
315 | - ); |
|
316 | - } |
|
317 | - |
|
318 | - private function parse(string $xml, array $elementMap = []): array { |
|
319 | - $reader = new Reader(); |
|
320 | - $reader->elementMap = array_merge($this->elementMap, $elementMap); |
|
321 | - $reader->xml($xml); |
|
322 | - return $reader->parse(); |
|
323 | - } |
|
290 | + $result = $this->parse($xml); |
|
291 | + |
|
292 | + $calendarSearchReport = new CalendarSearchReport(); |
|
293 | + $calendarSearchReport->properties = [ |
|
294 | + '{DAV:}getetag', |
|
295 | + '{urn:ietf:params:xml:ns:caldav}calendar-data', |
|
296 | + ]; |
|
297 | + $calendarSearchReport->filters = [ |
|
298 | + 'comps' => [ |
|
299 | + 'VEVENT', |
|
300 | + ], |
|
301 | + 'params' => [ |
|
302 | + [ |
|
303 | + 'property' => 'ATTENDEE', |
|
304 | + 'parameter' => 'CN' |
|
305 | + ] |
|
306 | + ], |
|
307 | + 'search-term' => 'foo' |
|
308 | + ]; |
|
309 | + $calendarSearchReport->limit = null; |
|
310 | + $calendarSearchReport->offset = null; |
|
311 | + |
|
312 | + $this->assertEquals( |
|
313 | + $calendarSearchReport, |
|
314 | + $result['value'] |
|
315 | + ); |
|
316 | + } |
|
317 | + |
|
318 | + private function parse(string $xml, array $elementMap = []): array { |
|
319 | + $reader = new Reader(); |
|
320 | + $reader->elementMap = array_merge($this->elementMap, $elementMap); |
|
321 | + $reader->xml($xml); |
|
322 | + return $reader->parse(); |
|
323 | + } |
|
324 | 324 | } |
@@ -20,55 +20,55 @@ |
||
20 | 20 | use Test\TestCase; |
21 | 21 | |
22 | 22 | class PublishingTest extends TestCase { |
23 | - private PublishPlugin $plugin; |
|
24 | - private Server $server; |
|
25 | - private Calendar&MockObject $book; |
|
26 | - private IConfig&MockObject $config; |
|
27 | - private IURLGenerator&MockObject $urlGenerator; |
|
23 | + private PublishPlugin $plugin; |
|
24 | + private Server $server; |
|
25 | + private Calendar&MockObject $book; |
|
26 | + private IConfig&MockObject $config; |
|
27 | + private IURLGenerator&MockObject $urlGenerator; |
|
28 | 28 | |
29 | - protected function setUp(): void { |
|
30 | - parent::setUp(); |
|
29 | + protected function setUp(): void { |
|
30 | + parent::setUp(); |
|
31 | 31 | |
32 | - $this->config = $this->createMock(IConfig::class); |
|
33 | - $this->config->expects($this->any())->method('getSystemValue') |
|
34 | - ->with($this->equalTo('secret')) |
|
35 | - ->willReturn('mysecret'); |
|
32 | + $this->config = $this->createMock(IConfig::class); |
|
33 | + $this->config->expects($this->any())->method('getSystemValue') |
|
34 | + ->with($this->equalTo('secret')) |
|
35 | + ->willReturn('mysecret'); |
|
36 | 36 | |
37 | - $this->urlGenerator = $this->createMock(IURLGenerator::class); |
|
37 | + $this->urlGenerator = $this->createMock(IURLGenerator::class); |
|
38 | 38 | |
39 | - /** @var IRequest $request */ |
|
40 | - $this->plugin = new PublishPlugin($this->config, $this->urlGenerator); |
|
39 | + /** @var IRequest $request */ |
|
40 | + $this->plugin = new PublishPlugin($this->config, $this->urlGenerator); |
|
41 | 41 | |
42 | - $root = new SimpleCollection('calendars'); |
|
43 | - $this->server = new Server($root); |
|
44 | - /** @var SimpleCollection $node */ |
|
45 | - $this->book = $this->getMockBuilder(Calendar::class)-> |
|
46 | - disableOriginalConstructor()-> |
|
47 | - getMock(); |
|
48 | - $this->book->method('getName')->willReturn('cal1'); |
|
49 | - $root->addChild($this->book); |
|
50 | - $this->plugin->initialize($this->server); |
|
51 | - } |
|
42 | + $root = new SimpleCollection('calendars'); |
|
43 | + $this->server = new Server($root); |
|
44 | + /** @var SimpleCollection $node */ |
|
45 | + $this->book = $this->getMockBuilder(Calendar::class)-> |
|
46 | + disableOriginalConstructor()-> |
|
47 | + getMock(); |
|
48 | + $this->book->method('getName')->willReturn('cal1'); |
|
49 | + $root->addChild($this->book); |
|
50 | + $this->plugin->initialize($this->server); |
|
51 | + } |
|
52 | 52 | |
53 | - public function testPublishing(): void { |
|
54 | - $this->book->expects($this->once())->method('setPublishStatus')->with(true); |
|
53 | + public function testPublishing(): void { |
|
54 | + $this->book->expects($this->once())->method('setPublishStatus')->with(true); |
|
55 | 55 | |
56 | - // setup request |
|
57 | - $request = new Request('POST', 'cal1'); |
|
58 | - $request->addHeader('Content-Type', 'application/xml'); |
|
59 | - $request->setBody('<o:publish-calendar xmlns:o="http://calendarserver.org/ns/"/>'); |
|
60 | - $response = new Response(); |
|
61 | - $this->plugin->httpPost($request, $response); |
|
62 | - } |
|
56 | + // setup request |
|
57 | + $request = new Request('POST', 'cal1'); |
|
58 | + $request->addHeader('Content-Type', 'application/xml'); |
|
59 | + $request->setBody('<o:publish-calendar xmlns:o="http://calendarserver.org/ns/"/>'); |
|
60 | + $response = new Response(); |
|
61 | + $this->plugin->httpPost($request, $response); |
|
62 | + } |
|
63 | 63 | |
64 | - public function testUnPublishing(): void { |
|
65 | - $this->book->expects($this->once())->method('setPublishStatus')->with(false); |
|
64 | + public function testUnPublishing(): void { |
|
65 | + $this->book->expects($this->once())->method('setPublishStatus')->with(false); |
|
66 | 66 | |
67 | - // setup request |
|
68 | - $request = new Request('POST', 'cal1'); |
|
69 | - $request->addHeader('Content-Type', 'application/xml'); |
|
70 | - $request->setBody('<o:unpublish-calendar xmlns:o="http://calendarserver.org/ns/"/>'); |
|
71 | - $response = new Response(); |
|
72 | - $this->plugin->httpPost($request, $response); |
|
73 | - } |
|
67 | + // setup request |
|
68 | + $request = new Request('POST', 'cal1'); |
|
69 | + $request->addHeader('Content-Type', 'application/xml'); |
|
70 | + $request->setBody('<o:unpublish-calendar xmlns:o="http://calendarserver.org/ns/"/>'); |
|
71 | + $response = new Response(); |
|
72 | + $this->plugin->httpPost($request, $response); |
|
73 | + } |
|
74 | 74 | } |
@@ -12,50 +12,50 @@ |
||
12 | 12 | use Test\TestCase; |
13 | 13 | |
14 | 14 | class PublisherTest extends TestCase { |
15 | - public const NS_CALENDARSERVER = 'http://calendarserver.org/ns/'; |
|
15 | + public const NS_CALENDARSERVER = 'http://calendarserver.org/ns/'; |
|
16 | 16 | |
17 | - public function testSerializePublished(): void { |
|
18 | - $publish = new Publisher('urltopublish', true); |
|
17 | + public function testSerializePublished(): void { |
|
18 | + $publish = new Publisher('urltopublish', true); |
|
19 | 19 | |
20 | - $xml = $this->write([ |
|
21 | - '{' . self::NS_CALENDARSERVER . '}publish-url' => $publish, |
|
22 | - ]); |
|
20 | + $xml = $this->write([ |
|
21 | + '{' . self::NS_CALENDARSERVER . '}publish-url' => $publish, |
|
22 | + ]); |
|
23 | 23 | |
24 | - $this->assertEquals('urltopublish', $publish->getValue()); |
|
24 | + $this->assertEquals('urltopublish', $publish->getValue()); |
|
25 | 25 | |
26 | - $this->assertXmlStringEqualsXmlString( |
|
27 | - '<?xml version="1.0"?> |
|
26 | + $this->assertXmlStringEqualsXmlString( |
|
27 | + '<?xml version="1.0"?> |
|
28 | 28 | <x1:publish-url xmlns:d="DAV:" xmlns:x1="' . self::NS_CALENDARSERVER . '"> |
29 | 29 | <d:href>urltopublish</d:href> |
30 | 30 | </x1:publish-url>', $xml); |
31 | - } |
|
31 | + } |
|
32 | 32 | |
33 | - public function testSerializeNotPublished(): void { |
|
34 | - $publish = new Publisher('urltopublish', false); |
|
33 | + public function testSerializeNotPublished(): void { |
|
34 | + $publish = new Publisher('urltopublish', false); |
|
35 | 35 | |
36 | - $xml = $this->write([ |
|
37 | - '{' . self::NS_CALENDARSERVER . '}pre-publish-url' => $publish, |
|
38 | - ]); |
|
36 | + $xml = $this->write([ |
|
37 | + '{' . self::NS_CALENDARSERVER . '}pre-publish-url' => $publish, |
|
38 | + ]); |
|
39 | 39 | |
40 | - $this->assertEquals('urltopublish', $publish->getValue()); |
|
40 | + $this->assertEquals('urltopublish', $publish->getValue()); |
|
41 | 41 | |
42 | - $this->assertXmlStringEqualsXmlString( |
|
43 | - '<?xml version="1.0"?> |
|
42 | + $this->assertXmlStringEqualsXmlString( |
|
43 | + '<?xml version="1.0"?> |
|
44 | 44 | <x1:pre-publish-url xmlns:d="DAV:" xmlns:x1="' . self::NS_CALENDARSERVER . '">urltopublish</x1:pre-publish-url>', $xml); |
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - protected array $elementMap = []; |
|
49 | - protected array $namespaceMap = ['DAV:' => 'd']; |
|
50 | - protected string $contextUri = '/'; |
|
51 | - |
|
52 | - private function write($input) { |
|
53 | - $writer = new Writer(); |
|
54 | - $writer->contextUri = $this->contextUri; |
|
55 | - $writer->namespaceMap = $this->namespaceMap; |
|
56 | - $writer->openMemory(); |
|
57 | - $writer->setIndent(true); |
|
58 | - $writer->write($input); |
|
59 | - return $writer->outputMemory(); |
|
60 | - } |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + protected array $elementMap = []; |
|
49 | + protected array $namespaceMap = ['DAV:' => 'd']; |
|
50 | + protected string $contextUri = '/'; |
|
51 | + |
|
52 | + private function write($input) { |
|
53 | + $writer = new Writer(); |
|
54 | + $writer->contextUri = $this->contextUri; |
|
55 | + $writer->namespaceMap = $this->namespaceMap; |
|
56 | + $writer->openMemory(); |
|
57 | + $writer->setIndent(true); |
|
58 | + $writer->write($input); |
|
59 | + return $writer->outputMemory(); |
|
60 | + } |
|
61 | 61 | } |
@@ -11,285 +11,285 @@ |
||
11 | 11 | use Sabre\DAV\PropPatch; |
12 | 12 | |
13 | 13 | class CachedSubscriptionTest extends \Test\TestCase { |
14 | - public function testGetACL(): void { |
|
15 | - $backend = $this->createMock(CalDavBackend::class); |
|
16 | - $calendarInfo = [ |
|
17 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
18 | - 'principaluri' => 'user2', |
|
19 | - 'id' => 666, |
|
20 | - 'uri' => 'cal', |
|
21 | - ]; |
|
22 | - |
|
23 | - $calendar = new CachedSubscription($backend, $calendarInfo); |
|
24 | - $this->assertEquals([ |
|
25 | - [ |
|
26 | - 'privilege' => '{DAV:}read', |
|
27 | - 'principal' => 'user1', |
|
28 | - 'protected' => true, |
|
29 | - ], |
|
30 | - [ |
|
31 | - 'privilege' => '{DAV:}read', |
|
32 | - 'principal' => 'user1/calendar-proxy-write', |
|
33 | - 'protected' => true, |
|
34 | - ], |
|
35 | - [ |
|
36 | - 'privilege' => '{DAV:}read', |
|
37 | - 'principal' => 'user1/calendar-proxy-read', |
|
38 | - 'protected' => true, |
|
39 | - ], |
|
40 | - [ |
|
41 | - 'privilege' => '{urn:ietf:params:xml:ns:caldav}read-free-busy', |
|
42 | - 'principal' => '{DAV:}authenticated', |
|
43 | - 'protected' => true, |
|
44 | - ], |
|
45 | - [ |
|
46 | - 'privilege' => '{DAV:}write-properties', |
|
47 | - 'principal' => 'user1', |
|
48 | - 'protected' => 'true' |
|
49 | - ] |
|
50 | - ], $calendar->getACL()); |
|
51 | - } |
|
52 | - |
|
53 | - public function testGetChildACL(): void { |
|
54 | - $backend = $this->createMock(CalDavBackend::class); |
|
55 | - $calendarInfo = [ |
|
56 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
57 | - 'principaluri' => 'user2', |
|
58 | - 'id' => 666, |
|
59 | - 'uri' => 'cal', |
|
60 | - ]; |
|
61 | - |
|
62 | - $calendar = new CachedSubscription($backend, $calendarInfo); |
|
63 | - $this->assertEquals([ |
|
64 | - [ |
|
65 | - 'privilege' => '{DAV:}read', |
|
66 | - 'principal' => 'user1', |
|
67 | - 'protected' => true, |
|
68 | - ], |
|
69 | - [ |
|
70 | - 'privilege' => '{DAV:}read', |
|
71 | - 'principal' => 'user1/calendar-proxy-write', |
|
72 | - 'protected' => true, |
|
73 | - ], |
|
74 | - [ |
|
75 | - 'privilege' => '{DAV:}read', |
|
76 | - 'principal' => 'user1/calendar-proxy-read', |
|
77 | - 'protected' => true, |
|
78 | - ] |
|
79 | - ], $calendar->getChildACL()); |
|
80 | - } |
|
81 | - |
|
82 | - public function testGetOwner(): void { |
|
83 | - $backend = $this->createMock(CalDavBackend::class); |
|
84 | - $calendarInfo = [ |
|
85 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
86 | - 'principaluri' => 'user2', |
|
87 | - 'id' => 666, |
|
88 | - 'uri' => 'cal', |
|
89 | - ]; |
|
90 | - |
|
91 | - $calendar = new CachedSubscription($backend, $calendarInfo); |
|
92 | - $this->assertEquals('user1', $calendar->getOwner()); |
|
93 | - } |
|
94 | - |
|
95 | - public function testDelete(): void { |
|
96 | - $backend = $this->createMock(CalDavBackend::class); |
|
97 | - $calendarInfo = [ |
|
98 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
99 | - 'principaluri' => 'user2', |
|
100 | - 'id' => 666, |
|
101 | - 'uri' => 'cal', |
|
102 | - ]; |
|
103 | - |
|
104 | - $backend->expects($this->once()) |
|
105 | - ->method('deleteSubscription') |
|
106 | - ->with(666); |
|
107 | - |
|
108 | - $calendar = new CachedSubscription($backend, $calendarInfo); |
|
109 | - $calendar->delete(); |
|
110 | - } |
|
111 | - |
|
112 | - public function testPropPatch(): void { |
|
113 | - $backend = $this->createMock(CalDavBackend::class); |
|
114 | - $calendarInfo = [ |
|
115 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
116 | - 'principaluri' => 'user2', |
|
117 | - 'id' => 666, |
|
118 | - 'uri' => 'cal', |
|
119 | - ]; |
|
120 | - $propPatch = $this->createMock(PropPatch::class); |
|
121 | - |
|
122 | - $backend->expects($this->once()) |
|
123 | - ->method('updateSubscription') |
|
124 | - ->with(666, $propPatch); |
|
125 | - |
|
126 | - $calendar = new CachedSubscription($backend, $calendarInfo); |
|
127 | - $calendar->propPatch($propPatch); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - public function testGetChild(): void { |
|
132 | - $this->expectException(\Sabre\DAV\Exception\NotFound::class); |
|
133 | - $this->expectExceptionMessage('Calendar object not found'); |
|
134 | - |
|
135 | - $backend = $this->createMock(CalDavBackend::class); |
|
136 | - $calendarInfo = [ |
|
137 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
138 | - 'principaluri' => 'user2', |
|
139 | - 'id' => 666, |
|
140 | - 'uri' => 'cal', |
|
141 | - ]; |
|
142 | - |
|
143 | - $calls = [ |
|
144 | - [666, 'foo1', 1, [ |
|
145 | - 'id' => 99, |
|
146 | - 'uri' => 'foo1' |
|
147 | - ]], |
|
148 | - [666, 'foo2', 1, null], |
|
149 | - ]; |
|
150 | - $backend->expects($this->exactly(2)) |
|
151 | - ->method('getCalendarObject') |
|
152 | - ->willReturnCallback(function () use (&$calls) { |
|
153 | - $expected = array_shift($calls); |
|
154 | - $return = array_pop($expected); |
|
155 | - $this->assertEquals($expected, func_get_args()); |
|
156 | - return $return; |
|
157 | - }); |
|
158 | - |
|
159 | - $calendar = new CachedSubscription($backend, $calendarInfo); |
|
160 | - |
|
161 | - $first = $calendar->getChild('foo1'); |
|
162 | - $this->assertInstanceOf(CachedSubscriptionObject::class, $first); |
|
163 | - |
|
164 | - $calendar->getChild('foo2'); |
|
165 | - } |
|
166 | - |
|
167 | - public function testGetChildren(): void { |
|
168 | - $backend = $this->createMock(CalDavBackend::class); |
|
169 | - $calendarInfo = [ |
|
170 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
171 | - 'principaluri' => 'user2', |
|
172 | - 'id' => 666, |
|
173 | - 'uri' => 'cal', |
|
174 | - ]; |
|
175 | - |
|
176 | - $backend->expects($this->once()) |
|
177 | - ->method('getCalendarObjects') |
|
178 | - ->with(666, 1) |
|
179 | - ->willReturn([ |
|
180 | - [ |
|
181 | - 'id' => 99, |
|
182 | - 'uri' => 'foo1' |
|
183 | - ], |
|
184 | - [ |
|
185 | - 'id' => 100, |
|
186 | - 'uri' => 'foo2' |
|
187 | - ], |
|
188 | - ]); |
|
189 | - |
|
190 | - $calendar = new CachedSubscription($backend, $calendarInfo); |
|
191 | - |
|
192 | - $res = $calendar->getChildren(); |
|
193 | - $this->assertCount(2, $res); |
|
194 | - $this->assertInstanceOf(CachedSubscriptionObject::class, $res[0]); |
|
195 | - $this->assertInstanceOf(CachedSubscriptionObject::class, $res[1]); |
|
196 | - } |
|
197 | - |
|
198 | - public function testGetMultipleChildren(): void { |
|
199 | - $backend = $this->createMock(CalDavBackend::class); |
|
200 | - $calendarInfo = [ |
|
201 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
202 | - 'principaluri' => 'user2', |
|
203 | - 'id' => 666, |
|
204 | - 'uri' => 'cal', |
|
205 | - ]; |
|
206 | - |
|
207 | - $backend->expects($this->once()) |
|
208 | - ->method('getMultipleCalendarObjects') |
|
209 | - ->with(666, ['foo1', 'foo2'], 1) |
|
210 | - ->willReturn([ |
|
211 | - [ |
|
212 | - 'id' => 99, |
|
213 | - 'uri' => 'foo1' |
|
214 | - ], |
|
215 | - [ |
|
216 | - 'id' => 100, |
|
217 | - 'uri' => 'foo2' |
|
218 | - ], |
|
219 | - ]); |
|
220 | - |
|
221 | - $calendar = new CachedSubscription($backend, $calendarInfo); |
|
222 | - |
|
223 | - $res = $calendar->getMultipleChildren(['foo1', 'foo2']); |
|
224 | - $this->assertCount(2, $res); |
|
225 | - $this->assertInstanceOf(CachedSubscriptionObject::class, $res[0]); |
|
226 | - $this->assertInstanceOf(CachedSubscriptionObject::class, $res[1]); |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - public function testCreateFile(): void { |
|
231 | - $this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class); |
|
232 | - $this->expectExceptionMessage('Creating objects in cached subscription is not allowed'); |
|
233 | - |
|
234 | - $backend = $this->createMock(CalDavBackend::class); |
|
235 | - $calendarInfo = [ |
|
236 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
237 | - 'principaluri' => 'user2', |
|
238 | - 'id' => 666, |
|
239 | - 'uri' => 'cal', |
|
240 | - ]; |
|
241 | - |
|
242 | - $calendar = new CachedSubscription($backend, $calendarInfo); |
|
243 | - $calendar->createFile('foo', []); |
|
244 | - } |
|
245 | - |
|
246 | - public function testChildExists(): void { |
|
247 | - $backend = $this->createMock(CalDavBackend::class); |
|
248 | - $calendarInfo = [ |
|
249 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
250 | - 'principaluri' => 'user2', |
|
251 | - 'id' => 666, |
|
252 | - 'uri' => 'cal', |
|
253 | - ]; |
|
254 | - |
|
255 | - $calls = [ |
|
256 | - [666, 'foo1', 1, [ |
|
257 | - 'id' => 99, |
|
258 | - 'uri' => 'foo1' |
|
259 | - ]], |
|
260 | - [666, 'foo2', 1, null], |
|
261 | - ]; |
|
262 | - $backend->expects($this->exactly(2)) |
|
263 | - ->method('getCalendarObject') |
|
264 | - ->willReturnCallback(function () use (&$calls) { |
|
265 | - $expected = array_shift($calls); |
|
266 | - $return = array_pop($expected); |
|
267 | - $this->assertEquals($expected, func_get_args()); |
|
268 | - return $return; |
|
269 | - }); |
|
270 | - |
|
271 | - $calendar = new CachedSubscription($backend, $calendarInfo); |
|
272 | - |
|
273 | - $this->assertEquals(true, $calendar->childExists('foo1')); |
|
274 | - $this->assertEquals(false, $calendar->childExists('foo2')); |
|
275 | - } |
|
276 | - |
|
277 | - public function testCalendarQuery(): void { |
|
278 | - $backend = $this->createMock(CalDavBackend::class); |
|
279 | - $calendarInfo = [ |
|
280 | - '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
281 | - 'principaluri' => 'user2', |
|
282 | - 'id' => 666, |
|
283 | - 'uri' => 'cal', |
|
284 | - ]; |
|
285 | - |
|
286 | - $backend->expects($this->once()) |
|
287 | - ->method('calendarQuery') |
|
288 | - ->with(666, ['foo'], 1) |
|
289 | - ->willReturn([99]); |
|
290 | - |
|
291 | - $calendar = new CachedSubscription($backend, $calendarInfo); |
|
292 | - |
|
293 | - $this->assertEquals([99], $calendar->calendarQuery(['foo'])); |
|
294 | - } |
|
14 | + public function testGetACL(): void { |
|
15 | + $backend = $this->createMock(CalDavBackend::class); |
|
16 | + $calendarInfo = [ |
|
17 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
18 | + 'principaluri' => 'user2', |
|
19 | + 'id' => 666, |
|
20 | + 'uri' => 'cal', |
|
21 | + ]; |
|
22 | + |
|
23 | + $calendar = new CachedSubscription($backend, $calendarInfo); |
|
24 | + $this->assertEquals([ |
|
25 | + [ |
|
26 | + 'privilege' => '{DAV:}read', |
|
27 | + 'principal' => 'user1', |
|
28 | + 'protected' => true, |
|
29 | + ], |
|
30 | + [ |
|
31 | + 'privilege' => '{DAV:}read', |
|
32 | + 'principal' => 'user1/calendar-proxy-write', |
|
33 | + 'protected' => true, |
|
34 | + ], |
|
35 | + [ |
|
36 | + 'privilege' => '{DAV:}read', |
|
37 | + 'principal' => 'user1/calendar-proxy-read', |
|
38 | + 'protected' => true, |
|
39 | + ], |
|
40 | + [ |
|
41 | + 'privilege' => '{urn:ietf:params:xml:ns:caldav}read-free-busy', |
|
42 | + 'principal' => '{DAV:}authenticated', |
|
43 | + 'protected' => true, |
|
44 | + ], |
|
45 | + [ |
|
46 | + 'privilege' => '{DAV:}write-properties', |
|
47 | + 'principal' => 'user1', |
|
48 | + 'protected' => 'true' |
|
49 | + ] |
|
50 | + ], $calendar->getACL()); |
|
51 | + } |
|
52 | + |
|
53 | + public function testGetChildACL(): void { |
|
54 | + $backend = $this->createMock(CalDavBackend::class); |
|
55 | + $calendarInfo = [ |
|
56 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
57 | + 'principaluri' => 'user2', |
|
58 | + 'id' => 666, |
|
59 | + 'uri' => 'cal', |
|
60 | + ]; |
|
61 | + |
|
62 | + $calendar = new CachedSubscription($backend, $calendarInfo); |
|
63 | + $this->assertEquals([ |
|
64 | + [ |
|
65 | + 'privilege' => '{DAV:}read', |
|
66 | + 'principal' => 'user1', |
|
67 | + 'protected' => true, |
|
68 | + ], |
|
69 | + [ |
|
70 | + 'privilege' => '{DAV:}read', |
|
71 | + 'principal' => 'user1/calendar-proxy-write', |
|
72 | + 'protected' => true, |
|
73 | + ], |
|
74 | + [ |
|
75 | + 'privilege' => '{DAV:}read', |
|
76 | + 'principal' => 'user1/calendar-proxy-read', |
|
77 | + 'protected' => true, |
|
78 | + ] |
|
79 | + ], $calendar->getChildACL()); |
|
80 | + } |
|
81 | + |
|
82 | + public function testGetOwner(): void { |
|
83 | + $backend = $this->createMock(CalDavBackend::class); |
|
84 | + $calendarInfo = [ |
|
85 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
86 | + 'principaluri' => 'user2', |
|
87 | + 'id' => 666, |
|
88 | + 'uri' => 'cal', |
|
89 | + ]; |
|
90 | + |
|
91 | + $calendar = new CachedSubscription($backend, $calendarInfo); |
|
92 | + $this->assertEquals('user1', $calendar->getOwner()); |
|
93 | + } |
|
94 | + |
|
95 | + public function testDelete(): void { |
|
96 | + $backend = $this->createMock(CalDavBackend::class); |
|
97 | + $calendarInfo = [ |
|
98 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
99 | + 'principaluri' => 'user2', |
|
100 | + 'id' => 666, |
|
101 | + 'uri' => 'cal', |
|
102 | + ]; |
|
103 | + |
|
104 | + $backend->expects($this->once()) |
|
105 | + ->method('deleteSubscription') |
|
106 | + ->with(666); |
|
107 | + |
|
108 | + $calendar = new CachedSubscription($backend, $calendarInfo); |
|
109 | + $calendar->delete(); |
|
110 | + } |
|
111 | + |
|
112 | + public function testPropPatch(): void { |
|
113 | + $backend = $this->createMock(CalDavBackend::class); |
|
114 | + $calendarInfo = [ |
|
115 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
116 | + 'principaluri' => 'user2', |
|
117 | + 'id' => 666, |
|
118 | + 'uri' => 'cal', |
|
119 | + ]; |
|
120 | + $propPatch = $this->createMock(PropPatch::class); |
|
121 | + |
|
122 | + $backend->expects($this->once()) |
|
123 | + ->method('updateSubscription') |
|
124 | + ->with(666, $propPatch); |
|
125 | + |
|
126 | + $calendar = new CachedSubscription($backend, $calendarInfo); |
|
127 | + $calendar->propPatch($propPatch); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + public function testGetChild(): void { |
|
132 | + $this->expectException(\Sabre\DAV\Exception\NotFound::class); |
|
133 | + $this->expectExceptionMessage('Calendar object not found'); |
|
134 | + |
|
135 | + $backend = $this->createMock(CalDavBackend::class); |
|
136 | + $calendarInfo = [ |
|
137 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
138 | + 'principaluri' => 'user2', |
|
139 | + 'id' => 666, |
|
140 | + 'uri' => 'cal', |
|
141 | + ]; |
|
142 | + |
|
143 | + $calls = [ |
|
144 | + [666, 'foo1', 1, [ |
|
145 | + 'id' => 99, |
|
146 | + 'uri' => 'foo1' |
|
147 | + ]], |
|
148 | + [666, 'foo2', 1, null], |
|
149 | + ]; |
|
150 | + $backend->expects($this->exactly(2)) |
|
151 | + ->method('getCalendarObject') |
|
152 | + ->willReturnCallback(function () use (&$calls) { |
|
153 | + $expected = array_shift($calls); |
|
154 | + $return = array_pop($expected); |
|
155 | + $this->assertEquals($expected, func_get_args()); |
|
156 | + return $return; |
|
157 | + }); |
|
158 | + |
|
159 | + $calendar = new CachedSubscription($backend, $calendarInfo); |
|
160 | + |
|
161 | + $first = $calendar->getChild('foo1'); |
|
162 | + $this->assertInstanceOf(CachedSubscriptionObject::class, $first); |
|
163 | + |
|
164 | + $calendar->getChild('foo2'); |
|
165 | + } |
|
166 | + |
|
167 | + public function testGetChildren(): void { |
|
168 | + $backend = $this->createMock(CalDavBackend::class); |
|
169 | + $calendarInfo = [ |
|
170 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
171 | + 'principaluri' => 'user2', |
|
172 | + 'id' => 666, |
|
173 | + 'uri' => 'cal', |
|
174 | + ]; |
|
175 | + |
|
176 | + $backend->expects($this->once()) |
|
177 | + ->method('getCalendarObjects') |
|
178 | + ->with(666, 1) |
|
179 | + ->willReturn([ |
|
180 | + [ |
|
181 | + 'id' => 99, |
|
182 | + 'uri' => 'foo1' |
|
183 | + ], |
|
184 | + [ |
|
185 | + 'id' => 100, |
|
186 | + 'uri' => 'foo2' |
|
187 | + ], |
|
188 | + ]); |
|
189 | + |
|
190 | + $calendar = new CachedSubscription($backend, $calendarInfo); |
|
191 | + |
|
192 | + $res = $calendar->getChildren(); |
|
193 | + $this->assertCount(2, $res); |
|
194 | + $this->assertInstanceOf(CachedSubscriptionObject::class, $res[0]); |
|
195 | + $this->assertInstanceOf(CachedSubscriptionObject::class, $res[1]); |
|
196 | + } |
|
197 | + |
|
198 | + public function testGetMultipleChildren(): void { |
|
199 | + $backend = $this->createMock(CalDavBackend::class); |
|
200 | + $calendarInfo = [ |
|
201 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
202 | + 'principaluri' => 'user2', |
|
203 | + 'id' => 666, |
|
204 | + 'uri' => 'cal', |
|
205 | + ]; |
|
206 | + |
|
207 | + $backend->expects($this->once()) |
|
208 | + ->method('getMultipleCalendarObjects') |
|
209 | + ->with(666, ['foo1', 'foo2'], 1) |
|
210 | + ->willReturn([ |
|
211 | + [ |
|
212 | + 'id' => 99, |
|
213 | + 'uri' => 'foo1' |
|
214 | + ], |
|
215 | + [ |
|
216 | + 'id' => 100, |
|
217 | + 'uri' => 'foo2' |
|
218 | + ], |
|
219 | + ]); |
|
220 | + |
|
221 | + $calendar = new CachedSubscription($backend, $calendarInfo); |
|
222 | + |
|
223 | + $res = $calendar->getMultipleChildren(['foo1', 'foo2']); |
|
224 | + $this->assertCount(2, $res); |
|
225 | + $this->assertInstanceOf(CachedSubscriptionObject::class, $res[0]); |
|
226 | + $this->assertInstanceOf(CachedSubscriptionObject::class, $res[1]); |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + public function testCreateFile(): void { |
|
231 | + $this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class); |
|
232 | + $this->expectExceptionMessage('Creating objects in cached subscription is not allowed'); |
|
233 | + |
|
234 | + $backend = $this->createMock(CalDavBackend::class); |
|
235 | + $calendarInfo = [ |
|
236 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
237 | + 'principaluri' => 'user2', |
|
238 | + 'id' => 666, |
|
239 | + 'uri' => 'cal', |
|
240 | + ]; |
|
241 | + |
|
242 | + $calendar = new CachedSubscription($backend, $calendarInfo); |
|
243 | + $calendar->createFile('foo', []); |
|
244 | + } |
|
245 | + |
|
246 | + public function testChildExists(): void { |
|
247 | + $backend = $this->createMock(CalDavBackend::class); |
|
248 | + $calendarInfo = [ |
|
249 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
250 | + 'principaluri' => 'user2', |
|
251 | + 'id' => 666, |
|
252 | + 'uri' => 'cal', |
|
253 | + ]; |
|
254 | + |
|
255 | + $calls = [ |
|
256 | + [666, 'foo1', 1, [ |
|
257 | + 'id' => 99, |
|
258 | + 'uri' => 'foo1' |
|
259 | + ]], |
|
260 | + [666, 'foo2', 1, null], |
|
261 | + ]; |
|
262 | + $backend->expects($this->exactly(2)) |
|
263 | + ->method('getCalendarObject') |
|
264 | + ->willReturnCallback(function () use (&$calls) { |
|
265 | + $expected = array_shift($calls); |
|
266 | + $return = array_pop($expected); |
|
267 | + $this->assertEquals($expected, func_get_args()); |
|
268 | + return $return; |
|
269 | + }); |
|
270 | + |
|
271 | + $calendar = new CachedSubscription($backend, $calendarInfo); |
|
272 | + |
|
273 | + $this->assertEquals(true, $calendar->childExists('foo1')); |
|
274 | + $this->assertEquals(false, $calendar->childExists('foo2')); |
|
275 | + } |
|
276 | + |
|
277 | + public function testCalendarQuery(): void { |
|
278 | + $backend = $this->createMock(CalDavBackend::class); |
|
279 | + $calendarInfo = [ |
|
280 | + '{http://owncloud.org/ns}owner-principal' => 'user1', |
|
281 | + 'principaluri' => 'user2', |
|
282 | + 'id' => 666, |
|
283 | + 'uri' => 'cal', |
|
284 | + ]; |
|
285 | + |
|
286 | + $backend->expects($this->once()) |
|
287 | + ->method('calendarQuery') |
|
288 | + ->with(666, ['foo'], 1) |
|
289 | + ->willReturn([99]); |
|
290 | + |
|
291 | + $calendar = new CachedSubscription($backend, $calendarInfo); |
|
292 | + |
|
293 | + $this->assertEquals([99], $calendar->calendarQuery(['foo'])); |
|
294 | + } |
|
295 | 295 | } |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | ]; |
150 | 150 | $backend->expects($this->exactly(2)) |
151 | 151 | ->method('getCalendarObject') |
152 | - ->willReturnCallback(function () use (&$calls) { |
|
152 | + ->willReturnCallback(function() use (&$calls) { |
|
153 | 153 | $expected = array_shift($calls); |
154 | 154 | $return = array_pop($expected); |
155 | 155 | $this->assertEquals($expected, func_get_args()); |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | ]; |
262 | 262 | $backend->expects($this->exactly(2)) |
263 | 263 | ->method('getCalendarObject') |
264 | - ->willReturnCallback(function () use (&$calls) { |
|
264 | + ->willReturnCallback(function() use (&$calls) { |
|
265 | 265 | $expected = array_shift($calls); |
266 | 266 | $return = array_pop($expected); |
267 | 267 | $this->assertEquals($expected, func_get_args()); |
@@ -24,165 +24,165 @@ |
||
24 | 24 | |
25 | 25 | class RateLimitingPluginTest extends TestCase { |
26 | 26 | |
27 | - private Limiter&MockObject $limiter; |
|
28 | - private CalDavBackend&MockObject $caldavBackend; |
|
29 | - private IUserManager&MockObject $userManager; |
|
30 | - private LoggerInterface&MockObject $logger; |
|
31 | - private IAppConfig&MockObject $config; |
|
32 | - private string $userId = 'user123'; |
|
33 | - private RateLimitingPlugin $plugin; |
|
34 | - |
|
35 | - protected function setUp(): void { |
|
36 | - parent::setUp(); |
|
37 | - |
|
38 | - $this->limiter = $this->createMock(Limiter::class); |
|
39 | - $this->userManager = $this->createMock(IUserManager::class); |
|
40 | - $this->caldavBackend = $this->createMock(CalDavBackend::class); |
|
41 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
42 | - $this->config = $this->createMock(IAppConfig::class); |
|
43 | - $this->plugin = new RateLimitingPlugin( |
|
44 | - $this->limiter, |
|
45 | - $this->userManager, |
|
46 | - $this->caldavBackend, |
|
47 | - $this->logger, |
|
48 | - $this->config, |
|
49 | - $this->userId, |
|
50 | - ); |
|
51 | - } |
|
52 | - |
|
53 | - public function testNoUserObject(): void { |
|
54 | - $this->limiter->expects(self::never()) |
|
55 | - ->method('registerUserRequest'); |
|
56 | - |
|
57 | - $this->plugin->beforeBind('calendars/foo/cal'); |
|
58 | - } |
|
59 | - |
|
60 | - public function testUnrelated(): void { |
|
61 | - $user = $this->createMock(IUser::class); |
|
62 | - $this->userManager->expects(self::once()) |
|
63 | - ->method('get') |
|
64 | - ->with($this->userId) |
|
65 | - ->willReturn($user); |
|
66 | - $this->limiter->expects(self::never()) |
|
67 | - ->method('registerUserRequest'); |
|
68 | - |
|
69 | - $this->plugin->beforeBind('foo/bar'); |
|
70 | - } |
|
71 | - |
|
72 | - public function testRegisterCalendarCreation(): void { |
|
73 | - $user = $this->createMock(IUser::class); |
|
74 | - $this->userManager->expects(self::once()) |
|
75 | - ->method('get') |
|
76 | - ->with($this->userId) |
|
77 | - ->willReturn($user); |
|
78 | - $this->config |
|
79 | - ->method('getValueInt') |
|
80 | - ->with('dav') |
|
81 | - ->willReturnArgument(2); |
|
82 | - $this->limiter->expects(self::once()) |
|
83 | - ->method('registerUserRequest') |
|
84 | - ->with( |
|
85 | - 'caldav-create-calendar', |
|
86 | - 10, |
|
87 | - 3600, |
|
88 | - $user, |
|
89 | - ); |
|
90 | - |
|
91 | - $this->plugin->beforeBind('calendars/foo/cal'); |
|
92 | - } |
|
93 | - |
|
94 | - public function testCalendarCreationRateLimitExceeded(): void { |
|
95 | - $user = $this->createMock(IUser::class); |
|
96 | - $this->userManager->expects(self::once()) |
|
97 | - ->method('get') |
|
98 | - ->with($this->userId) |
|
99 | - ->willReturn($user); |
|
100 | - $this->config |
|
101 | - ->method('getValueInt') |
|
102 | - ->with('dav') |
|
103 | - ->willReturnArgument(2); |
|
104 | - $this->limiter->expects(self::once()) |
|
105 | - ->method('registerUserRequest') |
|
106 | - ->with( |
|
107 | - 'caldav-create-calendar', |
|
108 | - 10, |
|
109 | - 3600, |
|
110 | - $user, |
|
111 | - ) |
|
112 | - ->willThrowException(new RateLimitExceededException()); |
|
113 | - $this->expectException(TooManyRequests::class); |
|
114 | - |
|
115 | - $this->plugin->beforeBind('calendars/foo/cal'); |
|
116 | - } |
|
117 | - |
|
118 | - public function testCalendarLimitReached(): void { |
|
119 | - $user = $this->createMock(IUser::class); |
|
120 | - $this->userManager->expects(self::once()) |
|
121 | - ->method('get') |
|
122 | - ->with($this->userId) |
|
123 | - ->willReturn($user); |
|
124 | - $user->method('getUID')->willReturn('user123'); |
|
125 | - $this->config |
|
126 | - ->method('getValueInt') |
|
127 | - ->with('dav') |
|
128 | - ->willReturnArgument(2); |
|
129 | - $this->limiter->expects(self::once()) |
|
130 | - ->method('registerUserRequest') |
|
131 | - ->with( |
|
132 | - 'caldav-create-calendar', |
|
133 | - 10, |
|
134 | - 3600, |
|
135 | - $user, |
|
136 | - ); |
|
137 | - $this->caldavBackend->expects(self::once()) |
|
138 | - ->method('getCalendarsForUserCount') |
|
139 | - ->with('principals/users/user123') |
|
140 | - ->willReturn(27); |
|
141 | - $this->caldavBackend->expects(self::once()) |
|
142 | - ->method('getSubscriptionsForUserCount') |
|
143 | - ->with('principals/users/user123') |
|
144 | - ->willReturn(3); |
|
145 | - $this->expectException(Forbidden::class); |
|
146 | - |
|
147 | - $this->plugin->beforeBind('calendars/foo/cal'); |
|
148 | - } |
|
149 | - |
|
150 | - public function testNoCalendarsSubscriptsLimit(): void { |
|
151 | - $user = $this->createMock(IUser::class); |
|
152 | - $this->userManager->expects(self::once()) |
|
153 | - ->method('get') |
|
154 | - ->with($this->userId) |
|
155 | - ->willReturn($user); |
|
156 | - $user->method('getUID')->willReturn('user123'); |
|
157 | - $this->config |
|
158 | - ->method('getValueInt') |
|
159 | - ->with('dav') |
|
160 | - ->willReturnCallback(function ($app, $key, $default) { |
|
161 | - switch ($key) { |
|
162 | - case 'maximumCalendarsSubscriptions': |
|
163 | - return -1; |
|
164 | - default: |
|
165 | - return $default; |
|
166 | - } |
|
167 | - }); |
|
168 | - $this->limiter->expects(self::once()) |
|
169 | - ->method('registerUserRequest') |
|
170 | - ->with( |
|
171 | - 'caldav-create-calendar', |
|
172 | - 10, |
|
173 | - 3600, |
|
174 | - $user, |
|
175 | - ); |
|
176 | - $this->caldavBackend->expects(self::never()) |
|
177 | - ->method('getCalendarsForUserCount') |
|
178 | - ->with('principals/users/user123') |
|
179 | - ->willReturn(27); |
|
180 | - $this->caldavBackend->expects(self::never()) |
|
181 | - ->method('getSubscriptionsForUserCount') |
|
182 | - ->with('principals/users/user123') |
|
183 | - ->willReturn(3); |
|
184 | - |
|
185 | - $this->plugin->beforeBind('calendars/foo/cal'); |
|
186 | - } |
|
27 | + private Limiter&MockObject $limiter; |
|
28 | + private CalDavBackend&MockObject $caldavBackend; |
|
29 | + private IUserManager&MockObject $userManager; |
|
30 | + private LoggerInterface&MockObject $logger; |
|
31 | + private IAppConfig&MockObject $config; |
|
32 | + private string $userId = 'user123'; |
|
33 | + private RateLimitingPlugin $plugin; |
|
34 | + |
|
35 | + protected function setUp(): void { |
|
36 | + parent::setUp(); |
|
37 | + |
|
38 | + $this->limiter = $this->createMock(Limiter::class); |
|
39 | + $this->userManager = $this->createMock(IUserManager::class); |
|
40 | + $this->caldavBackend = $this->createMock(CalDavBackend::class); |
|
41 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
42 | + $this->config = $this->createMock(IAppConfig::class); |
|
43 | + $this->plugin = new RateLimitingPlugin( |
|
44 | + $this->limiter, |
|
45 | + $this->userManager, |
|
46 | + $this->caldavBackend, |
|
47 | + $this->logger, |
|
48 | + $this->config, |
|
49 | + $this->userId, |
|
50 | + ); |
|
51 | + } |
|
52 | + |
|
53 | + public function testNoUserObject(): void { |
|
54 | + $this->limiter->expects(self::never()) |
|
55 | + ->method('registerUserRequest'); |
|
56 | + |
|
57 | + $this->plugin->beforeBind('calendars/foo/cal'); |
|
58 | + } |
|
59 | + |
|
60 | + public function testUnrelated(): void { |
|
61 | + $user = $this->createMock(IUser::class); |
|
62 | + $this->userManager->expects(self::once()) |
|
63 | + ->method('get') |
|
64 | + ->with($this->userId) |
|
65 | + ->willReturn($user); |
|
66 | + $this->limiter->expects(self::never()) |
|
67 | + ->method('registerUserRequest'); |
|
68 | + |
|
69 | + $this->plugin->beforeBind('foo/bar'); |
|
70 | + } |
|
71 | + |
|
72 | + public function testRegisterCalendarCreation(): void { |
|
73 | + $user = $this->createMock(IUser::class); |
|
74 | + $this->userManager->expects(self::once()) |
|
75 | + ->method('get') |
|
76 | + ->with($this->userId) |
|
77 | + ->willReturn($user); |
|
78 | + $this->config |
|
79 | + ->method('getValueInt') |
|
80 | + ->with('dav') |
|
81 | + ->willReturnArgument(2); |
|
82 | + $this->limiter->expects(self::once()) |
|
83 | + ->method('registerUserRequest') |
|
84 | + ->with( |
|
85 | + 'caldav-create-calendar', |
|
86 | + 10, |
|
87 | + 3600, |
|
88 | + $user, |
|
89 | + ); |
|
90 | + |
|
91 | + $this->plugin->beforeBind('calendars/foo/cal'); |
|
92 | + } |
|
93 | + |
|
94 | + public function testCalendarCreationRateLimitExceeded(): void { |
|
95 | + $user = $this->createMock(IUser::class); |
|
96 | + $this->userManager->expects(self::once()) |
|
97 | + ->method('get') |
|
98 | + ->with($this->userId) |
|
99 | + ->willReturn($user); |
|
100 | + $this->config |
|
101 | + ->method('getValueInt') |
|
102 | + ->with('dav') |
|
103 | + ->willReturnArgument(2); |
|
104 | + $this->limiter->expects(self::once()) |
|
105 | + ->method('registerUserRequest') |
|
106 | + ->with( |
|
107 | + 'caldav-create-calendar', |
|
108 | + 10, |
|
109 | + 3600, |
|
110 | + $user, |
|
111 | + ) |
|
112 | + ->willThrowException(new RateLimitExceededException()); |
|
113 | + $this->expectException(TooManyRequests::class); |
|
114 | + |
|
115 | + $this->plugin->beforeBind('calendars/foo/cal'); |
|
116 | + } |
|
117 | + |
|
118 | + public function testCalendarLimitReached(): void { |
|
119 | + $user = $this->createMock(IUser::class); |
|
120 | + $this->userManager->expects(self::once()) |
|
121 | + ->method('get') |
|
122 | + ->with($this->userId) |
|
123 | + ->willReturn($user); |
|
124 | + $user->method('getUID')->willReturn('user123'); |
|
125 | + $this->config |
|
126 | + ->method('getValueInt') |
|
127 | + ->with('dav') |
|
128 | + ->willReturnArgument(2); |
|
129 | + $this->limiter->expects(self::once()) |
|
130 | + ->method('registerUserRequest') |
|
131 | + ->with( |
|
132 | + 'caldav-create-calendar', |
|
133 | + 10, |
|
134 | + 3600, |
|
135 | + $user, |
|
136 | + ); |
|
137 | + $this->caldavBackend->expects(self::once()) |
|
138 | + ->method('getCalendarsForUserCount') |
|
139 | + ->with('principals/users/user123') |
|
140 | + ->willReturn(27); |
|
141 | + $this->caldavBackend->expects(self::once()) |
|
142 | + ->method('getSubscriptionsForUserCount') |
|
143 | + ->with('principals/users/user123') |
|
144 | + ->willReturn(3); |
|
145 | + $this->expectException(Forbidden::class); |
|
146 | + |
|
147 | + $this->plugin->beforeBind('calendars/foo/cal'); |
|
148 | + } |
|
149 | + |
|
150 | + public function testNoCalendarsSubscriptsLimit(): void { |
|
151 | + $user = $this->createMock(IUser::class); |
|
152 | + $this->userManager->expects(self::once()) |
|
153 | + ->method('get') |
|
154 | + ->with($this->userId) |
|
155 | + ->willReturn($user); |
|
156 | + $user->method('getUID')->willReturn('user123'); |
|
157 | + $this->config |
|
158 | + ->method('getValueInt') |
|
159 | + ->with('dav') |
|
160 | + ->willReturnCallback(function ($app, $key, $default) { |
|
161 | + switch ($key) { |
|
162 | + case 'maximumCalendarsSubscriptions': |
|
163 | + return -1; |
|
164 | + default: |
|
165 | + return $default; |
|
166 | + } |
|
167 | + }); |
|
168 | + $this->limiter->expects(self::once()) |
|
169 | + ->method('registerUserRequest') |
|
170 | + ->with( |
|
171 | + 'caldav-create-calendar', |
|
172 | + 10, |
|
173 | + 3600, |
|
174 | + $user, |
|
175 | + ); |
|
176 | + $this->caldavBackend->expects(self::never()) |
|
177 | + ->method('getCalendarsForUserCount') |
|
178 | + ->with('principals/users/user123') |
|
179 | + ->willReturn(27); |
|
180 | + $this->caldavBackend->expects(self::never()) |
|
181 | + ->method('getSubscriptionsForUserCount') |
|
182 | + ->with('principals/users/user123') |
|
183 | + ->willReturn(3); |
|
184 | + |
|
185 | + $this->plugin->beforeBind('calendars/foo/cal'); |
|
186 | + } |
|
187 | 187 | |
188 | 188 | } |
@@ -157,7 +157,7 @@ |
||
157 | 157 | $this->config |
158 | 158 | ->method('getValueInt') |
159 | 159 | ->with('dav') |
160 | - ->willReturnCallback(function ($app, $key, $default) { |
|
160 | + ->willReturnCallback(function($app, $key, $default) { |
|
161 | 161 | switch ($key) { |
162 | 162 | case 'maximumCalendarsSubscriptions': |
163 | 163 | return -1; |
@@ -18,47 +18,47 @@ |
||
18 | 18 | use Psr\Log\LoggerInterface; |
19 | 19 | |
20 | 20 | class CalendarManagerTest extends \Test\TestCase { |
21 | - private CalDavBackend&MockObject $backend; |
|
22 | - private IL10N&MockObject $l10n; |
|
23 | - private IConfig&MockObject $config; |
|
24 | - private LoggerInterface&MockObject $logger; |
|
25 | - private CalendarManager $manager; |
|
21 | + private CalDavBackend&MockObject $backend; |
|
22 | + private IL10N&MockObject $l10n; |
|
23 | + private IConfig&MockObject $config; |
|
24 | + private LoggerInterface&MockObject $logger; |
|
25 | + private CalendarManager $manager; |
|
26 | 26 | |
27 | - protected function setUp(): void { |
|
28 | - parent::setUp(); |
|
29 | - $this->backend = $this->createMock(CalDavBackend::class); |
|
30 | - $this->l10n = $this->createMock(IL10N::class); |
|
31 | - $this->config = $this->createMock(IConfig::class); |
|
32 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
33 | - $this->manager = new CalendarManager( |
|
34 | - $this->backend, |
|
35 | - $this->l10n, |
|
36 | - $this->config, |
|
37 | - $this->logger |
|
38 | - ); |
|
39 | - } |
|
27 | + protected function setUp(): void { |
|
28 | + parent::setUp(); |
|
29 | + $this->backend = $this->createMock(CalDavBackend::class); |
|
30 | + $this->l10n = $this->createMock(IL10N::class); |
|
31 | + $this->config = $this->createMock(IConfig::class); |
|
32 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
33 | + $this->manager = new CalendarManager( |
|
34 | + $this->backend, |
|
35 | + $this->l10n, |
|
36 | + $this->config, |
|
37 | + $this->logger |
|
38 | + ); |
|
39 | + } |
|
40 | 40 | |
41 | - public function testSetupCalendarProvider(): void { |
|
42 | - $this->backend->expects($this->once()) |
|
43 | - ->method('getCalendarsForUser') |
|
44 | - ->with('principals/users/user123') |
|
45 | - ->willReturn([ |
|
46 | - ['id' => 123, 'uri' => 'blablub1'], |
|
47 | - ['id' => 456, 'uri' => 'blablub2'], |
|
48 | - ]); |
|
41 | + public function testSetupCalendarProvider(): void { |
|
42 | + $this->backend->expects($this->once()) |
|
43 | + ->method('getCalendarsForUser') |
|
44 | + ->with('principals/users/user123') |
|
45 | + ->willReturn([ |
|
46 | + ['id' => 123, 'uri' => 'blablub1'], |
|
47 | + ['id' => 456, 'uri' => 'blablub2'], |
|
48 | + ]); |
|
49 | 49 | |
50 | - /** @var IManager&MockObject $calendarManager */ |
|
51 | - $calendarManager = $this->createMock(Manager::class); |
|
52 | - $registeredIds = []; |
|
53 | - $calendarManager->expects($this->exactly(2)) |
|
54 | - ->method('registerCalendar') |
|
55 | - ->willReturnCallback(function ($parameter) use (&$registeredIds): void { |
|
56 | - $this->assertInstanceOf(CalendarImpl::class, $parameter); |
|
57 | - $registeredIds[] = $parameter->getKey(); |
|
58 | - }); |
|
50 | + /** @var IManager&MockObject $calendarManager */ |
|
51 | + $calendarManager = $this->createMock(Manager::class); |
|
52 | + $registeredIds = []; |
|
53 | + $calendarManager->expects($this->exactly(2)) |
|
54 | + ->method('registerCalendar') |
|
55 | + ->willReturnCallback(function ($parameter) use (&$registeredIds): void { |
|
56 | + $this->assertInstanceOf(CalendarImpl::class, $parameter); |
|
57 | + $registeredIds[] = $parameter->getKey(); |
|
58 | + }); |
|
59 | 59 | |
60 | - $this->manager->setupCalendarProvider($calendarManager, 'user123'); |
|
60 | + $this->manager->setupCalendarProvider($calendarManager, 'user123'); |
|
61 | 61 | |
62 | - $this->assertEquals(['123','456'], $registeredIds); |
|
63 | - } |
|
62 | + $this->assertEquals(['123','456'], $registeredIds); |
|
63 | + } |
|
64 | 64 | } |
@@ -16,65 +16,65 @@ |
||
16 | 16 | use Test\TestCase; |
17 | 17 | |
18 | 18 | class CachedSubscriptionImplTest extends TestCase { |
19 | - private CachedSubscription&MockObject $cachedSubscription; |
|
20 | - private array $cachedSubscriptionInfo; |
|
21 | - private CalDavBackend&MockObject $backend; |
|
22 | - private CachedSubscriptionImpl $cachedSubscriptionImpl; |
|
23 | - |
|
24 | - protected function setUp(): void { |
|
25 | - parent::setUp(); |
|
26 | - |
|
27 | - $this->cachedSubscription = $this->createMock(CachedSubscription::class); |
|
28 | - $this->cachedSubscriptionInfo = [ |
|
29 | - 'id' => 'fancy_id_123', |
|
30 | - '{DAV:}displayname' => 'user readable name 123', |
|
31 | - '{http://apple.com/ns/ical/}calendar-color' => '#AABBCC', |
|
32 | - 'uri' => '/this/is/a/uri', |
|
33 | - 'source' => 'https://test.localhost/calendar1', |
|
34 | - ]; |
|
35 | - $this->backend = $this->createMock(CalDavBackend::class); |
|
36 | - |
|
37 | - $this->cachedSubscriptionImpl = new CachedSubscriptionImpl( |
|
38 | - $this->cachedSubscription, |
|
39 | - $this->cachedSubscriptionInfo, |
|
40 | - $this->backend |
|
41 | - ); |
|
42 | - } |
|
43 | - |
|
44 | - public function testGetKey(): void { |
|
45 | - $this->assertEquals($this->cachedSubscriptionImpl->getKey(), 'fancy_id_123'); |
|
46 | - } |
|
47 | - |
|
48 | - public function testGetDisplayname(): void { |
|
49 | - $this->assertEquals($this->cachedSubscriptionImpl->getDisplayName(), 'user readable name 123'); |
|
50 | - } |
|
51 | - |
|
52 | - public function testGetDisplayColor(): void { |
|
53 | - $this->assertEquals($this->cachedSubscriptionImpl->getDisplayColor(), '#AABBCC'); |
|
54 | - } |
|
55 | - |
|
56 | - public function testGetSource(): void { |
|
57 | - $this->assertEquals($this->cachedSubscriptionImpl->getSource(), 'https://test.localhost/calendar1'); |
|
58 | - } |
|
59 | - |
|
60 | - public function testSearch(): void { |
|
61 | - $this->backend->expects($this->once()) |
|
62 | - ->method('search') |
|
63 | - ->with($this->cachedSubscriptionInfo, 'abc', ['def'], ['ghi'], 42, 1337) |
|
64 | - ->willReturn(['SEARCHRESULTS']); |
|
65 | - |
|
66 | - $result = $this->cachedSubscriptionImpl->search('abc', ['def'], ['ghi'], 42, 1337); |
|
67 | - $this->assertEquals($result, ['SEARCHRESULTS']); |
|
68 | - } |
|
69 | - |
|
70 | - public function testGetPermissionRead(): void { |
|
71 | - $this->cachedSubscription->expects($this->once()) |
|
72 | - ->method('getACL') |
|
73 | - ->with() |
|
74 | - ->willReturn([ |
|
75 | - ['privilege' => '{DAV:}read'] |
|
76 | - ]); |
|
77 | - |
|
78 | - $this->assertEquals(1, $this->cachedSubscriptionImpl->getPermissions()); |
|
79 | - } |
|
19 | + private CachedSubscription&MockObject $cachedSubscription; |
|
20 | + private array $cachedSubscriptionInfo; |
|
21 | + private CalDavBackend&MockObject $backend; |
|
22 | + private CachedSubscriptionImpl $cachedSubscriptionImpl; |
|
23 | + |
|
24 | + protected function setUp(): void { |
|
25 | + parent::setUp(); |
|
26 | + |
|
27 | + $this->cachedSubscription = $this->createMock(CachedSubscription::class); |
|
28 | + $this->cachedSubscriptionInfo = [ |
|
29 | + 'id' => 'fancy_id_123', |
|
30 | + '{DAV:}displayname' => 'user readable name 123', |
|
31 | + '{http://apple.com/ns/ical/}calendar-color' => '#AABBCC', |
|
32 | + 'uri' => '/this/is/a/uri', |
|
33 | + 'source' => 'https://test.localhost/calendar1', |
|
34 | + ]; |
|
35 | + $this->backend = $this->createMock(CalDavBackend::class); |
|
36 | + |
|
37 | + $this->cachedSubscriptionImpl = new CachedSubscriptionImpl( |
|
38 | + $this->cachedSubscription, |
|
39 | + $this->cachedSubscriptionInfo, |
|
40 | + $this->backend |
|
41 | + ); |
|
42 | + } |
|
43 | + |
|
44 | + public function testGetKey(): void { |
|
45 | + $this->assertEquals($this->cachedSubscriptionImpl->getKey(), 'fancy_id_123'); |
|
46 | + } |
|
47 | + |
|
48 | + public function testGetDisplayname(): void { |
|
49 | + $this->assertEquals($this->cachedSubscriptionImpl->getDisplayName(), 'user readable name 123'); |
|
50 | + } |
|
51 | + |
|
52 | + public function testGetDisplayColor(): void { |
|
53 | + $this->assertEquals($this->cachedSubscriptionImpl->getDisplayColor(), '#AABBCC'); |
|
54 | + } |
|
55 | + |
|
56 | + public function testGetSource(): void { |
|
57 | + $this->assertEquals($this->cachedSubscriptionImpl->getSource(), 'https://test.localhost/calendar1'); |
|
58 | + } |
|
59 | + |
|
60 | + public function testSearch(): void { |
|
61 | + $this->backend->expects($this->once()) |
|
62 | + ->method('search') |
|
63 | + ->with($this->cachedSubscriptionInfo, 'abc', ['def'], ['ghi'], 42, 1337) |
|
64 | + ->willReturn(['SEARCHRESULTS']); |
|
65 | + |
|
66 | + $result = $this->cachedSubscriptionImpl->search('abc', ['def'], ['ghi'], 42, 1337); |
|
67 | + $this->assertEquals($result, ['SEARCHRESULTS']); |
|
68 | + } |
|
69 | + |
|
70 | + public function testGetPermissionRead(): void { |
|
71 | + $this->cachedSubscription->expects($this->once()) |
|
72 | + ->method('getACL') |
|
73 | + ->with() |
|
74 | + ->willReturn([ |
|
75 | + ['privilege' => '{DAV:}read'] |
|
76 | + ]); |
|
77 | + |
|
78 | + $this->assertEquals(1, $this->cachedSubscriptionImpl->getPermissions()); |
|
79 | + } |
|
80 | 80 | } |
@@ -43,144 +43,144 @@ discard block |
||
43 | 43 | abstract class AbstractCalDavBackend extends TestCase { |
44 | 44 | |
45 | 45 | |
46 | - protected CalDavBackend $backend; |
|
47 | - protected Principal&MockObject $principal; |
|
48 | - protected IUserManager&MockObject $userManager; |
|
49 | - protected IGroupManager&MockObject $groupManager; |
|
50 | - protected IEventDispatcher&MockObject $dispatcher; |
|
51 | - private LoggerInterface&MockObject $logger; |
|
52 | - private IConfig&MockObject $config; |
|
53 | - private ISecureRandom $random; |
|
54 | - protected SharingBackend $sharingBackend; |
|
55 | - protected IDBConnection $db; |
|
56 | - public const UNIT_TEST_USER = 'principals/users/caldav-unit-test'; |
|
57 | - public const UNIT_TEST_USER1 = 'principals/users/caldav-unit-test1'; |
|
58 | - public const UNIT_TEST_GROUP = 'principals/groups/caldav-unit-test-group'; |
|
59 | - public const UNIT_TEST_GROUP2 = 'principals/groups/caldav-unit-test-group2'; |
|
46 | + protected CalDavBackend $backend; |
|
47 | + protected Principal&MockObject $principal; |
|
48 | + protected IUserManager&MockObject $userManager; |
|
49 | + protected IGroupManager&MockObject $groupManager; |
|
50 | + protected IEventDispatcher&MockObject $dispatcher; |
|
51 | + private LoggerInterface&MockObject $logger; |
|
52 | + private IConfig&MockObject $config; |
|
53 | + private ISecureRandom $random; |
|
54 | + protected SharingBackend $sharingBackend; |
|
55 | + protected IDBConnection $db; |
|
56 | + public const UNIT_TEST_USER = 'principals/users/caldav-unit-test'; |
|
57 | + public const UNIT_TEST_USER1 = 'principals/users/caldav-unit-test1'; |
|
58 | + public const UNIT_TEST_GROUP = 'principals/groups/caldav-unit-test-group'; |
|
59 | + public const UNIT_TEST_GROUP2 = 'principals/groups/caldav-unit-test-group2'; |
|
60 | 60 | |
61 | - protected function setUp(): void { |
|
62 | - parent::setUp(); |
|
61 | + protected function setUp(): void { |
|
62 | + parent::setUp(); |
|
63 | 63 | |
64 | - $this->userManager = $this->createMock(IUserManager::class); |
|
65 | - $this->groupManager = $this->createMock(IGroupManager::class); |
|
66 | - $this->dispatcher = $this->createMock(IEventDispatcher::class); |
|
67 | - $this->principal = $this->getMockBuilder(Principal::class) |
|
68 | - ->setConstructorArgs([ |
|
69 | - $this->userManager, |
|
70 | - $this->groupManager, |
|
71 | - $this->createMock(IAccountManager::class), |
|
72 | - $this->createMock(ShareManager::class), |
|
73 | - $this->createMock(IUserSession::class), |
|
74 | - $this->createMock(IAppManager::class), |
|
75 | - $this->createMock(ProxyMapper::class), |
|
76 | - $this->createMock(KnownUserService::class), |
|
77 | - $this->createMock(IConfig::class), |
|
78 | - $this->createMock(IFactory::class) |
|
79 | - ]) |
|
80 | - ->onlyMethods(['getPrincipalByPath', 'getGroupMembership', 'findByUri']) |
|
81 | - ->getMock(); |
|
82 | - $this->principal->expects($this->any())->method('getPrincipalByPath') |
|
83 | - ->willReturn([ |
|
84 | - 'uri' => 'principals/best-friend', |
|
85 | - '{DAV:}displayname' => 'User\'s displayname', |
|
86 | - ]); |
|
87 | - $this->principal->expects($this->any())->method('getGroupMembership') |
|
88 | - ->withAnyParameters() |
|
89 | - ->willReturn([self::UNIT_TEST_GROUP, self::UNIT_TEST_GROUP2]); |
|
64 | + $this->userManager = $this->createMock(IUserManager::class); |
|
65 | + $this->groupManager = $this->createMock(IGroupManager::class); |
|
66 | + $this->dispatcher = $this->createMock(IEventDispatcher::class); |
|
67 | + $this->principal = $this->getMockBuilder(Principal::class) |
|
68 | + ->setConstructorArgs([ |
|
69 | + $this->userManager, |
|
70 | + $this->groupManager, |
|
71 | + $this->createMock(IAccountManager::class), |
|
72 | + $this->createMock(ShareManager::class), |
|
73 | + $this->createMock(IUserSession::class), |
|
74 | + $this->createMock(IAppManager::class), |
|
75 | + $this->createMock(ProxyMapper::class), |
|
76 | + $this->createMock(KnownUserService::class), |
|
77 | + $this->createMock(IConfig::class), |
|
78 | + $this->createMock(IFactory::class) |
|
79 | + ]) |
|
80 | + ->onlyMethods(['getPrincipalByPath', 'getGroupMembership', 'findByUri']) |
|
81 | + ->getMock(); |
|
82 | + $this->principal->expects($this->any())->method('getPrincipalByPath') |
|
83 | + ->willReturn([ |
|
84 | + 'uri' => 'principals/best-friend', |
|
85 | + '{DAV:}displayname' => 'User\'s displayname', |
|
86 | + ]); |
|
87 | + $this->principal->expects($this->any())->method('getGroupMembership') |
|
88 | + ->withAnyParameters() |
|
89 | + ->willReturn([self::UNIT_TEST_GROUP, self::UNIT_TEST_GROUP2]); |
|
90 | 90 | |
91 | - $this->db = Server::get(IDBConnection::class); |
|
92 | - $this->random = Server::get(ISecureRandom::class); |
|
93 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
94 | - $this->config = $this->createMock(IConfig::class); |
|
95 | - $this->sharingBackend = new SharingBackend( |
|
96 | - $this->userManager, |
|
97 | - $this->groupManager, |
|
98 | - $this->principal, |
|
99 | - $this->createMock(ICacheFactory::class), |
|
100 | - new Service(new SharingMapper($this->db)), |
|
101 | - $this->logger); |
|
102 | - $this->backend = new CalDavBackend( |
|
103 | - $this->db, |
|
104 | - $this->principal, |
|
105 | - $this->userManager, |
|
106 | - $this->random, |
|
107 | - $this->logger, |
|
108 | - $this->dispatcher, |
|
109 | - $this->config, |
|
110 | - $this->sharingBackend, |
|
111 | - false, |
|
112 | - ); |
|
91 | + $this->db = Server::get(IDBConnection::class); |
|
92 | + $this->random = Server::get(ISecureRandom::class); |
|
93 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
94 | + $this->config = $this->createMock(IConfig::class); |
|
95 | + $this->sharingBackend = new SharingBackend( |
|
96 | + $this->userManager, |
|
97 | + $this->groupManager, |
|
98 | + $this->principal, |
|
99 | + $this->createMock(ICacheFactory::class), |
|
100 | + new Service(new SharingMapper($this->db)), |
|
101 | + $this->logger); |
|
102 | + $this->backend = new CalDavBackend( |
|
103 | + $this->db, |
|
104 | + $this->principal, |
|
105 | + $this->userManager, |
|
106 | + $this->random, |
|
107 | + $this->logger, |
|
108 | + $this->dispatcher, |
|
109 | + $this->config, |
|
110 | + $this->sharingBackend, |
|
111 | + false, |
|
112 | + ); |
|
113 | 113 | |
114 | - $this->cleanUpBackend(); |
|
115 | - } |
|
114 | + $this->cleanUpBackend(); |
|
115 | + } |
|
116 | 116 | |
117 | - protected function tearDown(): void { |
|
118 | - $this->cleanUpBackend(); |
|
119 | - parent::tearDown(); |
|
120 | - } |
|
117 | + protected function tearDown(): void { |
|
118 | + $this->cleanUpBackend(); |
|
119 | + parent::tearDown(); |
|
120 | + } |
|
121 | 121 | |
122 | - public function cleanUpBackend(): void { |
|
123 | - if (is_null($this->backend)) { |
|
124 | - return; |
|
125 | - } |
|
126 | - $this->principal->expects($this->any())->method('getGroupMembership') |
|
127 | - ->withAnyParameters() |
|
128 | - ->willReturn([self::UNIT_TEST_GROUP, self::UNIT_TEST_GROUP2]); |
|
129 | - $this->cleanupForPrincipal(self::UNIT_TEST_USER); |
|
130 | - $this->cleanupForPrincipal(self::UNIT_TEST_USER1); |
|
131 | - } |
|
122 | + public function cleanUpBackend(): void { |
|
123 | + if (is_null($this->backend)) { |
|
124 | + return; |
|
125 | + } |
|
126 | + $this->principal->expects($this->any())->method('getGroupMembership') |
|
127 | + ->withAnyParameters() |
|
128 | + ->willReturn([self::UNIT_TEST_GROUP, self::UNIT_TEST_GROUP2]); |
|
129 | + $this->cleanupForPrincipal(self::UNIT_TEST_USER); |
|
130 | + $this->cleanupForPrincipal(self::UNIT_TEST_USER1); |
|
131 | + } |
|
132 | 132 | |
133 | - private function cleanupForPrincipal($principal): void { |
|
134 | - $calendars = $this->backend->getCalendarsForUser($principal); |
|
135 | - $this->dispatcher->expects(self::any()) |
|
136 | - ->method('dispatchTyped'); |
|
137 | - foreach ($calendars as $calendar) { |
|
138 | - $this->backend->deleteCalendar($calendar['id'], true); |
|
139 | - } |
|
140 | - $subscriptions = $this->backend->getSubscriptionsForUser($principal); |
|
141 | - foreach ($subscriptions as $subscription) { |
|
142 | - $this->backend->deleteSubscription($subscription['id']); |
|
143 | - } |
|
144 | - } |
|
133 | + private function cleanupForPrincipal($principal): void { |
|
134 | + $calendars = $this->backend->getCalendarsForUser($principal); |
|
135 | + $this->dispatcher->expects(self::any()) |
|
136 | + ->method('dispatchTyped'); |
|
137 | + foreach ($calendars as $calendar) { |
|
138 | + $this->backend->deleteCalendar($calendar['id'], true); |
|
139 | + } |
|
140 | + $subscriptions = $this->backend->getSubscriptionsForUser($principal); |
|
141 | + foreach ($subscriptions as $subscription) { |
|
142 | + $this->backend->deleteSubscription($subscription['id']); |
|
143 | + } |
|
144 | + } |
|
145 | 145 | |
146 | - protected function createTestCalendar(): int { |
|
147 | - $this->dispatcher->expects(self::any()) |
|
148 | - ->method('dispatchTyped'); |
|
146 | + protected function createTestCalendar(): int { |
|
147 | + $this->dispatcher->expects(self::any()) |
|
148 | + ->method('dispatchTyped'); |
|
149 | 149 | |
150 | - $this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', [ |
|
151 | - '{http://apple.com/ns/ical/}calendar-color' => '#1C4587FF' |
|
152 | - ]); |
|
153 | - $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); |
|
154 | - $this->assertEquals(1, count($calendars)); |
|
155 | - $this->assertEquals(self::UNIT_TEST_USER, $calendars[0]['principaluri']); |
|
156 | - /** @var SupportedCalendarComponentSet $components */ |
|
157 | - $components = $calendars[0]['{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set']; |
|
158 | - $this->assertEquals(['VEVENT','VTODO','VJOURNAL'], $components->getValue()); |
|
159 | - $color = $calendars[0]['{http://apple.com/ns/ical/}calendar-color']; |
|
160 | - $this->assertEquals('#1C4587FF', $color); |
|
161 | - $this->assertEquals('Example', $calendars[0]['uri']); |
|
162 | - $this->assertEquals('Example', $calendars[0]['{DAV:}displayname']); |
|
163 | - return (int)$calendars[0]['id']; |
|
164 | - } |
|
150 | + $this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', [ |
|
151 | + '{http://apple.com/ns/ical/}calendar-color' => '#1C4587FF' |
|
152 | + ]); |
|
153 | + $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); |
|
154 | + $this->assertEquals(1, count($calendars)); |
|
155 | + $this->assertEquals(self::UNIT_TEST_USER, $calendars[0]['principaluri']); |
|
156 | + /** @var SupportedCalendarComponentSet $components */ |
|
157 | + $components = $calendars[0]['{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set']; |
|
158 | + $this->assertEquals(['VEVENT','VTODO','VJOURNAL'], $components->getValue()); |
|
159 | + $color = $calendars[0]['{http://apple.com/ns/ical/}calendar-color']; |
|
160 | + $this->assertEquals('#1C4587FF', $color); |
|
161 | + $this->assertEquals('Example', $calendars[0]['uri']); |
|
162 | + $this->assertEquals('Example', $calendars[0]['{DAV:}displayname']); |
|
163 | + return (int)$calendars[0]['id']; |
|
164 | + } |
|
165 | 165 | |
166 | - protected function createTestSubscription() { |
|
167 | - $this->backend->createSubscription(self::UNIT_TEST_USER, 'Example', [ |
|
168 | - '{http://apple.com/ns/ical/}calendar-color' => '#1C4587FF', |
|
169 | - '{http://calendarserver.org/ns/}source' => new Href(['foo']), |
|
170 | - ]); |
|
171 | - $calendars = $this->backend->getSubscriptionsForUser(self::UNIT_TEST_USER); |
|
172 | - $this->assertEquals(1, count($calendars)); |
|
173 | - $this->assertEquals(self::UNIT_TEST_USER, $calendars[0]['principaluri']); |
|
174 | - $this->assertEquals('Example', $calendars[0]['uri']); |
|
175 | - $calendarId = $calendars[0]['id']; |
|
166 | + protected function createTestSubscription() { |
|
167 | + $this->backend->createSubscription(self::UNIT_TEST_USER, 'Example', [ |
|
168 | + '{http://apple.com/ns/ical/}calendar-color' => '#1C4587FF', |
|
169 | + '{http://calendarserver.org/ns/}source' => new Href(['foo']), |
|
170 | + ]); |
|
171 | + $calendars = $this->backend->getSubscriptionsForUser(self::UNIT_TEST_USER); |
|
172 | + $this->assertEquals(1, count($calendars)); |
|
173 | + $this->assertEquals(self::UNIT_TEST_USER, $calendars[0]['principaluri']); |
|
174 | + $this->assertEquals('Example', $calendars[0]['uri']); |
|
175 | + $calendarId = $calendars[0]['id']; |
|
176 | 176 | |
177 | - return $calendarId; |
|
178 | - } |
|
177 | + return $calendarId; |
|
178 | + } |
|
179 | 179 | |
180 | - protected function createEvent($calendarId, $start = '20130912T130000Z', $end = '20130912T140000Z') { |
|
181 | - $randomPart = self::getUniqueID(); |
|
180 | + protected function createEvent($calendarId, $start = '20130912T130000Z', $end = '20130912T140000Z') { |
|
181 | + $randomPart = self::getUniqueID(); |
|
182 | 182 | |
183 | - $calData = <<<EOD |
|
183 | + $calData = <<<EOD |
|
184 | 184 | BEGIN:VCALENDAR |
185 | 185 | VERSION:2.0 |
186 | 186 | PRODID:ownCloud Calendar |
@@ -196,20 +196,20 @@ discard block |
||
196 | 196 | END:VEVENT |
197 | 197 | END:VCALENDAR |
198 | 198 | EOD; |
199 | - $uri0 = $this->getUniqueID('event'); |
|
199 | + $uri0 = $this->getUniqueID('event'); |
|
200 | 200 | |
201 | - $this->dispatcher->expects(self::atLeastOnce()) |
|
202 | - ->method('dispatchTyped'); |
|
201 | + $this->dispatcher->expects(self::atLeastOnce()) |
|
202 | + ->method('dispatchTyped'); |
|
203 | 203 | |
204 | - $this->backend->createCalendarObject($calendarId, $uri0, $calData); |
|
204 | + $this->backend->createCalendarObject($calendarId, $uri0, $calData); |
|
205 | 205 | |
206 | - return $uri0; |
|
207 | - } |
|
206 | + return $uri0; |
|
207 | + } |
|
208 | 208 | |
209 | - protected function modifyEvent($calendarId, $objectId, $start = '20130912T130000Z', $end = '20130912T140000Z') { |
|
210 | - $randomPart = self::getUniqueID(); |
|
209 | + protected function modifyEvent($calendarId, $objectId, $start = '20130912T130000Z', $end = '20130912T140000Z') { |
|
210 | + $randomPart = self::getUniqueID(); |
|
211 | 211 | |
212 | - $calData = <<<EOD |
|
212 | + $calData = <<<EOD |
|
213 | 213 | BEGIN:VCALENDAR |
214 | 214 | VERSION:2.0 |
215 | 215 | PRODID:ownCloud Calendar |
@@ -226,38 +226,38 @@ discard block |
||
226 | 226 | END:VCALENDAR |
227 | 227 | EOD; |
228 | 228 | |
229 | - $this->backend->updateCalendarObject($calendarId, $objectId, $calData); |
|
230 | - } |
|
229 | + $this->backend->updateCalendarObject($calendarId, $objectId, $calData); |
|
230 | + } |
|
231 | 231 | |
232 | - protected function deleteEvent($calendarId, $objectId) { |
|
233 | - $this->backend->deleteCalendarObject($calendarId, $objectId); |
|
234 | - } |
|
232 | + protected function deleteEvent($calendarId, $objectId) { |
|
233 | + $this->backend->deleteCalendarObject($calendarId, $objectId); |
|
234 | + } |
|
235 | 235 | |
236 | - protected function assertAcl($principal, $privilege, $acl) { |
|
237 | - foreach ($acl as $a) { |
|
238 | - if ($a['principal'] === $principal && $a['privilege'] === $privilege) { |
|
239 | - $this->addToAssertionCount(1); |
|
240 | - return; |
|
241 | - } |
|
242 | - } |
|
243 | - $this->fail("ACL does not contain $principal / $privilege"); |
|
244 | - } |
|
236 | + protected function assertAcl($principal, $privilege, $acl) { |
|
237 | + foreach ($acl as $a) { |
|
238 | + if ($a['principal'] === $principal && $a['privilege'] === $privilege) { |
|
239 | + $this->addToAssertionCount(1); |
|
240 | + return; |
|
241 | + } |
|
242 | + } |
|
243 | + $this->fail("ACL does not contain $principal / $privilege"); |
|
244 | + } |
|
245 | 245 | |
246 | - protected function assertNotAcl($principal, $privilege, $acl) { |
|
247 | - foreach ($acl as $a) { |
|
248 | - if ($a['principal'] === $principal && $a['privilege'] === $privilege) { |
|
249 | - $this->fail("ACL contains $principal / $privilege"); |
|
250 | - return; |
|
251 | - } |
|
252 | - } |
|
253 | - $this->addToAssertionCount(1); |
|
254 | - } |
|
246 | + protected function assertNotAcl($principal, $privilege, $acl) { |
|
247 | + foreach ($acl as $a) { |
|
248 | + if ($a['principal'] === $principal && $a['privilege'] === $privilege) { |
|
249 | + $this->fail("ACL contains $principal / $privilege"); |
|
250 | + return; |
|
251 | + } |
|
252 | + } |
|
253 | + $this->addToAssertionCount(1); |
|
254 | + } |
|
255 | 255 | |
256 | - protected function assertAccess($shouldHaveAcl, $principal, $privilege, $acl) { |
|
257 | - if ($shouldHaveAcl) { |
|
258 | - $this->assertAcl($principal, $privilege, $acl); |
|
259 | - } else { |
|
260 | - $this->assertNotAcl($principal, $privilege, $acl); |
|
261 | - } |
|
262 | - } |
|
256 | + protected function assertAccess($shouldHaveAcl, $principal, $privilege, $acl) { |
|
257 | + if ($shouldHaveAcl) { |
|
258 | + $this->assertAcl($principal, $privilege, $acl); |
|
259 | + } else { |
|
260 | + $this->assertNotAcl($principal, $privilege, $acl); |
|
261 | + } |
|
262 | + } |
|
263 | 263 | } |
@@ -155,12 +155,12 @@ |
||
155 | 155 | $this->assertEquals(self::UNIT_TEST_USER, $calendars[0]['principaluri']); |
156 | 156 | /** @var SupportedCalendarComponentSet $components */ |
157 | 157 | $components = $calendars[0]['{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set']; |
158 | - $this->assertEquals(['VEVENT','VTODO','VJOURNAL'], $components->getValue()); |
|
158 | + $this->assertEquals(['VEVENT', 'VTODO', 'VJOURNAL'], $components->getValue()); |
|
159 | 159 | $color = $calendars[0]['{http://apple.com/ns/ical/}calendar-color']; |
160 | 160 | $this->assertEquals('#1C4587FF', $color); |
161 | 161 | $this->assertEquals('Example', $calendars[0]['uri']); |
162 | 162 | $this->assertEquals('Example', $calendars[0]['{DAV:}displayname']); |
163 | - return (int)$calendars[0]['id']; |
|
163 | + return (int) $calendars[0]['id']; |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | protected function createTestSubscription() { |