]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDbyDayTest.php
Initial Release of the calendar plugin
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / CalDAV / ExpandEventsDTSTARTandDTENDbyDayTest.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_ExpandEventsDTSTARTandDTENDbyDayTest 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=WEEKLY;INTERVAL=1;BYDAY=TU,TH
33 SUMMARY:RecurringEvents on tuesday and thursday
34 DTSTART;TZID=Europe/Berlin:20120207T181500
35 END:VEVENT
36 END:VCALENDAR
37 ',
38             ),
39         ),
40     );
41
42     function testExpandRecurringByDayEvent() {
43
44         $request = new Sabre_HTTP_Request(array(
45             'REQUEST_METHOD' => 'REPORT',
46             'HTTP_CONTENT_TYPE' => 'application/xml',
47             'REQUEST_URI' => '/calendars/user1/calendar1',
48             'HTTP_DEPTH' => '1',
49         ));
50
51         $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
52 <C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
53     <D:prop>
54         <C:calendar-data>
55             <C:expand start="20120210T230000Z" end="20120217T225959Z"/>
56         </C:calendar-data>
57         <D:getetag/>
58     </D:prop>
59     <C:filter>
60         <C:comp-filter name="VCALENDAR">
61             <C:comp-filter name="VEVENT">
62                 <C:time-range start="20120210T230000Z" end="20120217T225959Z"/>
63             </C:comp-filter>
64         </C:comp-filter>
65     </C:filter>
66 </C:calendar-query>');
67
68         $response = $this->request($request);
69
70         // Everts super awesome xml parser.
71         $body = substr(
72             $response->body,
73             $start = strpos($response->body, 'BEGIN:VCALENDAR'),
74             strpos($response->body, 'END:VCALENDAR') - $start + 13
75         );
76         $body = str_replace('&#13;','',$body);
77
78         $vObject = Sabre_VObject_Reader::read($body);
79
80         $this->assertEquals(2, count($vObject->VEVENT));
81
82         // check if DTSTARTs and DTENDs are correct
83         foreach ($vObject->VEVENT as $vevent) {
84             /** @var $vevent Sabre_VObject_Component_VEvent */
85             foreach ($vevent->children as $child) {
86                 /** @var $child Sabre_VObject_Property */
87
88                 if ($child->name == 'DTSTART') {
89                     // DTSTART has to be one of two valid values
90                     $this->assertContains($child->value, array('20120214T171500Z', '20120216T171500Z'), 'DTSTART is not a valid value: '.$child->value);
91                 } elseif ($child->name == 'DTEND') {
92                     // DTEND has to be one of two valid values
93                     $this->assertContains($child->value, array('20120214T181500Z', '20120216T181500Z'), 'DTEND is not a valid value: '.$child->value);
94                 }
95             }
96         }
97     }
98
99 }
100