aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate')
-rw-r--r--vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/FileMock.php54
-rw-r--r--vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/PluginTest.php119
-rw-r--r--vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/SpecificationTest.php38
3 files changed, 119 insertions, 92 deletions
diff --git a/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/FileMock.php b/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/FileMock.php
index e8cdc1666..d6cc406be 100644
--- a/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/FileMock.php
+++ b/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/FileMock.php
@@ -3,7 +3,7 @@
namespace Sabre\DAV\PartialUpdate;
use Sabre\DAV;
-class FileMock implements IFile {
+class FileMock implements IPatchSupport {
protected $data = '';
@@ -16,14 +16,56 @@ class FileMock implements IFile {
}
- function putRange($str,$start) {
-
- if (is_resource($str)) {
- $str = stream_get_contents($str);
+ /**
+ * Updates the file based on a range specification.
+ *
+ * The first argument is the data, which is either a readable stream
+ * resource or a string.
+ *
+ * The second argument is the type of update we're doing.
+ * This is either:
+ * * 1. append
+ * * 2. update based on a start byte
+ * * 3. update based on an end byte
+ *;
+ * The third argument is the start or end byte.
+ *
+ * After a successful put operation, you may choose to return an ETag. The
+ * etag must always be surrounded by double-quotes. These quotes must
+ * appear in the actual string you're returning.
+ *
+ * Clients may use the ETag from a PUT request to later on make sure that
+ * when they update the file, the contents haven't changed in the mean
+ * time.
+ *
+ * @param resource|string $data
+ * @param int $rangeType
+ * @param int $offset
+ * @return string|null
+ */
+ function patch($data, $rangeType, $offset = null) {
+
+ if (is_resource($data)) {
+ $data = stream_get_contents($data);
}
- $this->data = substr($this->data, 0, $start) . $str . substr($this->data, $start + strlen($str));
+ switch($rangeType) {
+
+ case 1 :
+ $this->data.=$data;
+ break;
+ case 3 :
+ // Turn the offset into an offset-offset.
+ $offset = strlen($this->data) - $offset;
+ // No break is intentional
+ case 2 :
+ $this->data =
+ substr($this->data, 0, $offset) .
+ $data .
+ substr($this->data, $offset + strlen($data));
+ break;
+ }
}
diff --git a/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/PluginTest.php b/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/PluginTest.php
index 32f7e4e2c..5bd696416 100644
--- a/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/PluginTest.php
+++ b/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/PluginTest.php
@@ -12,7 +12,7 @@ class PluginTest extends \Sabre\DAVServerTest {
protected $node;
protected $plugin;
- public function setUp() {
+ function setUp() {
$this->node = new FileMock();
$this->tree[] = $this->node;
@@ -26,124 +26,109 @@ class PluginTest extends \Sabre\DAVServerTest {
}
- public function testInit() {
+ function testInit() {
$this->assertEquals('partialupdate', $this->plugin->getPluginName());
- $this->assertEquals(array('sabredav-partialupdate'), $this->plugin->getFeatures());
- $this->assertEquals(array(
+ $this->assertEquals(['sabredav-partialupdate'], $this->plugin->getFeatures());
+ $this->assertEquals([
'PATCH'
- ), $this->plugin->getHTTPMethods('partial'));
- $this->assertEquals(array(
- ), $this->plugin->getHTTPMethods(''));
-
- $this->assertNull($this->plugin->unknownMethod('FOO','partial'));
+ ], $this->plugin->getHTTPMethods('partial'));
+ $this->assertEquals([
+ ], $this->plugin->getHTTPMethods(''));
}
- public function testPatchNoRange() {
+ function testPatchNoRange() {
- $this->node->put('00000000');
- $request = new HTTP\Request(array(
+ $this->node->put('aaaaaaaa');
+ $request = HTTP\Sapi::createFromServerArray([
'REQUEST_METHOD' => 'PATCH',
'REQUEST_URI' => '/partial',
- ));
+ ]);
$response = $this->request($request);
- $this->assertEquals('HTTP/1.1 400 Bad request', $response->status, 'Full response body:' . $response->body);
+ $this->assertEquals(400, $response->status, 'Full response body:' . $response->body);
}
- public function testPatchNotSupported() {
-
- $this->node->put('00000000');
- $request = new HTTP\Request(array(
- 'REQUEST_METHOD' => 'PATCH',
- 'REQUEST_URI' => '/',
- 'X_UPDATE_RANGE' => '3-4',
+ function testPatchNotSupported() {
- ));
+ $this->node->put('aaaaaaaa');
+ $request = new HTTP\Request('PATCH', '/', ['X-Update-Range' => '3-4']);
$request->setBody(
- '111'
+ 'bbb'
);
$response = $this->request($request);
- $this->assertEquals('HTTP/1.1 405 Method Not Allowed', $response->status, 'Full response body:' . $response->body);
+ $this->assertEquals(405, $response->status, 'Full response body:' . $response->body);
}
- public function testPatchNoContentType() {
+ function testPatchNoContentType() {
- $this->node->put('00000000');
- $request = new HTTP\Request(array(
- 'REQUEST_METHOD' => 'PATCH',
- 'REQUEST_URI' => '/partial',
- 'HTTP_X_UPDATE_RANGE' => 'bytes=3-4',
+ $this->node->put('aaaaaaaa');
+ $request = new HTTP\Request('PATCH', '/partial', ['X-Update-Range' => 'bytes=3-4']);
+ $request->setBody(
+ 'bbb'
+ );
+ $response = $this->request($request);
- ));
+ $this->assertEquals(415, $response->status, 'Full response body:' . $response->body);
+
+ }
+
+ function testPatchBadRange() {
+
+ $this->node->put('aaaaaaaa');
+ $request = new HTTP\Request('PATCH', '/partial', ['X-Update-Range' => 'bytes=3-4', 'Content-Type' => 'application/x-sabredav-partialupdate', 'Content-Length' => '3']);
$request->setBody(
- '111'
+ 'bbb'
);
$response = $this->request($request);
- $this->assertEquals('HTTP/1.1 415 Unsupported Media Type', $response->status, 'Full response body:' . $response->body);
+ $this->assertEquals(416, $response->status, 'Full response body:' . $response->body);
}
- public function testPatchBadRange() {
+ function testPatchNoLength() {
- $this->node->put('00000000');
- $request = new HTTP\Request(array(
- 'REQUEST_METHOD' => 'PATCH',
- 'REQUEST_URI' => '/partial',
- 'HTTP_X_UPDATE_RANGE' => 'bytes=3-4',
- 'HTTP_CONTENT_TYPE' => 'application/x-sabredav-partialupdate',
- ));
+ $this->node->put('aaaaaaaa');
+ $request = new HTTP\Request('PATCH', '/partial', ['X-Update-Range' => 'bytes=3-5', 'Content-Type' => 'application/x-sabredav-partialupdate']);
$request->setBody(
- '111'
+ 'bbb'
);
$response = $this->request($request);
- $this->assertEquals('HTTP/1.1 411 Length Required', $response->status, 'Full response body:' . $response->body);
+ $this->assertEquals(411, $response->status, 'Full response body:' . $response->body);
}
- public function testPatchSuccess() {
+ function testPatchSuccess() {
- $this->node->put('00000000');
- $request = new HTTP\Request(array(
- 'REQUEST_METHOD' => 'PATCH',
- 'REQUEST_URI' => '/partial',
- 'HTTP_X_UPDATE_RANGE' => 'bytes=3-5',
- 'HTTP_CONTENT_TYPE' => 'application/x-sabredav-partialupdate',
- 'HTTP_CONTENT_LENGTH' => 3,
- ));
+ $this->node->put('aaaaaaaa');
+ $request = new HTTP\Request('PATCH', '/partial', ['X-Update-Range' => 'bytes=3-5', 'Content-Type' => 'application/x-sabredav-partialupdate', 'Content-Length' => 3]);
$request->setBody(
- '111'
+ 'bbb'
);
$response = $this->request($request);
- $this->assertEquals('HTTP/1.1 204 No Content', $response->status, 'Full response body:' . $response->body);
- $this->assertEquals('00011100', $this->node->get());
+ $this->assertEquals(204, $response->status, 'Full response body:' . $response->body);
+ $this->assertEquals('aaabbbaa', $this->node->get());
}
- public function testPatchNoEndRange() {
+ function testPatchNoEndRange() {
- $this->node->put('00000');
- $request = new HTTP\Request(array(
- 'REQUEST_METHOD' => 'PATCH',
- 'REQUEST_URI' => '/partial',
- 'HTTP_X_UPDATE_RANGE' => 'bytes=3-',
- 'HTTP_CONTENT_TYPE' => 'application/x-sabredav-partialupdate',
- 'HTTP_CONTENT_LENGTH' => 3,
- ));
+ $this->node->put('aaaaa');
+ $request = new HTTP\Request('PATCH', '/partial', ['X-Update-Range' => 'bytes=3-', 'Content-Type' => 'application/x-sabredav-partialupdate', 'Content-Length' => '3']);
$request->setBody(
- '111'
+ 'bbb'
);
+
$response = $this->request($request);
- $this->assertEquals('HTTP/1.1 204 No Content', $response->status, 'Full response body:' . $response->body);
- $this->assertEquals('00111', $this->node->get());
+ $this->assertEquals(204, $response->getStatus(), 'Full response body:' . $response->getBodyAsString());
+ $this->assertEquals('aaabbb', $this->node->get());
}
diff --git a/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/SpecificationTest.php b/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/SpecificationTest.php
index 7abe69c55..31be2a1b1 100644
--- a/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/SpecificationTest.php
+++ b/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/SpecificationTest.php
@@ -42,21 +42,21 @@ class SpecificationTest extends \PHPUnit_Framework_TestCase {
*/
public function testUpdateRange($headerValue, $httpStatus, $endResult, $contentLength = 4) {
- $vars = array(
- 'REQUEST_METHOD' => 'PATCH',
- 'HTTP_CONTENT_TYPE' => 'application/x-sabredav-partialupdate',
- 'HTTP_X_UPDATE_RANGE' => $headerValue,
- 'REQUEST_URI' => '/foobar.txt',
- );
+ $headers = [
+ 'Content-Type' => 'application/x-sabredav-partialupdate',
+ 'X-Update-Range' => $headerValue,
+ ];
+
if ($contentLength) {
- $vars['HTTP_CONTENT_LENGTH'] = (string)$contentLength;
+ $headers['Content-Length'] = (string)$contentLength;
}
- $request = new HTTP\Request($vars);
+ $request = new HTTP\Request('PATCH', '/foobar.txt', $headers, '----');
$request->setBody('----');
$this->server->httpRequest = $request;
$this->server->httpResponse = new HTTP\ResponseMock();
+ $this->server->sapi = new HTTP\SapiMock();
$this->server->exec();
$this->assertEquals($httpStatus, $this->server->httpResponse->status, 'Incorrect http status received: ' . $this->server->httpResponse->body);
@@ -70,17 +70,17 @@ class SpecificationTest extends \PHPUnit_Framework_TestCase {
return array(
// Problems
- array('foo', 'HTTP/1.1 400 Bad request', null),
- array('bytes=0-3', 'HTTP/1.1 411 Length Required', null, 0),
- array('bytes=4-1', 'HTTP/1.1 416 Requested Range Not Satisfiable', null),
-
- array('bytes=0-3', 'HTTP/1.1 204 No Content', '----567890'),
- array('bytes=1-4', 'HTTP/1.1 204 No Content', '1----67890'),
- array('bytes=0-', 'HTTP/1.1 204 No Content', '----567890'),
- array('bytes=-4', 'HTTP/1.1 204 No Content', '123456----'),
- array('bytes=-2', 'HTTP/1.1 204 No Content', '12345678----'),
- array('bytes=2-', 'HTTP/1.1 204 No Content', '12----7890'),
- array('append', 'HTTP/1.1 204 No Content', '1234567890----'),
+ array('foo', 400, null),
+ array('bytes=0-3', 411, null, 0),
+ array('bytes=4-1', 416, null),
+
+ array('bytes=0-3', 204, '----567890'),
+ array('bytes=1-4', 204, '1----67890'),
+ array('bytes=0-', 204, '----567890'),
+ array('bytes=-4', 204, '123456----'),
+ array('bytes=-2', 204, '12345678----'),
+ array('bytes=2-', 204, '12----7890'),
+ array('append', 204, '1234567890----'),
);