aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/tests/Sabre/DAV/ServerRangeTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/sabre/dav/tests/Sabre/DAV/ServerRangeTest.php')
-rw-r--r--vendor/sabre/dav/tests/Sabre/DAV/ServerRangeTest.php350
1 files changed, 169 insertions, 181 deletions
diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerRangeTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerRangeTest.php
index a06fcb0be..bafbef6e4 100644
--- a/vendor/sabre/dav/tests/Sabre/DAV/ServerRangeTest.php
+++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerRangeTest.php
@@ -1,42 +1,62 @@
<?php
namespace Sabre\DAV;
-use Sabre\HTTP;
-require_once 'Sabre/DAV/AbstractServer.php';
+use DateTime;
+use Sabre\HTTP;
-class ServerRangeTest extends AbstractServer{
+/**
+ * This file tests HTTP requests that use the Range: header.
+ *
+ * @copyright Copyright (C) fruux GmbH. (https://fruux.com/)
+ * @author Evert Pot (http://evertpot.com/)
+ * @license http://sabre.io/license/ Modified BSD License
+ */
+class ServerRangeTest extends \Sabre\DAVServerTest {
- protected function getRootNode() {
+ protected $setupFiles = true;
- return new FSExt\Directory(SABRE_TEMPDIR);
+ /**
+ * We need this string a lot
+ */
+ protected $lastModified;
- }
+ function setUp() {
- function testRange() {
+ parent::setUp();
+ $this->server->createFile('files/test.txt', 'Test contents');
- $serverVars = array(
- 'REQUEST_URI' => '/test.txt',
- 'REQUEST_METHOD' => 'GET',
- 'HTTP_RANGE' => 'bytes=2-5',
+ $this->lastModified = HTTP\Util::toHTTPDate(
+ new DateTime('@' . $this->server->tree->getNodeForPath('files/test.txt')->getLastModified())
);
- $request = new HTTP\Request($serverVars);
- $this->server->httpRequest = ($request);
- $this->server->exec();
+ $stream = popen('echo "Test contents"', 'r');
+ $streamingFile = new Mock\StreamingFile(
+ 'no-seeking.txt',
+ $stream
+ );
+ $streamingFile->setSize(12);
+ $this->server->tree->getNodeForPath('files')->addNode($streamingFile);
- $this->assertEquals(array(
- 'Content-Type' => 'application/octet-stream',
- 'Content-Length' => 4,
- 'Content-Range' => 'bytes 2-5/13',
- 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))),
- 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')). '"',
- ),
- $this->response->headers
- );
+ }
- $this->assertEquals('HTTP/1.1 206 Partial Content',$this->response->status);
- $this->assertEquals('st c', stream_get_contents($this->response->body));
+ function testRange() {
+
+ $request = new HTTP\Request('GET', '/files/test.txt', ['Range' => 'bytes=2-5']);
+ $response = $this->request($request);
+
+ $this->assertEquals([
+ 'X-Sabre-Version' => [Version::VERSION],
+ 'Content-Type' => ['application/octet-stream'],
+ 'Content-Length' => [4],
+ 'Content-Range' => ['bytes 2-5/13'],
+ 'ETag' => ['"' . md5('Test contents') . '"'],
+ 'Last-Modified' => [$this->lastModified],
+ ],
+ $response->getHeaders()
+ );
+ $this->assertEquals(206, $response->getStatus());
+ $this->assertEquals('st c', $response->getBodyAsString());
}
@@ -45,28 +65,22 @@ class ServerRangeTest extends AbstractServer{
*/
function testStartRange() {
- $serverVars = array(
- 'REQUEST_URI' => '/test.txt',
- 'REQUEST_METHOD' => 'GET',
- 'HTTP_RANGE' => 'bytes=2-',
+ $request = new HTTP\Request('GET', '/files/test.txt', ['Range' => 'bytes=2-']);
+ $response = $this->request($request);
+
+ $this->assertEquals([
+ 'X-Sabre-Version' => [Version::VERSION],
+ 'Content-Type' => ['application/octet-stream'],
+ 'Content-Length' => [11],
+ 'Content-Range' => ['bytes 2-12/13'],
+ 'ETag' => ['"' . md5('Test contents') . '"'],
+ 'Last-Modified' => [$this->lastModified],
+ ],
+ $response->getHeaders()
);
- $request = new HTTP\Request($serverVars);
- $this->server->httpRequest = ($request);
- $this->server->exec();
-
- $this->assertEquals(array(
- 'Content-Type' => 'application/octet-stream',
- 'Content-Length' => 11,
- 'Content-Range' => 'bytes 2-12/13',
- 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))),
- 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')) . '"',
- ),
- $this->response->headers
- );
-
- $this->assertEquals('HTTP/1.1 206 Partial Content',$this->response->status);
- $this->assertEquals('st contents', stream_get_contents($this->response->body));
+ $this->assertEquals(206, $response->getStatus());
+ $this->assertEquals('st contents', $response->getBodyAsString());
}
@@ -75,28 +89,22 @@ class ServerRangeTest extends AbstractServer{
*/
function testEndRange() {
- $serverVars = array(
- 'REQUEST_URI' => '/test.txt',
- 'REQUEST_METHOD' => 'GET',
- 'HTTP_RANGE' => 'bytes=-8',
+ $request = new HTTP\Request('GET', '/files/test.txt', ['Range' => 'bytes=-8']);
+ $response = $this->request($request);
+
+ $this->assertEquals([
+ 'X-Sabre-Version' => [Version::VERSION],
+ 'Content-Type' => ['application/octet-stream'],
+ 'Content-Length' => [8],
+ 'Content-Range' => ['bytes 5-12/13'],
+ 'ETag' => ['"' . md5('Test contents') . '"'],
+ 'Last-Modified' => [$this->lastModified],
+ ],
+ $response->getHeaders()
);
- $request = new HTTP\Request($serverVars);
- $this->server->httpRequest = ($request);
- $this->server->exec();
-
- $this->assertEquals(array(
- 'Content-Type' => 'application/octet-stream',
- 'Content-Length' => 8,
- 'Content-Range' => 'bytes 5-12/13',
- 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))),
- 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')). '"',
- ),
- $this->response->headers
- );
-
- $this->assertEquals('HTTP/1.1 206 Partial Content',$this->response->status);
- $this->assertEquals('contents', stream_get_contents($this->response->body));
+ $this->assertEquals(206, $response->getStatus());
+ $this->assertEquals('contents', $response->getBodyAsString());
}
@@ -105,17 +113,10 @@ class ServerRangeTest extends AbstractServer{
*/
function testTooHighRange() {
- $serverVars = array(
- 'REQUEST_URI' => '/test.txt',
- 'REQUEST_METHOD' => 'GET',
- 'HTTP_RANGE' => 'bytes=100-200',
- );
+ $request = new HTTP\Request('GET', '/files/test.txt', ['Range' => 'bytes=100-200']);
+ $response = $this->request($request);
- $request = new HTTP\Request($serverVars);
- $this->server->httpRequest = ($request);
- $this->server->exec();
-
- $this->assertEquals('HTTP/1.1 416 Requested Range Not Satisfiable',$this->response->status);
+ $this->assertEquals(416, $response->getStatus());
}
@@ -124,151 +125,138 @@ class ServerRangeTest extends AbstractServer{
*/
function testCrazyRange() {
- $serverVars = array(
- 'REQUEST_URI' => '/test.txt',
- 'REQUEST_METHOD' => 'GET',
- 'HTTP_RANGE' => 'bytes=8-4',
- );
+ $request = new HTTP\Request('GET', '/files/test.txt', ['Range' => 'bytes=8-4']);
+ $response = $this->request($request);
- $request = new HTTP\Request($serverVars);
- $this->server->httpRequest = ($request);
- $this->server->exec();
+ $this->assertEquals(416, $response->getStatus());
- $this->assertEquals('HTTP/1.1 416 Requested Range Not Satisfiable',$this->response->status);
+ }
+
+ function testNonSeekableStream() {
+
+ $request = new HTTP\Request('GET', '/files/no-seeking.txt', ['Range' => 'bytes=2-5']);
+ $response = $this->request($request);
+
+ $this->assertEquals(206, $response->getStatus(), $response);
+ $this->assertEquals([
+ 'X-Sabre-Version' => [Version::VERSION],
+ 'Content-Type' => ['application/octet-stream'],
+ 'Content-Length' => [4],
+ 'Content-Range' => ['bytes 2-5/12'],
+ // 'ETag' => ['"' . md5('Test contents') . '"'],
+ 'Last-Modified' => [$this->lastModified],
+ ],
+ $response->getHeaders()
+ );
+
+ $this->assertEquals('st c', $response->getBodyAsString());
}
/**
* @depends testRange
- * @covers \Sabre\DAV\Server::httpGet
*/
function testIfRangeEtag() {
- $node = $this->server->tree->getNodeForPath('test.txt');
-
- $serverVars = array(
- 'REQUEST_URI' => '/test.txt',
- 'REQUEST_METHOD' => 'GET',
- 'HTTP_RANGE' => 'bytes=2-5',
- 'HTTP_IF_RANGE' => $node->getETag(),
+ $request = new HTTP\Request('GET', '/files/test.txt', [
+ 'Range' => 'bytes=2-5',
+ 'If-Range' => '"' . md5('Test contents') . '"',
+ ]);
+ $response = $this->request($request);
+
+ $this->assertEquals([
+ 'X-Sabre-Version' => [Version::VERSION],
+ 'Content-Type' => ['application/octet-stream'],
+ 'Content-Length' => [4],
+ 'Content-Range' => ['bytes 2-5/13'],
+ 'ETag' => ['"' . md5('Test contents') . '"'],
+ 'Last-Modified' => [$this->lastModified],
+ ],
+ $response->getHeaders()
);
- $request = new HTTP\Request($serverVars);
- $this->server->httpRequest = ($request);
- $this->server->exec();
-
- $this->assertEquals(array(
- 'Content-Type' => 'application/octet-stream',
- 'Content-Length' => 4,
- 'Content-Range' => 'bytes 2-5/13',
- 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))),
- 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')) . '"',
- ),
- $this->response->headers
- );
-
- $this->assertEquals('HTTP/1.1 206 Partial Content',$this->response->status);
- $this->assertEquals('st c', stream_get_contents($this->response->body));
+ $this->assertEquals(206, $response->getStatus());
+ $this->assertEquals('st c', $response->getBodyAsString());
}
/**
- * @depends testRange
- * @covers \Sabre\DAV\Server::httpGet
+ * @depends testIfRangeEtag
*/
function testIfRangeEtagIncorrect() {
- $node = $this->server->tree->getNodeForPath('test.txt');
-
- $serverVars = array(
- 'REQUEST_URI' => '/test.txt',
- 'REQUEST_METHOD' => 'GET',
- 'HTTP_RANGE' => 'bytes=2-5',
- 'HTTP_IF_RANGE' => $node->getETag() . 'blabla',
+ $request = new HTTP\Request('GET', '/files/test.txt', [
+ 'Range' => 'bytes=2-5',
+ 'If-Range' => '"foobar"',
+ ]);
+ $response = $this->request($request);
+
+ $this->assertEquals([
+ 'X-Sabre-Version' => [Version::VERSION],
+ 'Content-Type' => ['application/octet-stream'],
+ 'Content-Length' => [13],
+ 'ETag' => ['"' . md5('Test contents') . '"'],
+ 'Last-Modified' => [$this->lastModified],
+ ],
+ $response->getHeaders()
);
- $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_get_contents(SABRE_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));
+ $this->assertEquals(200, $response->getStatus());
+ $this->assertEquals('Test contents', $response->getBodyAsString());
}
/**
- * @depends testRange
- * @covers \Sabre\DAV\Server::httpGet
+ * @depends testIfRangeEtag
*/
function testIfRangeModificationDate() {
- $node = $this->server->tree->getNodeForPath('test.txt');
-
- $serverVars = array(
- 'REQUEST_URI' => '/test.txt',
- 'REQUEST_METHOD' => 'GET',
- 'HTTP_RANGE' => 'bytes=2-5',
- 'HTTP_IF_RANGE' => 'tomorrow',
+ $request = new HTTP\Request('GET', '/files/test.txt', [
+ 'Range' => 'bytes=2-5',
+ 'If-Range' => 'tomorrow',
+ ]);
+ $response = $this->request($request);
+
+ $this->assertEquals([
+ 'X-Sabre-Version' => [Version::VERSION],
+ 'Content-Type' => ['application/octet-stream'],
+ 'Content-Length' => [4],
+ 'Content-Range' => ['bytes 2-5/13'],
+ 'ETag' => ['"' . md5('Test contents') . '"'],
+ 'Last-Modified' => [$this->lastModified],
+ ],
+ $response->getHeaders()
);
- $request = new HTTP\Request($serverVars);
- $this->server->httpRequest = ($request);
- $this->server->exec();
-
- $this->assertEquals(array(
- 'Content-Type' => 'application/octet-stream',
- 'Content-Length' => 4,
- 'Content-Range' => 'bytes 2-5/13',
- 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))),
- 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')) . '"',
- ),
- $this->response->headers
- );
-
- $this->assertEquals('HTTP/1.1 206 Partial Content',$this->response->status);
- $this->assertEquals('st c', stream_get_contents($this->response->body));
+ $this->assertEquals(206, $response->getStatus());
+ $this->assertEquals('st c', $response->getBodyAsString());
}
/**
- * @depends testRange
- * @covers \Sabre\DAV\Server::httpGet
+ * @depends testIfRangeModificationDate
*/
function testIfRangeModificationDateModified() {
- $node = $this->server->tree->getNodeForPath('test.txt');
-
- $serverVars = array(
- 'REQUEST_URI' => '/test.txt',
- 'REQUEST_METHOD' => 'GET',
- 'HTTP_RANGE' => 'bytes=2-5',
- 'HTTP_IF_RANGE' => '-2 years',
+ $request = new HTTP\Request('GET', '/files/test.txt', [
+ 'Range' => 'bytes=2-5',
+ 'If-Range' => '-2 years',
+ ]);
+ $response = $this->request($request);
+
+ $this->assertEquals([
+ 'X-Sabre-Version' => [Version::VERSION],
+ 'Content-Type' => ['application/octet-stream'],
+ 'Content-Length' => [13],
+ 'ETag' => ['"' . md5('Test contents') . '"'],
+ 'Last-Modified' => [$this->lastModified],
+ ],
+ $response->getHeaders()
);
- $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_get_contents(SABRE_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));
+ $this->assertEquals(200, $response->getStatus());
+ $this->assertEquals('Test contents', $response->getBodyAsString());
}
+
}