1<?php
2
3namespace Sabre\CalDAV\Schedule;
4
5use Sabre\HTTP;
6
7class OutboxPostTest extends \Sabre\DAVServerTest {
8
9    protected $setupCalDAV = true;
10    protected $setupACL = true;
11    protected $autoLogin = 'user1';
12    protected $setupCalDAVScheduling = true;
13
14    function testPostPassThruNotFound() {
15
16        $req = HTTP\Sapi::createFromServerArray([
17            'REQUEST_METHOD'    => 'POST',
18            'REQUEST_URI'       => '/notfound',
19            'HTTP_CONTENT_TYPE' => 'text/calendar',
20        ]);
21
22        $this->assertHTTPStatus(501, $req);
23
24    }
25
26    function testPostPassThruNotTextCalendar() {
27
28        $req = HTTP\Sapi::createFromServerArray([
29            'REQUEST_METHOD' => 'POST',
30            'REQUEST_URI'    => '/calendars/user1/outbox',
31        ]);
32
33        $this->assertHTTPStatus(501, $req);
34
35    }
36
37    function testPostPassThruNoOutBox() {
38
39        $req = HTTP\Sapi::createFromServerArray([
40            'REQUEST_METHOD'    => 'POST',
41            'REQUEST_URI'       => '/calendars',
42            'HTTP_CONTENT_TYPE' => 'text/calendar',
43        ]);
44
45        $this->assertHTTPStatus(501, $req);
46
47    }
48
49    function testInvalidIcalBody() {
50
51        $req = HTTP\Sapi::createFromServerArray([
52            'REQUEST_METHOD'    => 'POST',
53            'REQUEST_URI'       => '/calendars/user1/outbox',
54            'HTTP_ORIGINATOR'   => 'mailto:user1.sabredav@sabredav.org',
55            'HTTP_RECIPIENT'    => 'mailto:user2@example.org',
56            'HTTP_CONTENT_TYPE' => 'text/calendar',
57        ]);
58        $req->setBody('foo');
59
60        $this->assertHTTPStatus(400, $req);
61
62    }
63
64    function testNoVEVENT() {
65
66        $req = HTTP\Sapi::createFromServerArray([
67            'REQUEST_METHOD'    => 'POST',
68            'REQUEST_URI'       => '/calendars/user1/outbox',
69            'HTTP_ORIGINATOR'   => 'mailto:user1.sabredav@sabredav.org',
70            'HTTP_RECIPIENT'    => 'mailto:user2@example.org',
71            'HTTP_CONTENT_TYPE' => 'text/calendar',
72        ]);
73
74        $body = [
75            'BEGIN:VCALENDAR',
76            'BEGIN:VTIMEZONE',
77            'END:VTIMEZONE',
78            'END:VCALENDAR',
79        ];
80
81        $req->setBody(implode("\r\n", $body));
82
83        $this->assertHTTPStatus(400, $req);
84
85    }
86
87    function testNoMETHOD() {
88
89        $req = HTTP\Sapi::createFromServerArray([
90            'REQUEST_METHOD'    => 'POST',
91            'REQUEST_URI'       => '/calendars/user1/outbox',
92            'HTTP_ORIGINATOR'   => 'mailto:user1.sabredav@sabredav.org',
93            'HTTP_RECIPIENT'    => 'mailto:user2@example.org',
94            'HTTP_CONTENT_TYPE' => 'text/calendar',
95        ]);
96
97        $body = [
98            'BEGIN:VCALENDAR',
99            'BEGIN:VEVENT',
100            'END:VEVENT',
101            'END:VCALENDAR',
102        ];
103
104        $req->setBody(implode("\r\n", $body));
105
106        $this->assertHTTPStatus(400, $req);
107
108    }
109
110    function testUnsupportedMethod() {
111
112        $req = HTTP\Sapi::createFromServerArray([
113            'REQUEST_METHOD'    => 'POST',
114            'REQUEST_URI'       => '/calendars/user1/outbox',
115            'HTTP_ORIGINATOR'   => 'mailto:user1.sabredav@sabredav.org',
116            'HTTP_RECIPIENT'    => 'mailto:user2@example.org',
117            'HTTP_CONTENT_TYPE' => 'text/calendar',
118        ]);
119
120        $body = [
121            'BEGIN:VCALENDAR',
122            'METHOD:PUBLISH',
123            'BEGIN:VEVENT',
124            'END:VEVENT',
125            'END:VCALENDAR',
126        ];
127
128        $req->setBody(implode("\r\n", $body));
129
130        $this->assertHTTPStatus(501, $req);
131
132    }
133
134}
135