ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ValidateICalTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\CalDAV;
4 
5 use Sabre\DAV;
6 use Sabre\DAVACL;
7 use Sabre\HTTP;
8 
9 require_once 'Sabre/HTTP/ResponseMock.php';
10 
12 
16  protected $server;
20  protected $calBackend;
21 
22  function setUp() {
23 
24  $calendars = [
25  [
26  'id' => 'calendar1',
27  'principaluri' => 'principals/admin',
28  'uri' => 'calendar1',
29  '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new Xml\Property\SupportedCalendarComponentSet(['VEVENT', 'VTODO', 'VJOURNAL']),
30  ],
31  [
32  'id' => 'calendar2',
33  'principaluri' => 'principals/admin',
34  'uri' => 'calendar2',
35  '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new Xml\Property\SupportedCalendarComponentSet(['VTODO', 'VJOURNAL']),
36  ]
37  ];
38 
39  $this->calBackend = new Backend\Mock($calendars, []);
41 
42  $tree = [
43  new CalendarRoot($principalBackend, $this->calBackend),
44  ];
45 
46  $this->server = new DAV\Server($tree);
47  $this->server->sapi = new HTTP\SapiMock();
48  $this->server->debugExceptions = true;
49 
50  $plugin = new Plugin();
51  $this->server->addPlugin($plugin);
52 
53  $response = new HTTP\ResponseMock();
54  $this->server->httpResponse = $response;
55 
56  }
57 
59 
60  $this->server->httpRequest = $request;
61  $this->server->exec();
62 
63  return $this->server->httpResponse;
64 
65  }
66 
67  function testCreateFile() {
68 
70  'REQUEST_METHOD' => 'PUT',
71  'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
72  ]);
73 
74  $response = $this->request($request);
75 
76  $this->assertEquals(415, $response->status);
77 
78  }
79 
80  function testCreateFileValid() {
81 
82  $request = new HTTP\Request(
83  'PUT',
84  '/calendars/admin/calendar1/blabla.ics',
85  ['Prefer' => 'handling=strict']
86  );
87 
88  $ics = <<<ICS
89 BEGIN:VCALENDAR
90 VERSION:2.0
91 PRODID:foo
92 BEGIN:VEVENT
93 UID:foo
94 DTSTAMP:20160406T052348Z
95 DTSTART:20160706T140000Z
96 END:VEVENT
97 END:VCALENDAR
98 ICS;
99 
100  $request->setBody($ics);
101 
102  $response = $this->request($request);
103 
104  $this->assertEquals(201, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
105  $this->assertEquals([
106  'X-Sabre-Version' => [DAV\Version::VERSION],
107  'Content-Length' => ['0'],
108  'ETag' => ['"' . md5($ics) . '"'],
109  ], $response->getHeaders());
110 
111  $expected = [
112  'uri' => 'blabla.ics',
113  'calendardata' => $ics,
114  'calendarid' => 'calendar1',
115  'lastmodified' => null,
116  ];
117 
118  $this->assertEquals($expected, $this->calBackend->getCalendarObject('calendar1', 'blabla.ics'));
119 
120  }
121 
123 
124  $request = new HTTP\Request(
125  'PUT',
126  '/calendars/admin/calendar1/blabla.ics',
127  ['Prefer' => 'handling=strict']
128  );
129 
130  $ics = <<<ICS
131 BEGIN:VCALENDAR
132 PRODID:foo
133 BEGIN:VEVENT
134 UID:foo
135 DTSTAMP:20160406T052348Z
136 DTSTART:20160706T140000Z
137 END:VEVENT
138 END:VCALENDAR
139 ICS;
140 
141  $request->setBody($ics);
142 
143  $response = $this->request($request);
144 
145  $this->assertEquals(415, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
146 
147  }
148 
150 
151  $request = new HTTP\Request(
152  'PUT',
153  '/calendars/admin/calendar1/blabla.ics',
154  ['Prefer' => 'handling=lenient']
155  );
156 
157  $ics = <<<ICS
158 BEGIN:VCALENDAR
159 PRODID:foo
160 BEGIN:VEVENT
161 UID:foo
162 DTSTAMP:20160406T052348Z
163 DTSTART:20160706T140000Z
164 END:VEVENT
165 END:VCALENDAR
166 ICS;
167 
168  $request->setBody($ics);
169 
170  $response = $this->request($request);
171 
172  $this->assertEquals(201, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
173  $this->assertEquals([
174  'X-Sabre-Version' => [DAV\Version::VERSION],
175  'Content-Length' => ['0'],
176  'X-Sabre-Ew-Gross' => ['iCalendar validation warning: VERSION MUST appear exactly once in a VCALENDAR component'],
177  ], $response->getHeaders());
178 
179  $ics = <<<ICS
180 BEGIN:VCALENDAR\r
181 VERSION:2.0\r
182 PRODID:foo\r
183 BEGIN:VEVENT\r
184 UID:foo\r
185 DTSTAMP:20160406T052348Z\r
186 DTSTART:20160706T140000Z\r
187 END:VEVENT\r
188 END:VCALENDAR\r
189 
190 ICS;
191 
192  $expected = [
193  'uri' => 'blabla.ics',
194  'calendardata' => $ics,
195  'calendarid' => 'calendar1',
196  'lastmodified' => null,
197  ];
198 
199  $this->assertEquals($expected, $this->calBackend->getCalendarObject('calendar1', 'blabla.ics'));
200 
201  }
202 
204 
205  $request = new HTTP\Request(
206  'PUT',
207  '/calendars/admin/calendar1/blabla.ics',
208  ['Prefer' => 'handling=strict']
209  );
210  $ics = <<<ICS
211 BEGIN:VCALENDAR
212 VERSION:2.0
213 PRODID:foo
214 END:VCALENDAR
215 ICS;
216 
217  $request->setBody($ics);
218 
219  $response = $this->request($request);
220  $this->assertEquals(403, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
221 
222  }
223 
224  function testCreateFileNoUID() {
225 
227  'REQUEST_METHOD' => 'PUT',
228  'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
229  ]);
230  $request->setBody("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
231 
232  $response = $this->request($request);
233 
234  $this->assertEquals(415, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
235 
236  }
237 
238  function testCreateFileVCard() {
239 
241  'REQUEST_METHOD' => 'PUT',
242  'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
243  ]);
244  $request->setBody("BEGIN:VCARD\r\nEND:VCARD\r\n");
245 
246  $response = $this->request($request);
247 
248  $this->assertEquals(415, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
249 
250  }
251 
253 
255  'REQUEST_METHOD' => 'PUT',
256  'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
257  ]);
258  $request->setBody("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nBEGIN:VJOURNAL\r\nUID:foo\r\nEND:VJOURNAL\r\nEND:VCALENDAR\r\n");
259 
260  $response = $this->request($request);
261 
262  $this->assertEquals(415, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
263 
264  }
265 
266  function testCreateFile2UIDS() {
267 
269  'REQUEST_METHOD' => 'PUT',
270  'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
271  ]);
272  $request->setBody("BEGIN:VCALENDAR\r\nBEGIN:VTIMEZONE\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nBEGIN:VEVENT\r\nUID:bar\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
273 
274  $response = $this->request($request);
275 
276  $this->assertEquals(415, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
277 
278  }
279 
281 
283  'REQUEST_METHOD' => 'PUT',
284  'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
285  ]);
286  $request->setBody("BEGIN:VCALENDAR\r\nBEGIN:VTIMEZONE\r\nEND:VTIMEZONE\r\nBEGIN:VFREEBUSY\r\nUID:foo\r\nEND:VFREEBUSY\r\nEND:VCALENDAR\r\n");
287 
288  $response = $this->request($request);
289 
290  $this->assertEquals(403, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
291 
292  }
293 
294  function testUpdateFile() {
295 
296  $this->calBackend->createCalendarObject('calendar1', 'blabla.ics', 'foo');
298  'REQUEST_METHOD' => 'PUT',
299  'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
300  ]);
301 
302  $response = $this->request($request);
303 
304  $this->assertEquals(415, $response->status);
305 
306  }
307 
309 
310  $this->calBackend->createCalendarObject('calendar1', 'blabla.ics', 'foo');
311  $request = new HTTP\Request(
312  'PUT',
313  '/calendars/admin/calendar1/blabla.ics'
314  );
315  $ics = <<<ICS
316 BEGIN:VCALENDAR
317 VERSION:2.0
318 PRODID:foo
319 BEGIN:VEVENT
320 UID:foo
321 DTSTAMP:20160406T052348Z
322 DTSTART:20160706T140000Z
323 END:VEVENT
324 END:VCALENDAR
325 ICS;
326 
327  $request->setBody($ics);
328  $response = $this->request($request);
329 
330  $this->assertEquals(204, $response->status);
331 
332  $expected = [
333  'uri' => 'blabla.ics',
334  'calendardata' => $ics,
335  'calendarid' => 'calendar1',
336  'lastmodified' => null,
337  ];
338 
339  $this->assertEquals($expected, $this->calBackend->getCalendarObject('calendar1', 'blabla.ics'));
340 
341  }
342 
344 
346  'REQUEST_METHOD' => 'PUT',
347  'REQUEST_URI' => '/calendars/admin/calendar2/blabla.ics',
348  ]);
349  $request->setBody("BEGIN:VCALENDAR\r\nBEGIN:VTIMEZONE\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
350 
351  $response = $this->request($request);
352 
353  $this->assertEquals(403, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
354 
355  }
356 
358 
359  $this->calBackend->createCalendarObject('calendar2', 'blabla.ics', 'foo');
361  'REQUEST_METHOD' => 'PUT',
362  'REQUEST_URI' => '/calendars/admin/calendar2/blabla.ics',
363  ]);
364  $request->setBody("BEGIN:VCALENDAR\r\nBEGIN:VTIMEZONE\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
365 
366  $response = $this->request($request);
367 
368  $this->assertEquals(403, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
369 
370  }
371 
380 
381  $request = new HTTP\Request(
382  'PUT',
383  '/calendars/admin/calendar1/blabla.ics'
384  );
385  $ics = <<<ICS
386 BEGIN:VCALENDAR
387 VERSION:2.0
388 PRODID:foo
389 BEGIN:VEVENT
390 UID:foo
391 SUMMARY:Meeting in M\xfcnster
392 DTSTAMP:20160406T052348Z
393 DTSTART:20160706T140000Z
394 END:VEVENT
395 END:VCALENDAR
396 ICS;
397 
398  $request->setBody($ics);
399 
400  $response = $this->request($request);
401 
402  $this->assertEquals(201, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
403  $this->assertNull($response->getHeader('ETag'));
404 
405  }
406 }
CalDAV plugin.
Definition: Plugin.php:28
foreach($paths as $path) $request
Definition: asyncclient.php:32
The Request class represents a single HTTP request.
Definition: Request.php:18
const VERSION
Full version number.
Definition: Version.php:17
Main DAV server class.
Definition: Server.php:23
request(HTTP\Request $request)
testCreateFileModified()
What we are testing here, is if we send in a latin1 character, the server should automatically transf...
static createFromServerArray(array $serverArray)
This static method will create a new Request object, based on a PHP $_SERVER array.
Definition: Sapi.php:107
Calendars collection.
$response
$principalBackend