ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ExpandEventsFloatingTimeTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\CalDAV;
4 
5 use Sabre\HTTP;
6 use Sabre\VObject;
7 
13 
14  protected $setupCalDAV = true;
15 
16  protected $setupCalDAVICSExport = true;
17 
18  protected $caldavCalendars = [
19  [
20  'id' => 1,
21  'name' => 'Calendar',
22  'principaluri' => 'principals/user1',
23  'uri' => 'calendar1',
24  '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => 'BEGIN:VCALENDAR
25 VERSION:2.0
26 CALSCALE:GREGORIAN
27 BEGIN:VTIMEZONE
28 TZID:Europe/Berlin
29 BEGIN:DAYLIGHT
30 TZOFFSETFROM:+0100
31 RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
32 DTSTART:19810329T020000
33 TZNAME:GMT+2
34 TZOFFSETTO:+0200
35 END:DAYLIGHT
36 BEGIN:STANDARD
37 TZOFFSETFROM:+0200
38 RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
39 DTSTART:19961027T030000
40 TZNAME:GMT+1
41 TZOFFSETTO:+0100
42 END:STANDARD
43 END:VTIMEZONE
44 END:VCALENDAR',
45  ]
46  ];
47 
48  protected $caldavCalendarObjects = [
49  1 => [
50  'event.ics' => [
51  'calendardata' => 'BEGIN:VCALENDAR
52 VERSION:2.0
53 CALSCALE:GREGORIAN
54 BEGIN:VEVENT
55 CREATED:20140701T143658Z
56 UID:dba46fe8-1631-4d98-a575-97963c364dfe
57 DTEND:20141108T073000
58 TRANSP:OPAQUE
59 SUMMARY:Floating Time event, starting 05:30am Europe/Berlin
60 DTSTART:20141108T053000
61 DTSTAMP:20140701T143706Z
62 SEQUENCE:1
63 END:VEVENT
64 END:VCALENDAR
65 ',
66  ],
67  ],
68  ];
69 
70  function testExpandCalendarQuery() {
71 
72  $request = new HTTP\Request('REPORT', '/calendars/user1/calendar1', [
73  'Depth' => 1,
74  'Content-Type' => 'application/xml',
75  ]);
76 
77  $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
78 <C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
79  <D:prop>
80  <C:calendar-data>
81  <C:expand start="20141107T230000Z" end="20141108T225959Z"/>
82  </C:calendar-data>
83  <D:getetag/>
84  </D:prop>
85  <C:filter>
86  <C:comp-filter name="VCALENDAR">
87  <C:comp-filter name="VEVENT">
88  <C:time-range start="20141107T230000Z" end="20141108T225959Z"/>
89  </C:comp-filter>
90  </C:comp-filter>
91  </C:filter>
92 </C:calendar-query>');
93 
94  $response = $this->request($request);
95 
96  // Everts super awesome xml parser.
97  $body = substr(
98  $response->body,
99  $start = strpos($response->body, 'BEGIN:VCALENDAR'),
100  strpos($response->body, 'END:VCALENDAR') - $start + 13
101  );
102  $body = str_replace('&#13;', '', $body);
103 
104  $vObject = VObject\Reader::read($body);
105 
106  // check if DTSTARTs and DTENDs are correct
107  foreach ($vObject->VEVENT as $vevent) {
109  foreach ($vevent->children() as $child) {
111  if ($child->name == 'DTSTART') {
112  // DTSTART should be the UTC equivalent of given floating time
113  $this->assertEquals('20141108T043000Z', $child->getValue());
114  } elseif ($child->name == 'DTEND') {
115  // DTEND should be the UTC equivalent of given floating time
116  $this->assertEquals('20141108T063000Z', $child->getValue());
117  }
118  }
119  }
120  }
121 
122  function testExpandMultiGet() {
123 
124  $request = new HTTP\Request('REPORT', '/calendars/user1/calendar1', [
125  'Depth' => 1,
126  'Content-Type' => 'application/xml',
127  ]);
128 
129  $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
130 <C:calendar-multiget xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
131  <D:prop>
132  <C:calendar-data>
133  <C:expand start="20141107T230000Z" end="20141108T225959Z"/>
134  </C:calendar-data>
135  <D:getetag/>
136  </D:prop>
137  <D:href>/calendars/user1/calendar1/event.ics</D:href>
138 </C:calendar-multiget>');
139 
140  $response = $this->request($request);
141 
142  $this->assertEquals(207, $response->getStatus());
143 
144  // Everts super awesome xml parser.
145  $body = substr(
146  $response->body,
147  $start = strpos($response->body, 'BEGIN:VCALENDAR'),
148  strpos($response->body, 'END:VCALENDAR') - $start + 13
149  );
150  $body = str_replace('&#13;', '', $body);
151 
152  $vObject = VObject\Reader::read($body);
153 
154  // check if DTSTARTs and DTENDs are correct
155  foreach ($vObject->VEVENT as $vevent) {
157  foreach ($vevent->children() as $child) {
159  if ($child->name == 'DTSTART') {
160  // DTSTART should be the UTC equivalent of given floating time
161  $this->assertEquals($child->getValue(), '20141108T043000Z');
162  } elseif ($child->name == 'DTEND') {
163  // DTEND should be the UTC equivalent of given floating time
164  $this->assertEquals($child->getValue(), '20141108T063000Z');
165  }
166  }
167  }
168  }
169 
170  function testExpandExport() {
171 
172  $request = new HTTP\Request('GET', '/calendars/user1/calendar1?export&start=1&end=2000000000&expand=1', [
173  'Depth' => 1,
174  'Content-Type' => 'application/xml',
175  ]);
176 
177  $response = $this->request($request);
178 
179  $this->assertEquals(200, $response->getStatus());
180 
181  // Everts super awesome xml parser.
182  $body = substr(
183  $response->body,
184  $start = strpos($response->body, 'BEGIN:VCALENDAR'),
185  strpos($response->body, 'END:VCALENDAR') - $start + 13
186  );
187  $body = str_replace('&#13;', '', $body);
188 
189  $vObject = VObject\Reader::read($body);
190 
191  // check if DTSTARTs and DTENDs are correct
192  foreach ($vObject->VEVENT as $vevent) {
194  foreach ($vevent->children() as $child) {
196  if ($child->name == 'DTSTART') {
197  // DTSTART should be the UTC equivalent of given floating time
198  $this->assertEquals('20141108T043000Z', $child->getValue());
199  } elseif ($child->name == 'DTEND') {
200  // DTEND should be the UTC equivalent of given floating time
201  $this->assertEquals('20141108T063000Z', $child->getValue());
202  }
203  }
204  }
205  }
206 
207 }
foreach($paths as $path) $request
Definition: asyncclient.php:32
$start
Definition: bench.php:8
This class may be used as a basis for other webdav-related unittests.
This unittest is created to check if expand() works correctly with floating times (using calendar-tim...
static read($data, $options=0, $charset='UTF-8')
Parses a vCard or iCalendar object, and returns the top component.
Definition: Reader.php:42
request($request, $expectedStatus=null)
Makes a request, and returns a response object.
$response