]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/CalDAV/Issue203Test.php
Second part of refactoring; should be runnable again, yet not thoroughly tested
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / CalDAV / Issue203Test.php
1 <?php
2
3 use Sabre\VObject;
4
5 /**
6  * This unittest is created to find out why an overwritten DAILY event has wrong DTSTART, DTEND, SUMMARY and RECURRENCEID
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_Issue203Test 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 UID:20120330T155305CEST-6585fBUVgV
33 DTSTAMP:20120330T135305Z
34 DTSTART;TZID=Europe/Berlin:20120326T155200
35 DTEND;TZID=Europe/Berlin:20120326T165200
36 RRULE:FREQ=DAILY;COUNT=2;INTERVAL=1
37 SUMMARY:original summary
38 TRANSP:OPAQUE
39 END:VEVENT
40 BEGIN:VEVENT
41 UID:20120330T155305CEST-6585fBUVgV
42 DTSTAMP:20120330T135352Z
43 DESCRIPTION:
44 DTSTART;TZID=Europe/Berlin:20120328T155200
45 DTEND;TZID=Europe/Berlin:20120328T165200
46 RECURRENCE-ID;TZID=Europe/Berlin:20120327T155200
47 SEQUENCE:1
48 SUMMARY:overwritten summary
49 TRANSP:OPAQUE
50 END:VEVENT
51 END:VCALENDAR
52 ',
53             ),
54         ),
55     );
56
57     function testIssue203() {
58
59         $request = new Sabre_HTTP_Request(array(
60             'REQUEST_METHOD' => 'REPORT',
61             'HTTP_CONTENT_TYPE' => 'application/xml',
62             'REQUEST_URI' => '/calendars/user1/calendar1',
63             'HTTP_DEPTH' => '1',
64         ));
65
66         $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
67 <C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
68     <D:prop>
69         <C:calendar-data>
70             <C:expand start="20120325T220000Z" end="20120401T215959Z"/>
71         </C:calendar-data>
72         <D:getetag/>
73     </D:prop>
74     <C:filter>
75         <C:comp-filter name="VCALENDAR">
76             <C:comp-filter name="VEVENT">
77                 <C:time-range start="20120325T220000Z" end="20120401T215959Z"/>
78             </C:comp-filter>
79         </C:comp-filter>
80     </C:filter>
81 </C:calendar-query>');
82
83         $response = $this->request($request);
84
85         // Everts super awesome xml parser.
86         $body = substr(
87             $response->body,
88             $start = strpos($response->body, 'BEGIN:VCALENDAR'),
89             strpos($response->body, 'END:VCALENDAR') - $start + 13
90         );
91         $body = str_replace('&#13;','',$body);
92
93         $vObject = VObject\Reader::read($body);
94
95         $this->assertEquals(2, count($vObject->VEVENT));
96
97
98         $expectedEvents = array(
99             array(
100                 'DTSTART' => '20120326T135200Z',
101                 'DTEND'   => '20120326T145200Z',
102                 'SUMMARY' => 'original summary',
103             ),
104             array(
105                 'DTSTART'       => '20120328T135200Z',
106                 'DTEND'         => '20120328T145200Z',
107                 'SUMMARY'       => 'overwritten summary',
108                 'RECURRENCE-ID' => '20120327T135200Z',
109             )
110         );
111
112         // try to match agains $expectedEvents array
113         foreach ($expectedEvents as $expectedEvent) {
114
115             $matching = false;
116
117             foreach ($vObject->VEVENT as $vevent) {
118                 /** @var $vevent Sabre\VObject\Component\VEvent */
119
120                 foreach ($vevent->children as $child) {
121                     /** @var $child Sabre\VObject\Property */
122
123                     if (isset($expectedEvent[$child->name])) {
124                         if ($expectedEvent[$child->name] != $child->value) {
125                             continue 2;
126                         }
127                     }
128                 }
129
130                 $matching = true;
131                 break;
132             }
133
134             $this->assertTrue($matching, 'Did not find the following event in the response: '.var_export($expectedEvent, true));
135         }
136     }
137 }