3 require_once 'Sabre/HTTP/ResponseMock.php';
4 require_once 'Sabre/DAV/Auth/MockBackend.php';
5 require_once 'Sabre/CalDAV/TestUtil.php';
6 require_once 'Sabre/DAVACL/MockPrincipalBackend.php';
8 class Sabre_CalDAV_PluginTest extends PHPUnit_Framework_TestCase {
11 * @var Sabre_DAV_Server
15 * @var Sabre_CalDAV_Plugin
20 * @var Sabre_CalDAV_Backend_PDO
22 protected $caldavBackend;
26 $this->caldavBackend = new Sabre_CalDAV_Backend_Mock(array(
29 'uri' => 'UUID-123467',
30 'principaluri' => 'principals/user1',
31 '{DAV:}displayname' => 'user1 calendar',
32 '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar description',
33 '{http://apple.com/ns/ical/}calendar-order' => '1',
34 '{http://apple.com/ns/ical/}calendar-color' => '#FF0000',
35 '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new Sabre_CalDAV_Property_SupportedCalendarComponentSet(array('VEVENT','VTODO')),
39 'uri' => 'UUID-123468',
40 'principaluri' => 'principals/user1',
41 '{DAV:}displayname' => 'user1 calendar2',
42 '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar description',
43 '{http://apple.com/ns/ical/}calendar-order' => '1',
44 '{http://apple.com/ns/ical/}calendar-color' => '#FF0000',
45 '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new Sabre_CalDAV_Property_SupportedCalendarComponentSet(array('VEVENT','VTODO')),
50 'calendardata' => Sabre_CalDAV_TestUtil::getTestCalendarData(),
54 $principalBackend = new Sabre_DAVACL_MockPrincipalBackend();
55 $principalBackend->setGroupMemberSet('principals/admin/calendar-proxy-read',array('principals/user1'));
56 $principalBackend->setGroupMemberSet('principals/admin/calendar-proxy-write',array('principals/user1'));
57 $principalBackend->addPrincipal(array(
58 'uri' => 'principals/admin/calendar-proxy-read',
60 $principalBackend->addPrincipal(array(
61 'uri' => 'principals/admin/calendar-proxy-write',
64 $calendars = new Sabre_CalDAV_CalendarRootNode($principalBackend,$this->caldavBackend);
65 $principals = new Sabre_CalDAV_Principal_Collection($principalBackend);
67 $root = new Sabre_DAV_SimpleCollection('root');
68 $root->addChild($calendars);
69 $root->addChild($principals);
71 $objectTree = new Sabre_DAV_ObjectTree($root);
72 $this->server = new Sabre_DAV_Server($objectTree);
73 $this->server->debugExceptions = true;
74 $this->server->setBaseUri('/');
75 $this->plugin = new Sabre_CalDAV_Plugin();
76 $this->server->addPlugin($this->plugin);
78 $this->response = new Sabre_HTTP_ResponseMock();
79 $this->server->httpResponse = $this->response;
83 function testSimple() {
85 $this->assertEquals(array('MKCALENDAR'), $this->plugin->getHTTPMethods('calendars/user1/randomnewcalendar'));
86 $this->assertEquals(array('calendar-access','calendar-proxy'), $this->plugin->getFeatures());
87 $this->assertArrayHasKey('urn:ietf:params:xml:ns:caldav', $this->server->xmlNamespaces);
91 function testUnknownMethodPassThrough() {
93 $request = new Sabre_HTTP_Request(array(
94 'REQUEST_METHOD' => 'MKBREAKFAST',
98 $this->server->httpRequest = $request;
99 $this->server->exec();
101 $this->assertEquals('HTTP/1.1 501 Not Implemented', $this->response->status,'Incorrect status returned. Full response body:' . $this->response->body);
105 function testReportPassThrough() {
107 $request = new Sabre_HTTP_Request(array(
108 'REQUEST_METHOD' => 'REPORT',
109 'HTTP_CONTENT_TYPE' => 'application/xml',
110 'REQUEST_URI' => '/',
112 $request->setBody('<?xml version="1.0"?><s:somereport xmlns:s="http://www.rooftopsolutions.nl/NS/example" />');
114 $this->server->httpRequest = $request;
115 $this->server->exec();
117 $this->assertEquals('HTTP/1.1 501 Not Implemented', $this->response->status);
121 function testMkCalendarBadLocation() {
123 $request = new Sabre_HTTP_Request(array(
124 'REQUEST_METHOD' => 'MKCALENDAR',
125 'REQUEST_URI' => '/blabla',
128 $body = '<?xml version="1.0" encoding="utf-8" ?>
129 <C:mkcalendar xmlns:D="DAV:"
130 xmlns:C="urn:ietf:params:xml:ns:caldav">
133 <D:displayname>Lisa\'s Events</D:displayname>
134 <C:calendar-description xml:lang="en"
135 >Calendar restricted to events.</C:calendar-description>
136 <C:supported-calendar-component-set>
137 <C:comp name="VEVENT"/>
138 </C:supported-calendar-component-set>
139 <C:calendar-timezone><![CDATA[BEGIN:VCALENDAR
140 PRODID:-//Example Corp.//CalDAV Client//EN
144 LAST-MODIFIED:19870101T000000Z
146 DTSTART:19671029T020000
147 RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
150 TZNAME:Eastern Standard Time (US & Canada)
153 DTSTART:19870405T020000
154 RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
157 TZNAME:Eastern Daylight Time (US & Canada)
161 ]]></C:calendar-timezone>
166 $request->setBody($body);
167 $this->server->httpRequest = $request;
168 $this->server->exec();
170 $this->assertEquals('HTTP/1.1 403 Forbidden', $this->response->status);
174 function testMkCalendarNoParentNode() {
176 $request = new Sabre_HTTP_Request(array(
177 'REQUEST_METHOD' => 'MKCALENDAR',
178 'REQUEST_URI' => '/doesntexist/calendar',
181 $body = '<?xml version="1.0" encoding="utf-8" ?>
182 <C:mkcalendar xmlns:D="DAV:"
183 xmlns:C="urn:ietf:params:xml:ns:caldav">
186 <D:displayname>Lisa\'s Events</D:displayname>
187 <C:calendar-description xml:lang="en"
188 >Calendar restricted to events.</C:calendar-description>
189 <C:supported-calendar-component-set>
190 <C:comp name="VEVENT"/>
191 </C:supported-calendar-component-set>
192 <C:calendar-timezone><![CDATA[BEGIN:VCALENDAR
193 PRODID:-//Example Corp.//CalDAV Client//EN
197 LAST-MODIFIED:19870101T000000Z
199 DTSTART:19671029T020000
200 RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
203 TZNAME:Eastern Standard Time (US & Canada)
206 DTSTART:19870405T020000
207 RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
210 TZNAME:Eastern Daylight Time (US & Canada)
214 ]]></C:calendar-timezone>
219 $request->setBody($body);
220 $this->server->httpRequest = $request;
221 $this->server->exec();
223 $this->assertEquals('HTTP/1.1 409 Conflict', $this->response->status);
227 function testMkCalendarExistingCalendar() {
229 $request = new Sabre_HTTP_Request(array(
230 'REQUEST_METHOD' => 'MKCALENDAR',
231 'REQUEST_URI' => '/calendars/user1/UUID-123467',
234 $body = '<?xml version="1.0" encoding="utf-8" ?>
235 <C:mkcalendar xmlns:D="DAV:"
236 xmlns:C="urn:ietf:params:xml:ns:caldav">
239 <D:displayname>Lisa\'s Events</D:displayname>
240 <C:calendar-description xml:lang="en"
241 >Calendar restricted to events.</C:calendar-description>
242 <C:supported-calendar-component-set>
243 <C:comp name="VEVENT"/>
244 </C:supported-calendar-component-set>
245 <C:calendar-timezone><![CDATA[BEGIN:VCALENDAR
246 PRODID:-//Example Corp.//CalDAV Client//EN
250 LAST-MODIFIED:19870101T000000Z
252 DTSTART:19671029T020000
253 RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
256 TZNAME:Eastern Standard Time (US & Canada)
259 DTSTART:19870405T020000
260 RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
263 TZNAME:Eastern Daylight Time (US & Canada)
267 ]]></C:calendar-timezone>
272 $request->setBody($body);
273 $this->server->httpRequest = $request;
274 $this->server->exec();
276 $this->assertEquals('HTTP/1.1 405 Method Not Allowed', $this->response->status);
280 function testMkCalendarSucceed() {
282 $request = new Sabre_HTTP_Request(array(
283 'REQUEST_METHOD' => 'MKCALENDAR',
284 'REQUEST_URI' => '/calendars/user1/NEWCALENDAR',
287 $timezone = 'BEGIN:VCALENDAR
288 PRODID:-//Example Corp.//CalDAV Client//EN
292 LAST-MODIFIED:19870101T000000Z
294 DTSTART:19671029T020000
295 RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
298 TZNAME:Eastern Standard Time (US & Canada)
301 DTSTART:19870405T020000
302 RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
305 TZNAME:Eastern Daylight Time (US & Canada)
310 $body = '<?xml version="1.0" encoding="utf-8" ?>
311 <C:mkcalendar xmlns:D="DAV:"
312 xmlns:C="urn:ietf:params:xml:ns:caldav">
315 <D:displayname>Lisa\'s Events</D:displayname>
316 <C:calendar-description xml:lang="en"
317 >Calendar restricted to events.</C:calendar-description>
318 <C:supported-calendar-component-set>
319 <C:comp name="VEVENT"/>
320 </C:supported-calendar-component-set>
321 <C:calendar-timezone><![CDATA[' . $timezone . ']]></C:calendar-timezone>
326 $request->setBody($body);
327 $this->server->httpRequest = $request;
328 $this->server->exec();
330 $this->assertEquals('HTTP/1.1 201 Created', $this->response->status,'Invalid response code received. Full response body: ' .$this->response->body);
332 $calendars = $this->caldavBackend->getCalendarsForUser('principals/user1');
333 $this->assertEquals(3, count($calendars));
336 foreach($calendars as $calendar) {
337 if ($calendar['uri'] === 'NEWCALENDAR') {
338 $newCalendar = $calendar;
343 $this->assertInternalType('array',$newCalendar);
346 'uri' => 'NEWCALENDAR',
348 '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar restricted to events.',
349 '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => $timezone,
350 '{DAV:}displayname' => 'Lisa\'s Events',
351 '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => null,
354 foreach($keys as $key=>$value) {
356 $this->assertArrayHasKey($key, $newCalendar);
358 if (is_null($value)) continue;
359 $this->assertEquals($value, $newCalendar[$key]);
362 $sccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set';
363 $this->assertTrue($newCalendar[$sccs] instanceof Sabre_CalDAV_Property_SupportedCalendarComponentSet);
364 $this->assertEquals(array('VEVENT'),$newCalendar[$sccs]->getValue());
368 function testMkCalendarEmptyBodySucceed() {
370 $request = new Sabre_HTTP_Request(array(
371 'REQUEST_METHOD' => 'MKCALENDAR',
372 'REQUEST_URI' => '/calendars/user1/NEWCALENDAR',
375 $request->setBody('');
376 $this->server->httpRequest = $request;
377 $this->server->exec();
379 $this->assertEquals('HTTP/1.1 201 Created', $this->response->status,'Invalid response code received. Full response body: ' .$this->response->body);
381 $calendars = $this->caldavBackend->getCalendarsForUser('principals/user1');
382 $this->assertEquals(3, count($calendars));
385 foreach($calendars as $calendar) {
386 if ($calendar['uri'] === 'NEWCALENDAR') {
387 $newCalendar = $calendar;
392 $this->assertInternalType('array',$newCalendar);
395 'uri' => 'NEWCALENDAR',
397 '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => null,
400 foreach($keys as $key=>$value) {
402 $this->assertArrayHasKey($key, $newCalendar);
404 if (is_null($value)) continue;
405 $this->assertEquals($value, $newCalendar[$key]);
408 $sccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set';
409 $this->assertTrue($newCalendar[$sccs] instanceof Sabre_CalDAV_Property_SupportedCalendarComponentSet);
410 $this->assertEquals(array('VEVENT','VTODO'),$newCalendar[$sccs]->getValue());
414 function testPrincipalProperties() {
416 $httpRequest = new Sabre_HTTP_Request(array(
417 'HTTP_HOST' => 'sabredav.org',
419 $this->server->httpRequest = $httpRequest;
421 $props = $this->server->getPropertiesForPath('/principals/user1',array(
422 '{urn:ietf:params:xml:ns:caldav}calendar-home-set',
423 '{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL',
424 '{urn:ietf:params:xml:ns:caldav}calendar-user-address-set',
425 '{' . Sabre_CalDAV_Plugin::NS_CALENDARSERVER . '}calendar-proxy-read-for',
426 '{' . Sabre_CalDAV_Plugin::NS_CALENDARSERVER . '}calendar-proxy-write-for',
427 '{' . Sabre_CalDAV_Plugin::NS_CALENDARSERVER . '}notification-URL',
430 $this->assertArrayHasKey(0,$props);
431 $this->assertArrayHasKey(200,$props[0]);
434 $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}calendar-home-set',$props[0][200]);
435 $prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}calendar-home-set'];
436 $this->assertTrue($prop instanceof Sabre_DAV_Property_Href);
437 $this->assertEquals('calendars/user1/',$prop->getHref());
439 $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL',$props[0][200]);
440 $prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL'];
441 $this->assertTrue($prop instanceof Sabre_DAV_Property_Href);
442 $this->assertEquals('calendars/user1/outbox',$prop->getHref());
444 $this->assertArrayHasKey('{'.Sabre_CalDAV_Plugin::NS_CALENDARSERVER .'}notification-URL',$props[0][200]);
445 $prop = $props[0][200]['{'.Sabre_CalDAV_Plugin::NS_CALENDARSERVER .'}notification-URL'];
446 $this->assertTrue($prop instanceof Sabre_DAV_Property_Href);
447 $this->assertEquals('calendars/user1/notifications/',$prop->getHref());
450 $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}calendar-user-address-set',$props[0][200]);
451 $prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set'];
452 $this->assertTrue($prop instanceof Sabre_DAV_Property_HrefList);
453 $this->assertEquals(array('mailto:user1.sabredav@sabredav.org','/principals/user1'),$prop->getHrefs());
455 $this->assertArrayHasKey('{http://calendarserver.org/ns/}calendar-proxy-read-for', $props[0][200]);
456 $prop = $props[0][200]['{http://calendarserver.org/ns/}calendar-proxy-read-for'];
457 $this->assertInstanceOf('Sabre_DAV_Property_HrefList', $prop);
458 $this->assertEquals(array('principals/admin'), $prop->getHrefs());
460 $this->assertArrayHasKey('{http://calendarserver.org/ns/}calendar-proxy-write-for', $props[0][200]);
461 $prop = $props[0][200]['{http://calendarserver.org/ns/}calendar-proxy-write-for'];
462 $this->assertInstanceOf('Sabre_DAV_Property_HrefList', $prop);
463 $this->assertEquals(array('principals/admin'), $prop->getHrefs());
468 function testSupportedReportSetPropertyNonCalendar() {
470 $props = $this->server->getPropertiesForPath('/calendars/user1',array(
471 '{DAV:}supported-report-set',
474 $this->assertArrayHasKey(0,$props);
475 $this->assertArrayHasKey(200,$props[0]);
476 $this->assertArrayHasKey('{DAV:}supported-report-set',$props[0][200]);
478 $prop = $props[0][200]['{DAV:}supported-report-set'];
480 $this->assertTrue($prop instanceof Sabre_DAV_Property_SupportedReportSet);
483 $this->assertEquals($value,$prop->getValue());
488 * @depends testSupportedReportSetPropertyNonCalendar
490 function testSupportedReportSetProperty() {
492 $props = $this->server->getPropertiesForPath('/calendars/user1/UUID-123467',array(
493 '{DAV:}supported-report-set',
496 $this->assertArrayHasKey(0,$props);
497 $this->assertArrayHasKey(200,$props[0]);
498 $this->assertArrayHasKey('{DAV:}supported-report-set',$props[0][200]);
500 $prop = $props[0][200]['{DAV:}supported-report-set'];
502 $this->assertTrue($prop instanceof Sabre_DAV_Property_SupportedReportSet);
504 '{urn:ietf:params:xml:ns:caldav}calendar-multiget',
505 '{urn:ietf:params:xml:ns:caldav}calendar-query',
506 '{urn:ietf:params:xml:ns:caldav}free-busy-query',
508 $this->assertEquals($value,$prop->getValue());
513 * @depends testSupportedReportSetProperty
515 function testCalendarMultiGetReport() {
518 '<?xml version="1.0"?>' .
519 '<c:calendar-multiget xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
521 ' <c:calendar-data />' .
524 '<d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>' .
525 '</c:calendar-multiget>';
527 $request = new Sabre_HTTP_Request(array(
528 'REQUEST_METHOD' => 'REPORT',
529 'REQUEST_URI' => '/calendars/user1',
532 $request->setBody($body);
534 $this->server->httpRequest = $request;
535 $this->server->exec();
537 $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Invalid HTTP status received. Full response body: ' . $this->response->body);
539 $xml = simplexml_load_string($this->response->body);
541 $xml->registerXPathNamespace('d','DAV:');
542 $xml->registerXPathNamespace('c','urn:ietf:params:xml:ns:caldav');
546 '/d:multistatus/d:response',
547 '/d:multistatus/d:response/d:href',
548 '/d:multistatus/d:response/d:propstat',
549 '/d:multistatus/d:response/d:propstat/d:prop',
550 '/d:multistatus/d:response/d:propstat/d:prop/d:getetag',
551 '/d:multistatus/d:response/d:propstat/d:prop/c:calendar-data',
552 '/d:multistatus/d:response/d:propstat/d:status' => 'HTTP/1.1 200 OK',
555 foreach($check as $v1=>$v2) {
557 $xpath = is_int($v1)?$v2:$v1;
559 $result = $xml->xpath($xpath);
560 $this->assertEquals(1,count($result));
562 if (!is_int($v1)) $this->assertEquals($v2,(string)$result[0]);
566 // The response object should have a reference to the Asia/Seoul
568 $this->assertTrue(strpos($this->response->body,'Asia/Seoul')!==false);
573 * @depends testCalendarMultiGetReport
575 function testCalendarMultiGetReportExpand() {
578 '<?xml version="1.0"?>' .
579 '<c:calendar-multiget xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
581 ' <c:calendar-data>' .
582 ' <c:expand start="20110101T000000Z" end="20111231T235959Z" />' .
583 ' </c:calendar-data>' .
586 '<d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>' .
587 '</c:calendar-multiget>';
589 $request = new Sabre_HTTP_Request(array(
590 'REQUEST_METHOD' => 'REPORT',
591 'REQUEST_URI' => '/calendars/user1',
594 $request->setBody($body);
596 $this->server->httpRequest = $request;
597 $this->server->exec();
599 $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Invalid HTTP status received. Full response body: ' . $this->response->body);
601 $xml = simplexml_load_string($this->response->body);
603 $xml->registerXPathNamespace('d','DAV:');
604 $xml->registerXPathNamespace('c','urn:ietf:params:xml:ns:caldav');
608 '/d:multistatus/d:response',
609 '/d:multistatus/d:response/d:href',
610 '/d:multistatus/d:response/d:propstat',
611 '/d:multistatus/d:response/d:propstat/d:prop',
612 '/d:multistatus/d:response/d:propstat/d:prop/d:getetag',
613 '/d:multistatus/d:response/d:propstat/d:prop/c:calendar-data',
614 '/d:multistatus/d:response/d:propstat/d:status' => 'HTTP/1.1 200 OK',
617 foreach($check as $v1=>$v2) {
619 $xpath = is_int($v1)?$v2:$v1;
621 $result = $xml->xpath($xpath);
622 $this->assertEquals(1,count($result));
624 if (!is_int($v1)) $this->assertEquals($v2,(string)$result[0]);
627 // The response object should no longer hold references to timezones.
628 $this->assertTrue(strpos($this->response->body,'Asia/Seoul')===false);
633 * @depends testSupportedReportSetProperty
634 * @depends testCalendarMultiGetReport
636 function testCalendarQueryReport() {
639 '<?xml version="1.0"?>' .
640 '<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
642 ' <c:calendar-data>' .
643 ' <c:expand start="20000101T000000Z" end="20101231T235959Z" />' .
644 ' </c:calendar-data>' .
648 ' <c:comp-filter name="VCALENDAR">' .
649 ' <c:comp-filter name="VEVENT" />' .
650 ' </c:comp-filter>' .
652 '</c:calendar-query>';
654 $request = new Sabre_HTTP_Request(array(
655 'REQUEST_METHOD' => 'REPORT',
656 'REQUEST_URI' => '/calendars/user1/UUID-123467',
659 $request->setBody($body);
661 $this->server->httpRequest = $request;
662 $this->server->exec();
664 $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Received an unexpected status. Full response body: ' . $this->response->body);
666 $xml = simplexml_load_string($this->response->body);
668 $xml->registerXPathNamespace('d','DAV:');
669 $xml->registerXPathNamespace('c','urn:ietf:params:xml:ns:caldav');
673 '/d:multistatus/d:response',
674 '/d:multistatus/d:response/d:href',
675 '/d:multistatus/d:response/d:propstat',
676 '/d:multistatus/d:response/d:propstat/d:prop',
677 '/d:multistatus/d:response/d:propstat/d:prop/d:getetag',
678 '/d:multistatus/d:response/d:propstat/d:prop/c:calendar-data',
679 '/d:multistatus/d:response/d:propstat/d:status' => 'HTTP/1.1 200 OK',
682 foreach($check as $v1=>$v2) {
684 $xpath = is_int($v1)?$v2:$v1;
686 $result = $xml->xpath($xpath);
687 $this->assertEquals(1,count($result), 'We expected 1 ' . $xpath . ' elements. We\'ve found ' . count($result) . '. Full result: ' . $this->response->body);
689 if (!is_int($v1)) $this->assertEquals($v2,(string)$result[0]);
696 * @depends testCalendarQueryReport
698 function testCalendarQueryReportNoCalData() {
701 '<?xml version="1.0"?>' .
702 '<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
707 ' <c:comp-filter name="VCALENDAR">' .
708 ' <c:comp-filter name="VEVENT" />' .
709 ' </c:comp-filter>' .
711 '</c:calendar-query>';
713 $request = new Sabre_HTTP_Request(array(
714 'REQUEST_METHOD' => 'REPORT',
715 'REQUEST_URI' => '/calendars/user1//UUID-123467',
718 $request->setBody($body);
720 $this->server->httpRequest = $request;
721 $this->server->exec();
723 $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Received an unexpected status. Full response body: ' . $this->response->body);
725 $xml = simplexml_load_string($this->response->body);
727 $xml->registerXPathNamespace('d','DAV:');
728 $xml->registerXPathNamespace('c','urn:ietf:params:xml:ns:caldav');
732 '/d:multistatus/d:response',
733 '/d:multistatus/d:response/d:href',
734 '/d:multistatus/d:response/d:propstat',
735 '/d:multistatus/d:response/d:propstat/d:prop',
736 '/d:multistatus/d:response/d:propstat/d:prop/d:getetag',
737 '/d:multistatus/d:response/d:propstat/d:status' => 'HTTP/1.1 200 OK',
740 foreach($check as $v1=>$v2) {
742 $xpath = is_int($v1)?$v2:$v1;
744 $result = $xml->xpath($xpath);
745 $this->assertEquals(1,count($result), 'We expected 1 ' . $xpath . ' elements. We\'ve found ' . count($result) . '. Full result: ' . $this->response->body);
747 if (!is_int($v1)) $this->assertEquals($v2,(string)$result[0]);
754 * @depends testCalendarQueryReport
756 function testCalendarQueryReportNoFilters() {
759 '<?xml version="1.0"?>' .
760 '<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
762 ' <c:calendar-data />' .
765 '</c:calendar-query>';
767 $request = new Sabre_HTTP_Request(array(
768 'REQUEST_METHOD' => 'REPORT',
769 'REQUEST_URI' => '/calendars/user1//UUID-123467',
771 $request->setBody($body);
773 $this->server->httpRequest = $request;
774 $this->server->exec();
776 $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status,'Received an unexpected status. Full response body: ' . $this->response->body);
781 * @depends testSupportedReportSetProperty
782 * @depends testCalendarMultiGetReport
784 function testCalendarQueryReport1Object() {
787 '<?xml version="1.0"?>' .
788 '<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
790 ' <c:calendar-data>' .
791 ' <c:expand start="20000101T000000Z" end="20101231T235959Z" />' .
792 ' </c:calendar-data>' .
796 ' <c:comp-filter name="VCALENDAR">' .
797 ' <c:comp-filter name="VEVENT" />' .
798 ' </c:comp-filter>' .
800 '</c:calendar-query>';
802 $request = new Sabre_HTTP_Request(array(
803 'REQUEST_METHOD' => 'REPORT',
804 'REQUEST_URI' => '/calendars/user1/UUID-123467/UUID-2345',
807 $request->setBody($body);
809 $this->server->httpRequest = $request;
810 $this->server->exec();
812 $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Received an unexpected status. Full response body: ' . $this->response->body);
814 $xml = simplexml_load_string($this->response->body);
816 $xml->registerXPathNamespace('d','DAV:');
817 $xml->registerXPathNamespace('c','urn:ietf:params:xml:ns:caldav');
821 '/d:multistatus/d:response',
822 '/d:multistatus/d:response/d:href',
823 '/d:multistatus/d:response/d:propstat',
824 '/d:multistatus/d:response/d:propstat/d:prop',
825 '/d:multistatus/d:response/d:propstat/d:prop/d:getetag',
826 '/d:multistatus/d:response/d:propstat/d:prop/c:calendar-data',
827 '/d:multistatus/d:response/d:propstat/d:status' => 'HTTP/1.1 200 OK',
830 foreach($check as $v1=>$v2) {
832 $xpath = is_int($v1)?$v2:$v1;
834 $result = $xml->xpath($xpath);
835 $this->assertEquals(1,count($result), 'We expected 1 ' . $xpath . ' elements. We\'ve found ' . count($result) . '. Full result: ' . $this->response->body);
837 if (!is_int($v1)) $this->assertEquals($v2,(string)$result[0]);
844 * @depends testSupportedReportSetProperty
845 * @depends testCalendarMultiGetReport
847 function testCalendarQueryReport1ObjectNoCalData() {
850 '<?xml version="1.0"?>' .
851 '<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
856 ' <c:comp-filter name="VCALENDAR">' .
857 ' <c:comp-filter name="VEVENT" />' .
858 ' </c:comp-filter>' .
860 '</c:calendar-query>';
862 $request = new Sabre_HTTP_Request(array(
863 'REQUEST_METHOD' => 'REPORT',
864 'REQUEST_URI' => '/calendars/user1/UUID-123467/UUID-2345',
867 $request->setBody($body);
869 $this->server->httpRequest = $request;
870 $this->server->exec();
872 $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Received an unexpected status. Full response body: ' . $this->response->body);
874 $xml = simplexml_load_string($this->response->body);
876 $xml->registerXPathNamespace('d','DAV:');
877 $xml->registerXPathNamespace('c','urn:ietf:params:xml:ns:caldav');
881 '/d:multistatus/d:response',
882 '/d:multistatus/d:response/d:href',
883 '/d:multistatus/d:response/d:propstat',
884 '/d:multistatus/d:response/d:propstat/d:prop',
885 '/d:multistatus/d:response/d:propstat/d:prop/d:getetag',
886 '/d:multistatus/d:response/d:propstat/d:status' => 'HTTP/1.1 200 OK',
889 foreach($check as $v1=>$v2) {
891 $xpath = is_int($v1)?$v2:$v1;
893 $result = $xml->xpath($xpath);
894 $this->assertEquals(1,count($result), 'We expected 1 ' . $xpath . ' elements. We\'ve found ' . count($result) . '. Full result: ' . $this->response->body);
896 if (!is_int($v1)) $this->assertEquals($v2,(string)$result[0]);
902 function testHTMLActionsPanel() {
905 $r = $this->server->broadcastEvent('onHTMLActionsPanel', array($this->server->tree->getNodeForPath('calendars/user1'), &$output));
906 $this->assertFalse($r);
908 $this->assertTrue(!!strpos($output,'Display name'));
912 function testBrowserPostAction() {
914 $r = $this->server->broadcastEvent('onBrowserPostAction', array('calendars/user1', 'mkcalendar', array(
915 'name' => 'NEWCALENDAR',
916 '{DAV:}displayname' => 'foo',
918 $this->assertFalse($r);
920 $calendars = $this->caldavBackend->getCalendarsForUser('principals/user1');
921 $this->assertEquals(3, count($calendars));
924 foreach($calendars as $calendar) {
925 if ($calendar['uri'] === 'NEWCALENDAR') {
926 $newCalendar = $calendar;
931 $this->fail('Could not find newly created calendar');
937 * @depends testCalendarMultiGetReport
939 function testCalendarMultiGetReportNoEnd() {
942 '<?xml version="1.0"?>' .
943 '<c:calendar-multiget xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
945 ' <c:calendar-data>' .
946 ' <c:expand start="20110101T000000Z" />' .
947 ' </c:calendar-data>' .
950 '<d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>' .
951 '</c:calendar-multiget>';
953 $request = new Sabre_HTTP_Request(array(
954 'REQUEST_METHOD' => 'REPORT',
955 'REQUEST_URI' => '/calendars/user1',
958 $request->setBody($body);
960 $this->server->httpRequest = $request;
961 $this->server->exec();
963 $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status,'Invalid HTTP status received. Full response body: ' . $this->response->body);
968 * @depends testCalendarMultiGetReport
970 function testCalendarMultiGetReportNoStart() {
973 '<?xml version="1.0"?>' .
974 '<c:calendar-multiget xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
976 ' <c:calendar-data>' .
977 ' <c:expand end="20110101T000000Z" />' .
978 ' </c:calendar-data>' .
981 '<d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>' .
982 '</c:calendar-multiget>';
984 $request = new Sabre_HTTP_Request(array(
985 'REQUEST_METHOD' => 'REPORT',
986 'REQUEST_URI' => '/calendars/user1',
989 $request->setBody($body);
991 $this->server->httpRequest = $request;
992 $this->server->exec();
994 $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status,'Invalid HTTP status received. Full response body: ' . $this->response->body);
999 * @depends testCalendarMultiGetReport
1001 function testCalendarMultiGetReportEndBeforeStart() {
1004 '<?xml version="1.0"?>' .
1005 '<c:calendar-multiget xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
1007 ' <c:calendar-data>' .
1008 ' <c:expand start="20200101T000000Z" end="20110101T000000Z" />' .
1009 ' </c:calendar-data>' .
1012 '<d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>' .
1013 '</c:calendar-multiget>';
1015 $request = new Sabre_HTTP_Request(array(
1016 'REQUEST_METHOD' => 'REPORT',
1017 'REQUEST_URI' => '/calendars/user1',
1018 'HTTP_DEPTH' => '1',
1020 $request->setBody($body);
1022 $this->server->httpRequest = $request;
1023 $this->server->exec();
1025 $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status,'Invalid HTTP status received. Full response body: ' . $this->response->body);
1029 function testNotificationProperties() {
1032 '{' . Sabre_CalDAV_Plugin::NS_CALENDARSERVER . '}notificationtype',
1035 $notification = new Sabre_CalDAV_Notifications_Node(
1036 $this->caldavBackend,
1037 new Sabre_CalDAV_Notifications_Notification_SystemStatus('foo')
1039 $this->plugin->beforeGetProperties('foo', $notification, $request, $result);
1041 $this->assertEquals(
1044 '{' . Sabre_CalDAV_Plugin::NS_CALENDARSERVER . '}notificationtype' => $notification->getNotificationType()
1050 function testNotificationGet() {
1052 $notification = new Sabre_CalDAV_Notifications_Node(
1053 $this->caldavBackend,
1054 new Sabre_CalDAV_Notifications_Notification_SystemStatus('foo')
1057 $server = new Sabre_DAV_Server(array($notification));
1058 $caldav = new Sabre_CalDAV_Plugin();
1060 $httpResponse = new Sabre_HTTP_ResponseMock();
1061 $server->httpResponse = $httpResponse;
1063 $server->addPlugin($caldav);
1065 $caldav->beforeMethod('GET','foo');
1067 $this->assertEquals('HTTP/1.1 200 OK', $httpResponse->status);
1068 $this->assertEquals(array(
1069 'Content-Type' => 'application/xml',
1070 ), $httpResponse->headers);
1073 '<?xml version="1.0" encoding="UTF-8"?>
1074 <cs:notification xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/">
1075 <cs:systemstatus type="high"/>
1079 $this->assertEquals($expected, $httpResponse->body);