3 require_once 'Sabre/CalDAV/Backend/Mock.php';
4 require_once 'Sabre/DAVACL/MockPrincipalBackend.php';
5 require_once 'Sabre/HTTP/ResponseMock.php';
7 class Sabre_CalDAV_ValidateICalTest extends PHPUnit_Framework_TestCase {
10 * @var Sabre_DAV_Server
14 * @var Sabre_CalDAV_Backend_Mock
16 protected $calBackend;
23 'principaluri' => 'principals/admin',
25 '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new Sabre_CalDAV_Property_SupportedCalendarComponentSet( array('VEVENT','VTODO','VJOURNAL') ),
29 'principaluri' => 'principals/admin',
31 '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new Sabre_CalDAV_Property_SupportedCalendarComponentSet( array('VTODO','VJOURNAL') ),
35 $this->calBackend = new Sabre_CalDAV_Backend_Mock($calendars,array());
36 $principalBackend = new Sabre_DAVACL_MockPrincipalBackend();
39 new Sabre_CalDAV_CalendarRootNode($principalBackend, $this->calBackend),
42 $this->server = new Sabre_DAV_Server($tree);
43 $this->server->debugExceptions = true;
45 $plugin = new Sabre_CalDAV_Plugin();
46 $this->server->addPlugin($plugin);
48 $response = new Sabre_HTTP_ResponseMock();
49 $this->server->httpResponse = $response;
53 function request(Sabre_HTTP_Request $request) {
55 $this->server->httpRequest = $request;
56 $this->server->exec();
58 return $this->server->httpResponse;
62 function testCreateFile() {
64 $request = new Sabre_HTTP_Request(array(
65 'REQUEST_METHOD' => 'PUT',
66 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
69 $response = $this->request($request);
71 $this->assertEquals('HTTP/1.1 415 Unsupported Media Type', $response->status);
75 function testCreateFileValid() {
77 $request = new Sabre_HTTP_Request(array(
78 'REQUEST_METHOD' => 'PUT',
79 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
81 $request->setBody("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
83 $response = $this->request($request);
85 $this->assertEquals('HTTP/1.1 201 Created', $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
87 'uri' => 'blabla.ics',
88 'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n",
89 'calendarid' => 'calendar1',
92 $this->assertEquals($expected, $this->calBackend->getCalendarObject('calendar1','blabla.ics'));
96 function testCreateFileNoComponents() {
98 $request = new Sabre_HTTP_Request(array(
99 'REQUEST_METHOD' => 'PUT',
100 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
102 $request->setBody("BEGIN:VCALENDAR\r\nEND:VCALENDAR\r\n");
104 $response = $this->request($request);
106 $this->assertEquals('HTTP/1.1 400 Bad request', $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
110 function testCreateFileNoUID() {
112 $request = new Sabre_HTTP_Request(array(
113 'REQUEST_METHOD' => 'PUT',
114 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
116 $request->setBody("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
118 $response = $this->request($request);
120 $this->assertEquals('HTTP/1.1 400 Bad request', $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
124 function testCreateFileVCard() {
126 $request = new Sabre_HTTP_Request(array(
127 'REQUEST_METHOD' => 'PUT',
128 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
130 $request->setBody("BEGIN:VCARD\r\nEND:VCARD\r\n");
132 $response = $this->request($request);
134 $this->assertEquals('HTTP/1.1 415 Unsupported Media Type', $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
138 function testCreateFile2Components() {
140 $request = new Sabre_HTTP_Request(array(
141 'REQUEST_METHOD' => 'PUT',
142 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
144 $request->setBody("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nBEGIN:VJOURNAL\r\nUID:foo\r\nEND:VJOURNAL\r\nEND:VCALENDAR\r\n");
146 $response = $this->request($request);
148 $this->assertEquals('HTTP/1.1 400 Bad request', $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
152 function testCreateFile2UIDS() {
154 $request = new Sabre_HTTP_Request(array(
155 'REQUEST_METHOD' => 'PUT',
156 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
158 $request->setBody("BEGIN:VCALENDAR\r\nBEGIN:VTIMEZONE\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nBEGIN:VEVENT\r\nUID:bar\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
160 $response = $this->request($request);
162 $this->assertEquals('HTTP/1.1 400 Bad request', $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
166 function testCreateFileWrongComponent() {
168 $request = new Sabre_HTTP_Request(array(
169 'REQUEST_METHOD' => 'PUT',
170 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
172 $request->setBody("BEGIN:VCALENDAR\r\nBEGIN:VTIMEZONE\r\nEND:VTIMEZONE\r\nBEGIN:VFREEBUSY\r\nUID:foo\r\nEND:VFREEBUSY\r\nEND:VCALENDAR\r\n");
174 $response = $this->request($request);
176 $this->assertEquals('HTTP/1.1 400 Bad request', $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
180 function testUpdateFile() {
182 $this->calBackend->createCalendarObject('calendar1','blabla.ics','foo');
183 $request = new Sabre_HTTP_Request(array(
184 'REQUEST_METHOD' => 'PUT',
185 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
188 $response = $this->request($request);
190 $this->assertEquals('HTTP/1.1 415 Unsupported Media Type', $response->status);
194 function testUpdateFileParsableBody() {
196 $this->calBackend->createCalendarObject('calendar1','blabla.ics','foo');
197 $request = new Sabre_HTTP_Request(array(
198 'REQUEST_METHOD' => 'PUT',
199 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
201 $body = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n";
202 $request->setBody($body);
204 $response = $this->request($request);
206 $this->assertEquals('HTTP/1.1 204 No Content', $response->status);
209 'uri' => 'blabla.ics',
210 'calendardata' => $body,
211 'calendarid' => 'calendar1',
214 $this->assertEquals($expected, $this->calBackend->getCalendarObject('calendar1','blabla.ics'));
218 function testCreateFileInvalidComponent() {
220 $request = new Sabre_HTTP_Request(array(
221 'REQUEST_METHOD' => 'PUT',
222 'REQUEST_URI' => '/calendars/admin/calendar2/blabla.ics',
224 $request->setBody("BEGIN:VCALENDAR\r\nBEGIN:VTIMEZONE\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
226 $response = $this->request($request);
228 $this->assertEquals('HTTP/1.1 403 Forbidden', $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
232 function testUpdateFileInvalidComponent() {
234 $this->calBackend->createCalendarObject('calendar2','blabla.ics','foo');
235 $request = new Sabre_HTTP_Request(array(
236 'REQUEST_METHOD' => 'PUT',
237 'REQUEST_URI' => '/calendars/admin/calendar2/blabla.ics',
239 $request->setBody("BEGIN:VCALENDAR\r\nBEGIN:VTIMEZONE\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
241 $response = $this->request($request);
243 $this->assertEquals('HTTP/1.1 403 Forbidden', $response->status, 'Incorrect status returned! Full response body: ' . $response->body);