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 if (!SABRE_HASSQLITE) $this->markTestSkipped('No PDO SQLite support');
27 $this->caldavBackend = Sabre_CalDAV_TestUtil::getBackend();
28 $principalBackend = new Sabre_DAVACL_MockPrincipalBackend();
29 $principalBackend->setGroupMemberSet('principals/admin/calendar-proxy-read',array('principals/user1'));
30 $principalBackend->setGroupMemberSet('principals/admin/calendar-proxy-write',array('principals/user1'));
31 $principalBackend->addPrincipal(array(
32 'uri' => 'principals/admin/calendar-proxy-read',
34 $principalBackend->addPrincipal(array(
35 'uri' => 'principals/admin/calendar-proxy-write',
38 $calendars = new Sabre_CalDAV_CalendarRootNode($principalBackend,$this->caldavBackend);
39 $principals = new Sabre_CalDAV_Principal_Collection($principalBackend);
41 $root = new Sabre_DAV_SimpleCollection('root');
42 $root->addChild($calendars);
43 $root->addChild($principals);
45 $objectTree = new Sabre_DAV_ObjectTree($root);
46 $this->server = new Sabre_DAV_Server($objectTree);
47 $this->server->debugExceptions = true;
48 $this->server->setBaseUri('/');
49 $this->plugin = new Sabre_CalDAV_Plugin();
50 $this->server->addPlugin($this->plugin);
52 $this->response = new Sabre_HTTP_ResponseMock();
53 $this->server->httpResponse = $this->response;
57 function testSimple() {
59 $this->assertEquals(array('MKCALENDAR'), $this->plugin->getHTTPMethods('calendars/user1/randomnewcalendar'));
60 $this->assertEquals(array('calendar-access','calendar-proxy'), $this->plugin->getFeatures());
61 $this->assertArrayHasKey('urn:ietf:params:xml:ns:caldav', $this->server->xmlNamespaces);
65 function testUnknownMethodPassThrough() {
67 $request = new Sabre_HTTP_Request(array(
68 'REQUEST_METHOD' => 'MKBREAKFAST',
72 $this->server->httpRequest = $request;
73 $this->server->exec();
75 $this->assertEquals('HTTP/1.1 501 Not Implemented', $this->response->status,'Incorrect status returned. Full response body:' . $this->response->body);
79 function testReportPassThrough() {
81 $request = new Sabre_HTTP_Request(array(
82 'REQUEST_METHOD' => 'REPORT',
83 'HTTP_CONTENT_TYPE' => 'application/xml',
86 $request->setBody('<?xml version="1.0"?><s:somereport xmlns:s="http://www.rooftopsolutions.nl/NS/example" />');
88 $this->server->httpRequest = $request;
89 $this->server->exec();
91 $this->assertEquals('HTTP/1.1 501 Not Implemented', $this->response->status);
95 function testMkCalendarBadLocation() {
97 $request = new Sabre_HTTP_Request(array(
98 'REQUEST_METHOD' => 'MKCALENDAR',
99 'REQUEST_URI' => '/blabla',
102 $body = '<?xml version="1.0" encoding="utf-8" ?>
103 <C:mkcalendar xmlns:D="DAV:"
104 xmlns:C="urn:ietf:params:xml:ns:caldav">
107 <D:displayname>Lisa\'s Events</D:displayname>
108 <C:calendar-description xml:lang="en"
109 >Calendar restricted to events.</C:calendar-description>
110 <C:supported-calendar-component-set>
111 <C:comp name="VEVENT"/>
112 </C:supported-calendar-component-set>
113 <C:calendar-timezone><![CDATA[BEGIN:VCALENDAR
114 PRODID:-//Example Corp.//CalDAV Client//EN
118 LAST-MODIFIED:19870101T000000Z
120 DTSTART:19671029T020000
121 RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
124 TZNAME:Eastern Standard Time (US & Canada)
127 DTSTART:19870405T020000
128 RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
131 TZNAME:Eastern Daylight Time (US & Canada)
135 ]]></C:calendar-timezone>
140 $request->setBody($body);
141 $this->server->httpRequest = $request;
142 $this->server->exec();
144 $this->assertEquals('HTTP/1.1 403 Forbidden', $this->response->status);
148 function testMkCalendarNoParentNode() {
150 $request = new Sabre_HTTP_Request(array(
151 'REQUEST_METHOD' => 'MKCALENDAR',
152 'REQUEST_URI' => '/doesntexist/calendar',
155 $body = '<?xml version="1.0" encoding="utf-8" ?>
156 <C:mkcalendar xmlns:D="DAV:"
157 xmlns:C="urn:ietf:params:xml:ns:caldav">
160 <D:displayname>Lisa\'s Events</D:displayname>
161 <C:calendar-description xml:lang="en"
162 >Calendar restricted to events.</C:calendar-description>
163 <C:supported-calendar-component-set>
164 <C:comp name="VEVENT"/>
165 </C:supported-calendar-component-set>
166 <C:calendar-timezone><![CDATA[BEGIN:VCALENDAR
167 PRODID:-//Example Corp.//CalDAV Client//EN
171 LAST-MODIFIED:19870101T000000Z
173 DTSTART:19671029T020000
174 RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
177 TZNAME:Eastern Standard Time (US & Canada)
180 DTSTART:19870405T020000
181 RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
184 TZNAME:Eastern Daylight Time (US & Canada)
188 ]]></C:calendar-timezone>
193 $request->setBody($body);
194 $this->server->httpRequest = $request;
195 $this->server->exec();
197 $this->assertEquals('HTTP/1.1 409 Conflict', $this->response->status);
201 function testMkCalendarExistingCalendar() {
203 $request = new Sabre_HTTP_Request(array(
204 'REQUEST_METHOD' => 'MKCALENDAR',
205 'REQUEST_URI' => '/calendars/user1/UUID-123467',
208 $body = '<?xml version="1.0" encoding="utf-8" ?>
209 <C:mkcalendar xmlns:D="DAV:"
210 xmlns:C="urn:ietf:params:xml:ns:caldav">
213 <D:displayname>Lisa\'s Events</D:displayname>
214 <C:calendar-description xml:lang="en"
215 >Calendar restricted to events.</C:calendar-description>
216 <C:supported-calendar-component-set>
217 <C:comp name="VEVENT"/>
218 </C:supported-calendar-component-set>
219 <C:calendar-timezone><![CDATA[BEGIN:VCALENDAR
220 PRODID:-//Example Corp.//CalDAV Client//EN
224 LAST-MODIFIED:19870101T000000Z
226 DTSTART:19671029T020000
227 RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
230 TZNAME:Eastern Standard Time (US & Canada)
233 DTSTART:19870405T020000
234 RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
237 TZNAME:Eastern Daylight Time (US & Canada)
241 ]]></C:calendar-timezone>
246 $request->setBody($body);
247 $this->server->httpRequest = $request;
248 $this->server->exec();
250 $this->assertEquals('HTTP/1.1 405 Method Not Allowed', $this->response->status);
254 function testMkCalendarSucceed() {
256 $request = new Sabre_HTTP_Request(array(
257 'REQUEST_METHOD' => 'MKCALENDAR',
258 'REQUEST_URI' => '/calendars/user1/NEWCALENDAR',
261 $timezone = 'BEGIN:VCALENDAR
262 PRODID:-//Example Corp.//CalDAV Client//EN
266 LAST-MODIFIED:19870101T000000Z
268 DTSTART:19671029T020000
269 RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
272 TZNAME:Eastern Standard Time (US & Canada)
275 DTSTART:19870405T020000
276 RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
279 TZNAME:Eastern Daylight Time (US & Canada)
284 $body = '<?xml version="1.0" encoding="utf-8" ?>
285 <C:mkcalendar xmlns:D="DAV:"
286 xmlns:C="urn:ietf:params:xml:ns:caldav">
289 <D:displayname>Lisa\'s Events</D:displayname>
290 <C:calendar-description xml:lang="en"
291 >Calendar restricted to events.</C:calendar-description>
292 <C:supported-calendar-component-set>
293 <C:comp name="VEVENT"/>
294 </C:supported-calendar-component-set>
295 <C:calendar-timezone><![CDATA[' . $timezone . ']]></C:calendar-timezone>
300 $request->setBody($body);
301 $this->server->httpRequest = $request;
302 $this->server->exec();
304 $this->assertEquals('HTTP/1.1 201 Created', $this->response->status,'Invalid response code received. Full response body: ' .$this->response->body);
306 $calendars = $this->caldavBackend->getCalendarsForUser('principals/user1');
307 $this->assertEquals(3, count($calendars));
310 foreach($calendars as $calendar) {
311 if ($calendar['uri'] === 'NEWCALENDAR') {
312 $newCalendar = $calendar;
317 $this->assertInternalType('array',$newCalendar);
320 'uri' => 'NEWCALENDAR',
322 '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar restricted to events.',
323 '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => $timezone,
324 '{DAV:}displayname' => 'Lisa\'s Events',
325 '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => null,
328 foreach($keys as $key=>$value) {
330 $this->assertArrayHasKey($key, $newCalendar);
332 if (is_null($value)) continue;
333 $this->assertEquals($value, $newCalendar[$key]);
336 $sccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set';
337 $this->assertTrue($newCalendar[$sccs] instanceof Sabre_CalDAV_Property_SupportedCalendarComponentSet);
338 $this->assertEquals(array('VEVENT'),$newCalendar[$sccs]->getValue());
342 function testMkCalendarEmptyBodySucceed() {
344 $request = new Sabre_HTTP_Request(array(
345 'REQUEST_METHOD' => 'MKCALENDAR',
346 'REQUEST_URI' => '/calendars/user1/NEWCALENDAR',
349 $request->setBody('');
350 $this->server->httpRequest = $request;
351 $this->server->exec();
353 $this->assertEquals('HTTP/1.1 201 Created', $this->response->status,'Invalid response code received. Full response body: ' .$this->response->body);
355 $calendars = $this->caldavBackend->getCalendarsForUser('principals/user1');
356 $this->assertEquals(3, count($calendars));
359 foreach($calendars as $calendar) {
360 if ($calendar['uri'] === 'NEWCALENDAR') {
361 $newCalendar = $calendar;
366 $this->assertInternalType('array',$newCalendar);
369 'uri' => 'NEWCALENDAR',
371 '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => null,
374 foreach($keys as $key=>$value) {
376 $this->assertArrayHasKey($key, $newCalendar);
378 if (is_null($value)) continue;
379 $this->assertEquals($value, $newCalendar[$key]);
382 $sccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set';
383 $this->assertTrue($newCalendar[$sccs] instanceof Sabre_CalDAV_Property_SupportedCalendarComponentSet);
384 $this->assertEquals(array('VEVENT','VTODO'),$newCalendar[$sccs]->getValue());
388 function testPrincipalProperties() {
390 $httpRequest = new Sabre_HTTP_Request(array(
391 'HTTP_HOST' => 'sabredav.org',
393 $this->server->httpRequest = $httpRequest;
395 $props = $this->server->getPropertiesForPath('/principals/user1',array(
396 '{urn:ietf:params:xml:ns:caldav}calendar-home-set',
397 '{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL',
398 '{urn:ietf:params:xml:ns:caldav}calendar-user-address-set',
399 '{' . Sabre_CalDAV_Plugin::NS_CALENDARSERVER . '}calendar-proxy-read-for',
400 '{' . Sabre_CalDAV_Plugin::NS_CALENDARSERVER . '}calendar-proxy-write-for',
403 $this->assertArrayHasKey(0,$props);
404 $this->assertArrayHasKey(200,$props[0]);
407 $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}calendar-home-set',$props[0][200]);
408 $prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}calendar-home-set'];
409 $this->assertTrue($prop instanceof Sabre_DAV_Property_Href);
410 $this->assertEquals('calendars/user1/',$prop->getHref());
412 $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL',$props[0][200]);
413 $prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL'];
414 $this->assertTrue($prop instanceof Sabre_DAV_Property_Href);
415 $this->assertEquals('calendars/user1/outbox',$prop->getHref());
417 $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}calendar-user-address-set',$props[0][200]);
418 $prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set'];
419 $this->assertTrue($prop instanceof Sabre_DAV_Property_HrefList);
420 $this->assertEquals(array('mailto:user1.sabredav@sabredav.org','/principals/user1'),$prop->getHrefs());
422 $this->assertArrayHasKey('{http://calendarserver.org/ns/}calendar-proxy-read-for', $props[0][200]);
423 $prop = $props[0][200]['{http://calendarserver.org/ns/}calendar-proxy-read-for'];
424 $this->assertInstanceOf('Sabre_DAV_Property_HrefList', $prop);
425 $this->assertEquals(array('principals/admin'), $prop->getHrefs());
427 $this->assertArrayHasKey('{http://calendarserver.org/ns/}calendar-proxy-write-for', $props[0][200]);
428 $prop = $props[0][200]['{http://calendarserver.org/ns/}calendar-proxy-write-for'];
429 $this->assertInstanceOf('Sabre_DAV_Property_HrefList', $prop);
430 $this->assertEquals(array('principals/admin'), $prop->getHrefs());
434 function testSupportedReportSetPropertyNonCalendar() {
436 $props = $this->server->getPropertiesForPath('/calendars/user1',array(
437 '{DAV:}supported-report-set',
440 $this->assertArrayHasKey(0,$props);
441 $this->assertArrayHasKey(200,$props[0]);
442 $this->assertArrayHasKey('{DAV:}supported-report-set',$props[0][200]);
444 $prop = $props[0][200]['{DAV:}supported-report-set'];
446 $this->assertTrue($prop instanceof Sabre_DAV_Property_SupportedReportSet);
449 $this->assertEquals($value,$prop->getValue());
454 * @depends testSupportedReportSetPropertyNonCalendar
456 function testSupportedReportSetProperty() {
458 $props = $this->server->getPropertiesForPath('/calendars/user1/UUID-123467',array(
459 '{DAV:}supported-report-set',
462 $this->assertArrayHasKey(0,$props);
463 $this->assertArrayHasKey(200,$props[0]);
464 $this->assertArrayHasKey('{DAV:}supported-report-set',$props[0][200]);
466 $prop = $props[0][200]['{DAV:}supported-report-set'];
468 $this->assertTrue($prop instanceof Sabre_DAV_Property_SupportedReportSet);
470 '{urn:ietf:params:xml:ns:caldav}calendar-multiget',
471 '{urn:ietf:params:xml:ns:caldav}calendar-query',
472 '{urn:ietf:params:xml:ns:caldav}free-busy-query',
474 $this->assertEquals($value,$prop->getValue());
479 * @depends testSupportedReportSetProperty
481 function testCalendarMultiGetReport() {
484 '<?xml version="1.0"?>' .
485 '<c:calendar-multiget xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
487 ' <c:calendar-data />' .
490 '<d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>' .
491 '</c:calendar-multiget>';
493 $request = new Sabre_HTTP_Request(array(
494 'REQUEST_METHOD' => 'REPORT',
495 'REQUEST_URI' => '/calendars/user1',
498 $request->setBody($body);
500 $this->server->httpRequest = $request;
501 $this->server->exec();
503 $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Invalid HTTP status received. Full response body: ' . $this->response->body);
505 $xml = simplexml_load_string(Sabre_DAV_XMLUtil::convertDAVNamespace($this->response->body));
507 $xml->registerXPathNamespace('d','urn:DAV');
508 $xml->registerXPathNamespace('c','urn:ietf:params:xml:ns:caldav');
512 '/d:multistatus/d:response',
513 '/d:multistatus/d:response/d:href',
514 '/d:multistatus/d:response/d:propstat',
515 '/d:multistatus/d:response/d:propstat/d:prop',
516 '/d:multistatus/d:response/d:propstat/d:prop/d:getetag',
517 '/d:multistatus/d:response/d:propstat/d:prop/c:calendar-data',
518 '/d:multistatus/d:response/d:propstat/d:status' => 'HTTP/1.1 200 OK',
521 foreach($check as $v1=>$v2) {
523 $xpath = is_int($v1)?$v2:$v1;
525 $result = $xml->xpath($xpath);
526 $this->assertEquals(1,count($result));
528 if (!is_int($v1)) $this->assertEquals($v2,(string)$result[0]);
532 // The response object should have a reference to the Asia/Seoul
534 $this->assertTrue(strpos($this->response->body,'Asia/Seoul')!==false);
539 * @depends testCalendarMultiGetReport
541 function testCalendarMultiGetReportExpand() {
544 '<?xml version="1.0"?>' .
545 '<c:calendar-multiget xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
547 ' <c:calendar-data>' .
548 ' <c:expand start="20110101T000000Z" end="20111231T235959Z" />' .
549 ' </c:calendar-data>' .
552 '<d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>' .
553 '</c:calendar-multiget>';
555 $request = new Sabre_HTTP_Request(array(
556 'REQUEST_METHOD' => 'REPORT',
557 'REQUEST_URI' => '/calendars/user1',
560 $request->setBody($body);
562 $this->server->httpRequest = $request;
563 $this->server->exec();
565 $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Invalid HTTP status received. Full response body: ' . $this->response->body);
567 $xml = simplexml_load_string(Sabre_DAV_XMLUtil::convertDAVNamespace($this->response->body));
569 $xml->registerXPathNamespace('d','urn:DAV');
570 $xml->registerXPathNamespace('c','urn:ietf:params:xml:ns:caldav');
574 '/d:multistatus/d:response',
575 '/d:multistatus/d:response/d:href',
576 '/d:multistatus/d:response/d:propstat',
577 '/d:multistatus/d:response/d:propstat/d:prop',
578 '/d:multistatus/d:response/d:propstat/d:prop/d:getetag',
579 '/d:multistatus/d:response/d:propstat/d:prop/c:calendar-data',
580 '/d:multistatus/d:response/d:propstat/d:status' => 'HTTP/1.1 200 OK',
583 foreach($check as $v1=>$v2) {
585 $xpath = is_int($v1)?$v2:$v1;
587 $result = $xml->xpath($xpath);
588 $this->assertEquals(1,count($result));
590 if (!is_int($v1)) $this->assertEquals($v2,(string)$result[0]);
593 // The response object should no longer hold references to timezones.
594 $this->assertTrue(strpos($this->response->body,'Asia/Seoul')===false);
599 * @depends testSupportedReportSetProperty
600 * @depends testCalendarMultiGetReport
602 function testCalendarQueryReport() {
605 '<?xml version="1.0"?>' .
606 '<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
608 ' <c:calendar-data>' .
609 ' <c:expand start="20000101T000000Z" end="20101231T235959Z" />' .
610 ' </c:calendar-data>' .
614 ' <c:comp-filter name="VCALENDAR">' .
615 ' <c:comp-filter name="VEVENT" />' .
616 ' </c:comp-filter>' .
618 '</c:calendar-query>';
620 $request = new Sabre_HTTP_Request(array(
621 'REQUEST_METHOD' => 'REPORT',
622 'REQUEST_URI' => '/calendars/user1/UUID-123467',
625 $request->setBody($body);
627 $this->server->httpRequest = $request;
628 $this->server->exec();
630 $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Received an unexpected status. Full response body: ' . $this->response->body);
632 $xml = simplexml_load_string(Sabre_DAV_XMLUtil::convertDAVNamespace($this->response->body));
634 $xml->registerXPathNamespace('d','urn:DAV');
635 $xml->registerXPathNamespace('c','urn:ietf:params:xml:ns:caldav');
639 '/d:multistatus/d:response',
640 '/d:multistatus/d:response/d:href',
641 '/d:multistatus/d:response/d:propstat',
642 '/d:multistatus/d:response/d:propstat/d:prop',
643 '/d:multistatus/d:response/d:propstat/d:prop/d:getetag',
644 '/d:multistatus/d:response/d:propstat/d:prop/c:calendar-data',
645 '/d:multistatus/d:response/d:propstat/d:status' => 'HTTP/1.1 200 OK',
648 foreach($check as $v1=>$v2) {
650 $xpath = is_int($v1)?$v2:$v1;
652 $result = $xml->xpath($xpath);
653 $this->assertEquals(1,count($result), 'We expected 1 ' . $xpath . ' elements. We\'ve found ' . count($result) . '. Full result: ' . $this->response->body);
655 if (!is_int($v1)) $this->assertEquals($v2,(string)$result[0]);
662 * @depends testCalendarQueryReport
664 function testCalendarQueryReportNoCalData() {
667 '<?xml version="1.0"?>' .
668 '<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
673 ' <c:comp-filter name="VCALENDAR">' .
674 ' <c:comp-filter name="VEVENT" />' .
675 ' </c:comp-filter>' .
677 '</c:calendar-query>';
679 $request = new Sabre_HTTP_Request(array(
680 'REQUEST_METHOD' => 'REPORT',
681 'REQUEST_URI' => '/calendars/user1//UUID-123467',
684 $request->setBody($body);
686 $this->server->httpRequest = $request;
687 $this->server->exec();
689 $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Received an unexpected status. Full response body: ' . $this->response->body);
691 $xml = simplexml_load_string(Sabre_DAV_XMLUtil::convertDAVNamespace($this->response->body));
693 $xml->registerXPathNamespace('d','urn:DAV');
694 $xml->registerXPathNamespace('c','urn:ietf:params:xml:ns:caldav');
698 '/d:multistatus/d:response',
699 '/d:multistatus/d:response/d:href',
700 '/d:multistatus/d:response/d:propstat',
701 '/d:multistatus/d:response/d:propstat/d:prop',
702 '/d:multistatus/d:response/d:propstat/d:prop/d:getetag',
703 '/d:multistatus/d:response/d:propstat/d:status' => 'HTTP/1.1 200 OK',
706 foreach($check as $v1=>$v2) {
708 $xpath = is_int($v1)?$v2:$v1;
710 $result = $xml->xpath($xpath);
711 $this->assertEquals(1,count($result), 'We expected 1 ' . $xpath . ' elements. We\'ve found ' . count($result) . '. Full result: ' . $this->response->body);
713 if (!is_int($v1)) $this->assertEquals($v2,(string)$result[0]);
720 * @depends testCalendarQueryReport
722 function testCalendarQueryReportNoFilters() {
725 '<?xml version="1.0"?>' .
726 '<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
728 ' <c:calendar-data />' .
731 '</c:calendar-query>';
733 $request = new Sabre_HTTP_Request(array(
734 'REQUEST_METHOD' => 'REPORT',
735 'REQUEST_URI' => '/calendars/user1//UUID-123467',
737 $request->setBody($body);
739 $this->server->httpRequest = $request;
740 $this->server->exec();
742 $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status,'Received an unexpected status. Full response body: ' . $this->response->body);
747 * @depends testSupportedReportSetProperty
748 * @depends testCalendarMultiGetReport
750 function testCalendarQueryReport1Object() {
753 '<?xml version="1.0"?>' .
754 '<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
756 ' <c:calendar-data>' .
757 ' <c:expand start="20000101T000000Z" end="20101231T235959Z" />' .
758 ' </c:calendar-data>' .
762 ' <c:comp-filter name="VCALENDAR">' .
763 ' <c:comp-filter name="VEVENT" />' .
764 ' </c:comp-filter>' .
766 '</c:calendar-query>';
768 $request = new Sabre_HTTP_Request(array(
769 'REQUEST_METHOD' => 'REPORT',
770 'REQUEST_URI' => '/calendars/user1/UUID-123467/UUID-2345',
773 $request->setBody($body);
775 $this->server->httpRequest = $request;
776 $this->server->exec();
778 $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Received an unexpected status. Full response body: ' . $this->response->body);
780 $xml = simplexml_load_string(Sabre_DAV_XMLUtil::convertDAVNamespace($this->response->body));
782 $xml->registerXPathNamespace('d','urn:DAV');
783 $xml->registerXPathNamespace('c','urn:ietf:params:xml:ns:caldav');
787 '/d:multistatus/d:response',
788 '/d:multistatus/d:response/d:href',
789 '/d:multistatus/d:response/d:propstat',
790 '/d:multistatus/d:response/d:propstat/d:prop',
791 '/d:multistatus/d:response/d:propstat/d:prop/d:getetag',
792 '/d:multistatus/d:response/d:propstat/d:prop/c:calendar-data',
793 '/d:multistatus/d:response/d:propstat/d:status' => 'HTTP/1.1 200 OK',
796 foreach($check as $v1=>$v2) {
798 $xpath = is_int($v1)?$v2:$v1;
800 $result = $xml->xpath($xpath);
801 $this->assertEquals(1,count($result), 'We expected 1 ' . $xpath . ' elements. We\'ve found ' . count($result) . '. Full result: ' . $this->response->body);
803 if (!is_int($v1)) $this->assertEquals($v2,(string)$result[0]);
810 * @depends testSupportedReportSetProperty
811 * @depends testCalendarMultiGetReport
813 function testCalendarQueryReport1ObjectNoCalData() {
816 '<?xml version="1.0"?>' .
817 '<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
822 ' <c:comp-filter name="VCALENDAR">' .
823 ' <c:comp-filter name="VEVENT" />' .
824 ' </c:comp-filter>' .
826 '</c:calendar-query>';
828 $request = new Sabre_HTTP_Request(array(
829 'REQUEST_METHOD' => 'REPORT',
830 'REQUEST_URI' => '/calendars/user1/UUID-123467/UUID-2345',
833 $request->setBody($body);
835 $this->server->httpRequest = $request;
836 $this->server->exec();
838 $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Received an unexpected status. Full response body: ' . $this->response->body);
840 $xml = simplexml_load_string(Sabre_DAV_XMLUtil::convertDAVNamespace($this->response->body));
842 $xml->registerXPathNamespace('d','urn:DAV');
843 $xml->registerXPathNamespace('c','urn:ietf:params:xml:ns:caldav');
847 '/d:multistatus/d:response',
848 '/d:multistatus/d:response/d:href',
849 '/d:multistatus/d:response/d:propstat',
850 '/d:multistatus/d:response/d:propstat/d:prop',
851 '/d:multistatus/d:response/d:propstat/d:prop/d:getetag',
852 '/d:multistatus/d:response/d:propstat/d:status' => 'HTTP/1.1 200 OK',
855 foreach($check as $v1=>$v2) {
857 $xpath = is_int($v1)?$v2:$v1;
859 $result = $xml->xpath($xpath);
860 $this->assertEquals(1,count($result), 'We expected 1 ' . $xpath . ' elements. We\'ve found ' . count($result) . '. Full result: ' . $this->response->body);
862 if (!is_int($v1)) $this->assertEquals($v2,(string)$result[0]);
868 function testHTMLActionsPanel() {
871 $r = $this->server->broadcastEvent('onHTMLActionsPanel', array($this->server->tree->getNodeForPath('calendars/user1'), &$output));
872 $this->assertFalse($r);
874 $this->assertTrue(!!strpos($output,'Display name'));
878 function testBrowserPostAction() {
880 $r = $this->server->broadcastEvent('onBrowserPostAction', array('calendars/user1', 'mkcalendar', array(
881 'name' => 'NEWCALENDAR',
882 '{DAV:}displayname' => 'foo',
884 $this->assertFalse($r);
886 $calendars = $this->caldavBackend->getCalendarsForUser('principals/user1');
887 $this->assertEquals(3, count($calendars));
890 foreach($calendars as $calendar) {
891 if ($calendar['uri'] === 'NEWCALENDAR') {
892 $newCalendar = $calendar;
897 $this->fail('Could not find newly created calendar');
903 * @depends testCalendarMultiGetReport
905 function testCalendarMultiGetReportNoEnd() {
908 '<?xml version="1.0"?>' .
909 '<c:calendar-multiget xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
911 ' <c:calendar-data>' .
912 ' <c:expand start="20110101T000000Z" />' .
913 ' </c:calendar-data>' .
916 '<d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>' .
917 '</c:calendar-multiget>';
919 $request = new Sabre_HTTP_Request(array(
920 'REQUEST_METHOD' => 'REPORT',
921 'REQUEST_URI' => '/calendars/user1',
924 $request->setBody($body);
926 $this->server->httpRequest = $request;
927 $this->server->exec();
929 $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status,'Invalid HTTP status received. Full response body: ' . $this->response->body);
934 * @depends testCalendarMultiGetReport
936 function testCalendarMultiGetReportNoStart() {
939 '<?xml version="1.0"?>' .
940 '<c:calendar-multiget xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
942 ' <c:calendar-data>' .
943 ' <c:expand end="20110101T000000Z" />' .
944 ' </c:calendar-data>' .
947 '<d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>' .
948 '</c:calendar-multiget>';
950 $request = new Sabre_HTTP_Request(array(
951 'REQUEST_METHOD' => 'REPORT',
952 'REQUEST_URI' => '/calendars/user1',
955 $request->setBody($body);
957 $this->server->httpRequest = $request;
958 $this->server->exec();
960 $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status,'Invalid HTTP status received. Full response body: ' . $this->response->body);
965 * @depends testCalendarMultiGetReport
967 function testCalendarMultiGetReportEndBeforeStart() {
970 '<?xml version="1.0"?>' .
971 '<c:calendar-multiget xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">' .
973 ' <c:calendar-data>' .
974 ' <c:expand start="20200101T000000Z" end="20110101T000000Z" />' .
975 ' </c:calendar-data>' .
978 '<d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>' .
979 '</c:calendar-multiget>';
981 $request = new Sabre_HTTP_Request(array(
982 'REQUEST_METHOD' => 'REPORT',
983 'REQUEST_URI' => '/calendars/user1',
986 $request->setBody($body);
988 $this->server->httpRequest = $request;
989 $this->server->exec();
991 $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status,'Invalid HTTP status received. Full response body: ' . $this->response->body);