3 require_once 'Sabre/DAVServerTest.php';
4 require_once 'Sabre/CalDAV/Schedule/IMip/Mock.php';
6 class Sabre_CalDAV_OutboxPostTest extends Sabre_DAVServerTest {
8 protected $setupCalDAV = true;
10 function testPostPassThruNotFound() {
12 $req = new Sabre_HTTP_Request(array(
13 'REQUEST_METHOD' => 'POST',
14 'REQUEST_URI' => '/notfound',
17 $this->assertHTTPStatus(501, $req);
21 function testPostPassThruNoOutBox() {
23 $req = new Sabre_HTTP_Request(array(
24 'REQUEST_METHOD' => 'POST',
25 'REQUEST_URI' => '/calendars',
28 $this->assertHTTPStatus(501, $req);
32 function testNoOriginator() {
34 $req = new Sabre_HTTP_Request(array(
35 'REQUEST_METHOD' => 'POST',
36 'REQUEST_URI' => '/calendars/admin/outbox',
39 $this->assertHTTPStatus(400, $req);
43 function testNoRecipient() {
45 $req = new Sabre_HTTP_Request(array(
46 'REQUEST_METHOD' => 'POST',
47 'REQUEST_URI' => '/calendars/admin/outbox',
48 'HTTP_ORIGINATOR' => 'mailto:orig@example.org',
51 $this->assertHTTPStatus(400, $req);
55 function testBadOriginator() {
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',
64 $this->assertHTTPStatus(400, $req);
68 function testBadRecipient() {
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',
77 $this->assertHTTPStatus(400, $req);
81 function testIncorrectOriginator() {
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',
90 $this->assertHTTPStatus(403, $req);
94 function testInvalidIcalBody() {
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',
102 $req->setBody('foo');
104 $this->assertHTTPStatus(400, $req);
108 function testNoVEVENT() {
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',
124 $req->setBody(implode("\r\n",$body));
126 $this->assertHTTPStatus(400, $req);
130 function testNoMETHOD() {
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',
146 $req->setBody(implode("\r\n",$body));
148 $this->assertHTTPStatus(400, $req);
152 function testUnsupportedMethod() {
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',
169 $req->setBody(implode("\r\n",$body));
171 $this->assertHTTPStatus(501, $req);
175 function testNoIMIPHandler() {
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',
192 $req->setBody(implode("\r\n",$body));
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);
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);
208 function testSuccessRequest() {
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',
221 'SUMMARY:An invitation',
226 $req->setBody(implode("\r\n",$body));
228 $handler = new Sabre_CalDAV_Schedule_IMip_Mock('server@example.org');
230 $this->caldavPlugin->setIMIPhandler($handler);
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);
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);
242 $this->assertEquals(array(
244 'to' => 'user2@example.org',
245 'subject' => 'Invitation for: An invitation',
246 'body' => implode("\r\n", $body) . "\r\n",
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,
254 ), $handler->getSentEmails());
258 function testSuccessRequestUpperCased() {
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',
271 'SUMMARY:An invitation',
276 $req->setBody(implode("\r\n",$body));
278 $handler = new Sabre_CalDAV_Schedule_IMip_Mock('server@example.org');
280 $this->caldavPlugin->setIMIPhandler($handler);
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);
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);
292 $this->assertEquals(array(
294 'to' => 'user2@example.org',
295 'subject' => 'Invitation for: An invitation',
296 'body' => implode("\r\n", $body) . "\r\n",
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,
304 ), $handler->getSentEmails());
308 function testSuccessReply() {
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',
321 'SUMMARY:An invitation',
326 $req->setBody(implode("\r\n",$body));
328 $handler = new Sabre_CalDAV_Schedule_IMip_Mock('server@example.org');
330 $this->caldavPlugin->setIMIPhandler($handler);
331 $this->assertHTTPStatus(200, $req);
333 $this->assertEquals(array(
335 'to' => 'user2@example.org',
336 'subject' => 'Response for: An invitation',
337 'body' => implode("\r\n", $body) . "\r\n",
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,
345 ), $handler->getSentEmails());
349 function testSuccessCancel() {
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',
362 'SUMMARY:An invitation',
367 $req->setBody(implode("\r\n",$body));
369 $handler = new Sabre_CalDAV_Schedule_IMip_Mock('server@example.org');
371 $this->caldavPlugin->setIMIPhandler($handler);
372 $this->assertHTTPStatus(200, $req);
374 $this->assertEquals(array(
376 'to' => 'user2@example.org',
377 'subject' => 'Cancelled event: An invitation',
378 'body' => implode("\r\n", $body) . "\r\n",
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,
386 ), $handler->getSentEmails());