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