]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/CalDAV/GetEventsByTimerangeTest.php
Move friendica-specific parts into an own subdirectory
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / CalDAV / GetEventsByTimerangeTest.php
1 <?php
2
3 /**
4  * This unittest is created to check if queries for time-range include the start timestamp or not
5  *
6  *
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
10  */
11 class Sabre_CalDAV_GetEventsByTimerangeTest extends Sabre_DAVServerTest {
12
13     protected $setupCalDAV = true;
14
15     protected $caldavCalendars = array(
16         array(
17             'id' => 1,
18             'name' => 'Calendar',
19             'principaluri' => 'principals/user1',
20             'uri' => 'calendar1',
21         )
22     );
23
24     protected $caldavCalendarObjects = array(
25         1 => array(
26            'event.ics' => array(
27                 'calendardata' => 'BEGIN:VCALENDAR
28 VERSION:2.0
29 BEGIN:VEVENT
30 CREATED:20120313T142342Z
31 UID:171EBEFC-C951-499D-B234-7BA7D677B45D
32 DTEND;TZID=Europe/Berlin:20120227T000000
33 TRANSP:OPAQUE
34 SUMMARY:Monday 0h
35 DTSTART;TZID=Europe/Berlin:20120227T000000
36 DTSTAMP:20120313T142416Z
37 SEQUENCE:4
38 END:VEVENT
39 END:VCALENDAR
40 ',
41             ),
42         ),
43     );
44
45     function testQueryTimerange() {
46
47         $request = new Sabre_HTTP_Request(array(
48             'REQUEST_METHOD' => 'REPORT',
49             'HTTP_CONTENT_TYPE' => 'application/xml',
50             'REQUEST_URI' => '/calendars/user1/calendar1',
51             'HTTP_DEPTH' => '1',
52         ));
53
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">
56     <D:prop>
57         <C:calendar-data>
58             <C:expand start="20120226T230000Z" end="20120228T225959Z"/>
59         </C:calendar-data>
60         <D:getetag/>
61     </D:prop>
62     <C:filter>
63         <C:comp-filter name="VCALENDAR">
64             <C:comp-filter name="VEVENT">
65                 <C:time-range start="20120226T230000Z" end="20120228T225959Z"/>
66             </C:comp-filter>
67         </C:comp-filter>
68     </C:filter>
69 </C:calendar-query>');
70
71         $response = $this->request($request);
72
73         if (strpos($response->body, 'BEGIN:VCALENDAR') === false) {
74             $this->fail('Got no events instead of 1. Output: '.$response->body);
75         }
76
77         // Everts super awesome xml parser.
78         $body = substr(
79             $response->body,
80             $start = strpos($response->body, 'BEGIN:VCALENDAR'),
81             strpos($response->body, 'END:VCALENDAR') - $start + 13
82         );
83         $body = str_replace('&#13;','',$body);
84
85         $vObject = Sabre_VObject_Reader::read($body);
86
87         // We expect 1 event
88         $this->assertEquals(1, count($vObject->VEVENT), 'We got 0 events instead of 1. Output: ' . $body);
89
90     }
91
92 }
93