ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ServerMKCOLTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\DAV;
4 
5 use Sabre\HTTP;
6 
8 
9  function testMkcol() {
10 
11  $serverVars = [
12  'REQUEST_URI' => '/testcol',
13  'REQUEST_METHOD' => 'MKCOL',
14  ];
15 
17  $request->setBody("");
18  $this->server->httpRequest = ($request);
19  $this->server->exec();
20 
21  $this->assertEquals([
22  'X-Sabre-Version' => [Version::VERSION],
23  'Content-Length' => ['0'],
24  ], $this->response->getHeaders());
25 
26  $this->assertEquals(201, $this->response->status);
27  $this->assertEquals('', $this->response->body);
28  $this->assertTrue(is_dir($this->tempDir . '/testcol'));
29 
30  }
31 
35  function testMKCOLUnknownBody() {
36 
37  $serverVars = [
38  'REQUEST_URI' => '/testcol',
39  'REQUEST_METHOD' => 'MKCOL',
40  ];
41 
43  $request->setBody("Hello");
44  $this->server->httpRequest = ($request);
45  $this->server->exec();
46 
47  $this->assertEquals([
48  'X-Sabre-Version' => [Version::VERSION],
49  'Content-Type' => ['application/xml; charset=utf-8'],
50  ], $this->response->getHeaders());
51 
52  $this->assertEquals(415, $this->response->status);
53 
54  }
55 
59  function testMKCOLBrokenXML() {
60 
61  $serverVars = [
62  'REQUEST_URI' => '/testcol',
63  'REQUEST_METHOD' => 'MKCOL',
64  'HTTP_CONTENT_TYPE' => 'application/xml',
65  ];
66 
68  $request->setBody("Hello");
69  $this->server->httpRequest = ($request);
70  $this->server->exec();
71 
72  $this->assertEquals([
73  'X-Sabre-Version' => [Version::VERSION],
74  'Content-Type' => ['application/xml; charset=utf-8'],
75  ], $this->response->getHeaders());
76 
77  $this->assertEquals(400, $this->response->getStatus(), $this->response->getBodyAsString());
78 
79  }
80 
84  function testMKCOLUnknownXML() {
85 
86  $serverVars = [
87  'REQUEST_URI' => '/testcol',
88  'REQUEST_METHOD' => 'MKCOL',
89  'HTTP_CONTENT_TYPE' => 'application/xml',
90  ];
91 
93  $request->setBody('<?xml version="1.0"?><html></html>');
94  $this->server->httpRequest = ($request);
95  $this->server->exec();
96 
97  $this->assertEquals([
98  'X-Sabre-Version' => [Version::VERSION],
99  'Content-Type' => ['application/xml; charset=utf-8'],
100  ], $this->response->getHeaders());
101 
102  $this->assertEquals(400, $this->response->getStatus());
103 
104  }
105 
110 
111  $serverVars = [
112  'REQUEST_URI' => '/testcol',
113  'REQUEST_METHOD' => 'MKCOL',
114  'HTTP_CONTENT_TYPE' => 'application/xml',
115  ];
116 
118  $request->setBody('<?xml version="1.0"?>
119 <mkcol xmlns="DAV:">
120  <set>
121  <prop>
122  <displayname>Evert</displayname>
123  </prop>
124  </set>
125 </mkcol>');
126  $this->server->httpRequest = ($request);
127  $this->server->exec();
128 
129  $this->assertEquals([
130  'X-Sabre-Version' => [Version::VERSION],
131  'Content-Type' => ['application/xml; charset=utf-8'],
132  ], $this->response->getHeaders());
133 
134  $this->assertEquals(400, $this->response->status, 'Wrong statuscode received. Full response body: ' . $this->response->body);
135 
136  }
137 
142 
143  $serverVars = [
144  'REQUEST_URI' => '/testcol',
145  'REQUEST_METHOD' => 'MKCOL',
146  'HTTP_CONTENT_TYPE' => 'application/xml',
147  ];
148 
150  $request->setBody('<?xml version="1.0"?>
151 <mkcol xmlns="DAV:">
152  <set>
153  <prop>
154  <resourcetype><collection /><blabla /></resourcetype>
155  </prop>
156  </set>
157 </mkcol>');
158  $this->server->httpRequest = ($request);
159  $this->server->exec();
160 
161  $this->assertEquals([
162  'X-Sabre-Version' => [Version::VERSION],
163  'Content-Type' => ['application/xml; charset=utf-8'],
164  ], $this->response->getHeaders());
165 
166  $this->assertEquals(403, $this->response->status, 'Wrong statuscode received. Full response body: ' . $this->response->body);
167 
168  }
169 
173  function testMKCOLSuccess() {
174 
175  $serverVars = [
176  'REQUEST_URI' => '/testcol',
177  'REQUEST_METHOD' => 'MKCOL',
178  'HTTP_CONTENT_TYPE' => 'application/xml',
179  ];
180 
182  $request->setBody('<?xml version="1.0"?>
183 <mkcol xmlns="DAV:">
184  <set>
185  <prop>
186  <resourcetype><collection /></resourcetype>
187  </prop>
188  </set>
189 </mkcol>');
190  $this->server->httpRequest = ($request);
191  $this->server->exec();
192 
193  $this->assertEquals([
194  'X-Sabre-Version' => [Version::VERSION],
195  'Content-Length' => ['0'],
196  ], $this->response->getHeaders());
197 
198  $this->assertEquals(201, $this->response->status, 'Wrong statuscode received. Full response body: ' . $this->response->body);
199 
200  }
201 
206 
207  $serverVars = [
208  'REQUEST_URI' => '/testcol',
209  'REQUEST_METHOD' => 'MKCOL',
210  'HTTP_CONTENT_TYPE' => 'application/xml',
211  ];
212 
214  $request->setBody('<?xml version="1.0"?>
215 <mkcol xmlns="DAV:">
216  <set>
217  <prop>
218  <resourcetype>
219  <collection />
220  </resourcetype>
221  </prop>
222  </set>
223 </mkcol>');
224  $this->server->httpRequest = ($request);
225  $this->server->exec();
226 
227  $this->assertEquals([
228  'X-Sabre-Version' => [Version::VERSION],
229  'Content-Length' => ['0'],
230  ], $this->response->getHeaders());
231 
232  $this->assertEquals(201, $this->response->status, 'Wrong statuscode received. Full response body: ' . $this->response->body);
233 
234  }
235 
239  function testMKCOLNoParent() {
240 
241  $serverVars = [
242  'REQUEST_URI' => '/testnoparent/409me',
243  'REQUEST_METHOD' => 'MKCOL',
244  ];
245 
247  $request->setBody('');
248 
249  $this->server->httpRequest = ($request);
250  $this->server->exec();
251 
252  $this->assertEquals([
253  'X-Sabre-Version' => [Version::VERSION],
254  'Content-Type' => ['application/xml; charset=utf-8'],
255  ], $this->response->getHeaders());
256 
257  $this->assertEquals(409, $this->response->status, 'Wrong statuscode received. Full response body: ' . $this->response->body);
258 
259  }
260 
265 
266  $serverVars = [
267  'REQUEST_URI' => '/test.txt/409me',
268  'REQUEST_METHOD' => 'MKCOL',
269  ];
270 
272  $request->setBody('');
273 
274  $this->server->httpRequest = ($request);
275  $this->server->exec();
276 
277  $this->assertEquals([
278  'X-Sabre-Version' => [Version::VERSION],
279  'Content-Type' => ['application/xml; charset=utf-8'],
280  ], $this->response->getHeaders());
281 
282  $this->assertEquals(409, $this->response->status, 'Wrong statuscode received. Full response body: ' . $this->response->body);
283 
284  }
285 
290 
291  $serverVars = [
292  'REQUEST_URI' => '/test.txt',
293  'REQUEST_METHOD' => 'MKCOL',
294  ];
295 
297  $request->setBody('');
298 
299  $this->server->httpRequest = ($request);
300  $this->server->exec();
301 
302  $this->assertEquals([
303  'X-Sabre-Version' => [Version::VERSION],
304  'Content-Type' => ['application/xml; charset=utf-8'],
305  'Allow' => ['OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT'],
306  ], $this->response->getHeaders());
307 
308  $this->assertEquals(405, $this->response->status, 'Wrong statuscode received. Full response body: ' . $this->response->body);
309 
310  }
311 
316  function testMKCOLAndProps() {
317 
318  $request = new HTTP\Request(
319  'MKCOL',
320  '/testcol',
321  ['Content-Type' => 'application/xml']
322  );
323  $request->setBody('<?xml version="1.0"?>
324 <mkcol xmlns="DAV:">
325  <set>
326  <prop>
327  <resourcetype><collection /></resourcetype>
328  <displayname>my new collection</displayname>
329  </prop>
330  </set>
331 </mkcol>');
332  $this->server->httpRequest = ($request);
333  $this->server->exec();
334 
335  $this->assertEquals(207, $this->response->status, 'Wrong statuscode received. Full response body: ' . $this->response->body);
336 
337  $this->assertEquals([
338  'X-Sabre-Version' => [Version::VERSION],
339  'Content-Type' => ['application/xml; charset=utf-8'],
340  ], $this->response->getHeaders());
341 
342  $responseBody = $this->response->getBodyAsString();
343 
344  $expected = <<<XML
345 <?xml version="1.0"?>
346 <d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
347  <d:response>
348  <d:href>/testcol</d:href>
349  <d:propstat>
350  <d:prop>
351  <d:displayname />
352  </d:prop>
353  <d:status>HTTP/1.1 403 Forbidden</d:status>
354  </d:propstat>
355  </d:response>
356 </d:multistatus>
357 XML;
358 
359  $this->assertXmlStringEqualsXmlString(
360  $expected,
361  $responseBody
362  );
363 
364  }
365 
366 }
testMKCOLSuccess()
testMKCOLIncorrectResourceType
testMKCOLParentIsNoCollection()
testMKCOLIncorrectResourceType
const VERSION
Full version number.
Definition: Version.php:17
testMKCOLAlreadyExists()
testMKCOLIncorrectResourceType
testMKCOLAndProps()
testMKCOLSuccess testMKCOLAlreadyExists
testMKCOLIncorrectResourceType()
testMkcol
testMKCOLNoParent()
testMKCOLIncorrectResourceType
static createFromServerArray(array $serverArray)
This static method will create a new Request object, based on a PHP $_SERVER array.
Definition: Sapi.php:107
testMKCOLWhiteSpaceResourceType()
testMKCOLIncorrectResourceType