/tests/Sabre/DAV/ServerMKCOLTest.php

https://github.com/lkneschke/SabreDAV · PHP · 338 lines · 221 code · 83 blank · 34 comment · 0 complexity · bcc8a0cc2550bf95f5b11ad1c8686ff0 MD5 · raw file

  1. <?php
  2. require_once 'Sabre/HTTP/ResponseMock.php';
  3. require_once 'Sabre/DAV/AbstractServer.php';
  4. require_once 'Sabre/DAV/Exception.php';
  5. class Sabre_DAV_ServerMKCOLTest extends Sabre_DAV_AbstractServer {
  6. function testMkcol() {
  7. $serverVars = array(
  8. 'REQUEST_URI' => '/testcol',
  9. 'REQUEST_METHOD' => 'MKCOL',
  10. );
  11. $request = new Sabre_HTTP_Request($serverVars);
  12. $request->setBody("");
  13. $this->server->httpRequest = ($request);
  14. $this->server->exec();
  15. $this->assertEquals(array(
  16. 'Content-Length' => '0',
  17. ),$this->response->headers);
  18. $this->assertEquals('HTTP/1.1 201 Created',$this->response->status);
  19. $this->assertEquals('', $this->response->body);
  20. $this->assertTrue(is_dir($this->tempDir . '/testcol'));
  21. }
  22. /**
  23. * @depends testMkcol
  24. */
  25. function testMKCOLUnknownBody() {
  26. $serverVars = array(
  27. 'REQUEST_URI' => '/testcol',
  28. 'REQUEST_METHOD' => 'MKCOL',
  29. );
  30. $request = new Sabre_HTTP_Request($serverVars);
  31. $request->setBody("Hello");
  32. $this->server->httpRequest = ($request);
  33. $this->server->exec();
  34. $this->assertEquals(array(
  35. 'Content-Type' => 'application/xml; charset=utf-8',
  36. ),$this->response->headers);
  37. $this->assertEquals('HTTP/1.1 415 Unsupported Media Type',$this->response->status);
  38. }
  39. /**
  40. * @depends testMkcol
  41. */
  42. function testMKCOLBrokenXML() {
  43. $serverVars = array(
  44. 'REQUEST_URI' => '/testcol',
  45. 'REQUEST_METHOD' => 'MKCOL',
  46. 'HTTP_CONTENT_TYPE' => 'application/xml',
  47. );
  48. $request = new Sabre_HTTP_Request($serverVars);
  49. $request->setBody("Hello");
  50. $this->server->httpRequest = ($request);
  51. $this->server->exec();
  52. $this->assertEquals(array(
  53. 'Content-Type' => 'application/xml; charset=utf-8',
  54. ),$this->response->headers);
  55. $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status);
  56. }
  57. /**
  58. * @depends testMkcol
  59. */
  60. function testMKCOLUnknownXML() {
  61. $serverVars = array(
  62. 'REQUEST_URI' => '/testcol',
  63. 'REQUEST_METHOD' => 'MKCOL',
  64. 'HTTP_CONTENT_TYPE' => 'application/xml',
  65. );
  66. $request = new Sabre_HTTP_Request($serverVars);
  67. $request->setBody('<?xml version="1.0"?><html></html>');
  68. $this->server->httpRequest = ($request);
  69. $this->server->exec();
  70. $this->assertEquals(array(
  71. 'Content-Type' => 'application/xml; charset=utf-8',
  72. ),$this->response->headers);
  73. $this->assertEquals('HTTP/1.1 415 Unsupported Media Type',$this->response->status);
  74. }
  75. /**
  76. * @depends testMkcol
  77. */
  78. function testMKCOLNoResourceType() {
  79. $serverVars = array(
  80. 'REQUEST_URI' => '/testcol',
  81. 'REQUEST_METHOD' => 'MKCOL',
  82. 'HTTP_CONTENT_TYPE' => 'application/xml',
  83. );
  84. $request = new Sabre_HTTP_Request($serverVars);
  85. $request->setBody('<?xml version="1.0"?>
  86. <mkcol xmlns="DAV:">
  87. <set>
  88. <prop>
  89. <displayname>Evert</displayname>
  90. </prop>
  91. </set>
  92. </mkcol>');
  93. $this->server->httpRequest = ($request);
  94. $this->server->exec();
  95. $this->assertEquals(array(
  96. 'Content-Type' => 'application/xml; charset=utf-8',
  97. ),$this->response->headers);
  98. $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
  99. }
  100. /**
  101. * @depends testMKCOLNoResourceType
  102. */
  103. function testMKCOLIncorrectResourceType() {
  104. $serverVars = array(
  105. 'REQUEST_URI' => '/testcol',
  106. 'REQUEST_METHOD' => 'MKCOL',
  107. 'HTTP_CONTENT_TYPE' => 'application/xml',
  108. );
  109. $request = new Sabre_HTTP_Request($serverVars);
  110. $request->setBody('<?xml version="1.0"?>
  111. <mkcol xmlns="DAV:">
  112. <set>
  113. <prop>
  114. <resourcetype><blabla /></resourcetype>
  115. </prop>
  116. </set>
  117. </mkcol>');
  118. $this->server->httpRequest = ($request);
  119. $this->server->exec();
  120. $this->assertEquals(array(
  121. 'Content-Type' => 'application/xml; charset=utf-8',
  122. ),$this->response->headers);
  123. $this->assertEquals('HTTP/1.1 403 Forbidden',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
  124. }
  125. /**
  126. * @depends testMKCOLIncorrectResourceType
  127. */
  128. function testMKCOLIncorrectResourceType2() {
  129. $serverVars = array(
  130. 'REQUEST_URI' => '/testcol',
  131. 'REQUEST_METHOD' => 'MKCOL',
  132. 'HTTP_CONTENT_TYPE' => 'application/xml',
  133. );
  134. $request = new Sabre_HTTP_Request($serverVars);
  135. $request->setBody('<?xml version="1.0"?>
  136. <mkcol xmlns="DAV:">
  137. <set>
  138. <prop>
  139. <resourcetype><collection /><blabla /></resourcetype>
  140. </prop>
  141. </set>
  142. </mkcol>');
  143. $this->server->httpRequest = ($request);
  144. $this->server->exec();
  145. $this->assertEquals(array(
  146. 'Content-Type' => 'application/xml; charset=utf-8',
  147. ),$this->response->headers);
  148. $this->assertEquals('HTTP/1.1 403 Forbidden',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
  149. }
  150. /**
  151. * @depends testMKCOLIncorrectResourceType2
  152. */
  153. function testMKCOLSuccess() {
  154. $serverVars = array(
  155. 'REQUEST_URI' => '/testcol',
  156. 'REQUEST_METHOD' => 'MKCOL',
  157. 'HTTP_CONTENT_TYPE' => 'application/xml',
  158. );
  159. $request = new Sabre_HTTP_Request($serverVars);
  160. $request->setBody('<?xml version="1.0"?>
  161. <mkcol xmlns="DAV:">
  162. <set>
  163. <prop>
  164. <resourcetype><collection /></resourcetype>
  165. </prop>
  166. </set>
  167. </mkcol>');
  168. $this->server->httpRequest = ($request);
  169. $this->server->exec();
  170. $this->assertEquals(array(
  171. 'Content-Length' => '0',
  172. ),$this->response->headers);
  173. $this->assertEquals('HTTP/1.1 201 Created',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
  174. }
  175. /**
  176. * @depends testMKCOLIncorrectResourceType2
  177. */
  178. function testMKCOLNoParent() {
  179. $serverVars = array(
  180. 'REQUEST_URI' => '/testnoparent/409me',
  181. 'REQUEST_METHOD' => 'MKCOL',
  182. );
  183. $request = new Sabre_HTTP_Request($serverVars);
  184. $request->setBody('');
  185. $this->server->httpRequest = ($request);
  186. $this->server->exec();
  187. $this->assertEquals(array(
  188. 'Content-Type' => 'application/xml; charset=utf-8',
  189. ),$this->response->headers);
  190. $this->assertEquals('HTTP/1.1 409 Conflict',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
  191. }
  192. /**
  193. * @depends testMKCOLIncorrectResourceType2
  194. */
  195. function testMKCOLParentIsNoCollection() {
  196. $serverVars = array(
  197. 'REQUEST_URI' => '/test.txt/409me',
  198. 'REQUEST_METHOD' => 'MKCOL',
  199. );
  200. $request = new Sabre_HTTP_Request($serverVars);
  201. $request->setBody('');
  202. $this->server->httpRequest = ($request);
  203. $this->server->exec();
  204. $this->assertEquals(array(
  205. 'Content-Type' => 'application/xml; charset=utf-8',
  206. ),$this->response->headers);
  207. $this->assertEquals('HTTP/1.1 409 Conflict',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
  208. }
  209. /**
  210. * @depends testMKCOLIncorrectResourceType2
  211. */
  212. function testMKCOLAlreadyExists() {
  213. $serverVars = array(
  214. 'REQUEST_URI' => '/test.txt',
  215. 'REQUEST_METHOD' => 'MKCOL',
  216. );
  217. $request = new Sabre_HTTP_Request($serverVars);
  218. $request->setBody('');
  219. $this->server->httpRequest = ($request);
  220. $this->server->exec();
  221. $this->assertEquals(array(
  222. 'Content-Type' => 'application/xml; charset=utf-8',
  223. 'Allow' => 'OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT',
  224. ),$this->response->headers);
  225. $this->assertEquals('HTTP/1.1 405 Method Not Allowed',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
  226. }
  227. /**
  228. * @depends testMKCOLSuccess
  229. * @depends testMKCOLAlreadyExists
  230. */
  231. function testMKCOLAndProps() {
  232. $serverVars = array(
  233. 'REQUEST_URI' => '/testcol',
  234. 'REQUEST_METHOD' => 'MKCOL',
  235. 'HTTP_CONTENT_TYPE' => 'application/xml',
  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><collection /></resourcetype>
  243. <displayname>my new collection</displayname>
  244. </prop>
  245. </set>
  246. </mkcol>');
  247. $this->server->httpRequest = ($request);
  248. $this->server->exec();
  249. $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body);
  250. $this->assertEquals(array(
  251. 'Content-Type' => 'application/xml; charset=utf-8',
  252. ),$this->response->headers);
  253. }
  254. }
  255. ?>