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