@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -20,314 +20,314 @@ |
||
20 | 20 | use Test\TestCase; |
21 | 21 | |
22 | 22 | class RefreshWebcalServiceTest extends TestCase { |
23 | - private CalDavBackend&MockObject $caldavBackend; |
|
24 | - private Connection&MockObject $connection; |
|
25 | - private LoggerInterface&MockObject $logger; |
|
26 | - private ITimeFactory&MockObject $time; |
|
27 | - |
|
28 | - protected function setUp(): void { |
|
29 | - parent::setUp(); |
|
30 | - |
|
31 | - $this->caldavBackend = $this->createMock(CalDavBackend::class); |
|
32 | - $this->connection = $this->createMock(Connection::class); |
|
33 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
34 | - $this->time = $this->createMock(ITimeFactory::class); |
|
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * @dataProvider runDataProvider |
|
39 | - */ |
|
40 | - public function testRun(string $body, string $contentType, string $result): void { |
|
41 | - $refreshWebcalService = $this->getMockBuilder(RefreshWebcalService::class) |
|
42 | - ->onlyMethods(['getRandomCalendarObjectUri']) |
|
43 | - ->setConstructorArgs([$this->caldavBackend, $this->logger, $this->connection, $this->time]) |
|
44 | - ->getMock(); |
|
45 | - |
|
46 | - $refreshWebcalService |
|
47 | - ->method('getRandomCalendarObjectUri') |
|
48 | - ->willReturn('uri-1.ics'); |
|
49 | - |
|
50 | - $this->caldavBackend->expects(self::once()) |
|
51 | - ->method('getSubscriptionsForUser') |
|
52 | - ->with('principals/users/testuser') |
|
53 | - ->willReturn([ |
|
54 | - [ |
|
55 | - 'id' => '99', |
|
56 | - 'uri' => 'sub456', |
|
57 | - RefreshWebcalService::REFRESH_RATE => 'P1D', |
|
58 | - RefreshWebcalService::STRIP_TODOS => '1', |
|
59 | - RefreshWebcalService::STRIP_ALARMS => '1', |
|
60 | - RefreshWebcalService::STRIP_ATTACHMENTS => '1', |
|
61 | - 'source' => 'webcal://foo.bar/bla', |
|
62 | - 'lastmodified' => 0, |
|
63 | - ], |
|
64 | - [ |
|
65 | - 'id' => '42', |
|
66 | - 'uri' => 'sub123', |
|
67 | - RefreshWebcalService::REFRESH_RATE => 'PT1H', |
|
68 | - RefreshWebcalService::STRIP_TODOS => '1', |
|
69 | - RefreshWebcalService::STRIP_ALARMS => '1', |
|
70 | - RefreshWebcalService::STRIP_ATTACHMENTS => '1', |
|
71 | - 'source' => 'webcal://foo.bar/bla2', |
|
72 | - 'lastmodified' => 0, |
|
73 | - ], |
|
74 | - ]); |
|
75 | - |
|
76 | - $this->connection->expects(self::once()) |
|
77 | - ->method('queryWebcalFeed') |
|
78 | - ->willReturn($result); |
|
79 | - $this->caldavBackend->expects(self::once()) |
|
80 | - ->method('createCalendarObject') |
|
81 | - ->with(42, 'uri-1.ics', $result, 1); |
|
82 | - |
|
83 | - $refreshWebcalService->refreshSubscription('principals/users/testuser', 'sub123'); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @dataProvider identicalDataProvider |
|
88 | - */ |
|
89 | - public function testRunIdentical(string $uid, array $calendarObject, string $body, string $contentType, string $result): void { |
|
90 | - $refreshWebcalService = $this->getMockBuilder(RefreshWebcalService::class) |
|
91 | - ->onlyMethods(['getRandomCalendarObjectUri']) |
|
92 | - ->setConstructorArgs([$this->caldavBackend, $this->logger, $this->connection, $this->time]) |
|
93 | - ->getMock(); |
|
94 | - |
|
95 | - $refreshWebcalService |
|
96 | - ->method('getRandomCalendarObjectUri') |
|
97 | - ->willReturn('uri-1.ics'); |
|
98 | - |
|
99 | - $this->caldavBackend->expects(self::once()) |
|
100 | - ->method('getSubscriptionsForUser') |
|
101 | - ->with('principals/users/testuser') |
|
102 | - ->willReturn([ |
|
103 | - [ |
|
104 | - 'id' => '99', |
|
105 | - 'uri' => 'sub456', |
|
106 | - RefreshWebcalService::REFRESH_RATE => 'P1D', |
|
107 | - RefreshWebcalService::STRIP_TODOS => '1', |
|
108 | - RefreshWebcalService::STRIP_ALARMS => '1', |
|
109 | - RefreshWebcalService::STRIP_ATTACHMENTS => '1', |
|
110 | - 'source' => 'webcal://foo.bar/bla', |
|
111 | - 'lastmodified' => 0, |
|
112 | - ], |
|
113 | - [ |
|
114 | - 'id' => '42', |
|
115 | - 'uri' => 'sub123', |
|
116 | - RefreshWebcalService::REFRESH_RATE => 'PT1H', |
|
117 | - RefreshWebcalService::STRIP_TODOS => '1', |
|
118 | - RefreshWebcalService::STRIP_ALARMS => '1', |
|
119 | - RefreshWebcalService::STRIP_ATTACHMENTS => '1', |
|
120 | - 'source' => 'webcal://foo.bar/bla2', |
|
121 | - 'lastmodified' => 0, |
|
122 | - ], |
|
123 | - ]); |
|
124 | - |
|
125 | - $this->connection->expects(self::once()) |
|
126 | - ->method('queryWebcalFeed') |
|
127 | - ->willReturn($result); |
|
128 | - |
|
129 | - $this->caldavBackend->expects(self::once()) |
|
130 | - ->method('getLimitedCalendarObjects') |
|
131 | - ->willReturn($calendarObject); |
|
132 | - |
|
133 | - $denormalised = [ |
|
134 | - 'etag' => 100, |
|
135 | - 'size' => strlen($calendarObject[$uid]['calendardata']), |
|
136 | - 'uid' => 'sub456' |
|
137 | - ]; |
|
138 | - |
|
139 | - $this->caldavBackend->expects(self::once()) |
|
140 | - ->method('getDenormalizedData') |
|
141 | - ->willReturn($denormalised); |
|
142 | - |
|
143 | - $this->caldavBackend->expects(self::never()) |
|
144 | - ->method('createCalendarObject'); |
|
145 | - |
|
146 | - $refreshWebcalService->refreshSubscription('principals/users/testuser', 'sub456'); |
|
147 | - } |
|
148 | - |
|
149 | - public function testRunJustUpdated(): void { |
|
150 | - $refreshWebcalService = $this->getMockBuilder(RefreshWebcalService::class) |
|
151 | - ->onlyMethods(['getRandomCalendarObjectUri']) |
|
152 | - ->setConstructorArgs([$this->caldavBackend, $this->logger, $this->connection, $this->time]) |
|
153 | - ->getMock(); |
|
154 | - |
|
155 | - $refreshWebcalService |
|
156 | - ->method('getRandomCalendarObjectUri') |
|
157 | - ->willReturn('uri-1.ics'); |
|
158 | - |
|
159 | - $this->caldavBackend->expects(self::once()) |
|
160 | - ->method('getSubscriptionsForUser') |
|
161 | - ->with('principals/users/testuser') |
|
162 | - ->willReturn([ |
|
163 | - [ |
|
164 | - 'id' => '99', |
|
165 | - 'uri' => 'sub456', |
|
166 | - RefreshWebcalService::REFRESH_RATE => 'P1D', |
|
167 | - RefreshWebcalService::STRIP_TODOS => '1', |
|
168 | - RefreshWebcalService::STRIP_ALARMS => '1', |
|
169 | - RefreshWebcalService::STRIP_ATTACHMENTS => '1', |
|
170 | - 'source' => 'webcal://foo.bar/bla', |
|
171 | - 'lastmodified' => time(), |
|
172 | - ], |
|
173 | - [ |
|
174 | - 'id' => '42', |
|
175 | - 'uri' => 'sub123', |
|
176 | - RefreshWebcalService::REFRESH_RATE => 'PT1H', |
|
177 | - RefreshWebcalService::STRIP_TODOS => '1', |
|
178 | - RefreshWebcalService::STRIP_ALARMS => '1', |
|
179 | - RefreshWebcalService::STRIP_ATTACHMENTS => '1', |
|
180 | - 'source' => 'webcal://foo.bar/bla2', |
|
181 | - 'lastmodified' => time(), |
|
182 | - ], |
|
183 | - ]); |
|
184 | - |
|
185 | - $timeMock = $this->createMock(\DateTime::class); |
|
186 | - $this->time->expects(self::once()) |
|
187 | - ->method('getDateTime') |
|
188 | - ->willReturn($timeMock); |
|
189 | - $timeMock->expects(self::once()) |
|
190 | - ->method('getTimestamp') |
|
191 | - ->willReturn(2101724667); |
|
192 | - $this->time->expects(self::once()) |
|
193 | - ->method('getTime') |
|
194 | - ->willReturn(time()); |
|
195 | - $this->connection->expects(self::never()) |
|
196 | - ->method('queryWebcalFeed'); |
|
197 | - $this->caldavBackend->expects(self::never()) |
|
198 | - ->method('createCalendarObject'); |
|
199 | - |
|
200 | - $refreshWebcalService->refreshSubscription('principals/users/testuser', 'sub123'); |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * @dataProvider runDataProvider |
|
205 | - */ |
|
206 | - public function testRunCreateCalendarNoException(string $body, string $contentType, string $result): void { |
|
207 | - $refreshWebcalService = $this->getMockBuilder(RefreshWebcalService::class) |
|
208 | - ->onlyMethods(['getRandomCalendarObjectUri', 'getSubscription',]) |
|
209 | - ->setConstructorArgs([$this->caldavBackend, $this->logger, $this->connection, $this->time]) |
|
210 | - ->getMock(); |
|
211 | - |
|
212 | - $refreshWebcalService |
|
213 | - ->method('getRandomCalendarObjectUri') |
|
214 | - ->willReturn('uri-1.ics'); |
|
215 | - |
|
216 | - $refreshWebcalService |
|
217 | - ->method('getSubscription') |
|
218 | - ->willReturn([ |
|
219 | - 'id' => '42', |
|
220 | - 'uri' => 'sub123', |
|
221 | - RefreshWebcalService::REFRESH_RATE => 'PT1H', |
|
222 | - RefreshWebcalService::STRIP_TODOS => '1', |
|
223 | - RefreshWebcalService::STRIP_ALARMS => '1', |
|
224 | - RefreshWebcalService::STRIP_ATTACHMENTS => '1', |
|
225 | - 'source' => 'webcal://foo.bar/bla2', |
|
226 | - 'lastmodified' => 0, |
|
227 | - ]); |
|
228 | - |
|
229 | - $this->connection->expects(self::once()) |
|
230 | - ->method('queryWebcalFeed') |
|
231 | - ->willReturn($result); |
|
232 | - |
|
233 | - $this->caldavBackend->expects(self::once()) |
|
234 | - ->method('createCalendarObject') |
|
235 | - ->with(42, 'uri-1.ics', $result, 1); |
|
236 | - |
|
237 | - $noInstanceException = new NoInstancesException("can't add calendar object"); |
|
238 | - $this->caldavBackend->expects(self::once()) |
|
239 | - ->method('createCalendarObject') |
|
240 | - ->willThrowException($noInstanceException); |
|
241 | - |
|
242 | - $this->logger->expects(self::once()) |
|
243 | - ->method('warning') |
|
244 | - ->with('Unable to create calendar object from subscription {subscriptionId}', ['exception' => $noInstanceException, 'subscriptionId' => '42', 'source' => 'webcal://foo.bar/bla2']); |
|
245 | - |
|
246 | - $refreshWebcalService->refreshSubscription('principals/users/testuser', 'sub123'); |
|
247 | - } |
|
248 | - |
|
249 | - /** |
|
250 | - * @dataProvider runDataProvider |
|
251 | - */ |
|
252 | - public function testRunCreateCalendarBadRequest(string $body, string $contentType, string $result): void { |
|
253 | - $refreshWebcalService = $this->getMockBuilder(RefreshWebcalService::class) |
|
254 | - ->onlyMethods(['getRandomCalendarObjectUri', 'getSubscription']) |
|
255 | - ->setConstructorArgs([$this->caldavBackend, $this->logger, $this->connection, $this->time]) |
|
256 | - ->getMock(); |
|
257 | - |
|
258 | - $refreshWebcalService |
|
259 | - ->method('getRandomCalendarObjectUri') |
|
260 | - ->willReturn('uri-1.ics'); |
|
261 | - |
|
262 | - $refreshWebcalService |
|
263 | - ->method('getSubscription') |
|
264 | - ->willReturn([ |
|
265 | - 'id' => '42', |
|
266 | - 'uri' => 'sub123', |
|
267 | - RefreshWebcalService::REFRESH_RATE => 'PT1H', |
|
268 | - RefreshWebcalService::STRIP_TODOS => '1', |
|
269 | - RefreshWebcalService::STRIP_ALARMS => '1', |
|
270 | - RefreshWebcalService::STRIP_ATTACHMENTS => '1', |
|
271 | - 'source' => 'webcal://foo.bar/bla2', |
|
272 | - 'lastmodified' => 0, |
|
273 | - ]); |
|
274 | - |
|
275 | - $this->connection->expects(self::once()) |
|
276 | - ->method('queryWebcalFeed') |
|
277 | - ->willReturn($result); |
|
278 | - |
|
279 | - $this->caldavBackend->expects(self::once()) |
|
280 | - ->method('createCalendarObject') |
|
281 | - ->with(42, 'uri-1.ics', $result, 1); |
|
282 | - |
|
283 | - $badRequestException = new BadRequest("can't add reach calendar url"); |
|
284 | - $this->caldavBackend->expects(self::once()) |
|
285 | - ->method('createCalendarObject') |
|
286 | - ->willThrowException($badRequestException); |
|
287 | - |
|
288 | - $this->logger->expects(self::once()) |
|
289 | - ->method('warning') |
|
290 | - ->with('Unable to create calendar object from subscription {subscriptionId}', ['exception' => $badRequestException, 'subscriptionId' => '42', 'source' => 'webcal://foo.bar/bla2']); |
|
291 | - |
|
292 | - $refreshWebcalService->refreshSubscription('principals/users/testuser', 'sub123'); |
|
293 | - } |
|
294 | - |
|
295 | - public static function identicalDataProvider(): array { |
|
296 | - return [ |
|
297 | - [ |
|
298 | - '12345', |
|
299 | - [ |
|
300 | - '12345' => [ |
|
301 | - 'id' => 42, |
|
302 | - 'etag' => 100, |
|
303 | - 'uri' => 'sub456', |
|
304 | - 'calendardata' => "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nUID:12345\r\nDTSTAMP:20160218T133704Z\r\nDTSTART;VALUE=DATE:19000101\r\nDTEND;VALUE=DATE:19000102\r\nRRULE:FREQ=YEARLY\r\nSUMMARY:12345's Birthday (1900)\r\nTRANSP:TRANSPARENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", |
|
305 | - ], |
|
306 | - ], |
|
307 | - "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nUID:12345\r\nDTSTAMP:20160218T133704Z\r\nDTSTART;VALUE=DATE:19000101\r\nDTEND;VALUE=DATE:19000102\r\nRRULE:FREQ=YEARLY\r\nSUMMARY:12345's Birthday (1900)\r\nTRANSP:TRANSPARENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", |
|
308 | - 'text/calendar;charset=utf8', |
|
309 | - "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nUID:12345\r\nDTSTAMP:20180218T133704Z\r\nDTSTART;VALUE=DATE:19000101\r\nDTEND;VALUE=DATE:19000102\r\nRRULE:FREQ=YEARLY\r\nSUMMARY:12345's Birthday (1900)\r\nTRANSP:TRANSPARENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", |
|
310 | - ], |
|
311 | - ]; |
|
312 | - } |
|
313 | - |
|
314 | - public static function runDataProvider(): array { |
|
315 | - return [ |
|
316 | - [ |
|
317 | - "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nUID:12345\r\nDTSTAMP:20160218T133704Z\r\nDTSTART;VALUE=DATE:19000101\r\nDTEND;VALUE=DATE:19000102\r\nRRULE:FREQ=YEARLY\r\nSUMMARY:12345's Birthday (1900)\r\nTRANSP:TRANSPARENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", |
|
318 | - 'text/calendar;charset=utf8', |
|
319 | - "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject " . VObject\Version::VERSION . "//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nUID:12345\r\nDTSTAMP:20160218T133704Z\r\nDTSTART;VALUE=DATE:19000101\r\nDTEND;VALUE=DATE:19000102\r\nRRULE:FREQ=YEARLY\r\nSUMMARY:12345's Birthday (1900)\r\nTRANSP:TRANSPARENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", |
|
320 | - ], |
|
321 | - [ |
|
322 | - '["vcalendar",[["prodid",{},"text","-//Example Corp.//Example Client//EN"],["version",{},"text","2.0"]],[["vtimezone",[["last-modified",{},"date-time","2004-01-10T03:28:45Z"],["tzid",{},"text","US/Eastern"]],[["daylight",[["dtstart",{},"date-time","2000-04-04T02:00:00"],["rrule",{},"recur",{"freq":"YEARLY","byday":"1SU","bymonth":4}],["tzname",{},"text","EDT"],["tzoffsetfrom",{},"utc-offset","-05:00"],["tzoffsetto",{},"utc-offset","-04:00"]],[]],["standard",[["dtstart",{},"date-time","2000-10-26T02:00:00"],["rrule",{},"recur",{"freq":"YEARLY","byday":"1SU","bymonth":10}],["tzname",{},"text","EST"],["tzoffsetfrom",{},"utc-offset","-04:00"],["tzoffsetto",{},"utc-offset","-05:00"]],[]]]],["vevent",[["dtstamp",{},"date-time","2006-02-06T00:11:21Z"],["dtstart",{"tzid":"US/Eastern"},"date-time","2006-01-02T14:00:00"],["duration",{},"duration","PT1H"],["recurrence-id",{"tzid":"US/Eastern"},"date-time","2006-01-04T12:00:00"],["summary",{},"text","Event #2"],["uid",{},"text","12345"]],[]]]]', |
|
323 | - 'application/calendar+json', |
|
324 | - "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject " . VObject\Version::VERSION . "//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VTIMEZONE\r\nLAST-MODIFIED:20040110T032845Z\r\nTZID:US/Eastern\r\nBEGIN:DAYLIGHT\r\nDTSTART:20000404T020000\r\nRRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4\r\nTZNAME:EDT\r\nTZOFFSETFROM:-0500\r\nTZOFFSETTO:-0400\r\nEND:DAYLIGHT\r\nBEGIN:STANDARD\r\nDTSTART:20001026T020000\r\nRRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=10\r\nTZNAME:EST\r\nTZOFFSETFROM:-0400\r\nTZOFFSETTO:-0500\r\nEND:STANDARD\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nDTSTAMP:20060206T001121Z\r\nDTSTART;TZID=US/Eastern:20060102T140000\r\nDURATION:PT1H\r\nRECURRENCE-ID;TZID=US/Eastern:20060104T120000\r\nSUMMARY:Event #2\r\nUID:12345\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n" |
|
325 | - ], |
|
326 | - [ |
|
327 | - '<?xml version="1.0" encoding="utf-8" ?><icalendar xmlns="urn:ietf:params:xml:ns:icalendar-2.0"><vcalendar><properties><prodid><text>-//Example Inc.//Example Client//EN</text></prodid><version><text>2.0</text></version></properties><components><vevent><properties><dtstamp><date-time>2006-02-06T00:11:21Z</date-time></dtstamp><dtstart><parameters><tzid><text>US/Eastern</text></tzid></parameters><date-time>2006-01-04T14:00:00</date-time></dtstart><duration><duration>PT1H</duration></duration><recurrence-id><parameters><tzid><text>US/Eastern</text></tzid></parameters><date-time>2006-01-04T12:00:00</date-time></recurrence-id><summary><text>Event #2 bis</text></summary><uid><text>12345</text></uid></properties></vevent></components></vcalendar></icalendar>', |
|
328 | - 'application/calendar+xml', |
|
329 | - "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject " . VObject\Version::VERSION . "//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nDTSTAMP:20060206T001121Z\r\nDTSTART;TZID=US/Eastern:20060104T140000\r\nDURATION:PT1H\r\nRECURRENCE-ID;TZID=US/Eastern:20060104T120000\r\nSUMMARY:Event #2 bis\r\nUID:12345\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n" |
|
330 | - ] |
|
331 | - ]; |
|
332 | - } |
|
23 | + private CalDavBackend&MockObject $caldavBackend; |
|
24 | + private Connection&MockObject $connection; |
|
25 | + private LoggerInterface&MockObject $logger; |
|
26 | + private ITimeFactory&MockObject $time; |
|
27 | + |
|
28 | + protected function setUp(): void { |
|
29 | + parent::setUp(); |
|
30 | + |
|
31 | + $this->caldavBackend = $this->createMock(CalDavBackend::class); |
|
32 | + $this->connection = $this->createMock(Connection::class); |
|
33 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
34 | + $this->time = $this->createMock(ITimeFactory::class); |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * @dataProvider runDataProvider |
|
39 | + */ |
|
40 | + public function testRun(string $body, string $contentType, string $result): void { |
|
41 | + $refreshWebcalService = $this->getMockBuilder(RefreshWebcalService::class) |
|
42 | + ->onlyMethods(['getRandomCalendarObjectUri']) |
|
43 | + ->setConstructorArgs([$this->caldavBackend, $this->logger, $this->connection, $this->time]) |
|
44 | + ->getMock(); |
|
45 | + |
|
46 | + $refreshWebcalService |
|
47 | + ->method('getRandomCalendarObjectUri') |
|
48 | + ->willReturn('uri-1.ics'); |
|
49 | + |
|
50 | + $this->caldavBackend->expects(self::once()) |
|
51 | + ->method('getSubscriptionsForUser') |
|
52 | + ->with('principals/users/testuser') |
|
53 | + ->willReturn([ |
|
54 | + [ |
|
55 | + 'id' => '99', |
|
56 | + 'uri' => 'sub456', |
|
57 | + RefreshWebcalService::REFRESH_RATE => 'P1D', |
|
58 | + RefreshWebcalService::STRIP_TODOS => '1', |
|
59 | + RefreshWebcalService::STRIP_ALARMS => '1', |
|
60 | + RefreshWebcalService::STRIP_ATTACHMENTS => '1', |
|
61 | + 'source' => 'webcal://foo.bar/bla', |
|
62 | + 'lastmodified' => 0, |
|
63 | + ], |
|
64 | + [ |
|
65 | + 'id' => '42', |
|
66 | + 'uri' => 'sub123', |
|
67 | + RefreshWebcalService::REFRESH_RATE => 'PT1H', |
|
68 | + RefreshWebcalService::STRIP_TODOS => '1', |
|
69 | + RefreshWebcalService::STRIP_ALARMS => '1', |
|
70 | + RefreshWebcalService::STRIP_ATTACHMENTS => '1', |
|
71 | + 'source' => 'webcal://foo.bar/bla2', |
|
72 | + 'lastmodified' => 0, |
|
73 | + ], |
|
74 | + ]); |
|
75 | + |
|
76 | + $this->connection->expects(self::once()) |
|
77 | + ->method('queryWebcalFeed') |
|
78 | + ->willReturn($result); |
|
79 | + $this->caldavBackend->expects(self::once()) |
|
80 | + ->method('createCalendarObject') |
|
81 | + ->with(42, 'uri-1.ics', $result, 1); |
|
82 | + |
|
83 | + $refreshWebcalService->refreshSubscription('principals/users/testuser', 'sub123'); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @dataProvider identicalDataProvider |
|
88 | + */ |
|
89 | + public function testRunIdentical(string $uid, array $calendarObject, string $body, string $contentType, string $result): void { |
|
90 | + $refreshWebcalService = $this->getMockBuilder(RefreshWebcalService::class) |
|
91 | + ->onlyMethods(['getRandomCalendarObjectUri']) |
|
92 | + ->setConstructorArgs([$this->caldavBackend, $this->logger, $this->connection, $this->time]) |
|
93 | + ->getMock(); |
|
94 | + |
|
95 | + $refreshWebcalService |
|
96 | + ->method('getRandomCalendarObjectUri') |
|
97 | + ->willReturn('uri-1.ics'); |
|
98 | + |
|
99 | + $this->caldavBackend->expects(self::once()) |
|
100 | + ->method('getSubscriptionsForUser') |
|
101 | + ->with('principals/users/testuser') |
|
102 | + ->willReturn([ |
|
103 | + [ |
|
104 | + 'id' => '99', |
|
105 | + 'uri' => 'sub456', |
|
106 | + RefreshWebcalService::REFRESH_RATE => 'P1D', |
|
107 | + RefreshWebcalService::STRIP_TODOS => '1', |
|
108 | + RefreshWebcalService::STRIP_ALARMS => '1', |
|
109 | + RefreshWebcalService::STRIP_ATTACHMENTS => '1', |
|
110 | + 'source' => 'webcal://foo.bar/bla', |
|
111 | + 'lastmodified' => 0, |
|
112 | + ], |
|
113 | + [ |
|
114 | + 'id' => '42', |
|
115 | + 'uri' => 'sub123', |
|
116 | + RefreshWebcalService::REFRESH_RATE => 'PT1H', |
|
117 | + RefreshWebcalService::STRIP_TODOS => '1', |
|
118 | + RefreshWebcalService::STRIP_ALARMS => '1', |
|
119 | + RefreshWebcalService::STRIP_ATTACHMENTS => '1', |
|
120 | + 'source' => 'webcal://foo.bar/bla2', |
|
121 | + 'lastmodified' => 0, |
|
122 | + ], |
|
123 | + ]); |
|
124 | + |
|
125 | + $this->connection->expects(self::once()) |
|
126 | + ->method('queryWebcalFeed') |
|
127 | + ->willReturn($result); |
|
128 | + |
|
129 | + $this->caldavBackend->expects(self::once()) |
|
130 | + ->method('getLimitedCalendarObjects') |
|
131 | + ->willReturn($calendarObject); |
|
132 | + |
|
133 | + $denormalised = [ |
|
134 | + 'etag' => 100, |
|
135 | + 'size' => strlen($calendarObject[$uid]['calendardata']), |
|
136 | + 'uid' => 'sub456' |
|
137 | + ]; |
|
138 | + |
|
139 | + $this->caldavBackend->expects(self::once()) |
|
140 | + ->method('getDenormalizedData') |
|
141 | + ->willReturn($denormalised); |
|
142 | + |
|
143 | + $this->caldavBackend->expects(self::never()) |
|
144 | + ->method('createCalendarObject'); |
|
145 | + |
|
146 | + $refreshWebcalService->refreshSubscription('principals/users/testuser', 'sub456'); |
|
147 | + } |
|
148 | + |
|
149 | + public function testRunJustUpdated(): void { |
|
150 | + $refreshWebcalService = $this->getMockBuilder(RefreshWebcalService::class) |
|
151 | + ->onlyMethods(['getRandomCalendarObjectUri']) |
|
152 | + ->setConstructorArgs([$this->caldavBackend, $this->logger, $this->connection, $this->time]) |
|
153 | + ->getMock(); |
|
154 | + |
|
155 | + $refreshWebcalService |
|
156 | + ->method('getRandomCalendarObjectUri') |
|
157 | + ->willReturn('uri-1.ics'); |
|
158 | + |
|
159 | + $this->caldavBackend->expects(self::once()) |
|
160 | + ->method('getSubscriptionsForUser') |
|
161 | + ->with('principals/users/testuser') |
|
162 | + ->willReturn([ |
|
163 | + [ |
|
164 | + 'id' => '99', |
|
165 | + 'uri' => 'sub456', |
|
166 | + RefreshWebcalService::REFRESH_RATE => 'P1D', |
|
167 | + RefreshWebcalService::STRIP_TODOS => '1', |
|
168 | + RefreshWebcalService::STRIP_ALARMS => '1', |
|
169 | + RefreshWebcalService::STRIP_ATTACHMENTS => '1', |
|
170 | + 'source' => 'webcal://foo.bar/bla', |
|
171 | + 'lastmodified' => time(), |
|
172 | + ], |
|
173 | + [ |
|
174 | + 'id' => '42', |
|
175 | + 'uri' => 'sub123', |
|
176 | + RefreshWebcalService::REFRESH_RATE => 'PT1H', |
|
177 | + RefreshWebcalService::STRIP_TODOS => '1', |
|
178 | + RefreshWebcalService::STRIP_ALARMS => '1', |
|
179 | + RefreshWebcalService::STRIP_ATTACHMENTS => '1', |
|
180 | + 'source' => 'webcal://foo.bar/bla2', |
|
181 | + 'lastmodified' => time(), |
|
182 | + ], |
|
183 | + ]); |
|
184 | + |
|
185 | + $timeMock = $this->createMock(\DateTime::class); |
|
186 | + $this->time->expects(self::once()) |
|
187 | + ->method('getDateTime') |
|
188 | + ->willReturn($timeMock); |
|
189 | + $timeMock->expects(self::once()) |
|
190 | + ->method('getTimestamp') |
|
191 | + ->willReturn(2101724667); |
|
192 | + $this->time->expects(self::once()) |
|
193 | + ->method('getTime') |
|
194 | + ->willReturn(time()); |
|
195 | + $this->connection->expects(self::never()) |
|
196 | + ->method('queryWebcalFeed'); |
|
197 | + $this->caldavBackend->expects(self::never()) |
|
198 | + ->method('createCalendarObject'); |
|
199 | + |
|
200 | + $refreshWebcalService->refreshSubscription('principals/users/testuser', 'sub123'); |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * @dataProvider runDataProvider |
|
205 | + */ |
|
206 | + public function testRunCreateCalendarNoException(string $body, string $contentType, string $result): void { |
|
207 | + $refreshWebcalService = $this->getMockBuilder(RefreshWebcalService::class) |
|
208 | + ->onlyMethods(['getRandomCalendarObjectUri', 'getSubscription',]) |
|
209 | + ->setConstructorArgs([$this->caldavBackend, $this->logger, $this->connection, $this->time]) |
|
210 | + ->getMock(); |
|
211 | + |
|
212 | + $refreshWebcalService |
|
213 | + ->method('getRandomCalendarObjectUri') |
|
214 | + ->willReturn('uri-1.ics'); |
|
215 | + |
|
216 | + $refreshWebcalService |
|
217 | + ->method('getSubscription') |
|
218 | + ->willReturn([ |
|
219 | + 'id' => '42', |
|
220 | + 'uri' => 'sub123', |
|
221 | + RefreshWebcalService::REFRESH_RATE => 'PT1H', |
|
222 | + RefreshWebcalService::STRIP_TODOS => '1', |
|
223 | + RefreshWebcalService::STRIP_ALARMS => '1', |
|
224 | + RefreshWebcalService::STRIP_ATTACHMENTS => '1', |
|
225 | + 'source' => 'webcal://foo.bar/bla2', |
|
226 | + 'lastmodified' => 0, |
|
227 | + ]); |
|
228 | + |
|
229 | + $this->connection->expects(self::once()) |
|
230 | + ->method('queryWebcalFeed') |
|
231 | + ->willReturn($result); |
|
232 | + |
|
233 | + $this->caldavBackend->expects(self::once()) |
|
234 | + ->method('createCalendarObject') |
|
235 | + ->with(42, 'uri-1.ics', $result, 1); |
|
236 | + |
|
237 | + $noInstanceException = new NoInstancesException("can't add calendar object"); |
|
238 | + $this->caldavBackend->expects(self::once()) |
|
239 | + ->method('createCalendarObject') |
|
240 | + ->willThrowException($noInstanceException); |
|
241 | + |
|
242 | + $this->logger->expects(self::once()) |
|
243 | + ->method('warning') |
|
244 | + ->with('Unable to create calendar object from subscription {subscriptionId}', ['exception' => $noInstanceException, 'subscriptionId' => '42', 'source' => 'webcal://foo.bar/bla2']); |
|
245 | + |
|
246 | + $refreshWebcalService->refreshSubscription('principals/users/testuser', 'sub123'); |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * @dataProvider runDataProvider |
|
251 | + */ |
|
252 | + public function testRunCreateCalendarBadRequest(string $body, string $contentType, string $result): void { |
|
253 | + $refreshWebcalService = $this->getMockBuilder(RefreshWebcalService::class) |
|
254 | + ->onlyMethods(['getRandomCalendarObjectUri', 'getSubscription']) |
|
255 | + ->setConstructorArgs([$this->caldavBackend, $this->logger, $this->connection, $this->time]) |
|
256 | + ->getMock(); |
|
257 | + |
|
258 | + $refreshWebcalService |
|
259 | + ->method('getRandomCalendarObjectUri') |
|
260 | + ->willReturn('uri-1.ics'); |
|
261 | + |
|
262 | + $refreshWebcalService |
|
263 | + ->method('getSubscription') |
|
264 | + ->willReturn([ |
|
265 | + 'id' => '42', |
|
266 | + 'uri' => 'sub123', |
|
267 | + RefreshWebcalService::REFRESH_RATE => 'PT1H', |
|
268 | + RefreshWebcalService::STRIP_TODOS => '1', |
|
269 | + RefreshWebcalService::STRIP_ALARMS => '1', |
|
270 | + RefreshWebcalService::STRIP_ATTACHMENTS => '1', |
|
271 | + 'source' => 'webcal://foo.bar/bla2', |
|
272 | + 'lastmodified' => 0, |
|
273 | + ]); |
|
274 | + |
|
275 | + $this->connection->expects(self::once()) |
|
276 | + ->method('queryWebcalFeed') |
|
277 | + ->willReturn($result); |
|
278 | + |
|
279 | + $this->caldavBackend->expects(self::once()) |
|
280 | + ->method('createCalendarObject') |
|
281 | + ->with(42, 'uri-1.ics', $result, 1); |
|
282 | + |
|
283 | + $badRequestException = new BadRequest("can't add reach calendar url"); |
|
284 | + $this->caldavBackend->expects(self::once()) |
|
285 | + ->method('createCalendarObject') |
|
286 | + ->willThrowException($badRequestException); |
|
287 | + |
|
288 | + $this->logger->expects(self::once()) |
|
289 | + ->method('warning') |
|
290 | + ->with('Unable to create calendar object from subscription {subscriptionId}', ['exception' => $badRequestException, 'subscriptionId' => '42', 'source' => 'webcal://foo.bar/bla2']); |
|
291 | + |
|
292 | + $refreshWebcalService->refreshSubscription('principals/users/testuser', 'sub123'); |
|
293 | + } |
|
294 | + |
|
295 | + public static function identicalDataProvider(): array { |
|
296 | + return [ |
|
297 | + [ |
|
298 | + '12345', |
|
299 | + [ |
|
300 | + '12345' => [ |
|
301 | + 'id' => 42, |
|
302 | + 'etag' => 100, |
|
303 | + 'uri' => 'sub456', |
|
304 | + 'calendardata' => "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nUID:12345\r\nDTSTAMP:20160218T133704Z\r\nDTSTART;VALUE=DATE:19000101\r\nDTEND;VALUE=DATE:19000102\r\nRRULE:FREQ=YEARLY\r\nSUMMARY:12345's Birthday (1900)\r\nTRANSP:TRANSPARENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", |
|
305 | + ], |
|
306 | + ], |
|
307 | + "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nUID:12345\r\nDTSTAMP:20160218T133704Z\r\nDTSTART;VALUE=DATE:19000101\r\nDTEND;VALUE=DATE:19000102\r\nRRULE:FREQ=YEARLY\r\nSUMMARY:12345's Birthday (1900)\r\nTRANSP:TRANSPARENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", |
|
308 | + 'text/calendar;charset=utf8', |
|
309 | + "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nUID:12345\r\nDTSTAMP:20180218T133704Z\r\nDTSTART;VALUE=DATE:19000101\r\nDTEND;VALUE=DATE:19000102\r\nRRULE:FREQ=YEARLY\r\nSUMMARY:12345's Birthday (1900)\r\nTRANSP:TRANSPARENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", |
|
310 | + ], |
|
311 | + ]; |
|
312 | + } |
|
313 | + |
|
314 | + public static function runDataProvider(): array { |
|
315 | + return [ |
|
316 | + [ |
|
317 | + "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nUID:12345\r\nDTSTAMP:20160218T133704Z\r\nDTSTART;VALUE=DATE:19000101\r\nDTEND;VALUE=DATE:19000102\r\nRRULE:FREQ=YEARLY\r\nSUMMARY:12345's Birthday (1900)\r\nTRANSP:TRANSPARENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", |
|
318 | + 'text/calendar;charset=utf8', |
|
319 | + "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject " . VObject\Version::VERSION . "//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nUID:12345\r\nDTSTAMP:20160218T133704Z\r\nDTSTART;VALUE=DATE:19000101\r\nDTEND;VALUE=DATE:19000102\r\nRRULE:FREQ=YEARLY\r\nSUMMARY:12345's Birthday (1900)\r\nTRANSP:TRANSPARENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", |
|
320 | + ], |
|
321 | + [ |
|
322 | + '["vcalendar",[["prodid",{},"text","-//Example Corp.//Example Client//EN"],["version",{},"text","2.0"]],[["vtimezone",[["last-modified",{},"date-time","2004-01-10T03:28:45Z"],["tzid",{},"text","US/Eastern"]],[["daylight",[["dtstart",{},"date-time","2000-04-04T02:00:00"],["rrule",{},"recur",{"freq":"YEARLY","byday":"1SU","bymonth":4}],["tzname",{},"text","EDT"],["tzoffsetfrom",{},"utc-offset","-05:00"],["tzoffsetto",{},"utc-offset","-04:00"]],[]],["standard",[["dtstart",{},"date-time","2000-10-26T02:00:00"],["rrule",{},"recur",{"freq":"YEARLY","byday":"1SU","bymonth":10}],["tzname",{},"text","EST"],["tzoffsetfrom",{},"utc-offset","-04:00"],["tzoffsetto",{},"utc-offset","-05:00"]],[]]]],["vevent",[["dtstamp",{},"date-time","2006-02-06T00:11:21Z"],["dtstart",{"tzid":"US/Eastern"},"date-time","2006-01-02T14:00:00"],["duration",{},"duration","PT1H"],["recurrence-id",{"tzid":"US/Eastern"},"date-time","2006-01-04T12:00:00"],["summary",{},"text","Event #2"],["uid",{},"text","12345"]],[]]]]', |
|
323 | + 'application/calendar+json', |
|
324 | + "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject " . VObject\Version::VERSION . "//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VTIMEZONE\r\nLAST-MODIFIED:20040110T032845Z\r\nTZID:US/Eastern\r\nBEGIN:DAYLIGHT\r\nDTSTART:20000404T020000\r\nRRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4\r\nTZNAME:EDT\r\nTZOFFSETFROM:-0500\r\nTZOFFSETTO:-0400\r\nEND:DAYLIGHT\r\nBEGIN:STANDARD\r\nDTSTART:20001026T020000\r\nRRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=10\r\nTZNAME:EST\r\nTZOFFSETFROM:-0400\r\nTZOFFSETTO:-0500\r\nEND:STANDARD\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nDTSTAMP:20060206T001121Z\r\nDTSTART;TZID=US/Eastern:20060102T140000\r\nDURATION:PT1H\r\nRECURRENCE-ID;TZID=US/Eastern:20060104T120000\r\nSUMMARY:Event #2\r\nUID:12345\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n" |
|
325 | + ], |
|
326 | + [ |
|
327 | + '<?xml version="1.0" encoding="utf-8" ?><icalendar xmlns="urn:ietf:params:xml:ns:icalendar-2.0"><vcalendar><properties><prodid><text>-//Example Inc.//Example Client//EN</text></prodid><version><text>2.0</text></version></properties><components><vevent><properties><dtstamp><date-time>2006-02-06T00:11:21Z</date-time></dtstamp><dtstart><parameters><tzid><text>US/Eastern</text></tzid></parameters><date-time>2006-01-04T14:00:00</date-time></dtstart><duration><duration>PT1H</duration></duration><recurrence-id><parameters><tzid><text>US/Eastern</text></tzid></parameters><date-time>2006-01-04T12:00:00</date-time></recurrence-id><summary><text>Event #2 bis</text></summary><uid><text>12345</text></uid></properties></vevent></components></vcalendar></icalendar>', |
|
328 | + 'application/calendar+xml', |
|
329 | + "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject " . VObject\Version::VERSION . "//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nDTSTAMP:20060206T001121Z\r\nDTSTART;TZID=US/Eastern:20060104T140000\r\nDURATION:PT1H\r\nRECURRENCE-ID;TZID=US/Eastern:20060104T120000\r\nSUMMARY:Event #2 bis\r\nUID:12345\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n" |
|
330 | + ] |
|
331 | + ]; |
|
332 | + } |
|
333 | 333 | } |