/webdav/vendors/SabreDAV/tests/Sabre/DAV/FSExt/ServerTest.php

https://github.com/phpnode/YiiBlocks · PHP · 222 lines · 161 code · 61 blank · 0 comment · 0 complexity · 42e3e013b27564369900576ba7458112 MD5 · raw file

  1. <?php
  2. require_once 'Sabre/DAV/AbstractServer.php';
  3. class Sabre_DAV_FSExt_ServerTest extends Sabre_DAV_AbstractServer{
  4. protected function getRootNode() {
  5. return new Sabre_DAV_FSExt_Directory($this->tempDir);
  6. }
  7. function testGet() {
  8. $serverVars = array(
  9. 'REQUEST_URI' => '/test.txt',
  10. 'REQUEST_METHOD' => 'GET',
  11. );
  12. $request = new Sabre_HTTP_Request($serverVars);
  13. $this->server->httpRequest = ($request);
  14. $this->server->exec();
  15. $this->assertEquals(array(
  16. 'Content-Type' => 'application/octet-stream',
  17. 'Content-Length' => 13,
  18. 'Last-Modified' => date(DateTime::RFC1123,filemtime($this->tempDir . '/test.txt')),
  19. 'ETag' => '"' .md5_file($this->tempDir . '/test.txt') . '"',
  20. ),
  21. $this->response->headers
  22. );
  23. $this->assertEquals('HTTP/1.1 200 Ok',$this->response->status);
  24. $this->assertEquals('Test contents', stream_get_contents($this->response->body));
  25. }
  26. function testHEAD() {
  27. $serverVars = array(
  28. 'REQUEST_URI' => '/test.txt',
  29. 'REQUEST_METHOD' => 'HEAD',
  30. );
  31. $request = new Sabre_HTTP_Request($serverVars);
  32. $this->server->httpRequest = ($request);
  33. $this->server->exec();
  34. $this->assertEquals(array(
  35. 'Content-Type' => 'application/octet-stream',
  36. 'Content-Length' => 13,
  37. 'Last-Modified' => date(DateTime::RFC1123,filemtime($this->tempDir . '/test.txt')),
  38. 'ETag' => '"' . md5_file($this->tempDir . '/test.txt') . '"',
  39. ),
  40. $this->response->headers
  41. );
  42. $this->assertEquals('HTTP/1.1 200 Ok',$this->response->status);
  43. $this->assertEquals('', $this->response->body);
  44. }
  45. function testPut() {
  46. $serverVars = array(
  47. 'REQUEST_URI' => '/testput.txt',
  48. 'REQUEST_METHOD' => 'PUT',
  49. );
  50. $request = new Sabre_HTTP_Request($serverVars);
  51. $request->setBody('Testing new file');
  52. $this->server->httpRequest = ($request);
  53. $this->server->exec();
  54. $this->assertEquals(array(
  55. 'Content-Length' => '0',
  56. ),$this->response->headers);
  57. $this->assertEquals('HTTP/1.1 201 Created',$this->response->status);
  58. $this->assertEquals('', $this->response->body);
  59. $this->assertEquals('Testing new file',file_get_contents($this->tempDir . '/testput.txt'));
  60. }
  61. function testPutAlreadyExists() {
  62. $serverVars = array(
  63. 'REQUEST_URI' => '/test.txt',
  64. 'REQUEST_METHOD' => 'PUT',
  65. 'HTTP_IF_NONE_MATCH' => '*',
  66. );
  67. $request = new Sabre_HTTP_Request($serverVars);
  68. $request->setBody('Testing new file');
  69. $this->server->httpRequest = ($request);
  70. $this->server->exec();
  71. $this->assertEquals(array(
  72. 'Content-Type' => 'application/xml; charset=utf-8',
  73. ),$this->response->headers);
  74. $this->assertEquals('HTTP/1.1 412 Precondition failed',$this->response->status);
  75. $this->assertNotEquals('Testing new file',file_get_contents($this->tempDir . '/test.txt'));
  76. }
  77. function testMkcol() {
  78. $serverVars = array(
  79. 'REQUEST_URI' => '/testcol',
  80. 'REQUEST_METHOD' => 'MKCOL',
  81. );
  82. $request = new Sabre_HTTP_Request($serverVars);
  83. $request->setBody("");
  84. $this->server->httpRequest = ($request);
  85. $this->server->exec();
  86. $this->assertEquals(array(
  87. 'Content-Length' => '0',
  88. ),$this->response->headers);
  89. $this->assertEquals('HTTP/1.1 201 Created',$this->response->status);
  90. $this->assertEquals('', $this->response->body);
  91. $this->assertTrue(is_dir($this->tempDir . '/testcol'));
  92. }
  93. function testPutUpdate() {
  94. $serverVars = array(
  95. 'REQUEST_URI' => '/test.txt',
  96. 'REQUEST_METHOD' => 'PUT',
  97. );
  98. $request = new Sabre_HTTP_Request($serverVars);
  99. $request->setBody('Testing updated file');
  100. $this->server->httpRequest = ($request);
  101. $this->server->exec();
  102. $this->assertEquals(array(
  103. 'Content-Length' => '0',
  104. ),$this->response->headers);
  105. $this->assertEquals('HTTP/1.1 200 Ok',$this->response->status);
  106. $this->assertEquals('', $this->response->body);
  107. $this->assertEquals('Testing updated file',file_get_contents($this->tempDir . '/test.txt'));
  108. }
  109. function testDelete() {
  110. $serverVars = array(
  111. 'REQUEST_URI' => '/test.txt',
  112. 'REQUEST_METHOD' => 'DELETE',
  113. );
  114. $request = new Sabre_HTTP_Request($serverVars);
  115. $this->server->httpRequest = ($request);
  116. $this->server->exec();
  117. $this->assertEquals(array(
  118. 'Content-Length' => '0',
  119. ),$this->response->headers);
  120. $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status);
  121. $this->assertEquals('', $this->response->body);
  122. $this->assertFalse(file_exists($this->tempDir . '/test.txt'));
  123. }
  124. function testDeleteDirectory() {
  125. $serverVars = array(
  126. 'REQUEST_URI' => '/testcol',
  127. 'REQUEST_METHOD' => 'DELETE',
  128. );
  129. mkdir($this->tempDir.'/testcol');
  130. file_put_contents($this->tempDir.'/testcol/test.txt','Hi! I\'m a file with a short lifespan');
  131. $request = new Sabre_HTTP_Request($serverVars);
  132. $this->server->httpRequest = ($request);
  133. $this->server->exec();
  134. $this->assertEquals(array(
  135. 'Content-Length' => '0',
  136. ),$this->response->headers);
  137. $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status);
  138. $this->assertEquals('', $this->response->body);
  139. $this->assertFalse(file_exists($this->tempDir . '/col'));
  140. }
  141. function testOptions() {
  142. $serverVars = array(
  143. 'REQUEST_URI' => '/',
  144. 'REQUEST_METHOD' => 'OPTIONS',
  145. );
  146. $request = new Sabre_HTTP_Request($serverVars);
  147. $this->server->httpRequest = ($request);
  148. $this->server->exec();
  149. $this->assertEquals(array(
  150. 'DAV' => '1, 3, extended-mkcol',
  151. 'MS-Author-Via' => 'DAV',
  152. 'Allow' => 'OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT',
  153. 'Accept-Ranges' => 'bytes',
  154. 'Content-Length' => '0',
  155. 'X-Sabre-Version'=> Sabre_DAV_Version::VERSION,
  156. ),$this->response->headers);
  157. $this->assertEquals('HTTP/1.1 200 Ok',$this->response->status);
  158. $this->assertEquals('', $this->response->body);
  159. }
  160. }
  161. ?>