]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/DAV/PartialUpdate/PluginTest.php
Merge branch 'master' of git://github.com/friendica/friendica-addons
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / DAV / PartialUpdate / PluginTest.php
1 <?php
2
3 require_once 'Sabre/DAV/PartialUpdate/FileMock.php';
4
5 class Sabre_DAV_PartialUpdate_PluginTest extends Sabre_DAVServerTest {
6
7     protected $node;
8     protected $plugin;
9
10     public function setUp() {
11
12         $this->node = new Sabre_DAV_PartialUpdate_FileMock();
13         $this->tree[] = $this->node;
14
15         parent::setUp();
16
17         $this->plugin = new Sabre_DAV_PartialUpdate_Plugin();
18         $this->server->addPlugin($this->plugin);
19
20
21
22     }
23
24     public function testInit() {
25
26         $this->assertEquals('partialupdate', $this->plugin->getPluginName());
27         $this->assertEquals(array('sabredav-partialupdate'), $this->plugin->getFeatures());
28         $this->assertEquals(array(
29             'PATCH'
30         ), $this->plugin->getHTTPMethods('partial'));
31         $this->assertEquals(array(
32         ), $this->plugin->getHTTPMethods(''));
33
34         $this->assertNull($this->plugin->unknownMethod('FOO','partial'));
35
36     }
37
38     public function testPatchNoRange() {
39
40         $this->node->put('00000000');
41         $request = new Sabre_HTTP_Request(array(
42             'REQUEST_METHOD' => 'PATCH',
43             'REQUEST_URI'    => '/partial',
44         ));
45         $response = $this->request($request);
46
47         $this->assertEquals('HTTP/1.1 400 Bad request', $response->status, 'Full response body:' . $response->body);
48
49     }
50
51     public function testPatchNotSupported() {
52
53         $this->node->put('00000000');
54         $request = new Sabre_HTTP_Request(array(
55             'REQUEST_METHOD' => 'PATCH',
56             'REQUEST_URI'    => '/',
57             'X_UPDATE_RANGE' => '3-4',
58
59         ));
60         $request->setBody(
61             '111'
62         );
63         $response = $this->request($request);
64
65         $this->assertEquals('HTTP/1.1 405 Method Not Allowed', $response->status, 'Full response body:' . $response->body);
66
67     }
68
69     public function testPatchNoContentType() {
70
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',
76
77         ));
78         $request->setBody(
79             '111'
80         );
81         $response = $this->request($request);
82
83         $this->assertEquals('HTTP/1.1 415 Unsupported Media Type', $response->status, 'Full response body:' . $response->body);
84
85     }
86
87     public function testPatchBadRange() {
88
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',
95         ));
96         $request->setBody(
97             '111'
98         );
99         $response = $this->request($request);
100
101         $this->assertEquals('HTTP/1.1 416 Requested Range Not Satisfiable', $response->status, 'Full response body:' . $response->body);
102
103     }
104
105     public function testPatchSuccess() {
106
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,
114         ));
115         $request->setBody(
116             '111'
117         );
118         $response = $this->request($request);
119
120         $this->assertEquals('HTTP/1.1 204 No Content', $response->status, 'Full response body:' . $response->body);
121         $this->assertEquals('00111000', $this->node->get());
122
123     }
124
125 }