ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PluginTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\CalDAV;
4 
5 use DateTime;
6 use DateTimeZone;
7 use Sabre\DAV;
8 use Sabre\DAVACL;
9 use Sabre\HTTP;
10 
12 
16  protected $server;
20  protected $plugin;
21  protected $response;
25  protected $caldavBackend;
26 
27  function setup() {
28 
29  $caldavNS = '{urn:ietf:params:xml:ns:caldav}';
30 
31  $this->caldavBackend = new Backend\Mock([
32  [
33  'id' => 1,
34  'uri' => 'UUID-123467',
35  'principaluri' => 'principals/user1',
36  '{DAV:}displayname' => 'user1 calendar',
37  $caldavNS . 'calendar-description' => 'Calendar description',
38  '{http://apple.com/ns/ical/}calendar-order' => '1',
39  '{http://apple.com/ns/ical/}calendar-color' => '#FF0000',
40  $caldavNS . 'supported-calendar-component-set' => new Xml\Property\SupportedCalendarComponentSet(['VEVENT', 'VTODO']),
41  ],
42  [
43  'id' => 2,
44  'uri' => 'UUID-123468',
45  'principaluri' => 'principals/user1',
46  '{DAV:}displayname' => 'user1 calendar2',
47  $caldavNS . 'calendar-description' => 'Calendar description',
48  '{http://apple.com/ns/ical/}calendar-order' => '1',
49  '{http://apple.com/ns/ical/}calendar-color' => '#FF0000',
50  $caldavNS . 'supported-calendar-component-set' => new Xml\Property\SupportedCalendarComponentSet(['VEVENT', 'VTODO']),
51  ]
52  ], [
53  1 => [
54  'UUID-2345' => [
55  'calendardata' => TestUtil::getTestCalendarData(),
56  ]
57  ]
58  ]);
60  $principalBackend->setGroupMemberSet('principals/admin/calendar-proxy-read', ['principals/user1']);
61  $principalBackend->setGroupMemberSet('principals/admin/calendar-proxy-write', ['principals/user1']);
62  $principalBackend->addPrincipal([
63  'uri' => 'principals/admin/calendar-proxy-read',
64  ]);
65  $principalBackend->addPrincipal([
66  'uri' => 'principals/admin/calendar-proxy-write',
67  ]);
68 
69  $calendars = new CalendarRoot($principalBackend, $this->caldavBackend);
70  $principals = new Principal\Collection($principalBackend);
71 
72  $root = new DAV\SimpleCollection('root');
73  $root->addChild($calendars);
74  $root->addChild($principals);
75 
76  $this->server = new DAV\Server($root);
77  $this->server->sapi = new HTTP\SapiMock();
78  $this->server->debugExceptions = true;
79  $this->server->setBaseUri('/');
80  $this->plugin = new Plugin();
81  $this->server->addPlugin($this->plugin);
82 
83  // Adding ACL plugin
84  $aclPlugin = new DAVACL\Plugin();
85  $aclPlugin->allowUnauthenticatedAccess = false;
86  $this->server->addPlugin($aclPlugin);
87 
88  // Adding Auth plugin, and ensuring that we are logged in.
90  $authBackend->setPrincipal('principals/user1');
92  $authPlugin->beforeMethod(new \Sabre\HTTP\Request(), new \Sabre\HTTP\Response());
93  $this->server->addPlugin($authPlugin);
94 
95  // This forces a login
96  $authPlugin->beforeMethod(new HTTP\Request(), new HTTP\Response());
97 
98  $this->response = new HTTP\ResponseMock();
99  $this->server->httpResponse = $this->response;
100 
101  }
102 
103  function testSimple() {
104 
105  $this->assertEquals(['MKCALENDAR'], $this->plugin->getHTTPMethods('calendars/user1/randomnewcalendar'));
106  $this->assertEquals(['calendar-access', 'calendar-proxy'], $this->plugin->getFeatures());
107  $this->assertEquals(
108  'caldav',
109  $this->plugin->getPluginInfo()['name']
110  );
111 
112  }
113 
115 
116  $request = new HTTP\Request('MKBREAKFAST', '/');
117 
118  $this->server->httpRequest = $request;
119  $this->server->exec();
120 
121  $this->assertEquals(501, $this->response->status, 'Incorrect status returned. Full response body:' . $this->response->body);
122 
123  }
124 
126 
127  $request = new HTTP\Request('REPORT', '/', ['Content-Type' => 'application/xml']);
128  $request->setBody('<?xml version="1.0"?><s:somereport xmlns:s="http://www.rooftopsolutions.nl/NS/example" />');
129 
130  $this->server->httpRequest = $request;
131  $this->server->exec();
132 
133  $this->assertEquals(415, $this->response->status);
134 
135  }
136 
138 
139  $request = new HTTP\Request('MKCALENDAR', '/blabla');
140 
141  $body = '<?xml version="1.0" encoding="utf-8" ?>
142  <C:mkcalendar xmlns:D="DAV:"
143  xmlns:C="urn:ietf:params:xml:ns:caldav">
144  <D:set>
145  <D:prop>
146  <D:displayname>Lisa\'s Events</D:displayname>
147  <C:calendar-description xml:lang="en"
148  >Calendar restricted to events.</C:calendar-description>
149  <C:supported-calendar-component-set>
150  <C:comp name="VEVENT"/>
151  </C:supported-calendar-component-set>
152  <C:calendar-timezone><![CDATA[BEGIN:VCALENDAR
153  PRODID:-//Example Corp.//CalDAV Client//EN
154  VERSION:2.0
155  BEGIN:VTIMEZONE
156  TZID:US-Eastern
157  LAST-MODIFIED:19870101T000000Z
158  BEGIN:STANDARD
159  DTSTART:19671029T020000
160  RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
161  TZOFFSETFROM:-0400
162  TZOFFSETTO:-0500
163  TZNAME:Eastern Standard Time (US & Canada)
164  END:STANDARD
165  BEGIN:DAYLIGHT
166  DTSTART:19870405T020000
167  RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
168  TZOFFSETFROM:-0500
169  TZOFFSETTO:-0400
170  TZNAME:Eastern Daylight Time (US & Canada)
171  END:DAYLIGHT
172  END:VTIMEZONE
173  END:VCALENDAR
174  ]]></C:calendar-timezone>
175  </D:prop>
176  </D:set>
177  </C:mkcalendar>';
178 
179  $request->setBody($body);
180  $this->server->httpRequest = $request;
181  $this->server->exec();
182 
183  $this->assertEquals(403, $this->response->status);
184 
185  }
186 
188 
189  $request = new HTTP\Request('MKCALENDAR', '/doesntexist/calendar');
190 
191  $body = '<?xml version="1.0" encoding="utf-8" ?>
192  <C:mkcalendar xmlns:D="DAV:"
193  xmlns:C="urn:ietf:params:xml:ns:caldav">
194  <D:set>
195  <D:prop>
196  <D:displayname>Lisa\'s Events</D:displayname>
197  <C:calendar-description xml:lang="en"
198  >Calendar restricted to events.</C:calendar-description>
199  <C:supported-calendar-component-set>
200  <C:comp name="VEVENT"/>
201  </C:supported-calendar-component-set>
202  <C:calendar-timezone><![CDATA[BEGIN:VCALENDAR
203  PRODID:-//Example Corp.//CalDAV Client//EN
204  VERSION:2.0
205  BEGIN:VTIMEZONE
206  TZID:US-Eastern
207  LAST-MODIFIED:19870101T000000Z
208  BEGIN:STANDARD
209  DTSTART:19671029T020000
210  RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
211  TZOFFSETFROM:-0400
212  TZOFFSETTO:-0500
213  TZNAME:Eastern Standard Time (US & Canada)
214  END:STANDARD
215  BEGIN:DAYLIGHT
216  DTSTART:19870405T020000
217  RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
218  TZOFFSETFROM:-0500
219  TZOFFSETTO:-0400
220  TZNAME:Eastern Daylight Time (US & Canada)
221  END:DAYLIGHT
222  END:VTIMEZONE
223  END:VCALENDAR
224  ]]></C:calendar-timezone>
225  </D:prop>
226  </D:set>
227  </C:mkcalendar>';
228 
229  $request->setBody($body);
230  $this->server->httpRequest = $request;
231  $this->server->exec();
232 
233  $this->assertEquals(409, $this->response->status);
234 
235  }
236 
238 
240  'REQUEST_METHOD' => 'MKCALENDAR',
241  'REQUEST_URI' => '/calendars/user1/UUID-123467',
242  ]);
243 
244  $body = '<?xml version="1.0" encoding="utf-8" ?>
245  <C:mkcalendar xmlns:D="DAV:"
246  xmlns:C="urn:ietf:params:xml:ns:caldav">
247  <D:set>
248  <D:prop>
249  <D:displayname>Lisa\'s Events</D:displayname>
250  <C:calendar-description xml:lang="en"
251  >Calendar restricted to events.</C:calendar-description>
252  <C:supported-calendar-component-set>
253  <C:comp name="VEVENT"/>
254  </C:supported-calendar-component-set>
255  <C:calendar-timezone><![CDATA[BEGIN:VCALENDAR
256  PRODID:-//Example Corp.//CalDAV Client//EN
257  VERSION:2.0
258  BEGIN:VTIMEZONE
259  TZID:US-Eastern
260  LAST-MODIFIED:19870101T000000Z
261  BEGIN:STANDARD
262  DTSTART:19671029T020000
263  RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
264  TZOFFSETFROM:-0400
265  TZOFFSETTO:-0500
266  TZNAME:Eastern Standard Time (US & Canada)
267  END:STANDARD
268  BEGIN:DAYLIGHT
269  DTSTART:19870405T020000
270  RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
271  TZOFFSETFROM:-0500
272  TZOFFSETTO:-0400
273  TZNAME:Eastern Daylight Time (US & Canada)
274  END:DAYLIGHT
275  END:VTIMEZONE
276  END:VCALENDAR
277  ]]></C:calendar-timezone>
278  </D:prop>
279  </D:set>
280  </C:mkcalendar>';
281 
282  $request->setBody($body);
283  $this->server->httpRequest = $request;
284  $this->server->exec();
285 
286  $this->assertEquals(405, $this->response->status);
287 
288  }
289 
291 
292  $request = new HTTP\Request('MKCALENDAR', '/calendars/user1/NEWCALENDAR');
293 
294  $timezone = 'BEGIN:VCALENDAR
295 PRODID:-//Example Corp.//CalDAV Client//EN
296 VERSION:2.0
297 BEGIN:VTIMEZONE
298 TZID:US-Eastern
299 LAST-MODIFIED:19870101T000000Z
300 BEGIN:STANDARD
301 DTSTART:19671029T020000
302 RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
303 TZOFFSETFROM:-0400
304 TZOFFSETTO:-0500
305 TZNAME:Eastern Standard Time (US & Canada)
306 END:STANDARD
307 BEGIN:DAYLIGHT
308 DTSTART:19870405T020000
309 RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
310 TZOFFSETFROM:-0500
311 TZOFFSETTO:-0400
312 TZNAME:Eastern Daylight Time (US & Canada)
313 END:DAYLIGHT
314 END:VTIMEZONE
315 END:VCALENDAR';
316 
317  $body = '<?xml version="1.0" encoding="utf-8" ?>
318  <C:mkcalendar xmlns:D="DAV:"
319  xmlns:C="urn:ietf:params:xml:ns:caldav">
320  <D:set>
321  <D:prop>
322  <D:displayname>Lisa\'s Events</D:displayname>
323  <C:calendar-description xml:lang="en"
324  >Calendar restricted to events.</C:calendar-description>
325  <C:supported-calendar-component-set>
326  <C:comp name="VEVENT"/>
327  </C:supported-calendar-component-set>
328  <C:calendar-timezone><![CDATA[' . $timezone . ']]></C:calendar-timezone>
329  </D:prop>
330  </D:set>
331  </C:mkcalendar>';
332 
333  $request->setBody($body);
334  $this->server->httpRequest = $request;
335  $this->server->exec();
336 
337  $this->assertEquals(201, $this->response->status, 'Invalid response code received. Full response body: ' . $this->response->body);
338 
339  $calendars = $this->caldavBackend->getCalendarsForUser('principals/user1');
340  $this->assertEquals(3, count($calendars));
341 
342  $newCalendar = null;
343  foreach ($calendars as $calendar) {
344  if ($calendar['uri'] === 'NEWCALENDAR') {
345  $newCalendar = $calendar;
346  break;
347  }
348  }
349 
350  $this->assertInternalType('array', $newCalendar);
351 
352  $keys = [
353  'uri' => 'NEWCALENDAR',
354  'id' => null,
355  '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar restricted to events.',
356  '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => $timezone,
357  '{DAV:}displayname' => 'Lisa\'s Events',
358  '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => null,
359  ];
360 
361  foreach ($keys as $key => $value) {
362 
363  $this->assertArrayHasKey($key, $newCalendar);
364 
365  if (is_null($value)) continue;
366  $this->assertEquals($value, $newCalendar[$key]);
367 
368  }
369  $sccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set';
370  $this->assertTrue($newCalendar[$sccs] instanceof Xml\Property\SupportedCalendarComponentSet);
371  $this->assertEquals(['VEVENT'], $newCalendar[$sccs]->getValue());
372 
373  }
374 
376 
377  $request = new HTTP\Request('MKCALENDAR', '/calendars/user1/NEWCALENDAR');
378 
379  $request->setBody('');
380  $this->server->httpRequest = $request;
381  $this->server->exec();
382 
383  $this->assertEquals(201, $this->response->status, 'Invalid response code received. Full response body: ' . $this->response->body);
384 
385  $calendars = $this->caldavBackend->getCalendarsForUser('principals/user1');
386  $this->assertEquals(3, count($calendars));
387 
388  $newCalendar = null;
389  foreach ($calendars as $calendar) {
390  if ($calendar['uri'] === 'NEWCALENDAR') {
391  $newCalendar = $calendar;
392  break;
393  }
394  }
395 
396  $this->assertInternalType('array', $newCalendar);
397 
398  $keys = [
399  'uri' => 'NEWCALENDAR',
400  'id' => null,
401  '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => null,
402  ];
403 
404  foreach ($keys as $key => $value) {
405 
406  $this->assertArrayHasKey($key, $newCalendar);
407 
408  if (is_null($value)) continue;
409  $this->assertEquals($value, $newCalendar[$key]);
410 
411  }
412  $sccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set';
413  $this->assertTrue($newCalendar[$sccs] instanceof Xml\Property\SupportedCalendarComponentSet);
414  $this->assertEquals(['VEVENT', 'VTODO'], $newCalendar[$sccs]->getValue());
415 
416  }
417 
418  function testMkCalendarBadXml() {
419 
420  $request = new HTTP\Request('MKCALENDAR', '/blabla');
421  $body = 'This is not xml';
422 
423  $request->setBody($body);
424  $this->server->httpRequest = $request;
425  $this->server->exec();
426 
427  $this->assertEquals(400, $this->response->status);
428 
429  }
430 
432 
433  $httpRequest = new HTTP\Request('FOO', '/blabla', ['Host' => 'sabredav.org']);
434  $this->server->httpRequest = $httpRequest;
435 
436  $props = $this->server->getPropertiesForPath('/principals/user1', [
437  '{' . Plugin::NS_CALDAV . '}calendar-home-set',
438  '{' . Plugin::NS_CALENDARSERVER . '}calendar-proxy-read-for',
439  '{' . Plugin::NS_CALENDARSERVER . '}calendar-proxy-write-for',
440  '{' . Plugin::NS_CALENDARSERVER . '}notification-URL',
441  '{' . Plugin::NS_CALENDARSERVER . '}email-address-set',
442  ]);
443 
444  $this->assertArrayHasKey(0, $props);
445  $this->assertArrayHasKey(200, $props[0]);
446 
447 
448  $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}calendar-home-set', $props[0][200]);
449  $prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}calendar-home-set'];
450  $this->assertInstanceOf('Sabre\\DAV\\Xml\\Property\\Href', $prop);
451  $this->assertEquals('calendars/user1/', $prop->getHref());
452 
453  $this->assertArrayHasKey('{http://calendarserver.org/ns/}calendar-proxy-read-for', $props[0][200]);
454  $prop = $props[0][200]['{http://calendarserver.org/ns/}calendar-proxy-read-for'];
455  $this->assertInstanceOf('Sabre\\DAV\\Xml\\Property\\Href', $prop);
456  $this->assertEquals(['principals/admin/'], $prop->getHrefs());
457 
458  $this->assertArrayHasKey('{http://calendarserver.org/ns/}calendar-proxy-write-for', $props[0][200]);
459  $prop = $props[0][200]['{http://calendarserver.org/ns/}calendar-proxy-write-for'];
460  $this->assertInstanceOf('Sabre\\DAV\\Xml\\Property\\Href', $prop);
461  $this->assertEquals(['principals/admin/'], $prop->getHrefs());
462 
463  $this->assertArrayHasKey('{' . Plugin::NS_CALENDARSERVER . '}email-address-set', $props[0][200]);
464  $prop = $props[0][200]['{' . Plugin::NS_CALENDARSERVER . '}email-address-set'];
465  $this->assertInstanceOf('Sabre\\CalDAV\\Xml\\Property\\EmailAddressSet', $prop);
466  $this->assertEquals(['user1.sabredav@sabredav.org'], $prop->getValue());
467 
468  }
469 
471 
472  $props = $this->server->getPropertiesForPath('/calendars/user1', [
473  '{DAV:}supported-report-set',
474  ]);
475 
476  $this->assertArrayHasKey(0, $props);
477  $this->assertArrayHasKey(200, $props[0]);
478  $this->assertArrayHasKey('{DAV:}supported-report-set', $props[0][200]);
479 
480  $prop = $props[0][200]['{DAV:}supported-report-set'];
481 
482  $this->assertInstanceOf('\\Sabre\\DAV\\Xml\\Property\\SupportedReportSet', $prop);
483  $value = [
484  '{DAV:}expand-property',
485  '{DAV:}principal-match',
486  '{DAV:}principal-property-search',
487  '{DAV:}principal-search-property-set',
488  ];
489  $this->assertEquals($value, $prop->getValue());
490 
491  }
492 
497 
498  $props = $this->server->getPropertiesForPath('/calendars/user1/UUID-123467', [
499  '{DAV:}supported-report-set',
500  ]);
501 
502  $this->assertArrayHasKey(0, $props);
503  $this->assertArrayHasKey(200, $props[0]);
504  $this->assertArrayHasKey('{DAV:}supported-report-set', $props[0][200]);
505 
506  $prop = $props[0][200]['{DAV:}supported-report-set'];
507 
508  $this->assertInstanceOf('\\Sabre\\DAV\\Xml\\Property\\SupportedReportSet', $prop);
509  $value = [
510  '{urn:ietf:params:xml:ns:caldav}calendar-multiget',
511  '{urn:ietf:params:xml:ns:caldav}calendar-query',
512  '{urn:ietf:params:xml:ns:caldav}free-busy-query',
513  '{DAV:}expand-property',
514  '{DAV:}principal-match',
515  '{DAV:}principal-property-search',
516  '{DAV:}principal-search-property-set'
517  ];
518  $this->assertEquals($value, $prop->getValue());
519 
520  }
521 
523 
524  $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin());
525 
526  $props = $this->server->getPropertiesForPath('/calendars/user1', [
527  '{DAV:}supported-report-set',
528  ]);
529 
530  $this->assertArrayHasKey(0, $props);
531  $this->assertArrayHasKey(200, $props[0]);
532  $this->assertArrayHasKey('{DAV:}supported-report-set', $props[0][200]);
533 
534  $prop = $props[0][200]['{DAV:}supported-report-set'];
535 
536  $this->assertInstanceOf('\\Sabre\\DAV\\Xml\\Property\\SupportedReportSet', $prop);
537  $value = [
538  '{DAV:}sync-collection',
539  '{DAV:}expand-property',
540  '{DAV:}principal-match',
541  '{DAV:}principal-property-search',
542  '{DAV:}principal-search-property-set',
543  ];
544  $this->assertEquals($value, $prop->getValue());
545 
546  }
547 
552 
553  $body =
554  '<?xml version="1.0"?>' .
555  '<c:calendar-multiget xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
556  '<d:prop>' .
557  ' <c:calendar-data />' .
558  ' <d:getetag />' .
559  '</d:prop>' .
560  '<d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>' .
561  '</c:calendar-multiget>';
562 
563  $request = new HTTP\Request('REPORT', '/calendars/user1', ['Depth' => '1']);
564  $request->setBody($body);
565 
566  $this->server->httpRequest = $request;
567  $this->server->exec();
568 
569  $this->assertEquals(207, $this->response->status, 'Invalid HTTP status received. Full response body');
570 
571  $expectedIcal = TestUtil::getTestCalendarData();
572 
573  $expected = <<<XML
574 <?xml version="1.0"?>
575 <d:multistatus xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
576 <d:response>
577  <d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>
578  <d:propstat>
579  <d:prop>
580  <cal:calendar-data>$expectedIcal</cal:calendar-data>
581  <d:getetag>"e207e33c10e5fb9c12cfb35b5d9116e1"</d:getetag>
582  </d:prop>
583  <d:status>HTTP/1.1 200 OK</d:status>
584  </d:propstat>
585 </d:response>
586 </d:multistatus>
587 XML;
588 
589  $this->assertXmlStringEqualsXmlString($expected, $this->response->getBodyAsString());
590 
591  }
592 
597 
598  $body =
599  '<?xml version="1.0"?>' .
600  '<c:calendar-multiget xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
601  '<d:prop>' .
602  ' <c:calendar-data>' .
603  ' <c:expand start="20110101T000000Z" end="20111231T235959Z" />' .
604  ' </c:calendar-data>' .
605  ' <d:getetag />' .
606  '</d:prop>' .
607  '<d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>' .
608  '</c:calendar-multiget>';
609 
610  $request = new HTTP\Request('REPORT', '/calendars/user1', ['Depth' => '1']);
611  $request->setBody($body);
612 
613  $this->server->httpRequest = $request;
614  $this->server->exec();
615 
616  $this->assertEquals(207, $this->response->status, 'Invalid HTTP status received. Full response body: ' . $this->response->body);
617 
618  $expectedIcal = TestUtil::getTestCalendarData();
619  $expectedIcal = \Sabre\VObject\Reader::read($expectedIcal);
620  $expectedIcal = $expectedIcal->expand(
621  new DateTime('2011-01-01 00:00:00', new DateTimeZone('UTC')),
622  new DateTime('2011-12-31 23:59:59', new DateTimeZone('UTC'))
623  );
624  $expectedIcal = str_replace("\r\n", "&#xD;\n", $expectedIcal->serialize());
625 
626  $expected = <<<XML
627 <?xml version="1.0"?>
628 <d:multistatus xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
629 <d:response>
630  <d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>
631  <d:propstat>
632  <d:prop>
633  <cal:calendar-data>$expectedIcal</cal:calendar-data>
634  <d:getetag>"e207e33c10e5fb9c12cfb35b5d9116e1"</d:getetag>
635  </d:prop>
636  <d:status>HTTP/1.1 200 OK</d:status>
637  </d:propstat>
638 </d:response>
639 </d:multistatus>
640 XML;
641 
642  $this->assertXmlStringEqualsXmlString($expected, $this->response->getBodyAsString());
643 
644  }
645 
651 
652  $body =
653  '<?xml version="1.0"?>' .
654  '<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
655  '<d:prop>' .
656  ' <c:calendar-data>' .
657  ' <c:expand start="20000101T000000Z" end="20101231T235959Z" />' .
658  ' </c:calendar-data>' .
659  ' <d:getetag />' .
660  '</d:prop>' .
661  '<c:filter>' .
662  ' <c:comp-filter name="VCALENDAR">' .
663  ' <c:comp-filter name="VEVENT" />' .
664  ' </c:comp-filter>' .
665  '</c:filter>' .
666  '</c:calendar-query>';
667 
668  $request = new HTTP\Request('REPORT', '/calendars/user1/UUID-123467', ['Depth' => '1']);
669  $request->setBody($body);
670 
671  $this->server->httpRequest = $request;
672  $this->server->exec();
673 
674  $this->assertEquals(207, $this->response->status, 'Received an unexpected status. Full response body: ' . $this->response->body);
675 
676  $expectedIcal = TestUtil::getTestCalendarData();
677  $expectedIcal = \Sabre\VObject\Reader::read($expectedIcal);
678  $expectedIcal = $expectedIcal->expand(
679  new DateTime('2000-01-01 00:00:00', new DateTimeZone('UTC')),
680  new DateTime('2010-12-31 23:59:59', new DateTimeZone('UTC'))
681  );
682  $expectedIcal = str_replace("\r\n", "&#xD;\n", $expectedIcal->serialize());
683 
684  $expected = <<<XML
685 <?xml version="1.0"?>
686 <d:multistatus xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
687 <d:response>
688  <d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>
689  <d:propstat>
690  <d:prop>
691  <cal:calendar-data>$expectedIcal</cal:calendar-data>
692  <d:getetag>"e207e33c10e5fb9c12cfb35b5d9116e1"</d:getetag>
693  </d:prop>
694  <d:status>HTTP/1.1 200 OK</d:status>
695  </d:propstat>
696 </d:response>
697 </d:multistatus>
698 XML;
699 
700  $this->assertXmlStringEqualsXmlString($expected, $this->response->getBodyAsString());
701 
702  }
703 
709 
710  $body =
711  '<?xml version="1.0"?>' .
712  '<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
713  '<d:prop>' .
714  ' <c:calendar-data>' .
715  ' <c:expand start="20000101T000000Z" end="20101231T235959Z" />' .
716  ' </c:calendar-data>' .
717  ' <d:getetag />' .
718  '</d:prop>' .
719  '<c:filter>' .
720  ' <c:comp-filter name="VCALENDAR">' .
721  ' <c:comp-filter name="VEVENT" />' .
722  ' </c:comp-filter>' .
723  '</c:filter>' .
724  '</c:calendar-query>';
725 
726  $request = new HTTP\Request('REPORT', '/calendars/user1/UUID-123467', [
727  'Depth' => '0',
728  'User-Agent' => 'MSFT-WP/8.10.14219 (gzip)',
729  ]);
730 
731  $request->setBody($body);
732 
733  $this->server->httpRequest = $request;
734  $this->server->exec();
735 
736  $this->assertEquals(207, $this->response->status, 'Received an unexpected status. Full response body: ' . $this->response->body);
737 
738  $expectedIcal = TestUtil::getTestCalendarData();
739  $expectedIcal = \Sabre\VObject\Reader::read($expectedIcal);
740  $expectedIcal = $expectedIcal->expand(
741  new DateTime('2000-01-01 00:00:00', new DateTimeZone('UTC')),
742  new DateTime('2010-12-31 23:59:59', new DateTimeZone('UTC'))
743  );
744  $expectedIcal = str_replace("\r\n", "&#xD;\n", $expectedIcal->serialize());
745 
746  $expected = <<<XML
747 <?xml version="1.0"?>
748 <d:multistatus xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
749 <d:response>
750  <d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>
751  <d:propstat>
752  <d:prop>
753  <cal:calendar-data>$expectedIcal</cal:calendar-data>
754  <d:getetag>"e207e33c10e5fb9c12cfb35b5d9116e1"</d:getetag>
755  </d:prop>
756  <d:status>HTTP/1.1 200 OK</d:status>
757  </d:propstat>
758 </d:response>
759 </d:multistatus>
760 XML;
761 
762  $this->assertXmlStringEqualsXmlString($expected, $this->response->getBodyAsString());
763 
764  }
765 
771 
772  $body =
773  '<?xml version="1.0"?>' .
774  '<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
775  '<d:prop>' .
776  ' <c:calendar-data>' .
777  ' <c:expand start="20000101T000000Z" end="20101231T235959Z" />' .
778  ' </c:calendar-data>' .
779  ' <d:getetag />' .
780  '</d:prop>' .
781  '<c:filter>' .
782  ' <c:comp-filter name="VCALENDAR">' .
783  ' <c:comp-filter name="VEVENT" />' .
784  ' </c:comp-filter>' .
785  '</c:filter>' .
786  '</c:calendar-query>';
787 
788  $request = new HTTP\Request('REPORT', '/calendars/user1/UUID-123467', [
789  'Depth' => '0',
790  ]);
791  $request->setBody($body);
792 
793  $this->server->httpRequest = $request;
794  $this->server->exec();
795 
796  $this->assertEquals(400, $this->response->status, 'Received an unexpected status. Full response body: ' . $this->response->body);
797 
798  }
799 
804 
805  $body =
806  '<?xml version="1.0"?>' .
807  '<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
808  '<d:prop>' .
809  ' <d:getetag />' .
810  '</d:prop>' .
811  '<c:filter>' .
812  ' <c:comp-filter name="VCALENDAR">' .
813  ' <c:comp-filter name="VEVENT" />' .
814  ' </c:comp-filter>' .
815  '</c:filter>' .
816  '</c:calendar-query>';
817 
818  $request = new HTTP\Request('REPORT', '/calendars/user1/UUID-123467', [
819  'Depth' => '1',
820  ]);
821  $request->setBody($body);
822 
823  $this->server->httpRequest = $request;
824  $this->server->exec();
825 
826  $this->assertEquals(207, $this->response->status, 'Received an unexpected status. Full response body: ' . $this->response->body);
827 
828  $expected = <<<XML
829 <?xml version="1.0"?>
830 <d:multistatus xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
831 <d:response>
832  <d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>
833  <d:propstat>
834  <d:prop>
835  <d:getetag>"e207e33c10e5fb9c12cfb35b5d9116e1"</d:getetag>
836  </d:prop>
837  <d:status>HTTP/1.1 200 OK</d:status>
838  </d:propstat>
839 </d:response>
840 </d:multistatus>
841 XML;
842 
843  $this->assertXmlStringEqualsXmlString($expected, $this->response->getBodyAsString());
844 
845  }
846 
851 
852  $body =
853  '<?xml version="1.0"?>' .
854  '<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
855  '<d:prop>' .
856  ' <c:calendar-data />' .
857  ' <d:getetag />' .
858  '</d:prop>' .
859  '</c:calendar-query>';
860 
861  $request = new HTTP\Request('REPORT', '/calendars/user1/UUID-123467');
862  $request->setBody($body);
863 
864  $this->server->httpRequest = $request;
865  $this->server->exec();
866 
867  $this->assertEquals(400, $this->response->status, 'Received an unexpected status. Full response body: ' . $this->response->body);
868 
869  }
870 
876 
877  $body =
878  '<?xml version="1.0"?>' .
879  '<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
880  '<d:prop>' .
881  ' <c:calendar-data>' .
882  ' <c:expand start="20000101T000000Z" end="20101231T235959Z" />' .
883  ' </c:calendar-data>' .
884  ' <d:getetag />' .
885  '</d:prop>' .
886  '<c:filter>' .
887  ' <c:comp-filter name="VCALENDAR">' .
888  ' <c:comp-filter name="VEVENT" />' .
889  ' </c:comp-filter>' .
890  '</c:filter>' .
891  '</c:calendar-query>';
892 
893  $request = new HTTP\Request('REPORT', '/calendars/user1/UUID-123467/UUID-2345', ['Depth' => '0']);
894  $request->setBody($body);
895 
896  $this->server->httpRequest = $request;
897  $this->server->exec();
898 
899  $this->assertEquals(207, $this->response->status, 'Received an unexpected status. Full response body: ' . $this->response->body);
900 
901  $expectedIcal = TestUtil::getTestCalendarData();
902  $expectedIcal = \Sabre\VObject\Reader::read($expectedIcal);
903  $expectedIcal = $expectedIcal->expand(
904  new DateTime('2000-01-01 00:00:00', new DateTimeZone('UTC')),
905  new DateTime('2010-12-31 23:59:59', new DateTimeZone('UTC'))
906  );
907  $expectedIcal = str_replace("\r\n", "&#xD;\n", $expectedIcal->serialize());
908 
909  $expected = <<<XML
910 <?xml version="1.0"?>
911 <d:multistatus xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
912 <d:response>
913  <d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>
914  <d:propstat>
915  <d:prop>
916  <cal:calendar-data>$expectedIcal</cal:calendar-data>
917  <d:getetag>"e207e33c10e5fb9c12cfb35b5d9116e1"</d:getetag>
918  </d:prop>
919  <d:status>HTTP/1.1 200 OK</d:status>
920  </d:propstat>
921 </d:response>
922 </d:multistatus>
923 XML;
924 
925  $this->assertXmlStringEqualsXmlString($expected, $this->response->getBodyAsString());
926 
927  }
928 
934 
935  $body =
936  '<?xml version="1.0"?>' .
937  '<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
938  '<d:prop>' .
939  ' <d:getetag />' .
940  '</d:prop>' .
941  '<c:filter>' .
942  ' <c:comp-filter name="VCALENDAR">' .
943  ' <c:comp-filter name="VEVENT" />' .
944  ' </c:comp-filter>' .
945  '</c:filter>' .
946  '</c:calendar-query>';
947 
948  $request = new HTTP\Request('REPORT', '/calendars/user1/UUID-123467/UUID-2345', ['Depth' => '0']);
949  $request->setBody($body);
950 
951  $this->server->httpRequest = $request;
952  $this->server->exec();
953 
954  $this->assertEquals(207, $this->response->status, 'Received an unexpected status. Full response body: ' . $this->response->body);
955 
956  $expected = <<<XML
957 <?xml version="1.0"?>
958 <d:multistatus xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
959 <d:response>
960  <d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>
961  <d:propstat>
962  <d:prop>
963  <d:getetag>"e207e33c10e5fb9c12cfb35b5d9116e1"</d:getetag>
964  </d:prop>
965  <d:status>HTTP/1.1 200 OK</d:status>
966  </d:propstat>
967 </d:response>
968 </d:multistatus>
969 XML;
970 
971  $this->assertXmlStringEqualsXmlString($expected, $this->response->getBodyAsString());
972 
973  }
974 
975  function testHTMLActionsPanel() {
976 
977  $output = '';
978  $r = $this->server->emit('onHTMLActionsPanel', [$this->server->tree->getNodeForPath('calendars/user1'), &$output]);
979  $this->assertFalse($r);
980 
981  $this->assertTrue(!!strpos($output, 'Display name'));
982 
983  }
984 
989 
990  $body =
991  '<?xml version="1.0"?>' .
992  '<c:calendar-multiget xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
993  '<d:prop>' .
994  ' <c:calendar-data>' .
995  ' <c:expand start="20110101T000000Z" />' .
996  ' </c:calendar-data>' .
997  ' <d:getetag />' .
998  '</d:prop>' .
999  '<d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>' .
1000  '</c:calendar-multiget>';
1001 
1002  $request = new HTTP\Request('REPORT', '/calendars/user1', ['Depth' => '1']);
1003  $request->setBody($body);
1004 
1005  $this->server->httpRequest = $request;
1006  $this->server->exec();
1007 
1008  $this->assertEquals(400, $this->response->status, 'Invalid HTTP status received. Full response body: ' . $this->response->body);
1009 
1010  }
1011 
1016 
1017  $body =
1018  '<?xml version="1.0"?>' .
1019  '<c:calendar-multiget xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
1020  '<d:prop>' .
1021  ' <c:calendar-data>' .
1022  ' <c:expand end="20110101T000000Z" />' .
1023  ' </c:calendar-data>' .
1024  ' <d:getetag />' .
1025  '</d:prop>' .
1026  '<d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>' .
1027  '</c:calendar-multiget>';
1028 
1029  $request = new HTTP\Request('REPORT', '/calendars/user1', ['Depth' => '1']);
1030  $request->setBody($body);
1031 
1032  $this->server->httpRequest = $request;
1033  $this->server->exec();
1034 
1035  $this->assertEquals(400, $this->response->status, 'Invalid HTTP status received. Full response body: ' . $this->response->body);
1036 
1037  }
1038 
1043 
1044  $body =
1045  '<?xml version="1.0"?>' .
1046  '<c:calendar-multiget xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
1047  '<d:prop>' .
1048  ' <c:calendar-data>' .
1049  ' <c:expand start="20200101T000000Z" end="20110101T000000Z" />' .
1050  ' </c:calendar-data>' .
1051  ' <d:getetag />' .
1052  '</d:prop>' .
1053  '<d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>' .
1054  '</c:calendar-multiget>';
1055 
1056  $request = new HTTP\Request('REPORT', '/calendars/user1', ['Depth' => '1']);
1057  $request->setBody($body);
1058 
1059  $this->server->httpRequest = $request;
1060  $this->server->exec();
1061 
1062  $this->assertEquals(400, $this->response->status, 'Invalid HTTP status received. Full response body: ' . $this->response->body);
1063 
1064  }
1065 
1070 
1071  $ns = '{urn:ietf:params:xml:ns:caldav}';
1072  $props = $this->server->getProperties('calendars/user1/UUID-123467', [
1073  $ns . 'max-resource-size',
1074  $ns . 'supported-calendar-data',
1075  $ns . 'supported-collation-set',
1076  ]);
1077 
1078  $this->assertEquals([
1079  $ns . 'max-resource-size' => 10000000,
1080  $ns . 'supported-calendar-data' => new Xml\Property\SupportedCalendarData(),
1081  $ns . 'supported-collation-set' => new Xml\Property\SupportedCollationSet(),
1082  ], $props);
1083 
1084  }
1085 
1086 }
CalDAV plugin.
Definition: Plugin.php:28
This plugin provides Authentication for a WebDAV server.
Definition: Plugin.php:25
foreach($paths as $path) $request
Definition: asyncclient.php:32
The Request class represents a single HTTP request.
Definition: Request.php:18
testCalendarMultiGetReportNoStart()
testCalendarMultiGetReport
testCalendarMultiGetReport()
testSupportedReportSetProperty
Definition: PluginTest.php:551
testCalendarMultiGetReportExpand()
testCalendarMultiGetReport
Definition: PluginTest.php:596
static getTestCalendarData($type=1)
Definition: TestUtil.php:35
$keys
Principal collection.
Definition: Collection.php:19
testCalendarQueryReport()
testSupportedReportSetProperty testCalendarMultiGetReport
Definition: PluginTest.php:650
testCalendarQueryReportBadDepth()
testSupportedReportSetProperty testCalendarMultiGetReport
Definition: PluginTest.php:770
$r
Definition: example_031.php:79
const NS_CALENDARSERVER
This is the namespace for the proprietary calendarserver extensions.
Definition: Plugin.php:38
testSupportedReportSetProperty()
testSupportedReportSetPropertyNonCalendar
Definition: PluginTest.php:496
This class represents a single HTTP response.
Definition: Response.php:12
testCalendarQueryReportWindowsPhone()
testSupportedReportSetProperty testCalendarMultiGetReport
Definition: PluginTest.php:708
testCalendarQueryReport1ObjectNoCalData()
testSupportedReportSetProperty testCalendarMultiGetReport
Definition: PluginTest.php:933
Main DAV server class.
Definition: Server.php:23
testCalendarProperties()
testSupportedReportSetPropertyNonCalendar
$root
Definition: sabredav.php:45
testCalendarQueryReport1Object()
testSupportedReportSetProperty testCalendarMultiGetReport
Definition: PluginTest.php:875
$authPlugin
$authBackend
static read($data, $options=0, $charset='UTF-8')
Parses a vCard or iCalendar object, and returns the top component.
Definition: Reader.php:42
$this data['403_header']
testCalendarQueryReportNoCalData()
testCalendarQueryReport
Definition: PluginTest.php:803
testCalendarMultiGetReportEndBeforeStart()
testCalendarMultiGetReport
testCalendarQueryReportNoFilters()
testCalendarQueryReport
Definition: PluginTest.php:850
static createFromServerArray(array $serverArray)
This static method will create a new Request object, based on a PHP $_SERVER array.
Definition: Sapi.php:107
Calendars collection.
$key
Definition: croninfo.php:18
SabreDAV ACL Plugin.
Definition: Plugin.php:31
const NS_CALDAV
This is the official CalDAV namespace.
Definition: Plugin.php:33
testCalendarMultiGetReportNoEnd()
testCalendarMultiGetReport
Definition: PluginTest.php:988
$principalBackend
$aclPlugin