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