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));
194 $this->assertHTTPStatus(501, $req);
198 function testSuccessRequest() {
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',
211 'SUMMARY:An invitation',
216 $req->setBody(implode("\r\n",$body));
218 $handler = new Sabre_CalDAV_Schedule_IMip_Mock('server@example.org');
220 $this->caldavPlugin->setIMIPhandler($handler);
221 $this->assertHTTPStatus(200, $req);
223 $this->assertEquals(array(
225 'to' => 'user2@example.org',
226 'subject' => 'Invitation for: An invitation',
227 'body' => implode("\r\n", $body) . "\r\n",
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,
235 ), $handler->getSentEmails());
239 function testSuccessReply() {
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',
252 'SUMMARY:An invitation',
257 $req->setBody(implode("\r\n",$body));
259 $handler = new Sabre_CalDAV_Schedule_IMip_Mock('server@example.org');
261 $this->caldavPlugin->setIMIPhandler($handler);
262 $this->assertHTTPStatus(200, $req);
264 $this->assertEquals(array(
266 'to' => 'user2@example.org',
267 'subject' => 'Response for: An invitation',
268 'body' => implode("\r\n", $body) . "\r\n",
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,
276 ), $handler->getSentEmails());
280 function testSuccessCancel() {
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',
293 'SUMMARY:An invitation',
298 $req->setBody(implode("\r\n",$body));
300 $handler = new Sabre_CalDAV_Schedule_IMip_Mock('server@example.org');
302 $this->caldavPlugin->setIMIPhandler($handler);
303 $this->assertHTTPStatus(200, $req);
305 $this->assertEquals(array(
307 'to' => 'user2@example.org',
308 'subject' => 'Cancelled event: An invitation',
309 'body' => implode("\r\n", $body) . "\r\n",
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,
317 ), $handler->getSentEmails());