3 require_once 'Sabre/DAV/PartialUpdate/FileMock.php';
5 class Sabre_DAV_PartialUpdate_PluginTest extends Sabre_DAVServerTest {
10 public function setUp() {
12 $this->node = new Sabre_DAV_PartialUpdate_FileMock();
13 $this->tree[] = $this->node;
17 $this->plugin = new Sabre_DAV_PartialUpdate_Plugin();
18 $this->server->addPlugin($this->plugin);
24 public function testInit() {
26 $this->assertEquals('partialupdate', $this->plugin->getPluginName());
27 $this->assertEquals(array('sabredav-partialupdate'), $this->plugin->getFeatures());
28 $this->assertEquals(array(
30 ), $this->plugin->getHTTPMethods('partial'));
31 $this->assertEquals(array(
32 ), $this->plugin->getHTTPMethods(''));
34 $this->assertNull($this->plugin->unknownMethod('FOO','partial'));
38 public function testPatchNoRange() {
40 $this->node->put('00000000');
41 $request = new Sabre_HTTP_Request(array(
42 'REQUEST_METHOD' => 'PATCH',
43 'REQUEST_URI' => '/partial',
45 $response = $this->request($request);
47 $this->assertEquals('HTTP/1.1 400 Bad request', $response->status, 'Full response body:' . $response->body);
51 public function testPatchNotSupported() {
53 $this->node->put('00000000');
54 $request = new Sabre_HTTP_Request(array(
55 'REQUEST_METHOD' => 'PATCH',
57 'X_UPDATE_RANGE' => '3-4',
63 $response = $this->request($request);
65 $this->assertEquals('HTTP/1.1 405 Method Not Allowed', $response->status, 'Full response body:' . $response->body);
69 public function testPatchNoContentType() {
71 $this->node->put('00000000');
72 $request = new Sabre_HTTP_Request(array(
73 'REQUEST_METHOD' => 'PATCH',
74 'REQUEST_URI' => '/partial',
75 'HTTP_X_UPDATE_RANGE' => 'bytes=3-4',
81 $response = $this->request($request);
83 $this->assertEquals('HTTP/1.1 415 Unsupported Media Type', $response->status, 'Full response body:' . $response->body);
87 public function testPatchBadRange() {
89 $this->node->put('00000000');
90 $request = new Sabre_HTTP_Request(array(
91 'REQUEST_METHOD' => 'PATCH',
92 'REQUEST_URI' => '/partial',
93 'HTTP_X_UPDATE_RANGE' => 'bytes=3-4',
94 'HTTP_CONTENT_TYPE' => 'application/x-sabredav-partialupdate',
99 $response = $this->request($request);
101 $this->assertEquals('HTTP/1.1 416 Requested Range Not Satisfiable', $response->status, 'Full response body:' . $response->body);
105 public function testPatchSuccess() {
107 $this->node->put('00000000');
108 $request = new Sabre_HTTP_Request(array(
109 'REQUEST_METHOD' => 'PATCH',
110 'REQUEST_URI' => '/partial',
111 'HTTP_X_UPDATE_RANGE' => 'bytes=3-5',
112 'HTTP_CONTENT_TYPE' => 'application/x-sabredav-partialupdate',
113 'HTTP_CONTENT_LENGTH' => 3,
118 $response = $this->request($request);
120 $this->assertEquals('HTTP/1.1 204 No Content', $response->status, 'Full response body:' . $response->body);
121 $this->assertEquals('00111000', $this->node->get());