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);
197 * @depends testMKCOLIncorrectResourceType2
199 function testMKCOLSuccess() {
202 'REQUEST_URI' => '/testcol',
203 'REQUEST_METHOD' => 'MKCOL',
204 'HTTP_CONTENT_TYPE' => 'application/xml',
207 $request = new Sabre_HTTP_Request($serverVars);
208 $request->setBody('<?xml version="1.0"?>
212 <resourcetype><collection /></resourcetype>
216 $this->server->httpRequest = ($request);
217 $this->server->exec();
219 $this->assertEquals(array(
220 'Content-Length' => '0',
221 ),$this->response->headers);
223 $this->assertEquals('HTTP/1.1 201 Created',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
229 * @depends testMKCOLIncorrectResourceType2
231 function testMKCOLNoParent() {
234 'REQUEST_URI' => '/testnoparent/409me',
235 'REQUEST_METHOD' => 'MKCOL',
238 $request = new Sabre_HTTP_Request($serverVars);
239 $request->setBody('');
241 $this->server->httpRequest = ($request);
242 $this->server->exec();
244 $this->assertEquals(array(
245 'Content-Type' => 'application/xml; charset=utf-8',
246 ),$this->response->headers);
248 $this->assertEquals('HTTP/1.1 409 Conflict',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
253 * @depends testMKCOLIncorrectResourceType2
255 function testMKCOLParentIsNoCollection() {
258 'REQUEST_URI' => '/test.txt/409me',
259 'REQUEST_METHOD' => 'MKCOL',
262 $request = new Sabre_HTTP_Request($serverVars);
263 $request->setBody('');
265 $this->server->httpRequest = ($request);
266 $this->server->exec();
268 $this->assertEquals(array(
269 'Content-Type' => 'application/xml; charset=utf-8',
270 ),$this->response->headers);
272 $this->assertEquals('HTTP/1.1 409 Conflict',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
277 * @depends testMKCOLIncorrectResourceType2
279 function testMKCOLAlreadyExists() {
282 'REQUEST_URI' => '/test.txt',
283 'REQUEST_METHOD' => 'MKCOL',
286 $request = new Sabre_HTTP_Request($serverVars);
287 $request->setBody('');
289 $this->server->httpRequest = ($request);
290 $this->server->exec();
292 $this->assertEquals(array(
293 'Content-Type' => 'application/xml; charset=utf-8',
294 'Allow' => 'OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT',
295 ),$this->response->headers);
297 $this->assertEquals('HTTP/1.1 405 Method Not Allowed',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
302 * @depends testMKCOLSuccess
303 * @depends testMKCOLAlreadyExists
305 function testMKCOLAndProps() {
308 'REQUEST_URI' => '/testcol',
309 'REQUEST_METHOD' => 'MKCOL',
310 'HTTP_CONTENT_TYPE' => 'application/xml',
313 $request = new Sabre_HTTP_Request($serverVars);
314 $request->setBody('<?xml version="1.0"?>
318 <resourcetype><collection /></resourcetype>
319 <displayname>my new collection</displayname>
323 $this->server->httpRequest = ($request);
324 $this->server->exec();
326 $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
328 $this->assertEquals(array(
329 'Content-Type' => 'application/xml; charset=utf-8',
330 ),$this->response->headers);