]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/CalDAV/OutboxPostTest.php
Merge remote branch 'upstream/master'
[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         $this->assertHTTPStatus(501, $req);
195
196     }
197
198     function testSuccessRequest() {
199
200         $req = new Sabre_HTTP_Request(array(
201             'REQUEST_METHOD'  => 'POST',
202             'REQUEST_URI'     => '/calendars/user1/outbox',
203             'HTTP_ORIGINATOR' => 'mailto:user1.sabredav@sabredav.org',
204             'HTTP_RECIPIENT'  => 'mailto:user2@example.org',
205         ));
206
207         $body = array(
208             'BEGIN:VCALENDAR',
209             'METHOD:REQUEST',
210             'BEGIN:VEVENT',
211             'SUMMARY:An invitation',
212             'END:VEVENT',
213             'END:VCALENDAR',
214         );
215
216         $req->setBody(implode("\r\n",$body));
217
218         $handler = new Sabre_CalDAV_Schedule_IMip_Mock('server@example.org');
219
220         $this->caldavPlugin->setIMIPhandler($handler);
221         $this->assertHTTPStatus(200, $req);
222
223         $this->assertEquals(array(
224             array(
225                 'to' => 'user2@example.org',
226                 'subject' => 'Invitation for: An invitation',
227                 'body' => implode("\r\n", $body) . "\r\n",
228                 'headers' => array(
229                     'Reply-To: user1.sabredav@sabredav.org',
230                     'From: server@example.org',
231                     'Content-Type: text/calendar; method=REQUEST; charset=utf-8',
232                     'X-Sabre-Version: ' . Sabre_DAV_Version::VERSION . '-' . Sabre_DAV_Version::STABILITY,
233                 ),
234            )
235         ), $handler->getSentEmails());
236
237     }
238
239     function testSuccessReply() {
240
241         $req = new Sabre_HTTP_Request(array(
242             'REQUEST_METHOD'  => 'POST',
243             'REQUEST_URI'     => '/calendars/user1/outbox',
244             'HTTP_ORIGINATOR' => 'mailto:user1.sabredav@sabredav.org',
245             'HTTP_RECIPIENT'  => 'mailto:user2@example.org',
246         ));
247
248         $body = array(
249             'BEGIN:VCALENDAR',
250             'METHOD:REPLY',
251             'BEGIN:VEVENT',
252             'SUMMARY:An invitation',
253             'END:VEVENT',
254             'END:VCALENDAR',
255         );
256
257         $req->setBody(implode("\r\n",$body));
258
259         $handler = new Sabre_CalDAV_Schedule_IMip_Mock('server@example.org');
260
261         $this->caldavPlugin->setIMIPhandler($handler);
262         $this->assertHTTPStatus(200, $req);
263
264         $this->assertEquals(array(
265             array(
266                 'to' => 'user2@example.org',
267                 'subject' => 'Response for: An invitation',
268                 'body' => implode("\r\n", $body) . "\r\n",
269                 'headers' => array(
270                     'Reply-To: user1.sabredav@sabredav.org',
271                     'From: server@example.org',
272                     'Content-Type: text/calendar; method=REPLY; charset=utf-8',
273                     'X-Sabre-Version: ' . Sabre_DAV_Version::VERSION . '-' . Sabre_DAV_Version::STABILITY,
274                 ),
275            )
276         ), $handler->getSentEmails());
277
278     }
279
280     function testSuccessCancel() {
281
282         $req = new Sabre_HTTP_Request(array(
283             'REQUEST_METHOD'  => 'POST',
284             'REQUEST_URI'     => '/calendars/user1/outbox',
285             'HTTP_ORIGINATOR' => 'mailto:user1.sabredav@sabredav.org',
286             'HTTP_RECIPIENT'  => 'mailto:user2@example.org',
287         ));
288
289         $body = array(
290             'BEGIN:VCALENDAR',
291             'METHOD:CANCEL',
292             'BEGIN:VEVENT',
293             'SUMMARY:An invitation',
294             'END:VEVENT',
295             'END:VCALENDAR',
296         );
297
298         $req->setBody(implode("\r\n",$body));
299
300         $handler = new Sabre_CalDAV_Schedule_IMip_Mock('server@example.org');
301
302         $this->caldavPlugin->setIMIPhandler($handler);
303         $this->assertHTTPStatus(200, $req);
304
305         $this->assertEquals(array(
306             array(
307                 'to' => 'user2@example.org',
308                 'subject' => 'Cancelled event: An invitation',
309                 'body' => implode("\r\n", $body) . "\r\n",
310                 'headers' => array(
311                     'Reply-To: user1.sabredav@sabredav.org',
312                     'From: server@example.org',
313                     'Content-Type: text/calendar; method=CANCEL; charset=utf-8',
314                     'X-Sabre-Version: ' . Sabre_DAV_Version::VERSION . '-' . Sabre_DAV_Version::STABILITY,
315                 ),
316            )
317         ), $handler->getSentEmails());
318
319
320     }
321 }