]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/CalDAV/OutboxPostTest.php
Merge branch '3.6-release'
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / CalDAV / OutboxPostTest.php
1 <?php
2
3 require_once 'Sabre/DAVServerTest.php';
4 require_once 'Sabre/CalDAV/Schedule/IMip/Mock.php';
5
6 class Sabre_CalDAV_OutboxPostTest extends Sabre_DAVServerTest {
7
8     protected $setupCalDAV = true;
9
10     function testPostPassThruNotFound() {
11
12         $req = new Sabre_HTTP_Request(array(
13             'REQUEST_METHOD' => 'POST',
14             'REQUEST_URI' => '/notfound',
15         ));
16
17         $this->assertHTTPStatus(501, $req);
18
19     }
20
21     function testPostPassThruNoOutBox() {
22
23         $req = new Sabre_HTTP_Request(array(
24             'REQUEST_METHOD' => 'POST',
25             'REQUEST_URI' => '/calendars',
26         ));
27
28         $this->assertHTTPStatus(501, $req);
29
30     }
31
32     function testNoOriginator() {
33
34         $req = new Sabre_HTTP_Request(array(
35             'REQUEST_METHOD' => 'POST',
36             'REQUEST_URI' => '/calendars/admin/outbox',
37         ));
38
39         $this->assertHTTPStatus(400, $req);
40
41     }
42
43     function testNoRecipient() {
44
45         $req = new Sabre_HTTP_Request(array(
46             'REQUEST_METHOD'  => 'POST',
47             'REQUEST_URI'     => '/calendars/admin/outbox',
48             'HTTP_ORIGINATOR' => 'mailto:orig@example.org',
49         ));
50
51         $this->assertHTTPStatus(400, $req);
52
53     }
54
55     function testBadOriginator() {
56
57         $req = new Sabre_HTTP_Request(array(
58             'REQUEST_METHOD'  => 'POST',
59             'REQUEST_URI'     => '/calendars/admin/outbox',
60             'HTTP_ORIGINATOR' => 'nomailto:orig@example.org',
61             'HTTP_RECIPIENT'  => 'mailto:user1@example.org',
62         ));
63
64         $this->assertHTTPStatus(400, $req);
65
66     }
67
68     function testBadRecipient() {
69
70         $req = new Sabre_HTTP_Request(array(
71             'REQUEST_METHOD'  => 'POST',
72             'REQUEST_URI'     => '/calendars/admin/outbox',
73             'HTTP_ORIGINATOR' => 'mailto:orig@example.org',
74             'HTTP_RECIPIENT'  => 'http://user1@example.org, mailto:user2@example.org',
75         ));
76
77         $this->assertHTTPStatus(400, $req);
78
79     }
80
81     function testIncorrectOriginator() {
82
83         $req = new Sabre_HTTP_Request(array(
84             'REQUEST_METHOD'  => 'POST',
85             'REQUEST_URI'     => '/calendars/admin/outbox',
86             'HTTP_ORIGINATOR' => 'mailto:orig@example.org',
87             'HTTP_RECIPIENT'  => 'mailto:user1@example.org, mailto:user2@example.org',
88         ));
89
90         $this->assertHTTPStatus(403, $req);
91
92     }
93
94     function testInvalidIcalBody() {
95
96         $req = new Sabre_HTTP_Request(array(
97             'REQUEST_METHOD'  => 'POST',
98             'REQUEST_URI'     => '/calendars/user1/outbox',
99             'HTTP_ORIGINATOR' => 'mailto:user1.sabredav@sabredav.org',
100             'HTTP_RECIPIENT'  => 'mailto:user2@example.org',
101         ));
102         $req->setBody('foo');
103
104         $this->assertHTTPStatus(400, $req);
105
106     }
107
108     function testNoVEVENT() {
109
110         $req = new Sabre_HTTP_Request(array(
111             'REQUEST_METHOD'  => 'POST',
112             'REQUEST_URI'     => '/calendars/user1/outbox',
113             'HTTP_ORIGINATOR' => 'mailto:user1.sabredav@sabredav.org',
114             'HTTP_RECIPIENT'  => 'mailto:user2@example.org',
115         ));
116
117         $body = array(
118             'BEGIN:VCALENDAR',
119             'BEGIN:VTIMEZONE',
120             'END:VTIMEZONE',
121             'END:VCALENDAR',
122         );
123
124         $req->setBody(implode("\r\n",$body));
125
126         $this->assertHTTPStatus(400, $req);
127
128     }
129
130     function testNoMETHOD() {
131
132         $req = new Sabre_HTTP_Request(array(
133             'REQUEST_METHOD'  => 'POST',
134             'REQUEST_URI'     => '/calendars/user1/outbox',
135             'HTTP_ORIGINATOR' => 'mailto:user1.sabredav@sabredav.org',
136             'HTTP_RECIPIENT'  => 'mailto:user2@example.org',
137         ));
138
139         $body = array(
140             'BEGIN:VCALENDAR',
141             'BEGIN:VEVENT',
142             'END:VEVENT',
143             'END:VCALENDAR',
144         );
145
146         $req->setBody(implode("\r\n",$body));
147
148         $this->assertHTTPStatus(400, $req);
149
150     }
151
152     function testUnsupportedMethod() {
153
154         $req = new Sabre_HTTP_Request(array(
155             'REQUEST_METHOD'  => 'POST',
156             'REQUEST_URI'     => '/calendars/user1/outbox',
157             'HTTP_ORIGINATOR' => 'mailto:user1.sabredav@sabredav.org',
158             'HTTP_RECIPIENT'  => 'mailto:user2@example.org',
159         ));
160
161         $body = array(
162             'BEGIN:VCALENDAR',
163             'METHOD:PUBLISH',
164             'BEGIN:VEVENT',
165             'END:VEVENT',
166             'END:VCALENDAR',
167         );
168
169         $req->setBody(implode("\r\n",$body));
170
171         $this->assertHTTPStatus(501, $req);
172
173     }
174
175     function testNoIMIPHandler() {
176
177         $req = new Sabre_HTTP_Request(array(
178             'REQUEST_METHOD'  => 'POST',
179             'REQUEST_URI'     => '/calendars/user1/outbox',
180             'HTTP_ORIGINATOR' => 'mailto:user1.sabredav@sabredav.org',
181             'HTTP_RECIPIENT'  => 'mailto:user2@example.org',
182         ));
183
184         $body = array(
185             'BEGIN:VCALENDAR',
186             'METHOD:REQUEST',
187             'BEGIN:VEVENT',
188             'END:VEVENT',
189             'END:VCALENDAR',
190         );
191
192         $req->setBody(implode("\r\n",$body));
193
194
195         $response = $this->request($req);
196         $this->assertEquals('HTTP/1.1 200 OK', $response->status);
197         $this->assertEquals(array(
198             'Content-Type' => 'application/xml',
199         ), $response->headers);
200
201         // Lazily checking the body for a few expected values.
202         $this->assertTrue(strpos($response->body, '5.2;')!==false);
203         $this->assertTrue(strpos($response->body,'user2@example.org')!==false);
204
205
206     }
207
208     function testSuccessRequest() {
209
210         $req = new Sabre_HTTP_Request(array(
211             'REQUEST_METHOD'  => 'POST',
212             'REQUEST_URI'     => '/calendars/user1/outbox',
213             'HTTP_ORIGINATOR' => 'mailto:user1.sabredav@sabredav.org',
214             'HTTP_RECIPIENT'  => 'mailto:user2@example.org',
215         ));
216
217         $body = array(
218             'BEGIN:VCALENDAR',
219             'METHOD:REQUEST',
220             'BEGIN:VEVENT',
221             'SUMMARY:An invitation',
222             'END:VEVENT',
223             'END:VCALENDAR',
224         );
225
226         $req->setBody(implode("\r\n",$body));
227
228         $handler = new Sabre_CalDAV_Schedule_IMip_Mock('server@example.org');
229
230         $this->caldavPlugin->setIMIPhandler($handler);
231
232         $response = $this->request($req);
233         $this->assertEquals('HTTP/1.1 200 OK', $response->status);
234         $this->assertEquals(array(
235             'Content-Type' => 'application/xml',
236         ), $response->headers);
237
238         // Lazily checking the body for a few expected values.
239         $this->assertTrue(strpos($response->body, '2.0;')!==false);
240         $this->assertTrue(strpos($response->body,'user2@example.org')!==false);
241
242         $this->assertEquals(array(
243             array(
244                 'to' => 'user2@example.org',
245                 'subject' => 'Invitation for: An invitation',
246                 'body' => implode("\r\n", $body) . "\r\n",
247                 'headers' => array(
248                     'Reply-To: user1.sabredav@sabredav.org',
249                     'From: server@example.org',
250                     'Content-Type: text/calendar; method=REQUEST; charset=utf-8',
251                     'X-Sabre-Version: ' . Sabre_DAV_Version::VERSION . '-' . Sabre_DAV_Version::STABILITY,
252                 ),
253            )
254         ), $handler->getSentEmails());
255
256     }
257
258     function testSuccessRequestUpperCased() {
259
260         $req = new Sabre_HTTP_Request(array(
261             'REQUEST_METHOD'  => 'POST',
262             'REQUEST_URI'     => '/calendars/user1/outbox',
263             'HTTP_ORIGINATOR' => 'MAILTO:user1.sabredav@sabredav.org',
264             'HTTP_RECIPIENT'  => 'MAILTO:user2@example.org',
265         ));
266
267         $body = array(
268             'BEGIN:VCALENDAR',
269             'METHOD:REQUEST',
270             'BEGIN:VEVENT',
271             'SUMMARY:An invitation',
272             'END:VEVENT',
273             'END:VCALENDAR',
274         );
275
276         $req->setBody(implode("\r\n",$body));
277
278         $handler = new Sabre_CalDAV_Schedule_IMip_Mock('server@example.org');
279
280         $this->caldavPlugin->setIMIPhandler($handler);
281
282         $response = $this->request($req);
283         $this->assertEquals('HTTP/1.1 200 OK', $response->status);
284         $this->assertEquals(array(
285             'Content-Type' => 'application/xml',
286         ), $response->headers);
287
288         // Lazily checking the body for a few expected values.
289         $this->assertTrue(strpos($response->body, '2.0;')!==false);
290         $this->assertTrue(strpos($response->body,'user2@example.org')!==false);
291
292         $this->assertEquals(array(
293             array(
294                 'to' => 'user2@example.org',
295                 'subject' => 'Invitation for: An invitation',
296                 'body' => implode("\r\n", $body) . "\r\n",
297                 'headers' => array(
298                     'Reply-To: user1.sabredav@sabredav.org',
299                     'From: server@example.org',
300                     'Content-Type: text/calendar; method=REQUEST; charset=utf-8',
301                     'X-Sabre-Version: ' . Sabre_DAV_Version::VERSION . '-' . Sabre_DAV_Version::STABILITY,
302                 ),
303            )
304         ), $handler->getSentEmails());
305
306     }
307
308     function testSuccessReply() {
309
310         $req = new Sabre_HTTP_Request(array(
311             'REQUEST_METHOD'  => 'POST',
312             'REQUEST_URI'     => '/calendars/user1/outbox',
313             'HTTP_ORIGINATOR' => 'mailto:user1.sabredav@sabredav.org',
314             'HTTP_RECIPIENT'  => 'mailto:user2@example.org',
315         ));
316
317         $body = array(
318             'BEGIN:VCALENDAR',
319             'METHOD:REPLY',
320             'BEGIN:VEVENT',
321             'SUMMARY:An invitation',
322             'END:VEVENT',
323             'END:VCALENDAR',
324         );
325
326         $req->setBody(implode("\r\n",$body));
327
328         $handler = new Sabre_CalDAV_Schedule_IMip_Mock('server@example.org');
329
330         $this->caldavPlugin->setIMIPhandler($handler);
331         $this->assertHTTPStatus(200, $req);
332
333         $this->assertEquals(array(
334             array(
335                 'to' => 'user2@example.org',
336                 'subject' => 'Response for: An invitation',
337                 'body' => implode("\r\n", $body) . "\r\n",
338                 'headers' => array(
339                     'Reply-To: user1.sabredav@sabredav.org',
340                     'From: server@example.org',
341                     'Content-Type: text/calendar; method=REPLY; charset=utf-8',
342                     'X-Sabre-Version: ' . Sabre_DAV_Version::VERSION . '-' . Sabre_DAV_Version::STABILITY,
343                 ),
344            )
345         ), $handler->getSentEmails());
346
347     }
348
349     function testSuccessCancel() {
350
351         $req = new Sabre_HTTP_Request(array(
352             'REQUEST_METHOD'  => 'POST',
353             'REQUEST_URI'     => '/calendars/user1/outbox',
354             'HTTP_ORIGINATOR' => 'mailto:user1.sabredav@sabredav.org',
355             'HTTP_RECIPIENT'  => 'mailto:user2@example.org',
356         ));
357
358         $body = array(
359             'BEGIN:VCALENDAR',
360             'METHOD:CANCEL',
361             'BEGIN:VEVENT',
362             'SUMMARY:An invitation',
363             'END:VEVENT',
364             'END:VCALENDAR',
365         );
366
367         $req->setBody(implode("\r\n",$body));
368
369         $handler = new Sabre_CalDAV_Schedule_IMip_Mock('server@example.org');
370
371         $this->caldavPlugin->setIMIPhandler($handler);
372         $this->assertHTTPStatus(200, $req);
373
374         $this->assertEquals(array(
375             array(
376                 'to' => 'user2@example.org',
377                 'subject' => 'Cancelled event: An invitation',
378                 'body' => implode("\r\n", $body) . "\r\n",
379                 'headers' => array(
380                     'Reply-To: user1.sabredav@sabredav.org',
381                     'From: server@example.org',
382                     'Content-Type: text/calendar; method=CANCEL; charset=utf-8',
383                     'X-Sabre-Version: ' . Sabre_DAV_Version::VERSION . '-' . Sabre_DAV_Version::STABILITY,
384                 ),
385            )
386         ), $handler->getSentEmails());
387
388
389     }
390 }