/tine20/vendor/sabre/dav/tests/Sabre/DAV/FSExt/ServerTest.php

https://gitlab.com/israel.correa/Expresso · PHP · 224 lines · 162 code · 62 blank · 0 comment · 0 complexity · c472166aca21905329d6810d4c987f8c MD5 · raw file

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