]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDTest.php
Merge pull request #57 from CatoTH/master
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / CalDAV / ExpandEventsDTSTARTandDTENDTest.php
1 <?php
2
3 /**
4  * This unittests is created to find out why recurring events have wrong DTSTART value
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_ExpandEventsDTSTARTandDTENDTest 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:foobar
31 DTEND;TZID=Europe/Berlin:20120207T191500
32 RRULE:FREQ=DAILY;INTERVAL=1;COUNT=3
33 SUMMARY:RecurringEvents 3 times
34 DTSTART;TZID=Europe/Berlin:20120207T181500
35 END:VEVENT
36 BEGIN:VEVENT
37 CREATED:20120207T111900Z
38 UID:foobar
39 DTEND;TZID=Europe/Berlin:20120208T191500
40 SUMMARY:RecurringEvents 3 times OVERWRITTEN
41 DTSTART;TZID=Europe/Berlin:20120208T181500
42 RECURRENCE-ID;TZID=Europe/Berlin:20120208T181500
43 END:VEVENT
44 END:VCALENDAR
45 ',
46             ),
47         ),
48     );
49
50     function testExpand() {
51
52         $request = new Sabre_HTTP_Request(array(
53             'REQUEST_METHOD' => 'REPORT',
54             'HTTP_CONTENT_TYPE' => 'application/xml',
55             'REQUEST_URI' => '/calendars/user1/calendar1',
56             'HTTP_DEPTH' => '1',
57         ));
58
59         $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
60 <C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
61     <D:prop>
62         <C:calendar-data>
63             <C:expand start="20120205T230000Z" end="20120212T225959Z"/>
64         </C:calendar-data>
65         <D:getetag/>
66     </D:prop>
67     <C:filter>
68         <C:comp-filter name="VCALENDAR">
69             <C:comp-filter name="VEVENT">
70                 <C:time-range start="20120205T230000Z" end="20120212T225959Z"/>
71             </C:comp-filter>
72         </C:comp-filter>
73     </C:filter>
74 </C:calendar-query>');
75
76         $response = $this->request($request);
77
78         // Everts super awesome xml parser.
79         $body = substr(
80             $response->body,
81             $start = strpos($response->body, 'BEGIN:VCALENDAR'),
82             strpos($response->body, 'END:VCALENDAR') - $start + 13
83         );
84         $body = str_replace('&#13;','',$body);
85
86         $vObject = Sabre_VObject_Reader::read($body);
87
88         // check if DTSTARTs and DTENDs are correct
89         foreach ($vObject->VEVENT as $vevent) {
90             /** @var $vevent Sabre_VObject_Component_VEvent */
91             foreach ($vevent->children as $child) {
92                 /** @var $child Sabre_VObject_Property */
93
94                 if ($child->name == 'DTSTART') {
95                     // DTSTART has to be one of three valid values
96                     $this->assertContains($child->value, array('20120207T171500Z', '20120208T171500Z', '20120209T171500Z'), 'DTSTART is not a valid value: '.$child->value);
97                 } elseif ($child->name == 'DTEND') {
98                     // DTEND has to be one of three valid values
99                     $this->assertContains($child->value, array('20120207T181500Z', '20120208T181500Z', '20120209T181500Z'), 'DTEND is not a valid value: '.$child->value);
100                 }
101             }
102         }
103     }
104
105 }
106