3 require_once 'Sabre/HTTP/ResponseMock.php';
4 require_once 'Sabre/DAV/AbstractServer.php';
5 require_once 'Sabre/DAV/Exception.php';
7 class Sabre_DAV_ServerMKCOLTest extends Sabre_DAV_AbstractServer {
12 'REQUEST_URI' => '/testcol',
13 'REQUEST_METHOD' => 'MKCOL',
16 $request = new Sabre_HTTP_Request($serverVars);
17 $request->setBody("");
18 $this->server->httpRequest = ($request);
19 $this->server->exec();
21 $this->assertEquals(array(
22 'Content-Length' => '0',
23 ),$this->response->headers);
25 $this->assertEquals('HTTP/1.1 201 Created',$this->response->status);
26 $this->assertEquals('', $this->response->body);
27 $this->assertTrue(is_dir($this->tempDir . '/testcol'));
34 function testMKCOLUnknownBody() {
37 'REQUEST_URI' => '/testcol',
38 'REQUEST_METHOD' => 'MKCOL',
41 $request = new Sabre_HTTP_Request($serverVars);
42 $request->setBody("Hello");
43 $this->server->httpRequest = ($request);
44 $this->server->exec();
46 $this->assertEquals(array(
47 'Content-Type' => 'application/xml; charset=utf-8',
48 ),$this->response->headers);
50 $this->assertEquals('HTTP/1.1 415 Unsupported Media Type',$this->response->status);
57 function testMKCOLBrokenXML() {
60 'REQUEST_URI' => '/testcol',
61 'REQUEST_METHOD' => 'MKCOL',
62 'HTTP_CONTENT_TYPE' => 'application/xml',
65 $request = new Sabre_HTTP_Request($serverVars);
66 $request->setBody("Hello");
67 $this->server->httpRequest = ($request);
68 $this->server->exec();
70 $this->assertEquals(array(
71 'Content-Type' => 'application/xml; charset=utf-8',
72 ),$this->response->headers);
74 $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status);
81 function testMKCOLUnknownXML() {
84 'REQUEST_URI' => '/testcol',
85 'REQUEST_METHOD' => 'MKCOL',
86 'HTTP_CONTENT_TYPE' => 'application/xml',
89 $request = new Sabre_HTTP_Request($serverVars);
90 $request->setBody('<?xml version="1.0"?><html></html>');
91 $this->server->httpRequest = ($request);
92 $this->server->exec();
94 $this->assertEquals(array(
95 'Content-Type' => 'application/xml; charset=utf-8',
96 ),$this->response->headers);
98 $this->assertEquals('HTTP/1.1 415 Unsupported Media Type',$this->response->status);
105 function testMKCOLNoResourceType() {
108 'REQUEST_URI' => '/testcol',
109 'REQUEST_METHOD' => 'MKCOL',
110 'HTTP_CONTENT_TYPE' => 'application/xml',
113 $request = new Sabre_HTTP_Request($serverVars);
114 $request->setBody('<?xml version="1.0"?>
118 <displayname>Evert</displayname>
122 $this->server->httpRequest = ($request);
123 $this->server->exec();
125 $this->assertEquals(array(
126 'Content-Type' => 'application/xml; charset=utf-8',
127 ),$this->response->headers);
129 $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
134 * @depends testMKCOLNoResourceType
136 function testMKCOLIncorrectResourceType() {
139 'REQUEST_URI' => '/testcol',
140 'REQUEST_METHOD' => 'MKCOL',
141 'HTTP_CONTENT_TYPE' => 'application/xml',
144 $request = new Sabre_HTTP_Request($serverVars);
145 $request->setBody('<?xml version="1.0"?>
149 <resourcetype><blabla /></resourcetype>
153 $this->server->httpRequest = ($request);
154 $this->server->exec();
156 $this->assertEquals(array(
157 'Content-Type' => 'application/xml; charset=utf-8',
158 ),$this->response->headers);
160 $this->assertEquals('HTTP/1.1 403 Forbidden',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
165 * @depends testMKCOLIncorrectResourceType
167 function testMKCOLIncorrectResourceType2() {
170 'REQUEST_URI' => '/testcol',
171 'REQUEST_METHOD' => 'MKCOL',
172 'HTTP_CONTENT_TYPE' => 'application/xml',
175 $request = new Sabre_HTTP_Request($serverVars);
176 $request->setBody('<?xml version="1.0"?>
180 <resourcetype><collection /><blabla /></resourcetype>
184 $this->server->httpRequest = ($request);
185 $this->server->exec();
187 $this->assertEquals(array(
188 'Content-Type' => 'application/xml; charset=utf-8',
189 ),$this->response->headers);
191 $this->assertEquals('HTTP/1.1 403 Forbidden',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
196 * @depends testMKCOLIncorrectResourceType2
198 function testMKCOLSuccess() {
201 'REQUEST_URI' => '/testcol',
202 'REQUEST_METHOD' => 'MKCOL',
203 'HTTP_CONTENT_TYPE' => 'application/xml',
206 $request = new Sabre_HTTP_Request($serverVars);
207 $request->setBody('<?xml version="1.0"?>
211 <resourcetype><collection /></resourcetype>
215 $this->server->httpRequest = ($request);
216 $this->server->exec();
218 $this->assertEquals(array(
219 'Content-Length' => '0',
220 ),$this->response->headers);
222 $this->assertEquals('HTTP/1.1 201 Created',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
227 * @depends testMKCOLIncorrectResourceType2
229 function testMKCOLWhiteSpaceResourceType() {
232 'REQUEST_URI' => '/testcol',
233 'REQUEST_METHOD' => 'MKCOL',
234 'HTTP_CONTENT_TYPE' => 'application/xml',
237 $request = new Sabre_HTTP_Request($serverVars);
238 $request->setBody('<?xml version="1.0"?>
248 $this->server->httpRequest = ($request);
249 $this->server->exec();
251 $this->assertEquals(array(
252 'Content-Length' => '0',
253 ),$this->response->headers);
255 $this->assertEquals('HTTP/1.1 201 Created',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
260 * @depends testMKCOLIncorrectResourceType2
262 function testMKCOLNoParent() {
265 'REQUEST_URI' => '/testnoparent/409me',
266 'REQUEST_METHOD' => 'MKCOL',
269 $request = new Sabre_HTTP_Request($serverVars);
270 $request->setBody('');
272 $this->server->httpRequest = ($request);
273 $this->server->exec();
275 $this->assertEquals(array(
276 'Content-Type' => 'application/xml; charset=utf-8',
277 ),$this->response->headers);
279 $this->assertEquals('HTTP/1.1 409 Conflict',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
284 * @depends testMKCOLIncorrectResourceType2
286 function testMKCOLParentIsNoCollection() {
289 'REQUEST_URI' => '/test.txt/409me',
290 'REQUEST_METHOD' => 'MKCOL',
293 $request = new Sabre_HTTP_Request($serverVars);
294 $request->setBody('');
296 $this->server->httpRequest = ($request);
297 $this->server->exec();
299 $this->assertEquals(array(
300 'Content-Type' => 'application/xml; charset=utf-8',
301 ),$this->response->headers);
303 $this->assertEquals('HTTP/1.1 409 Conflict',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
308 * @depends testMKCOLIncorrectResourceType2
310 function testMKCOLAlreadyExists() {
313 'REQUEST_URI' => '/test.txt',
314 'REQUEST_METHOD' => 'MKCOL',
317 $request = new Sabre_HTTP_Request($serverVars);
318 $request->setBody('');
320 $this->server->httpRequest = ($request);
321 $this->server->exec();
323 $this->assertEquals(array(
324 'Content-Type' => 'application/xml; charset=utf-8',
325 'Allow' => 'OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT',
326 ),$this->response->headers);
328 $this->assertEquals('HTTP/1.1 405 Method Not Allowed',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
333 * @depends testMKCOLSuccess
334 * @depends testMKCOLAlreadyExists
336 function testMKCOLAndProps() {
339 'REQUEST_URI' => '/testcol',
340 'REQUEST_METHOD' => 'MKCOL',
341 'HTTP_CONTENT_TYPE' => 'application/xml',
344 $request = new Sabre_HTTP_Request($serverVars);
345 $request->setBody('<?xml version="1.0"?>
349 <resourcetype><collection /></resourcetype>
350 <displayname>my new collection</displayname>
354 $this->server->httpRequest = ($request);
355 $this->server->exec();
357 $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
359 $this->assertEquals(array(
360 'Content-Type' => 'application/xml; charset=utf-8',
361 ),$this->response->headers);