]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/DAV/ServerMKCOLTest.php
Merge branch 'master' of git://github.com/friendica/friendica-addons
[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     /**
197      * @depends testMKCOLIncorrectResourceType2
198      */
199     function testMKCOLSuccess() {
200
201         $serverVars = array(
202             'REQUEST_URI'    => '/testcol',
203             'REQUEST_METHOD' => 'MKCOL',
204             'HTTP_CONTENT_TYPE' => 'application/xml',
205         );
206
207         $request = new Sabre_HTTP_Request($serverVars);
208         $request->setBody('<?xml version="1.0"?>
209 <mkcol xmlns="DAV:">
210   <set>
211     <prop>
212         <resourcetype><collection /></resourcetype>
213     </prop>
214   </set>
215 </mkcol>');
216         $this->server->httpRequest = ($request);
217         $this->server->exec();
218
219         $this->assertEquals(array(
220             'Content-Length' => '0',
221         ),$this->response->headers);
222
223         $this->assertEquals('HTTP/1.1 201 Created',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
224
225     }
226
227
228     /**
229      * @depends testMKCOLIncorrectResourceType2
230      */
231     function testMKCOLNoParent() {
232
233         $serverVars = array(
234             'REQUEST_URI'    => '/testnoparent/409me',
235             'REQUEST_METHOD' => 'MKCOL',
236         );
237
238         $request = new Sabre_HTTP_Request($serverVars);
239         $request->setBody('');
240
241         $this->server->httpRequest = ($request);
242         $this->server->exec();
243
244         $this->assertEquals(array(
245             'Content-Type' => 'application/xml; charset=utf-8',
246         ),$this->response->headers);
247
248         $this->assertEquals('HTTP/1.1 409 Conflict',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
249
250     }
251
252     /**
253      * @depends testMKCOLIncorrectResourceType2
254      */
255     function testMKCOLParentIsNoCollection() {
256
257         $serverVars = array(
258             'REQUEST_URI'    => '/test.txt/409me',
259             'REQUEST_METHOD' => 'MKCOL',
260         );
261
262         $request = new Sabre_HTTP_Request($serverVars);
263         $request->setBody('');
264
265         $this->server->httpRequest = ($request);
266         $this->server->exec();
267
268         $this->assertEquals(array(
269             'Content-Type' => 'application/xml; charset=utf-8',
270         ),$this->response->headers);
271
272         $this->assertEquals('HTTP/1.1 409 Conflict',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
273
274     }
275
276     /**
277      * @depends testMKCOLIncorrectResourceType2
278      */
279     function testMKCOLAlreadyExists() {
280
281         $serverVars = array(
282             'REQUEST_URI'    => '/test.txt',
283             'REQUEST_METHOD' => 'MKCOL',
284         );
285
286         $request = new Sabre_HTTP_Request($serverVars);
287         $request->setBody('');
288
289         $this->server->httpRequest = ($request);
290         $this->server->exec();
291
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);
296
297         $this->assertEquals('HTTP/1.1 405 Method Not Allowed',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
298
299     }
300
301     /**
302      * @depends testMKCOLSuccess
303      * @depends testMKCOLAlreadyExists
304      */
305     function testMKCOLAndProps() {
306
307         $serverVars = array(
308             'REQUEST_URI'    => '/testcol',
309             'REQUEST_METHOD' => 'MKCOL',
310             'HTTP_CONTENT_TYPE' => 'application/xml',
311         );
312
313         $request = new Sabre_HTTP_Request($serverVars);
314         $request->setBody('<?xml version="1.0"?>
315 <mkcol xmlns="DAV:">
316   <set>
317     <prop>
318         <resourcetype><collection /></resourcetype>
319         <displayname>my new collection</displayname>
320     </prop>
321   </set>
322 </mkcol>');
323         $this->server->httpRequest = ($request);
324         $this->server->exec();
325
326         $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
327
328         $this->assertEquals(array(
329             'Content-Type' => 'application/xml; charset=utf-8',
330         ),$this->response->headers);
331
332
333
334     }
335
336 }