3 require_once 'Sabre/DAV/AbstractServer.php';
5 class Sabre_DAV_FSExt_ServerTest extends Sabre_DAV_AbstractServer{
7 protected function getRootNode() {
9 return new Sabre_DAV_FSExt_Directory($this->tempDir);
16 'REQUEST_URI' => '/test.txt',
17 'REQUEST_METHOD' => 'GET',
20 $request = new Sabre_HTTP_Request($serverVars);
21 $this->server->httpRequest = ($request);
22 $this->server->exec();
24 $this->assertEquals(array(
25 'Content-Type' => 'application/octet-stream',
26 'Content-Length' => 13,
27 'Last-Modified' => Sabre_HTTP_Util::toHTTPDate(new DateTime('@' . filemtime($this->tempDir . '/test.txt'))),
28 'ETag' => '"' .md5_file($this->tempDir . '/test.txt') . '"',
30 $this->response->headers
33 $this->assertEquals('HTTP/1.1 200 OK',$this->response->status);
34 $this->assertEquals('Test contents', stream_get_contents($this->response->body));
41 'REQUEST_URI' => '/test.txt',
42 'REQUEST_METHOD' => 'HEAD',
45 $request = new Sabre_HTTP_Request($serverVars);
46 $this->server->httpRequest = ($request);
47 $this->server->exec();
49 $this->assertEquals(array(
50 'Content-Type' => 'application/octet-stream',
51 'Content-Length' => 13,
52 'Last-Modified' => Sabre_HTTP_Util::toHTTPDate(new DateTime('@' . filemtime($this->tempDir . '/test.txt'))),
53 'ETag' => '"' . md5_file($this->tempDir . '/test.txt') . '"',
55 $this->response->headers
58 $this->assertEquals('HTTP/1.1 200 OK',$this->response->status);
59 $this->assertEquals('', $this->response->body);
66 'REQUEST_URI' => '/testput.txt',
67 'REQUEST_METHOD' => 'PUT',
70 $request = new Sabre_HTTP_Request($serverVars);
71 $request->setBody('Testing new file');
72 $this->server->httpRequest = ($request);
73 $this->server->exec();
75 $this->assertEquals(array(
76 'Content-Length' => 0,
77 'ETag' => '"' . md5('Testing new file') . '"',
78 ), $this->response->headers);
80 $this->assertEquals('HTTP/1.1 201 Created',$this->response->status);
81 $this->assertEquals('', $this->response->body);
82 $this->assertEquals('Testing new file',file_get_contents($this->tempDir . '/testput.txt'));
86 function testPutAlreadyExists() {
89 'REQUEST_URI' => '/test.txt',
90 'REQUEST_METHOD' => 'PUT',
91 'HTTP_IF_NONE_MATCH' => '*',
94 $request = new Sabre_HTTP_Request($serverVars);
95 $request->setBody('Testing new file');
96 $this->server->httpRequest = ($request);
97 $this->server->exec();
99 $this->assertEquals(array(
100 'Content-Type' => 'application/xml; charset=utf-8',
101 ),$this->response->headers);
103 $this->assertEquals('HTTP/1.1 412 Precondition failed',$this->response->status);
104 $this->assertNotEquals('Testing new file',file_get_contents($this->tempDir . '/test.txt'));
108 function testMkcol() {
111 'REQUEST_URI' => '/testcol',
112 'REQUEST_METHOD' => 'MKCOL',
115 $request = new Sabre_HTTP_Request($serverVars);
116 $request->setBody("");
117 $this->server->httpRequest = ($request);
118 $this->server->exec();
120 $this->assertEquals(array(
121 'Content-Length' => '0',
122 ),$this->response->headers);
124 $this->assertEquals('HTTP/1.1 201 Created',$this->response->status);
125 $this->assertEquals('', $this->response->body);
126 $this->assertTrue(is_dir($this->tempDir . '/testcol'));
130 function testPutUpdate() {
133 'REQUEST_URI' => '/test.txt',
134 'REQUEST_METHOD' => 'PUT',
137 $request = new Sabre_HTTP_Request($serverVars);
138 $request->setBody('Testing updated file');
139 $this->server->httpRequest = ($request);
140 $this->server->exec();
142 $this->assertEquals('0', $this->response->headers['Content-Length']);
144 $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status);
145 $this->assertEquals('', $this->response->body);
146 $this->assertEquals('Testing updated file',file_get_contents($this->tempDir . '/test.txt'));
150 function testDelete() {
153 'REQUEST_URI' => '/test.txt',
154 'REQUEST_METHOD' => 'DELETE',
157 $request = new Sabre_HTTP_Request($serverVars);
158 $this->server->httpRequest = ($request);
159 $this->server->exec();
161 $this->assertEquals(array(
162 'Content-Length' => '0',
163 ),$this->response->headers);
165 $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status);
166 $this->assertEquals('', $this->response->body);
167 $this->assertFalse(file_exists($this->tempDir . '/test.txt'));
171 function testDeleteDirectory() {
174 'REQUEST_URI' => '/testcol',
175 'REQUEST_METHOD' => 'DELETE',
178 mkdir($this->tempDir.'/testcol');
179 file_put_contents($this->tempDir.'/testcol/test.txt','Hi! I\'m a file with a short lifespan');
181 $request = new Sabre_HTTP_Request($serverVars);
182 $this->server->httpRequest = ($request);
183 $this->server->exec();
185 $this->assertEquals(array(
186 'Content-Length' => '0',
187 ),$this->response->headers);
188 $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status);
189 $this->assertEquals('', $this->response->body);
190 $this->assertFalse(file_exists($this->tempDir . '/col'));
194 function testOptions() {
197 'REQUEST_URI' => '/',
198 'REQUEST_METHOD' => 'OPTIONS',
201 $request = new Sabre_HTTP_Request($serverVars);
202 $this->server->httpRequest = ($request);
203 $this->server->exec();
205 $this->assertEquals(array(
206 'DAV' => '1, 3, extended-mkcol',
207 'MS-Author-Via' => 'DAV',
208 'Allow' => 'OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT',
209 'Accept-Ranges' => 'bytes',
210 'Content-Length' => '0',
211 'X-Sabre-Version'=> Sabre_DAV_Version::VERSION,
212 ),$this->response->headers);
214 $this->assertEquals('HTTP/1.1 200 OK',$this->response->status);
215 $this->assertEquals('', $this->response->body);