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.php111
-rw-r--r--vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/PluginTest.php122
-rw-r--r--vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/SpecificationTest.php90
3 files changed, 0 insertions, 323 deletions
diff --git a/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/FileMock.php b/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/FileMock.php
deleted file mode 100644
index 72fdb5ec8..000000000
--- a/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/FileMock.php
+++ /dev/null
@@ -1,111 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Sabre\DAV\PartialUpdate;
-
-use Sabre\DAV;
-
-class FileMock implements IPatchSupport
-{
- protected $data = '';
-
- public function put($str)
- {
- if (is_resource($str)) {
- $str = stream_get_contents($str);
- }
- $this->data = $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
- */
- public function patch($data, $rangeType, $offset = null)
- {
- if (is_resource($data)) {
- $data = stream_get_contents($data);
- }
-
- 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;
- }
- }
-
- public function get()
- {
- return $this->data;
- }
-
- public function getContentType()
- {
- return 'text/plain';
- }
-
- public function getSize()
- {
- return strlen($this->data);
- }
-
- public function getETag()
- {
- return '"'.$this->data.'"';
- }
-
- public function delete()
- {
- throw new DAV\Exception\MethodNotAllowed();
- }
-
- public function setName($name)
- {
- throw new DAV\Exception\MethodNotAllowed();
- }
-
- public function getName()
- {
- return 'partial';
- }
-
- public function getLastModified()
- {
- return null;
- }
-}
diff --git a/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/PluginTest.php b/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/PluginTest.php
deleted file mode 100644
index 4d99aee7d..000000000
--- a/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/PluginTest.php
+++ /dev/null
@@ -1,122 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Sabre\DAV\PartialUpdate;
-
-use Sabre\HTTP;
-
-class PluginTest extends \Sabre\DAVServerTest
-{
- protected $node;
- protected $plugin;
-
- public function setup(): void
- {
- $this->node = new FileMock();
- $this->tree[] = $this->node;
-
- parent::setUp();
-
- $this->plugin = new Plugin();
- $this->server->addPlugin($this->plugin);
- }
-
- public function testInit()
- {
- $this->assertEquals('partialupdate', $this->plugin->getPluginName());
- $this->assertEquals(['sabredav-partialupdate'], $this->plugin->getFeatures());
- $this->assertEquals([
- 'PATCH',
- ], $this->plugin->getHTTPMethods('partial'));
- $this->assertEquals([
- ], $this->plugin->getHTTPMethods(''));
- }
-
- public function testPatchNoRange()
- {
- $this->node->put('aaaaaaaa');
- $request = HTTP\Sapi::createFromServerArray([
- 'REQUEST_METHOD' => 'PATCH',
- 'REQUEST_URI' => '/partial',
- ]);
- $response = $this->request($request);
-
- $this->assertEquals(400, $response->status, 'Full response body:'.$response->getBodyAsString());
- }
-
- public function testPatchNotSupported()
- {
- $this->node->put('aaaaaaaa');
- $request = new HTTP\Request('PATCH', '/', ['X-Update-Range' => '3-4']);
- $request->setBody(
- 'bbb'
- );
- $response = $this->request($request);
-
- $this->assertEquals(405, $response->status, 'Full response body:'.$response->getBodyAsString());
- }
-
- public function testPatchNoContentType()
- {
- $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->getBodyAsString());
- }
-
- public 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(
- 'bbb'
- );
- $response = $this->request($request);
-
- $this->assertEquals(416, $response->status, 'Full response body:'.$response->getBodyAsString());
- }
-
- public function testPatchNoLength()
- {
- $this->node->put('aaaaaaaa');
- $request = new HTTP\Request('PATCH', '/partial', ['X-Update-Range' => 'bytes=3-5', 'Content-Type' => 'application/x-sabredav-partialupdate']);
- $request->setBody(
- 'bbb'
- );
- $response = $this->request($request);
-
- $this->assertEquals(411, $response->status, 'Full response body:'.$response->getBodyAsString());
- }
-
- public function testPatchSuccess()
- {
- $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(
- 'bbb'
- );
- $response = $this->request($request);
-
- $this->assertEquals(204, $response->status, 'Full response body:'.$response->getBodyAsString());
- $this->assertEquals('aaabbbaa', $this->node->get());
- }
-
- public function testPatchNoEndRange()
- {
- $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(
- 'bbb'
- );
-
- $response = $this->request($request);
-
- $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
deleted file mode 100644
index a727a13e2..000000000
--- a/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/SpecificationTest.php
+++ /dev/null
@@ -1,90 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Sabre\DAV\PartialUpdate;
-
-use Sabre\DAV\FSExt\File;
-use Sabre\DAV\Server;
-use Sabre\HTTP;
-
-/**
- * This test is an end-to-end sabredav test that goes through all
- * the cases in the specification.
- *
- * See: http://sabre.io/dav/http-patch/
- */
-class SpecificationTest extends \PHPUnit\Framework\TestCase
-{
- protected $server;
-
- public function setup(): void
- {
- $tree = [
- new File(SABRE_TEMPDIR.'/foobar.txt'),
- ];
- $server = new Server($tree);
- $server->debugExceptions = true;
- $server->addPlugin(new Plugin());
-
- $tree[0]->put('1234567890');
-
- $this->server = $server;
- }
-
- public function teardown(): void
- {
- \Sabre\TestUtil::clearTempDir();
- }
-
- /**
- * @param string $headerValue
- * @param string $httpStatus
- * @param string $endResult
- * @param int $contentLength
- *
- * @dataProvider data
- */
- public function testUpdateRange($headerValue, $httpStatus, $endResult, $contentLength = 4)
- {
- $headers = [
- 'Content-Type' => 'application/x-sabredav-partialupdate',
- 'X-Update-Range' => $headerValue,
- ];
-
- if ($contentLength) {
- $headers['Content-Length'] = (string) $contentLength;
- }
-
- $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);
- if (!is_null($endResult)) {
- $this->assertEquals($endResult, file_get_contents(SABRE_TEMPDIR.'/foobar.txt'));
- }
- }
-
- public function data()
- {
- return [
- // Problems
- ['foo', 400, null],
- ['bytes=0-3', 411, null, 0],
- ['bytes=4-1', 416, null],
-
- ['bytes=0-3', 204, '----567890'],
- ['bytes=1-4', 204, '1----67890'],
- ['bytes=0-', 204, '----567890'],
- ['bytes=-4', 204, '123456----'],
- ['bytes=-2', 204, '12345678----'],
- ['bytes=2-', 204, '12----7890'],
- ['append', 204, '1234567890----'],
- ];
- }
-}