xref: /plugin/davcal/vendor/sabre/dav/tests/Sabre/CalDAV/ExpandEventsFloatingTimeTest.php (revision a1a3b6794e0e143a4a8b51d3185ce2d339be61ab)
1*a1a3b679SAndreas Boehler<?php
2*a1a3b679SAndreas Boehler
3*a1a3b679SAndreas Boehlernamespace Sabre\CalDAV;
4*a1a3b679SAndreas Boehleruse Sabre\HTTP;
5*a1a3b679SAndreas Boehleruse Sabre\VObject;
6*a1a3b679SAndreas Boehler
7*a1a3b679SAndreas Boehler/**
8*a1a3b679SAndreas Boehler * This unittest is created to check if expand() works correctly with
9*a1a3b679SAndreas Boehler * floating times (using calendar-timezone information).
10*a1a3b679SAndreas Boehler */
11*a1a3b679SAndreas Boehlerclass ExpandEventsFloatingTimeTest extends \Sabre\DAVServerTest {
12*a1a3b679SAndreas Boehler
13*a1a3b679SAndreas Boehler    protected $setupCalDAV = true;
14*a1a3b679SAndreas Boehler
15*a1a3b679SAndreas Boehler    protected $setupCalDAVICSExport = true;
16*a1a3b679SAndreas Boehler
17*a1a3b679SAndreas Boehler    protected $caldavCalendars = array(
18*a1a3b679SAndreas Boehler        array(
19*a1a3b679SAndreas Boehler            'id' => 1,
20*a1a3b679SAndreas Boehler            'name' => 'Calendar',
21*a1a3b679SAndreas Boehler            'principaluri' => 'principals/user1',
22*a1a3b679SAndreas Boehler            'uri' => 'calendar1',
23*a1a3b679SAndreas Boehler            '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => 'BEGIN:VCALENDAR
24*a1a3b679SAndreas BoehlerVERSION:2.0
25*a1a3b679SAndreas BoehlerCALSCALE:GREGORIAN
26*a1a3b679SAndreas BoehlerBEGIN:VTIMEZONE
27*a1a3b679SAndreas BoehlerTZID:Europe/Berlin
28*a1a3b679SAndreas BoehlerBEGIN:DAYLIGHT
29*a1a3b679SAndreas BoehlerTZOFFSETFROM:+0100
30*a1a3b679SAndreas BoehlerRRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
31*a1a3b679SAndreas BoehlerDTSTART:19810329T020000
32*a1a3b679SAndreas BoehlerTZNAME:GMT+2
33*a1a3b679SAndreas BoehlerTZOFFSETTO:+0200
34*a1a3b679SAndreas BoehlerEND:DAYLIGHT
35*a1a3b679SAndreas BoehlerBEGIN:STANDARD
36*a1a3b679SAndreas BoehlerTZOFFSETFROM:+0200
37*a1a3b679SAndreas BoehlerRRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
38*a1a3b679SAndreas BoehlerDTSTART:19961027T030000
39*a1a3b679SAndreas BoehlerTZNAME:GMT+1
40*a1a3b679SAndreas BoehlerTZOFFSETTO:+0100
41*a1a3b679SAndreas BoehlerEND:STANDARD
42*a1a3b679SAndreas BoehlerEND:VTIMEZONE
43*a1a3b679SAndreas BoehlerEND:VCALENDAR',
44*a1a3b679SAndreas Boehler        )
45*a1a3b679SAndreas Boehler    );
46*a1a3b679SAndreas Boehler
47*a1a3b679SAndreas Boehler    protected $caldavCalendarObjects = array(
48*a1a3b679SAndreas Boehler        1 => array(
49*a1a3b679SAndreas Boehler           'event.ics' => array(
50*a1a3b679SAndreas Boehler                'calendardata' => 'BEGIN:VCALENDAR
51*a1a3b679SAndreas BoehlerVERSION:2.0
52*a1a3b679SAndreas BoehlerCALSCALE:GREGORIAN
53*a1a3b679SAndreas BoehlerBEGIN:VEVENT
54*a1a3b679SAndreas BoehlerCREATED:20140701T143658Z
55*a1a3b679SAndreas BoehlerUID:dba46fe8-1631-4d98-a575-97963c364dfe
56*a1a3b679SAndreas BoehlerDTEND:20141108T073000
57*a1a3b679SAndreas BoehlerTRANSP:OPAQUE
58*a1a3b679SAndreas BoehlerSUMMARY:Floating Time event, starting 05:30am Europe/Berlin
59*a1a3b679SAndreas BoehlerDTSTART:20141108T053000
60*a1a3b679SAndreas BoehlerDTSTAMP:20140701T143706Z
61*a1a3b679SAndreas BoehlerSEQUENCE:1
62*a1a3b679SAndreas BoehlerEND:VEVENT
63*a1a3b679SAndreas BoehlerEND:VCALENDAR
64*a1a3b679SAndreas Boehler',
65*a1a3b679SAndreas Boehler            ),
66*a1a3b679SAndreas Boehler        ),
67*a1a3b679SAndreas Boehler    );
68*a1a3b679SAndreas Boehler
69*a1a3b679SAndreas Boehler    function testExpandCalendarQuery() {
70*a1a3b679SAndreas Boehler
71*a1a3b679SAndreas Boehler        $request = new HTTP\Request('REPORT', '/calendars/user1/calendar1', [
72*a1a3b679SAndreas Boehler            'Depth' => 1,
73*a1a3b679SAndreas Boehler            'Content-Type' => 'application/xml',
74*a1a3b679SAndreas Boehler        ]);
75*a1a3b679SAndreas Boehler
76*a1a3b679SAndreas Boehler        $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
77*a1a3b679SAndreas Boehler<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
78*a1a3b679SAndreas Boehler    <D:prop>
79*a1a3b679SAndreas Boehler        <C:calendar-data>
80*a1a3b679SAndreas Boehler            <C:expand start="20141107T230000Z" end="20141108T225959Z"/>
81*a1a3b679SAndreas Boehler        </C:calendar-data>
82*a1a3b679SAndreas Boehler        <D:getetag/>
83*a1a3b679SAndreas Boehler    </D:prop>
84*a1a3b679SAndreas Boehler    <C:filter>
85*a1a3b679SAndreas Boehler        <C:comp-filter name="VCALENDAR">
86*a1a3b679SAndreas Boehler            <C:comp-filter name="VEVENT">
87*a1a3b679SAndreas Boehler                <C:time-range start="20141107T230000Z" end="20141108T225959Z"/>
88*a1a3b679SAndreas Boehler            </C:comp-filter>
89*a1a3b679SAndreas Boehler        </C:comp-filter>
90*a1a3b679SAndreas Boehler    </C:filter>
91*a1a3b679SAndreas Boehler</C:calendar-query>');
92*a1a3b679SAndreas Boehler
93*a1a3b679SAndreas Boehler        $response = $this->request($request);
94*a1a3b679SAndreas Boehler
95*a1a3b679SAndreas Boehler        // Everts super awesome xml parser.
96*a1a3b679SAndreas Boehler        $body = substr(
97*a1a3b679SAndreas Boehler            $response->body,
98*a1a3b679SAndreas Boehler            $start = strpos($response->body, 'BEGIN:VCALENDAR'),
99*a1a3b679SAndreas Boehler            strpos($response->body, 'END:VCALENDAR') - $start + 13
100*a1a3b679SAndreas Boehler        );
101*a1a3b679SAndreas Boehler        $body = str_replace('&#13;','',$body);
102*a1a3b679SAndreas Boehler
103*a1a3b679SAndreas Boehler        $vObject = VObject\Reader::read($body);
104*a1a3b679SAndreas Boehler
105*a1a3b679SAndreas Boehler        // check if DTSTARTs and DTENDs are correct
106*a1a3b679SAndreas Boehler        foreach ($vObject->VEVENT as $vevent) {
107*a1a3b679SAndreas Boehler            /** @var $vevent Sabre\VObject\Component\VEvent */
108*a1a3b679SAndreas Boehler            foreach ($vevent->children as $child) {
109*a1a3b679SAndreas Boehler                /** @var $child Sabre\VObject\Property */
110*a1a3b679SAndreas Boehler
111*a1a3b679SAndreas Boehler                if ($child->name == 'DTSTART') {
112*a1a3b679SAndreas Boehler                    // DTSTART should be the UTC equivalent of given floating time
113*a1a3b679SAndreas Boehler                    $this->assertEquals($child->getValue(), '20141108T043000Z');
114*a1a3b679SAndreas Boehler                } elseif ($child->name == 'DTEND') {
115*a1a3b679SAndreas Boehler                    // DTEND should be the UTC equivalent of given floating time
116*a1a3b679SAndreas Boehler                    $this->assertEquals($child->getValue(), '20141108T063000Z');
117*a1a3b679SAndreas Boehler                }
118*a1a3b679SAndreas Boehler            }
119*a1a3b679SAndreas Boehler        }
120*a1a3b679SAndreas Boehler    }
121*a1a3b679SAndreas Boehler
122*a1a3b679SAndreas Boehler    function testExpandMultiGet() {
123*a1a3b679SAndreas Boehler
124*a1a3b679SAndreas Boehler        $request = new HTTP\Request('REPORT', '/calendars/user1/calendar1', [
125*a1a3b679SAndreas Boehler            'Depth' => 1,
126*a1a3b679SAndreas Boehler            'Content-Type' => 'application/xml',
127*a1a3b679SAndreas Boehler        ]);
128*a1a3b679SAndreas Boehler
129*a1a3b679SAndreas Boehler        $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
130*a1a3b679SAndreas Boehler<C:calendar-multiget xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
131*a1a3b679SAndreas Boehler    <D:prop>
132*a1a3b679SAndreas Boehler        <C:calendar-data>
133*a1a3b679SAndreas Boehler            <C:expand start="20141107T230000Z" end="20141108T225959Z"/>
134*a1a3b679SAndreas Boehler        </C:calendar-data>
135*a1a3b679SAndreas Boehler        <D:getetag/>
136*a1a3b679SAndreas Boehler    </D:prop>
137*a1a3b679SAndreas Boehler    <D:href>/calendars/user1/calendar1/event.ics</D:href>
138*a1a3b679SAndreas Boehler</C:calendar-multiget>');
139*a1a3b679SAndreas Boehler
140*a1a3b679SAndreas Boehler        $response = $this->request($request);
141*a1a3b679SAndreas Boehler
142*a1a3b679SAndreas Boehler        $this->assertEquals(207, $response->getStatus());
143*a1a3b679SAndreas Boehler
144*a1a3b679SAndreas Boehler        // Everts super awesome xml parser.
145*a1a3b679SAndreas Boehler        $body = substr(
146*a1a3b679SAndreas Boehler            $response->body,
147*a1a3b679SAndreas Boehler            $start = strpos($response->body, 'BEGIN:VCALENDAR'),
148*a1a3b679SAndreas Boehler            strpos($response->body, 'END:VCALENDAR') - $start + 13
149*a1a3b679SAndreas Boehler        );
150*a1a3b679SAndreas Boehler        $body = str_replace('&#13;','',$body);
151*a1a3b679SAndreas Boehler
152*a1a3b679SAndreas Boehler        $vObject = VObject\Reader::read($body);
153*a1a3b679SAndreas Boehler
154*a1a3b679SAndreas Boehler        // check if DTSTARTs and DTENDs are correct
155*a1a3b679SAndreas Boehler        foreach ($vObject->VEVENT as $vevent) {
156*a1a3b679SAndreas Boehler            /** @var $vevent Sabre\VObject\Component\VEvent */
157*a1a3b679SAndreas Boehler            foreach ($vevent->children as $child) {
158*a1a3b679SAndreas Boehler                /** @var $child Sabre\VObject\Property */
159*a1a3b679SAndreas Boehler
160*a1a3b679SAndreas Boehler                if ($child->name == 'DTSTART') {
161*a1a3b679SAndreas Boehler                    // DTSTART should be the UTC equivalent of given floating time
162*a1a3b679SAndreas Boehler                    $this->assertEquals($child->getValue(), '20141108T043000Z');
163*a1a3b679SAndreas Boehler                } elseif ($child->name == 'DTEND') {
164*a1a3b679SAndreas Boehler                    // DTEND should be the UTC equivalent of given floating time
165*a1a3b679SAndreas Boehler                    $this->assertEquals($child->getValue(), '20141108T063000Z');
166*a1a3b679SAndreas Boehler                }
167*a1a3b679SAndreas Boehler            }
168*a1a3b679SAndreas Boehler        }
169*a1a3b679SAndreas Boehler    }
170*a1a3b679SAndreas Boehler
171*a1a3b679SAndreas Boehler    function testExpandExport() {
172*a1a3b679SAndreas Boehler
173*a1a3b679SAndreas Boehler        $request = new HTTP\Request('GET', '/calendars/user1/calendar1?export&start=1&end=2000000000&expand=1', [
174*a1a3b679SAndreas Boehler            'Depth' => 1,
175*a1a3b679SAndreas Boehler            'Content-Type' => 'application/xml',
176*a1a3b679SAndreas Boehler        ]);
177*a1a3b679SAndreas Boehler
178*a1a3b679SAndreas Boehler        $response = $this->request($request);
179*a1a3b679SAndreas Boehler
180*a1a3b679SAndreas Boehler        $this->assertEquals(200, $response->getStatus());
181*a1a3b679SAndreas Boehler
182*a1a3b679SAndreas Boehler        // Everts super awesome xml parser.
183*a1a3b679SAndreas Boehler        $body = substr(
184*a1a3b679SAndreas Boehler            $response->body,
185*a1a3b679SAndreas Boehler            $start = strpos($response->body, 'BEGIN:VCALENDAR'),
186*a1a3b679SAndreas Boehler            strpos($response->body, 'END:VCALENDAR') - $start + 13
187*a1a3b679SAndreas Boehler        );
188*a1a3b679SAndreas Boehler        $body = str_replace('&#13;','',$body);
189*a1a3b679SAndreas Boehler
190*a1a3b679SAndreas Boehler        $vObject = VObject\Reader::read($body);
191*a1a3b679SAndreas Boehler
192*a1a3b679SAndreas Boehler        // check if DTSTARTs and DTENDs are correct
193*a1a3b679SAndreas Boehler        foreach ($vObject->VEVENT as $vevent) {
194*a1a3b679SAndreas Boehler            /** @var $vevent Sabre\VObject\Component\VEvent */
195*a1a3b679SAndreas Boehler            foreach ($vevent->children as $child) {
196*a1a3b679SAndreas Boehler                /** @var $child Sabre\VObject\Property */
197*a1a3b679SAndreas Boehler
198*a1a3b679SAndreas Boehler                if ($child->name == 'DTSTART') {
199*a1a3b679SAndreas Boehler                    // DTSTART should be the UTC equivalent of given floating time
200*a1a3b679SAndreas Boehler                    $this->assertEquals($child->getValue(), '20141108T043000Z');
201*a1a3b679SAndreas Boehler                } elseif ($child->name == 'DTEND') {
202*a1a3b679SAndreas Boehler                    // DTEND should be the UTC equivalent of given floating time
203*a1a3b679SAndreas Boehler                    $this->assertEquals($child->getValue(), '20141108T063000Z');
204*a1a3b679SAndreas Boehler                }
205*a1a3b679SAndreas Boehler            }
206*a1a3b679SAndreas Boehler        }
207*a1a3b679SAndreas Boehler    }
208*a1a3b679SAndreas Boehler
209*a1a3b679SAndreas Boehler}
210*a1a3b679SAndreas Boehler
211