3 require_once 'Sabre/DAV/AbstractServer.php';
5 class Sabre_DAV_ServerRangeTest extends Sabre_DAV_AbstractServer{
7 protected function getRootNode() {
9 return new Sabre_DAV_FSExt_Directory(SABRE_TEMPDIR);
13 function testRange() {
16 'REQUEST_URI' => '/test.txt',
17 'REQUEST_METHOD' => 'GET',
18 'HTTP_RANGE' => 'bytes=2-5',
21 $request = new Sabre_HTTP_Request($serverVars);
22 $this->server->httpRequest = ($request);
23 $this->server->exec();
25 $this->assertEquals(array(
26 'Content-Type' => 'application/octet-stream',
27 'Content-Length' => 4,
28 'Content-Range' => 'bytes 2-5/13',
29 'Last-Modified' => Sabre_HTTP_Util::toHTTPDate(new DateTime('@' . filemtime($this->tempDir . '/test.txt'))),
30 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')). '"',
32 $this->response->headers
35 $this->assertEquals('HTTP/1.1 206 Partial Content',$this->response->status);
36 $this->assertEquals('st c', stream_get_contents($this->response->body));
43 function testStartRange() {
46 'REQUEST_URI' => '/test.txt',
47 'REQUEST_METHOD' => 'GET',
48 'HTTP_RANGE' => 'bytes=2-',
51 $request = new Sabre_HTTP_Request($serverVars);
52 $this->server->httpRequest = ($request);
53 $this->server->exec();
55 $this->assertEquals(array(
56 'Content-Type' => 'application/octet-stream',
57 'Content-Length' => 11,
58 'Content-Range' => 'bytes 2-12/13',
59 'Last-Modified' => Sabre_HTTP_Util::toHTTPDate(new DateTime('@' . filemtime($this->tempDir . '/test.txt'))),
60 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')) . '"',
62 $this->response->headers
65 $this->assertEquals('HTTP/1.1 206 Partial Content',$this->response->status);
66 $this->assertEquals('st contents', stream_get_contents($this->response->body));
73 function testEndRange() {
76 'REQUEST_URI' => '/test.txt',
77 'REQUEST_METHOD' => 'GET',
78 'HTTP_RANGE' => 'bytes=-8',
81 $request = new Sabre_HTTP_Request($serverVars);
82 $this->server->httpRequest = ($request);
83 $this->server->exec();
85 $this->assertEquals(array(
86 'Content-Type' => 'application/octet-stream',
87 'Content-Length' => 8,
88 'Content-Range' => 'bytes 5-12/13',
89 'Last-Modified' => Sabre_HTTP_Util::toHTTPDate(new DateTime('@' . filemtime($this->tempDir . '/test.txt'))),
90 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')). '"',
92 $this->response->headers
95 $this->assertEquals('HTTP/1.1 206 Partial Content',$this->response->status);
96 $this->assertEquals('contents', stream_get_contents($this->response->body));
103 function testTooHighRange() {
106 'REQUEST_URI' => '/test.txt',
107 'REQUEST_METHOD' => 'GET',
108 'HTTP_RANGE' => 'bytes=100-200',
111 $request = new Sabre_HTTP_Request($serverVars);
112 $this->server->httpRequest = ($request);
113 $this->server->exec();
115 $this->assertEquals('HTTP/1.1 416 Requested Range Not Satisfiable',$this->response->status);
122 function testCrazyRange() {
125 'REQUEST_URI' => '/test.txt',
126 'REQUEST_METHOD' => 'GET',
127 'HTTP_RANGE' => 'bytes=8-4',
130 $request = new Sabre_HTTP_Request($serverVars);
131 $this->server->httpRequest = ($request);
132 $this->server->exec();
134 $this->assertEquals('HTTP/1.1 416 Requested Range Not Satisfiable',$this->response->status);
140 * @covers Sabre_DAV_Server::httpGet
142 function testIfRangeEtag() {
144 $node = $this->server->tree->getNodeForPath('test.txt');
147 'REQUEST_URI' => '/test.txt',
148 'REQUEST_METHOD' => 'GET',
149 'HTTP_RANGE' => 'bytes=2-5',
150 'HTTP_IF_RANGE' => $node->getETag(),
153 $request = new Sabre_HTTP_Request($serverVars);
154 $this->server->httpRequest = ($request);
155 $this->server->exec();
157 $this->assertEquals(array(
158 'Content-Type' => 'application/octet-stream',
159 'Content-Length' => 4,
160 'Content-Range' => 'bytes 2-5/13',
161 'Last-Modified' => Sabre_HTTP_Util::toHTTPDate(new DateTime('@' . filemtime($this->tempDir . '/test.txt'))),
162 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')) . '"',
164 $this->response->headers
167 $this->assertEquals('HTTP/1.1 206 Partial Content',$this->response->status);
168 $this->assertEquals('st c', stream_get_contents($this->response->body));
174 * @covers Sabre_DAV_Server::httpGet
176 function testIfRangeEtagIncorrect() {
178 $node = $this->server->tree->getNodeForPath('test.txt');
181 'REQUEST_URI' => '/test.txt',
182 'REQUEST_METHOD' => 'GET',
183 'HTTP_RANGE' => 'bytes=2-5',
184 'HTTP_IF_RANGE' => $node->getETag() . 'blabla',
187 $request = new Sabre_HTTP_Request($serverVars);
188 $this->server->httpRequest = ($request);
189 $this->server->exec();
191 $this->assertEquals(array(
192 'Content-Type' => 'application/octet-stream',
193 'Content-Length' => 13,
194 'Last-Modified' => Sabre_HTTP_Util::toHTTPDate(new DateTime('@' . filemtime($this->tempDir . '/test.txt'))),
195 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')) . '"',
197 $this->response->headers
200 $this->assertEquals('HTTP/1.1 200 OK',$this->response->status);
201 $this->assertEquals('Test contents', stream_get_contents($this->response->body));
207 * @covers Sabre_DAV_Server::httpGet
209 function testIfRangeModificationDate() {
211 $node = $this->server->tree->getNodeForPath('test.txt');
214 'REQUEST_URI' => '/test.txt',
215 'REQUEST_METHOD' => 'GET',
216 'HTTP_RANGE' => 'bytes=2-5',
217 'HTTP_IF_RANGE' => 'tomorrow',
220 $request = new Sabre_HTTP_Request($serverVars);
221 $this->server->httpRequest = ($request);
222 $this->server->exec();
224 $this->assertEquals(array(
225 'Content-Type' => 'application/octet-stream',
226 'Content-Length' => 4,
227 'Content-Range' => 'bytes 2-5/13',
228 'Last-Modified' => Sabre_HTTP_Util::toHTTPDate(new DateTime('@' . filemtime($this->tempDir . '/test.txt'))),
229 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')) . '"',
231 $this->response->headers
234 $this->assertEquals('HTTP/1.1 206 Partial Content',$this->response->status);
235 $this->assertEquals('st c', stream_get_contents($this->response->body));
241 * @covers Sabre_DAV_Server::httpGet
243 function testIfRangeModificationDateModified() {
245 $node = $this->server->tree->getNodeForPath('test.txt');
248 'REQUEST_URI' => '/test.txt',
249 'REQUEST_METHOD' => 'GET',
250 'HTTP_RANGE' => 'bytes=2-5',
251 'HTTP_IF_RANGE' => '-2 years',
254 $request = new Sabre_HTTP_Request($serverVars);
255 $this->server->httpRequest = ($request);
256 $this->server->exec();
258 $this->assertEquals(array(
259 'Content-Type' => 'application/octet-stream',
260 'Content-Length' => 13,
261 'Last-Modified' => Sabre_HTTP_Util::toHTTPDate(new DateTime('@' . filemtime($this->tempDir . '/test.txt'))),
262 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')) . '"',
264 $this->response->headers
267 $this->assertEquals('HTTP/1.1 200 OK',$this->response->status);
268 $this->assertEquals('Test contents', stream_get_contents($this->response->body));