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