ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ServerPreconditionTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\DAV;
4 
5 use Sabre\HTTP;
6 
7 require_once 'Sabre/HTTP/ResponseMock.php';
8 
10 
14  function testIfMatchNoNode() {
15 
16  $root = new SimpleCollection('root', [new ServerPreconditionsNode()]);
17  $server = new Server($root);
18  $httpRequest = new HTTP\Request('GET', '/bar', ['If-Match' => '*']);
19  $httpResponse = new HTTP\Response();
20  $server->checkPreconditions($httpRequest, $httpResponse);
21 
22  }
23 
26  function testIfMatchHasNode() {
27 
28  $root = new SimpleCollection('root', [new ServerPreconditionsNode()]);
29  $server = new Server($root);
30  $httpRequest = new HTTP\Request('GET', '/foo', ['If-Match' => '*']);
31  $httpResponse = new HTTP\Response();
32  $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
33 
34  }
35 
39  function testIfMatchWrongEtag() {
40 
41  $root = new SimpleCollection('root', [new ServerPreconditionsNode()]);
42  $server = new Server($root);
43  $httpRequest = new HTTP\Request('GET', '/foo', ['If-Match' => '1234']);
44  $httpResponse = new HTTP\Response();
45  $server->checkPreconditions($httpRequest, $httpResponse);
46 
47  }
48 
52 
53  $root = new SimpleCollection('root', [new ServerPreconditionsNode()]);
54  $server = new Server($root);
55  $httpRequest = new HTTP\Request('GET', '/foo', ['If-Match' => '"abc123"']);
56  $httpResponse = new HTTP\Response();
57  $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
58 
59  }
60 
67 
68  $root = new SimpleCollection('root', [new ServerPreconditionsNode()]);
69  $server = new Server($root);
70  $httpRequest = new HTTP\Request('GET', '/foo', ['If-Match' => '\\"abc123\\"']);
71  $httpResponse = new HTTP\Response();
72  $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
73 
74  }
75 
78  function testIfMatchMultiple() {
79 
80  $root = new SimpleCollection('root', [new ServerPreconditionsNode()]);
81  $server = new Server($root);
82  $httpRequest = new HTTP\Request('GET', '/foo', ['If-Match' => '"hellothere", "abc123"']);
83  $httpResponse = new HTTP\Response();
84  $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
85 
86  }
87 
90  function testIfNoneMatchNoNode() {
91 
92  $root = new SimpleCollection('root', [new ServerPreconditionsNode()]);
93  $server = new Server($root);
94  $httpRequest = new HTTP\Request('GET', '/bar', ['If-None-Match' => '*']);
95  $httpResponse = new HTTP\Response();
96  $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
97 
98  }
99 
104 
105  $root = new SimpleCollection('root', [new ServerPreconditionsNode()]);
106  $server = new Server($root);
107  $httpRequest = new HTTP\Request('POST', '/foo', ['If-None-Match' => '*']);
108  $httpResponse = new HTTP\Response();
109  $server->checkPreconditions($httpRequest, $httpResponse);
110 
111  }
112 
116 
117  $root = new SimpleCollection('root', [new ServerPreconditionsNode()]);
118  $server = new Server($root);
119  $httpRequest = new HTTP\Request('POST', '/foo', ['If-None-Match' => '"1234"']);
120  $httpResponse = new HTTP\Response();
121  $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
122 
123  }
124 
128 
129  $root = new SimpleCollection('root', [new ServerPreconditionsNode()]);
130  $server = new Server($root);
131  $httpRequest = new HTTP\Request('POST', '/foo', ['If-None-Match' => '"1234", "5678"']);
132  $httpResponse = new HTTP\Response();
133  $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
134 
135  }
136 
141 
142  $root = new SimpleCollection('root', [new ServerPreconditionsNode()]);
143  $server = new Server($root);
144  $httpRequest = new HTTP\Request('POST', '/foo', ['If-None-Match' => '"abc123"']);
145  $httpResponse = new HTTP\Response();
146  $server->checkPreconditions($httpRequest, $httpResponse);
147 
148  }
149 
154 
155  $root = new SimpleCollection('root', [new ServerPreconditionsNode()]);
156  $server = new Server($root);
157  $httpRequest = new HTTP\Request('POST', '/foo', ['If-None-Match' => '"1234, "abc123"']);
158  $httpResponse = new HTTP\Response();
159  $server->checkPreconditions($httpRequest, $httpResponse);
160 
161  }
162 
166 
167  $root = new SimpleCollection('root', [new ServerPreconditionsNode()]);
168  $server = new Server($root);
169  $httpRequest = new HTTP\Request('GET', '/foo', ['If-None-Match' => '"abc123"']);
170  $server->httpResponse = new HTTP\ResponseMock();
171 
172  $this->assertFalse($server->checkPreconditions($httpRequest, $server->httpResponse));
173  $this->assertEquals(304, $server->httpResponse->getStatus());
174  $this->assertEquals(['ETag' => ['"abc123"']], $server->httpResponse->getHeaders());
175 
176  }
177 
182 
183  $root = new SimpleCollection('root', [new ServerPreconditionsNode()]);
184  $server = new Server($root);
185  $server->sapi = new HTTP\SapiMock();
187  $httpRequest = new HTTP\Request('GET', '/foo', ['If-None-Match' => '"abc123"']);
188  $server->httpRequest = $httpRequest;
189  $server->httpResponse = new HTTP\ResponseMock();
190 
191  $server->exec();
192 
193  $this->assertFalse($server->checkPreconditions($httpRequest, $server->httpResponse));
194  $this->assertEquals(304, $server->httpResponse->getStatus());
195  $this->assertEquals([
196  'ETag' => ['"abc123"'],
197  'X-Sabre-Version' => [Version::VERSION],
198  ], $server->httpResponse->getHeaders());
199  $this->assertEquals(1, HTTP\SapiMock::$sent);
200 
201  }
202 
206 
207  $root = new SimpleCollection('root', [new ServerPreconditionsNode()]);
208  $server = new Server($root);
209  $httpRequest = HTTP\Sapi::createFromServerArray([
210  'HTTP_IF_MODIFIED_SINCE' => 'Sun, 06 Nov 1994 08:49:37 GMT',
211  'REQUEST_URI' => '/foo'
212  ]);
213  $server->httpResponse = new HTTP\ResponseMock();
214  $this->assertFalse($server->checkPreconditions($httpRequest, $server->httpResponse));
215 
216  $this->assertEquals(304, $server->httpResponse->status);
217  $this->assertEquals([
218  'Last-Modified' => ['Sat, 06 Apr 1985 23:30:00 GMT'],
219  ], $server->httpResponse->getHeaders());
220 
221  }
222 
223 
227 
228  $root = new SimpleCollection('root', [new ServerPreconditionsNode()]);
229  $server = new Server($root);
230  $httpRequest = HTTP\Sapi::createFromServerArray([
231  'HTTP_IF_MODIFIED_SINCE' => 'Tue, 06 Nov 1984 08:49:37 GMT',
232  'REQUEST_URI' => '/foo'
233  ]);
234 
235  $httpResponse = new HTTP\ResponseMock();
236  $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
237 
238  }
239 
243 
244  $root = new SimpleCollection('root', [new ServerPreconditionsNode()]);
245  $server = new Server($root);
246  $httpRequest = HTTP\Sapi::createFromServerArray([
247  'HTTP_IF_MODIFIED_SINCE' => 'Your mother',
248  'REQUEST_URI' => '/foo'
249  ]);
250  $httpResponse = new HTTP\ResponseMock();
251 
252  // Invalid dates must be ignored, so this should return true
253  $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
254 
255  }
256 
260 
261  $root = new SimpleCollection('root', [new ServerPreconditionsNode()]);
262  $server = new Server($root);
263  $httpRequest = HTTP\Sapi::createFromServerArray([
264  'HTTP_IF_MODIFIED_SINCE' => 'Sun, 06 Nov 1994 08:49:37 EST',
265  'REQUEST_URI' => '/foo'
266  ]);
267  $httpResponse = new HTTP\ResponseMock();
268  $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
269 
270  }
271 
272 
276 
277  $root = new SimpleCollection('root', [new ServerPreconditionsNode()]);
278  $server = new Server($root);
279  $httpRequest = HTTP\Sapi::createFromServerArray([
280  'HTTP_IF_UNMODIFIED_SINCE' => 'Sun, 06 Nov 1994 08:49:37 GMT',
281  'REQUEST_URI' => '/foo'
282  ]);
283  $httpResponse = new HTTP\Response();
284  $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
285 
286  }
287 
288 
293 
294  $root = new SimpleCollection('root', [new ServerPreconditionsNode()]);
295  $server = new Server($root);
296  $httpRequest = HTTP\Sapi::createFromServerArray([
297  'HTTP_IF_UNMODIFIED_SINCE' => 'Tue, 06 Nov 1984 08:49:37 GMT',
298  'REQUEST_URI' => '/foo'
299  ]);
300  $httpResponse = new HTTP\ResponseMock();
301  $server->checkPreconditions($httpRequest, $httpResponse);
302 
303  }
304 
308 
309  $root = new SimpleCollection('root', [new ServerPreconditionsNode()]);
310  $server = new Server($root);
311  $httpRequest = HTTP\Sapi::createFromServerArray([
312  'HTTP_IF_UNMODIFIED_SINCE' => 'Sun, 06 Nov 1984 08:49:37 CET',
313  'REQUEST_URI' => '/foo'
314  ]);
315  $httpResponse = new HTTP\ResponseMock();
316  $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse));
317 
318  }
319 
320 
321 }
322 
324 
325  function getETag() {
326 
327  return '"abc123"';
328 
329  }
330 
331  function getLastModified() {
332 
333  /* my birthday & time, I believe */
334  return strtotime('1985-04-07 01:30 +02:00');
335 
336  }
337 
338  function getName() {
339 
340  return 'foo';
341 
342  }
343 
344 }
getLastModified()
Returns the last modification time, as a unix timestamp.
testIfMatchEvolutionEtag()
Evolution sometimes uses " instead of " for If-Match headers.
getName()
Returns the name of the node.
$server
Definition: sabredav.php:48
const VERSION
Full version number.
Definition: Version.php:17
testNoneMatchCorrectEtagEnsureSapiSent()
This was a test written for issue #515.
Main DAV server class.
Definition: Server.php:23
$root
Definition: sabredav.php:45
static createFromServerArray(array $serverArray)
This static method will create a new Request object, based on a PHP $_SERVER array.
Definition: Sapi.php:107
getETag()
Returns the ETag for a file.