]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/DAV/ServerMKCOLTest.php
Merge branch '3.6-release'
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / DAV / ServerMKCOLTest.php
1 <?php
2
3 require_once 'Sabre/HTTP/ResponseMock.php';
4 require_once 'Sabre/DAV/AbstractServer.php';
5 require_once 'Sabre/DAV/Exception.php';
6
7 class Sabre_DAV_ServerMKCOLTest extends Sabre_DAV_AbstractServer {
8
9     function testMkcol() {
10
11         $serverVars = array(
12             'REQUEST_URI'    => '/testcol',
13             'REQUEST_METHOD' => 'MKCOL',
14         );
15
16         $request = new Sabre_HTTP_Request($serverVars);
17         $request->setBody("");
18         $this->server->httpRequest = ($request);
19         $this->server->exec();
20
21         $this->assertEquals(array(
22             'Content-Length' => '0',
23         ),$this->response->headers);
24
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'));
28
29     }
30
31     /**
32      * @depends testMkcol
33      */
34     function testMKCOLUnknownBody() {
35
36         $serverVars = array(
37             'REQUEST_URI'    => '/testcol',
38             'REQUEST_METHOD' => 'MKCOL',
39         );
40
41         $request = new Sabre_HTTP_Request($serverVars);
42         $request->setBody("Hello");
43         $this->server->httpRequest = ($request);
44         $this->server->exec();
45
46         $this->assertEquals(array(
47             'Content-Type' => 'application/xml; charset=utf-8',
48         ),$this->response->headers);
49
50         $this->assertEquals('HTTP/1.1 415 Unsupported Media Type',$this->response->status);
51
52     }
53
54     /**
55      * @depends testMkcol
56      */
57     function testMKCOLBrokenXML() {
58
59         $serverVars = array(
60             'REQUEST_URI'    => '/testcol',
61             'REQUEST_METHOD' => 'MKCOL',
62             'HTTP_CONTENT_TYPE' => 'application/xml',
63         );
64
65         $request = new Sabre_HTTP_Request($serverVars);
66         $request->setBody("Hello");
67         $this->server->httpRequest = ($request);
68         $this->server->exec();
69
70         $this->assertEquals(array(
71             'Content-Type' => 'application/xml; charset=utf-8',
72         ),$this->response->headers);
73
74         $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status);
75
76     }
77
78     /**
79      * @depends testMkcol
80      */
81     function testMKCOLUnknownXML() {
82
83         $serverVars = array(
84             'REQUEST_URI'    => '/testcol',
85             'REQUEST_METHOD' => 'MKCOL',
86             'HTTP_CONTENT_TYPE' => 'application/xml',
87         );
88
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();
93
94         $this->assertEquals(array(
95             'Content-Type' => 'application/xml; charset=utf-8',
96         ),$this->response->headers);
97
98         $this->assertEquals('HTTP/1.1 415 Unsupported Media Type',$this->response->status);
99
100     }
101
102     /**
103      * @depends testMkcol
104      */
105     function testMKCOLNoResourceType() {
106
107         $serverVars = array(
108             'REQUEST_URI'    => '/testcol',
109             'REQUEST_METHOD' => 'MKCOL',
110             'HTTP_CONTENT_TYPE' => 'application/xml',
111         );
112
113         $request = new Sabre_HTTP_Request($serverVars);
114         $request->setBody('<?xml version="1.0"?>
115 <mkcol xmlns="DAV:">
116   <set>
117     <prop>
118         <displayname>Evert</displayname>
119     </prop>
120   </set>
121 </mkcol>');
122         $this->server->httpRequest = ($request);
123         $this->server->exec();
124
125         $this->assertEquals(array(
126             'Content-Type' => 'application/xml; charset=utf-8',
127         ),$this->response->headers);
128
129         $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
130
131     }
132
133     /**
134      * @depends testMKCOLNoResourceType
135      */
136     function testMKCOLIncorrectResourceType() {
137
138         $serverVars = array(
139             'REQUEST_URI'    => '/testcol',
140             'REQUEST_METHOD' => 'MKCOL',
141             'HTTP_CONTENT_TYPE' => 'application/xml',
142         );
143
144         $request = new Sabre_HTTP_Request($serverVars);
145         $request->setBody('<?xml version="1.0"?>
146 <mkcol xmlns="DAV:">
147   <set>
148     <prop>
149         <resourcetype><blabla /></resourcetype>
150     </prop>
151   </set>
152 </mkcol>');
153         $this->server->httpRequest = ($request);
154         $this->server->exec();
155
156         $this->assertEquals(array(
157             'Content-Type' => 'application/xml; charset=utf-8',
158         ),$this->response->headers);
159
160         $this->assertEquals('HTTP/1.1 403 Forbidden',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
161
162     }
163
164     /**
165      * @depends testMKCOLIncorrectResourceType
166      */
167     function testMKCOLIncorrectResourceType2() {
168
169         $serverVars = array(
170             'REQUEST_URI'    => '/testcol',
171             'REQUEST_METHOD' => 'MKCOL',
172             'HTTP_CONTENT_TYPE' => 'application/xml',
173         );
174
175         $request = new Sabre_HTTP_Request($serverVars);
176         $request->setBody('<?xml version="1.0"?>
177 <mkcol xmlns="DAV:">
178   <set>
179     <prop>
180         <resourcetype><collection /><blabla /></resourcetype>
181     </prop>
182   </set>
183 </mkcol>');
184         $this->server->httpRequest = ($request);
185         $this->server->exec();
186
187         $this->assertEquals(array(
188             'Content-Type' => 'application/xml; charset=utf-8',
189         ),$this->response->headers);
190
191         $this->assertEquals('HTTP/1.1 403 Forbidden',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
192
193     }
194
195     /**
196      * @depends testMKCOLIncorrectResourceType2
197      */
198     function testMKCOLSuccess() {
199
200         $serverVars = array(
201             'REQUEST_URI'    => '/testcol',
202             'REQUEST_METHOD' => 'MKCOL',
203             'HTTP_CONTENT_TYPE' => 'application/xml',
204         );
205
206         $request = new Sabre_HTTP_Request($serverVars);
207         $request->setBody('<?xml version="1.0"?>
208 <mkcol xmlns="DAV:">
209   <set>
210     <prop>
211         <resourcetype><collection /></resourcetype>
212     </prop>
213   </set>
214 </mkcol>');
215         $this->server->httpRequest = ($request);
216         $this->server->exec();
217
218         $this->assertEquals(array(
219             'Content-Length' => '0',
220         ),$this->response->headers);
221
222         $this->assertEquals('HTTP/1.1 201 Created',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
223
224     }
225
226     /**
227      * @depends testMKCOLIncorrectResourceType2
228      */
229     function testMKCOLWhiteSpaceResourceType() {
230
231         $serverVars = array(
232             'REQUEST_URI'    => '/testcol',
233             'REQUEST_METHOD' => 'MKCOL',
234             'HTTP_CONTENT_TYPE' => 'application/xml',
235         );
236
237         $request = new Sabre_HTTP_Request($serverVars);
238         $request->setBody('<?xml version="1.0"?>
239 <mkcol xmlns="DAV:">
240   <set>
241     <prop>
242         <resourcetype>
243             <collection />
244         </resourcetype>
245     </prop>
246   </set>
247 </mkcol>');
248         $this->server->httpRequest = ($request);
249         $this->server->exec();
250
251         $this->assertEquals(array(
252             'Content-Length' => '0',
253         ),$this->response->headers);
254
255         $this->assertEquals('HTTP/1.1 201 Created',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
256
257     }
258
259     /**
260      * @depends testMKCOLIncorrectResourceType2
261      */
262     function testMKCOLNoParent() {
263
264         $serverVars = array(
265             'REQUEST_URI'    => '/testnoparent/409me',
266             'REQUEST_METHOD' => 'MKCOL',
267         );
268
269         $request = new Sabre_HTTP_Request($serverVars);
270         $request->setBody('');
271
272         $this->server->httpRequest = ($request);
273         $this->server->exec();
274
275         $this->assertEquals(array(
276             'Content-Type' => 'application/xml; charset=utf-8',
277         ),$this->response->headers);
278
279         $this->assertEquals('HTTP/1.1 409 Conflict',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
280
281     }
282
283     /**
284      * @depends testMKCOLIncorrectResourceType2
285      */
286     function testMKCOLParentIsNoCollection() {
287
288         $serverVars = array(
289             'REQUEST_URI'    => '/test.txt/409me',
290             'REQUEST_METHOD' => 'MKCOL',
291         );
292
293         $request = new Sabre_HTTP_Request($serverVars);
294         $request->setBody('');
295
296         $this->server->httpRequest = ($request);
297         $this->server->exec();
298
299         $this->assertEquals(array(
300             'Content-Type' => 'application/xml; charset=utf-8',
301         ),$this->response->headers);
302
303         $this->assertEquals('HTTP/1.1 409 Conflict',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
304
305     }
306
307     /**
308      * @depends testMKCOLIncorrectResourceType2
309      */
310     function testMKCOLAlreadyExists() {
311
312         $serverVars = array(
313             'REQUEST_URI'    => '/test.txt',
314             'REQUEST_METHOD' => 'MKCOL',
315         );
316
317         $request = new Sabre_HTTP_Request($serverVars);
318         $request->setBody('');
319
320         $this->server->httpRequest = ($request);
321         $this->server->exec();
322
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);
327
328         $this->assertEquals('HTTP/1.1 405 Method Not Allowed',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
329
330     }
331
332     /**
333      * @depends testMKCOLSuccess
334      * @depends testMKCOLAlreadyExists
335      */
336     function testMKCOLAndProps() {
337
338         $serverVars = array(
339             'REQUEST_URI'    => '/testcol',
340             'REQUEST_METHOD' => 'MKCOL',
341             'HTTP_CONTENT_TYPE' => 'application/xml',
342         );
343
344         $request = new Sabre_HTTP_Request($serverVars);
345         $request->setBody('<?xml version="1.0"?>
346 <mkcol xmlns="DAV:">
347   <set>
348     <prop>
349         <resourcetype><collection /></resourcetype>
350         <displayname>my new collection</displayname>
351     </prop>
352   </set>
353 </mkcol>');
354         $this->server->httpRequest = ($request);
355         $this->server->exec();
356
357         $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
358
359         $this->assertEquals(array(
360             'Content-Type' => 'application/xml; charset=utf-8',
361         ),$this->response->headers);
362
363
364
365     }
366
367 }