]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/CalDAV/GetEventsByTimerangeTest.php
Second part of refactoring; should be runnable again, yet not thoroughly tested
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / CalDAV / GetEventsByTimerangeTest.php
1 <?php
2
3 use Sabre\VObject;
4
5 /**
6  * This unittest is created to check if queries for time-range include the start timestamp or not
7  *
8  *
9  * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
10  * @author Evert Pot (http://www.rooftopsolutions.nl/)
11  * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
12  */
13 class Sabre_CalDAV_GetEventsByTimerangeTest extends Sabre_DAVServerTest {
14
15     protected $setupCalDAV = true;
16
17     protected $caldavCalendars = array(
18         array(
19             'id' => 1,
20             'name' => 'Calendar',
21             'principaluri' => 'principals/user1',
22             'uri' => 'calendar1',
23         )
24     );
25
26     protected $caldavCalendarObjects = array(
27         1 => array(
28            'event.ics' => array(
29                 'calendardata' => 'BEGIN:VCALENDAR
30 VERSION:2.0
31 BEGIN:VEVENT
32 CREATED:20120313T142342Z
33 UID:171EBEFC-C951-499D-B234-7BA7D677B45D
34 DTEND;TZID=Europe/Berlin:20120227T000000
35 TRANSP:OPAQUE
36 SUMMARY:Monday 0h
37 DTSTART;TZID=Europe/Berlin:20120227T000000
38 DTSTAMP:20120313T142416Z
39 SEQUENCE:4
40 END:VEVENT
41 END:VCALENDAR
42 ',
43             ),
44         ),
45     );
46
47     function testQueryTimerange() {
48
49         $request = new Sabre_HTTP_Request(array(
50             'REQUEST_METHOD' => 'REPORT',
51             'HTTP_CONTENT_TYPE' => 'application/xml',
52             'REQUEST_URI' => '/calendars/user1/calendar1',
53             'HTTP_DEPTH' => '1',
54         ));
55
56         $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
57 <C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
58     <D:prop>
59         <C:calendar-data>
60             <C:expand start="20120226T230000Z" end="20120228T225959Z"/>
61         </C:calendar-data>
62         <D:getetag/>
63     </D:prop>
64     <C:filter>
65         <C:comp-filter name="VCALENDAR">
66             <C:comp-filter name="VEVENT">
67                 <C:time-range start="20120226T230000Z" end="20120228T225959Z"/>
68             </C:comp-filter>
69         </C:comp-filter>
70     </C:filter>
71 </C:calendar-query>');
72
73         $response = $this->request($request);
74
75         if (strpos($response->body, 'BEGIN:VCALENDAR') === false) {
76             $this->fail('Got no events instead of 1. Output: '.$response->body);
77         }
78
79         // Everts super awesome xml parser.
80         $body = substr(
81             $response->body,
82             $start = strpos($response->body, 'BEGIN:VCALENDAR'),
83             strpos($response->body, 'END:VCALENDAR') - $start + 13
84         );
85         $body = str_replace('&#13;','',$body);
86
87         $vObject = VObject\Reader::read($body);
88
89         // We expect 1 event
90         $this->assertEquals(1, count($vObject->VEVENT), 'We got 0 events instead of 1. Output: ' . $body);
91
92     }
93
94 }
95