]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/DAV/FSExt/ServerTest.php
Merge branch 'master' of git://github.com/friendica/friendica-addons
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / DAV / FSExt / ServerTest.php
1 <?php
2
3 require_once 'Sabre/DAV/AbstractServer.php';
4
5 class Sabre_DAV_FSExt_ServerTest extends Sabre_DAV_AbstractServer{
6
7     protected function getRootNode() {
8
9         return new Sabre_DAV_FSExt_Directory($this->tempDir);
10
11     }
12
13     function testGet() {
14
15         $serverVars = array(
16             'REQUEST_URI'    => '/test.txt',
17             'REQUEST_METHOD' => 'GET',
18         );
19
20         $request = new Sabre_HTTP_Request($serverVars);
21         $this->server->httpRequest = ($request);
22         $this->server->exec();
23
24         $this->assertEquals(array(
25             'Content-Type' => 'application/octet-stream',
26             'Content-Length' => 13,
27             'Last-Modified' => Sabre_HTTP_Util::toHTTPDate(new DateTime('@' . filemtime($this->tempDir . '/test.txt'))),
28             'ETag' => '"'  .md5_file($this->tempDir . '/test.txt') . '"',
29             ),
30             $this->response->headers
31          );
32
33         $this->assertEquals('HTTP/1.1 200 OK',$this->response->status);
34         $this->assertEquals('Test contents', stream_get_contents($this->response->body));
35
36     }
37
38     function testHEAD() {
39
40         $serverVars = array(
41             'REQUEST_URI'    => '/test.txt',
42             'REQUEST_METHOD' => 'HEAD',
43         );
44
45         $request = new Sabre_HTTP_Request($serverVars);
46         $this->server->httpRequest = ($request);
47         $this->server->exec();
48
49         $this->assertEquals(array(
50             'Content-Type' => 'application/octet-stream',
51             'Content-Length' => 13,
52             'Last-Modified' => Sabre_HTTP_Util::toHTTPDate(new DateTime('@' . filemtime($this->tempDir . '/test.txt'))),
53             'ETag' => '"' . md5_file($this->tempDir . '/test.txt') . '"',
54             ),
55             $this->response->headers
56          );
57
58         $this->assertEquals('HTTP/1.1 200 OK',$this->response->status);
59         $this->assertEquals('', $this->response->body);
60
61     }
62
63     function testPut() {
64
65         $serverVars = array(
66             'REQUEST_URI'    => '/testput.txt',
67             'REQUEST_METHOD' => 'PUT',
68         );
69
70         $request = new Sabre_HTTP_Request($serverVars);
71         $request->setBody('Testing new file');
72         $this->server->httpRequest = ($request);
73         $this->server->exec();
74
75         $this->assertEquals(array(
76             'Content-Length' => 0,
77             'ETag'           => '"' . md5('Testing new file') . '"',
78         ), $this->response->headers);
79
80         $this->assertEquals('HTTP/1.1 201 Created',$this->response->status);
81         $this->assertEquals('', $this->response->body);
82         $this->assertEquals('Testing new file',file_get_contents($this->tempDir . '/testput.txt'));
83
84     }
85
86     function testPutAlreadyExists() {
87
88         $serverVars = array(
89             'REQUEST_URI'    => '/test.txt',
90             'REQUEST_METHOD' => 'PUT',
91             'HTTP_IF_NONE_MATCH' => '*',
92         );
93
94         $request = new Sabre_HTTP_Request($serverVars);
95         $request->setBody('Testing new file');
96         $this->server->httpRequest = ($request);
97         $this->server->exec();
98
99         $this->assertEquals(array(
100             'Content-Type' => 'application/xml; charset=utf-8',
101         ),$this->response->headers);
102
103         $this->assertEquals('HTTP/1.1 412 Precondition failed',$this->response->status);
104         $this->assertNotEquals('Testing new file',file_get_contents($this->tempDir . '/test.txt'));
105
106     }
107
108     function testMkcol() {
109
110         $serverVars = array(
111             'REQUEST_URI'    => '/testcol',
112             'REQUEST_METHOD' => 'MKCOL',
113         );
114
115         $request = new Sabre_HTTP_Request($serverVars);
116         $request->setBody("");
117         $this->server->httpRequest = ($request);
118         $this->server->exec();
119
120         $this->assertEquals(array(
121             'Content-Length' => '0',
122         ),$this->response->headers);
123
124         $this->assertEquals('HTTP/1.1 201 Created',$this->response->status);
125         $this->assertEquals('', $this->response->body);
126         $this->assertTrue(is_dir($this->tempDir . '/testcol'));
127
128     }
129
130     function testPutUpdate() {
131
132         $serverVars = array(
133             'REQUEST_URI'    => '/test.txt',
134             'REQUEST_METHOD' => 'PUT',
135         );
136
137         $request = new Sabre_HTTP_Request($serverVars);
138         $request->setBody('Testing updated file');
139         $this->server->httpRequest = ($request);
140         $this->server->exec();
141
142         $this->assertEquals('0', $this->response->headers['Content-Length']);
143
144         $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status);
145         $this->assertEquals('', $this->response->body);
146         $this->assertEquals('Testing updated file',file_get_contents($this->tempDir . '/test.txt'));
147
148     }
149
150     function testDelete() {
151
152         $serverVars = array(
153             'REQUEST_URI'    => '/test.txt',
154             'REQUEST_METHOD' => 'DELETE',
155         );
156
157         $request = new Sabre_HTTP_Request($serverVars);
158         $this->server->httpRequest = ($request);
159         $this->server->exec();
160
161         $this->assertEquals(array(
162             'Content-Length' => '0',
163         ),$this->response->headers);
164
165         $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status);
166         $this->assertEquals('', $this->response->body);
167         $this->assertFalse(file_exists($this->tempDir . '/test.txt'));
168
169     }
170
171     function testDeleteDirectory() {
172
173         $serverVars = array(
174             'REQUEST_URI'    => '/testcol',
175             'REQUEST_METHOD' => 'DELETE',
176         );
177
178         mkdir($this->tempDir.'/testcol');
179         file_put_contents($this->tempDir.'/testcol/test.txt','Hi! I\'m a file with a short lifespan');
180
181         $request = new Sabre_HTTP_Request($serverVars);
182         $this->server->httpRequest = ($request);
183         $this->server->exec();
184
185         $this->assertEquals(array(
186             'Content-Length' => '0',
187         ),$this->response->headers);
188         $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status);
189         $this->assertEquals('', $this->response->body);
190         $this->assertFalse(file_exists($this->tempDir . '/col'));
191
192     }
193
194     function testOptions() {
195
196         $serverVars = array(
197             'REQUEST_URI'    => '/',
198             'REQUEST_METHOD' => 'OPTIONS',
199         );
200
201         $request = new Sabre_HTTP_Request($serverVars);
202         $this->server->httpRequest = ($request);
203         $this->server->exec();
204
205         $this->assertEquals(array(
206             'DAV'            => '1, 3, extended-mkcol',
207             'MS-Author-Via'  => 'DAV',
208             'Allow'          => 'OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT',
209             'Accept-Ranges'  => 'bytes',
210             'Content-Length' => '0',
211             'X-Sabre-Version'=> Sabre_DAV_Version::VERSION,
212         ),$this->response->headers);
213
214         $this->assertEquals('HTTP/1.1 200 OK',$this->response->status);
215         $this->assertEquals('', $this->response->body);
216
217     }
218
219 }