3 class Sabre_DAV_TemporaryFileFilterTest extends Sabre_DAV_AbstractServer {
8 $plugin = new Sabre_DAV_TemporaryFileFilterPlugin(SABRE_TEMPDIR . '/tff');
9 $this->server->addPlugin($plugin);
13 function testPutNormal() {
16 'REQUEST_URI' => '/testput.txt',
17 'REQUEST_METHOD' => 'PUT',
20 $request = new Sabre_HTTP_Request($serverVars);
21 $request->setBody('Testing new file');
22 $this->server->httpRequest = ($request);
23 $this->server->exec();
25 $this->assertEquals('', $this->response->body);
26 $this->assertEquals('HTTP/1.1 201 Created',$this->response->status);
27 $this->assertEquals('0', $this->response->headers['Content-Length']);
29 $this->assertEquals('Testing new file',file_get_contents(SABRE_TEMPDIR . '/testput.txt'));
33 function testPutTemp() {
35 // mimicking an OS/X resource fork
37 'REQUEST_URI' => '/._testput.txt',
38 'REQUEST_METHOD' => 'PUT',
41 $request = new Sabre_HTTP_Request($serverVars);
42 $request->setBody('Testing new file');
43 $this->server->httpRequest = ($request);
44 $this->server->exec();
46 $this->assertEquals('', $this->response->body);
47 $this->assertEquals('HTTP/1.1 201 Created',$this->response->status);
48 $this->assertEquals(array(
49 'X-Sabre-Temp' => 'true',
50 ),$this->response->headers);
52 $this->assertFalse(file_exists(SABRE_TEMPDIR . '/._testput.txt'),'._testput.txt should not exist in the regular file structure.');
56 function testPutTempIfNoneMatch() {
58 // mimicking an OS/X resource fork
60 'REQUEST_URI' => '/._testput.txt',
61 'REQUEST_METHOD' => 'PUT',
62 'HTTP_IF_NONE_MATCH' => '*',
65 $request = new Sabre_HTTP_Request($serverVars);
66 $request->setBody('Testing new file');
67 $this->server->httpRequest = ($request);
68 $this->server->exec();
70 $this->assertEquals('', $this->response->body);
71 $this->assertEquals('HTTP/1.1 201 Created',$this->response->status);
72 $this->assertEquals(array(
73 'X-Sabre-Temp' => 'true',
74 ),$this->response->headers);
76 $this->assertFalse(file_exists(SABRE_TEMPDIR . '/._testput.txt'),'._testput.txt should not exist in the regular file structure.');
79 $this->server->exec();
81 $this->assertEquals('HTTP/1.1 412 Precondition failed',$this->response->status);
82 $this->assertEquals(array(
83 'X-Sabre-Temp' => 'true',
84 'Content-Type' => 'application/xml; charset=utf-8',
85 ),$this->response->headers);
89 function testPutGet() {
91 // mimicking an OS/X resource fork
93 'REQUEST_URI' => '/._testput.txt',
94 'REQUEST_METHOD' => 'PUT',
97 $request = new Sabre_HTTP_Request($serverVars);
98 $request->setBody('Testing new file');
99 $this->server->httpRequest = ($request);
100 $this->server->exec();
102 $this->assertEquals('', $this->response->body);
103 $this->assertEquals('HTTP/1.1 201 Created',$this->response->status);
104 $this->assertEquals(array(
105 'X-Sabre-Temp' => 'true',
106 ),$this->response->headers);
109 'REQUEST_URI' => '/._testput.txt',
110 'REQUEST_METHOD' => 'GET',
113 $request = new Sabre_HTTP_Request($serverVars);
114 $this->server->httpRequest = ($request);
115 $this->server->exec();
117 $this->assertEquals('HTTP/1.1 200 OK',$this->response->status);
118 $this->assertEquals(array(
119 'X-Sabre-Temp' => 'true',
120 'Content-Length' => 16,
121 'Content-Type' => 'application/octet-stream',
122 ),$this->response->headers);
124 $this->assertEquals('Testing new file',stream_get_contents($this->response->body));
128 function testLockNonExistant() {
130 mkdir(SABRE_TEMPDIR . '/locksdir');
131 $locksBackend = new Sabre_DAV_Locks_Backend_FS(SABRE_TEMPDIR . '/locksdir');
132 $locksPlugin = new Sabre_DAV_Locks_Plugin($locksBackend);
133 $this->server->addPlugin($locksPlugin);
135 // mimicking an OS/X resource fork
137 'REQUEST_URI' => '/._testlock.txt',
138 'REQUEST_METHOD' => 'LOCK',
141 $request = new Sabre_HTTP_Request($serverVars);
143 $request->setBody('<?xml version="1.0"?>
144 <D:lockinfo xmlns:D="DAV:">
145 <D:lockscope><D:exclusive/></D:lockscope>
146 <D:locktype><D:write/></D:locktype>
148 <D:href>http://example.org/~ejw/contact.html</D:href>
152 $this->server->httpRequest = ($request);
153 $this->server->exec();
155 $this->assertEquals('HTTP/1.1 201 Created',$this->response->status);
156 $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
157 $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
158 $this->assertEquals('true',$this->response->headers['X-Sabre-Temp']);
160 $this->assertFalse(file_exists(SABRE_TEMPDIR . '/._testlock.txt'),'._testlock.txt should not exist in the regular file structure.');
164 function testPutDelete() {
166 // mimicking an OS/X resource fork
168 'REQUEST_URI' => '/._testput.txt',
169 'REQUEST_METHOD' => 'PUT',
172 $request = new Sabre_HTTP_Request($serverVars);
173 $request->setBody('Testing new file');
174 $this->server->httpRequest = ($request);
175 $this->server->exec();
177 $this->assertEquals('', $this->response->body);
178 $this->assertEquals('HTTP/1.1 201 Created',$this->response->status);
179 $this->assertEquals(array(
180 'X-Sabre-Temp' => 'true',
181 ),$this->response->headers);
184 'REQUEST_URI' => '/._testput.txt',
185 'REQUEST_METHOD' => 'DELETE',
188 $request = new Sabre_HTTP_Request($serverVars);
189 $this->server->httpRequest = ($request);
190 $this->server->exec();
192 $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status, "Incorrect status code received. Full body:\n". $this->response->body);
193 $this->assertEquals(array(
194 'X-Sabre-Temp' => 'true',
195 ),$this->response->headers);
197 $this->assertEquals('',$this->response->body);
201 function testPutPropfind() {
203 // mimicking an OS/X resource fork
205 'REQUEST_URI' => '/._testput.txt',
206 'REQUEST_METHOD' => 'PUT',
209 $request = new Sabre_HTTP_Request($serverVars);
210 $request->setBody('Testing new file');
211 $this->server->httpRequest = ($request);
212 $this->server->exec();
214 $this->assertEquals('', $this->response->body);
215 $this->assertEquals('HTTP/1.1 201 Created',$this->response->status);
216 $this->assertEquals(array(
217 'X-Sabre-Temp' => 'true',
218 ),$this->response->headers);
221 'REQUEST_URI' => '/._testput.txt',
222 'REQUEST_METHOD' => 'PROPFIND',
225 $request = new Sabre_HTTP_Request($serverVars);
226 $request->setBody('');
227 $this->server->httpRequest = ($request);
228 $this->server->exec();
230 $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Incorrect status code returned. Body: ' . $this->response->body);
231 $this->assertEquals(array(
232 'X-Sabre-Temp' => 'true',
233 'Content-Type' => 'application/xml; charset=utf-8',
234 ),$this->response->headers);
236 $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/","xmlns\\1=\"DAV:\"",$this->response->body);
237 $xml = simplexml_load_string($body);
238 $xml->registerXPathNamespace('d','DAV:');
240 list($data) = $xml->xpath('/d:multistatus/d:response/d:href');
241 $this->assertEquals('/._testput.txt',(string)$data,'href element should have been /._testput.txt');
243 $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:resourcetype');
244 $this->assertEquals(1,count($data));