4 * This unittest is created to check if queries for time-range include the start timestamp or not
7 * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
8 * @author Evert Pot (http://www.rooftopsolutions.nl/)
9 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
11 class Sabre_CalDAV_GetEventsByTimerangeTest extends Sabre_DAVServerTest {
13 protected $setupCalDAV = true;
15 protected $caldavCalendars = array(
19 'principaluri' => 'principals/user1',
24 protected $caldavCalendarObjects = array(
27 'calendardata' => 'BEGIN:VCALENDAR
30 CREATED:20120313T142342Z
31 UID:171EBEFC-C951-499D-B234-7BA7D677B45D
32 DTEND;TZID=Europe/Berlin:20120227T000000
35 DTSTART;TZID=Europe/Berlin:20120227T000000
36 DTSTAMP:20120313T142416Z
45 function testQueryTimerange() {
47 $request = new Sabre_HTTP_Request(array(
48 'REQUEST_METHOD' => 'REPORT',
49 'HTTP_CONTENT_TYPE' => 'application/xml',
50 'REQUEST_URI' => '/calendars/user1/calendar1',
54 $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
55 <C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
58 <C:expand start="20120226T230000Z" end="20120228T225959Z"/>
63 <C:comp-filter name="VCALENDAR">
64 <C:comp-filter name="VEVENT">
65 <C:time-range start="20120226T230000Z" end="20120228T225959Z"/>
69 </C:calendar-query>');
71 $response = $this->request($request);
73 if (strpos($response->body, 'BEGIN:VCALENDAR') === false) {
74 $this->fail('Got no events instead of 1. Output: '.$response->body);
77 // Everts super awesome xml parser.
80 $start = strpos($response->body, 'BEGIN:VCALENDAR'),
81 strpos($response->body, 'END:VCALENDAR') - $start + 13
83 $body = str_replace(' ','',$body);
85 $vObject = Sabre_VObject_Reader::read($body);
88 $this->assertEquals(1, count($vObject->VEVENT), 'We got 0 events instead of 1. Output: ' . $body);