2014-06-28 20:28:08 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
function setUp() {
|
2014-06-28 20:28:08 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$tree = [
|
2014-06-28 20:28:08 +00:00
|
|
|
new File(SABRE_TEMPDIR . '/foobar.txt')
|
2016-05-28 15:46:24 +00:00
|
|
|
];
|
2014-06-28 20:28:08 +00:00
|
|
|
$server = new Server($tree);
|
|
|
|
$server->debugExceptions = true;
|
|
|
|
$server->addPlugin(new Plugin());
|
|
|
|
|
|
|
|
$tree[0]->put('1234567890');
|
|
|
|
|
|
|
|
$this->server = $server;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
function tearDown() {
|
2014-06-28 20:28:08 +00:00
|
|
|
|
|
|
|
\Sabre\TestUtil::clearTempDir();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider data
|
|
|
|
*/
|
2016-05-28 15:46:24 +00:00
|
|
|
function testUpdateRange($headerValue, $httpStatus, $endResult, $contentLength = 4) {
|
2014-06-28 20:28:08 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$headers = [
|
2016-05-28 15:46:24 +00:00
|
|
|
'Content-Type' => 'application/x-sabredav-partialupdate',
|
2016-05-11 00:26:44 +00:00
|
|
|
'X-Update-Range' => $headerValue,
|
|
|
|
];
|
|
|
|
|
2014-06-28 20:28:08 +00:00
|
|
|
if ($contentLength) {
|
2016-05-11 00:26:44 +00:00
|
|
|
$headers['Content-Length'] = (string)$contentLength;
|
2014-06-28 20:28:08 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$request = new HTTP\Request('PATCH', '/foobar.txt', $headers, '----');
|
2014-06-28 20:28:08 +00:00
|
|
|
|
|
|
|
$request->setBody('----');
|
|
|
|
$this->server->httpRequest = $request;
|
|
|
|
$this->server->httpResponse = new HTTP\ResponseMock();
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->server->sapi = new HTTP\SapiMock();
|
2014-06-28 20:28:08 +00:00
|
|
|
$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'));
|
|
|
|
}
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
}
|
2014-06-28 20:28:08 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
function data() {
|
2014-06-28 20:28:08 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
return [
|
2014-06-28 20:28:08 +00:00
|
|
|
// Problems
|
2016-05-28 15:46:24 +00:00
|
|
|
['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----'],
|
|
|
|
|
|
|
|
];
|
2014-06-28 20:28:08 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|