3 require_once 'Sabre/DAV/AbstractServer.php';
5 class Sabre_DAV_Locks_PluginTest extends Sabre_DAV_AbstractServer {
8 * @var Sabre_DAV_Locks_Plugin
10 protected $locksPlugin;
15 $locksBackend = new Sabre_DAV_Locks_Backend_File(SABRE_TEMPDIR . '/locksdb');
16 $locksPlugin = new Sabre_DAV_Locks_Plugin($locksBackend);
17 $this->server->addPlugin($locksPlugin);
18 $this->locksPlugin = $locksPlugin;
22 function testGetFeatures() {
24 $this->assertEquals(array(2),$this->locksPlugin->getFeatures());
28 function testGetHTTPMethods() {
30 $this->assertEquals(array('LOCK','UNLOCK'),$this->locksPlugin->getHTTPMethods(''));
34 function testGetHTTPMethodsNoBackend() {
36 $locksPlugin = new Sabre_DAV_Locks_Plugin();
37 $this->server->addPlugin($locksPlugin);
38 $this->assertEquals(array(),$locksPlugin->getHTTPMethods(''));
42 function testUnknownMethodPassthough() {
44 $this->assertNull($this->locksPlugin->unknownMethod('BLA','/'));
48 function testLockNoBody() {
51 'REQUEST_URI' => '/test.txt',
52 'REQUEST_METHOD' => 'LOCK',
55 $request = new Sabre_HTTP_Request($serverVars);
56 $request->setBody('');
57 $this->server->httpRequest = ($request);
58 $this->server->exec();
60 $this->assertEquals(array(
61 'Content-Type' => 'application/xml; charset=utf-8',
63 $this->response->headers
66 $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status);
73 'REQUEST_URI' => '/test.txt',
74 'REQUEST_METHOD' => 'LOCK',
77 $request = new Sabre_HTTP_Request($serverVars);
78 $request->setBody('<?xml version="1.0"?>
79 <D:lockinfo xmlns:D="DAV:">
80 <D:lockscope><D:exclusive/></D:lockscope>
81 <D:locktype><D:write/></D:locktype>
83 <D:href>http://example.org/~ejw/contact.html</D:href>
87 $this->server->httpRequest = $request;
88 $this->server->exec();
90 $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
91 $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
93 $this->assertEquals('HTTP/1.1 200 OK',$this->response->status,'Got an incorrect status back. Response body: ' . $this->response->body);
95 $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/","xmlns\\1=\"DAV:\"",$this->response->body);
96 $xml = simplexml_load_string($body);
97 $xml->registerXPathNamespace('d','DAV:');
101 '/d:prop/d:lockdiscovery',
102 '/d:prop/d:lockdiscovery/d:activelock',
103 '/d:prop/d:lockdiscovery/d:activelock/d:locktype',
104 '/d:prop/d:lockdiscovery/d:activelock/d:lockroot',
105 '/d:prop/d:lockdiscovery/d:activelock/d:lockroot/d:href',
106 '/d:prop/d:lockdiscovery/d:activelock/d:locktype/d:write',
107 '/d:prop/d:lockdiscovery/d:activelock/d:lockscope',
108 '/d:prop/d:lockdiscovery/d:activelock/d:lockscope/d:exclusive',
109 '/d:prop/d:lockdiscovery/d:activelock/d:depth',
110 '/d:prop/d:lockdiscovery/d:activelock/d:owner',
111 '/d:prop/d:lockdiscovery/d:activelock/d:timeout',
112 '/d:prop/d:lockdiscovery/d:activelock/d:locktoken',
113 '/d:prop/d:lockdiscovery/d:activelock/d:locktoken/d:href',
116 foreach($elements as $elem) {
117 $data = $xml->xpath($elem);
118 $this->assertEquals(1,count($data),'We expected 1 match for the xpath expression "' . $elem . '". ' . count($data) . ' were found. Full response body: ' . $this->response->body);
121 $depth = $xml->xpath('/d:prop/d:lockdiscovery/d:activelock/d:depth');
122 $this->assertEquals('infinity',(string)$depth[0]);
124 $token = $xml->xpath('/d:prop/d:lockdiscovery/d:activelock/d:locktoken/d:href');
125 $this->assertEquals($this->response->headers['Lock-Token'],'<' . (string)$token[0] . '>','Token in response body didn\'t match token in response header.');
132 function testDoubleLock() {
135 'REQUEST_URI' => '/test.txt',
136 'REQUEST_METHOD' => 'LOCK',
139 $request = new Sabre_HTTP_Request($serverVars);
140 $request->setBody('<?xml version="1.0"?>
141 <D:lockinfo xmlns:D="DAV:">
142 <D:lockscope><D:exclusive/></D:lockscope>
143 <D:locktype><D:write/></D:locktype>
145 <D:href>http://example.org/~ejw/contact.html</D:href>
149 $this->server->httpRequest = $request;
150 $this->server->exec();
152 $this->response = new Sabre_HTTP_ResponseMock();
153 $this->server->httpResponse = $this->response;
155 $this->server->exec();
157 $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
159 $this->assertEquals('HTTP/1.1 423 Locked',$this->response->status);
166 function testLockRefresh() {
169 'REQUEST_URI' => '/test.txt',
170 'REQUEST_METHOD' => 'LOCK',
173 $request = new Sabre_HTTP_Request($serverVars);
174 $request->setBody('<?xml version="1.0"?>
175 <D:lockinfo xmlns:D="DAV:">
176 <D:lockscope><D:exclusive/></D:lockscope>
177 <D:locktype><D:write/></D:locktype>
179 <D:href>http://example.org/~ejw/contact.html</D:href>
183 $this->server->httpRequest = $request;
184 $this->server->exec();
186 $lockToken = $this->response->headers['Lock-Token'];
188 $this->response = new Sabre_HTTP_ResponseMock();
189 $this->server->httpResponse = $this->response;
192 'REQUEST_URI' => '/test.txt',
193 'REQUEST_METHOD' => 'LOCK',
194 'HTTP_IF' => '(' . $lockToken . ')',
196 $request = new Sabre_HTTP_Request($serverVars);
197 $request->setBody('');
198 $this->server->httpRequest = $request;
200 $this->server->exec();
202 $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
204 $this->assertEquals('HTTP/1.1 200 OK',$this->response->status,'We received an incorrect status code. Full response body: ' . $this->response->body);
211 function testLockNoFile() {
214 'REQUEST_URI' => '/notfound.txt',
215 'REQUEST_METHOD' => 'LOCK',
218 $request = new Sabre_HTTP_Request($serverVars);
219 $request->setBody('<?xml version="1.0"?>
220 <D:lockinfo xmlns:D="DAV:">
221 <D:lockscope><D:exclusive/></D:lockscope>
222 <D:locktype><D:write/></D:locktype>
224 <D:href>http://example.org/~ejw/contact.html</D:href>
228 $this->server->httpRequest = $request;
229 $this->server->exec();
231 $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
232 $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
234 $this->assertEquals('HTTP/1.1 201 Created',$this->response->status);
241 function testUnlockNoToken() {
244 'REQUEST_URI' => '/test.txt',
245 'REQUEST_METHOD' => 'UNLOCK',
248 $request = new Sabre_HTTP_Request($serverVars);
249 $this->server->httpRequest = ($request);
250 $this->server->exec();
252 $this->assertEquals(array(
253 'Content-Type' => 'application/xml; charset=utf-8',
255 $this->response->headers
258 $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status);
265 function testUnlockBadToken() {
268 'REQUEST_URI' => '/test.txt',
269 'REQUEST_METHOD' => 'UNLOCK',
270 'HTTP_LOCK_TOKEN' => '<opaquelocktoken:blablabla>',
273 $request = new Sabre_HTTP_Request($serverVars);
274 $this->server->httpRequest = ($request);
275 $this->server->exec();
277 $this->assertEquals(array(
278 'Content-Type' => 'application/xml; charset=utf-8',
280 $this->response->headers
283 $this->assertEquals('HTTP/1.1 409 Conflict',$this->response->status,'Got an incorrect status code. Full response body: ' . $this->response->body);
290 function testLockPutNoToken() {
293 'REQUEST_URI' => '/test.txt',
294 'REQUEST_METHOD' => 'LOCK',
297 $request = new Sabre_HTTP_Request($serverVars);
298 $request->setBody('<?xml version="1.0"?>
299 <D:lockinfo xmlns:D="DAV:">
300 <D:lockscope><D:exclusive/></D:lockscope>
301 <D:locktype><D:write/></D:locktype>
303 <D:href>http://example.org/~ejw/contact.html</D:href>
307 $this->server->httpRequest = $request;
308 $this->server->exec();
310 $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
311 $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
313 $this->assertEquals('HTTP/1.1 200 OK',$this->response->status);
316 'REQUEST_URI' => '/test.txt',
317 'REQUEST_METHOD' => 'PUT',
320 $request = new Sabre_HTTP_Request($serverVars);
321 $request->setBody('newbody');
322 $this->server->httpRequest = $request;
323 $this->server->exec();
325 $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
326 $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
328 $this->assertEquals('HTTP/1.1 423 Locked',$this->response->status);
335 function testUnlock() {
337 $request = new Sabre_HTTP_Request(array());
338 $this->server->httpRequest = $request;
340 $request->setBody('<?xml version="1.0"?>
341 <D:lockinfo xmlns:D="DAV:">
342 <D:lockscope><D:exclusive/></D:lockscope>
343 <D:locktype><D:write/></D:locktype>
345 <D:href>http://example.org/~ejw/contact.html</D:href>
349 $this->server->invokeMethod('LOCK','test.txt');
350 $lockToken = $this->server->httpResponse->headers['Lock-Token'];
353 'HTTP_LOCK_TOKEN' => $lockToken,
356 $request = new Sabre_HTTP_Request($serverVars);
357 $this->server->httpRequest = ($request);
358 $this->server->httpResponse = new Sabre_HTTP_ResponseMock();
359 $this->server->invokeMethod('UNLOCK', 'test.txt');
361 $this->assertEquals('HTTP/1.1 204 No Content',$this->server->httpResponse->status,'Got an incorrect status code. Full response body: ' . $this->response->body);
362 $this->assertEquals(array(
363 'Content-Length' => '0',
365 $this->server->httpResponse->headers
374 function testUnlockWindowsBug() {
376 $request = new Sabre_HTTP_Request(array());
377 $this->server->httpRequest = $request;
379 $request->setBody('<?xml version="1.0"?>
380 <D:lockinfo xmlns:D="DAV:">
381 <D:lockscope><D:exclusive/></D:lockscope>
382 <D:locktype><D:write/></D:locktype>
384 <D:href>http://example.org/~ejw/contact.html</D:href>
388 $this->server->invokeMethod('LOCK','test.txt');
389 $lockToken = $this->server->httpResponse->headers['Lock-Token'];
392 $lockToken = trim($lockToken,'<>');
395 'HTTP_LOCK_TOKEN' => $lockToken,
398 $request = new Sabre_HTTP_Request($serverVars);
399 $this->server->httpRequest = ($request);
400 $this->server->httpResponse = new Sabre_HTTP_ResponseMock();
401 $this->server->invokeMethod('UNLOCK', 'test.txt');
403 $this->assertEquals('HTTP/1.1 204 No Content',$this->server->httpResponse->status,'Got an incorrect status code. Full response body: ' . $this->response->body);
404 $this->assertEquals(array(
405 'Content-Length' => '0',
407 $this->server->httpResponse->headers
416 function testLockRetainOwner() {
418 $request = new Sabre_HTTP_Request(array());
419 $this->server->httpRequest = $request;
421 $request->setBody('<?xml version="1.0"?>
422 <D:lockinfo xmlns:D="DAV:">
423 <D:lockscope><D:exclusive/></D:lockscope>
424 <D:locktype><D:write/></D:locktype>
425 <D:owner>Evert</D:owner>
428 $this->server->invokeMethod('LOCK','test.txt');
429 $lockToken = $this->server->httpResponse->headers['Lock-Token'];
431 $locks = $this->locksPlugin->getLocks('test.txt');
432 $this->assertEquals(1,count($locks));
433 $this->assertEquals('Evert',$locks[0]->owner);
441 function testLockPutBadToken() {
444 'REQUEST_URI' => '/test.txt',
445 'REQUEST_METHOD' => 'LOCK',
448 $request = new Sabre_HTTP_Request($serverVars);
449 $request->setBody('<?xml version="1.0"?>
450 <D:lockinfo xmlns:D="DAV:">
451 <D:lockscope><D:exclusive/></D:lockscope>
452 <D:locktype><D:write/></D:locktype>
454 <D:href>http://example.org/~ejw/contact.html</D:href>
458 $this->server->httpRequest = $request;
459 $this->server->exec();
461 $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
462 $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
464 $this->assertEquals('HTTP/1.1 200 OK',$this->response->status);
467 'REQUEST_URI' => '/test.txt',
468 'REQUEST_METHOD' => 'PUT',
469 'HTTP_IF' => '(<opaquelocktoken:token1>)',
472 $request = new Sabre_HTTP_Request($serverVars);
473 $request->setBody('newbody');
474 $this->server->httpRequest = $request;
475 $this->server->exec();
477 $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
478 $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
480 $this->assertEquals('HTTP/1.1 412 Precondition failed',$this->response->status);
487 function testLockDeleteParent() {
490 'REQUEST_URI' => '/dir/child.txt',
491 'REQUEST_METHOD' => 'LOCK',
494 $request = new Sabre_HTTP_Request($serverVars);
495 $request->setBody('<?xml version="1.0"?>
496 <D:lockinfo xmlns:D="DAV:">
497 <D:lockscope><D:exclusive/></D:lockscope>
498 <D:locktype><D:write/></D:locktype>
500 <D:href>http://example.org/~ejw/contact.html</D:href>
504 $this->server->httpRequest = $request;
505 $this->server->exec();
507 $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
508 $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
510 $this->assertEquals('HTTP/1.1 200 OK',$this->response->status);
513 'REQUEST_URI' => '/dir',
514 'REQUEST_METHOD' => 'DELETE',
517 $request = new Sabre_HTTP_Request($serverVars);
518 $this->server->httpRequest = $request;
519 $this->server->exec();
521 $this->assertEquals('HTTP/1.1 423 Locked',$this->response->status);
522 $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
528 function testLockDeleteSucceed() {
531 'REQUEST_URI' => '/dir/child.txt',
532 'REQUEST_METHOD' => 'LOCK',
535 $request = new Sabre_HTTP_Request($serverVars);
536 $request->setBody('<?xml version="1.0"?>
537 <D:lockinfo xmlns:D="DAV:">
538 <D:lockscope><D:exclusive/></D:lockscope>
539 <D:locktype><D:write/></D:locktype>
541 <D:href>http://example.org/~ejw/contact.html</D:href>
545 $this->server->httpRequest = $request;
546 $this->server->exec();
548 $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
549 $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
551 $this->assertEquals('HTTP/1.1 200 OK',$this->response->status);
554 'REQUEST_URI' => '/dir/child.txt',
555 'REQUEST_METHOD' => 'DELETE',
556 'HTTP_IF' => '(' . $this->response->headers['Lock-Token'] . ')',
559 $request = new Sabre_HTTP_Request($serverVars);
560 $this->server->httpRequest = $request;
561 $this->server->exec();
563 $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status);
564 $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
571 function testLockCopyLockSource() {
574 'REQUEST_URI' => '/dir/child.txt',
575 'REQUEST_METHOD' => 'LOCK',
578 $request = new Sabre_HTTP_Request($serverVars);
579 $request->setBody('<?xml version="1.0"?>
580 <D:lockinfo xmlns:D="DAV:">
581 <D:lockscope><D:exclusive/></D:lockscope>
582 <D:locktype><D:write/></D:locktype>
584 <D:href>http://example.org/~ejw/contact.html</D:href>
588 $this->server->httpRequest = $request;
589 $this->server->exec();
591 $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
592 $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
594 $this->assertEquals('HTTP/1.1 200 OK',$this->response->status);
597 'REQUEST_URI' => '/dir/child.txt',
598 'REQUEST_METHOD' => 'COPY',
599 'HTTP_DESTINATION' => '/dir/child2.txt',
602 $request = new Sabre_HTTP_Request($serverVars);
603 $this->server->httpRequest = $request;
604 $this->server->exec();
606 $this->assertEquals('HTTP/1.1 201 Created',$this->response->status,'Copy must succeed if only the source is locked, but not the destination');
607 $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
613 function testLockCopyLockDestination() {
616 'REQUEST_URI' => '/dir/child2.txt',
617 'REQUEST_METHOD' => 'LOCK',
620 $request = new Sabre_HTTP_Request($serverVars);
621 $request->setBody('<?xml version="1.0"?>
622 <D:lockinfo xmlns:D="DAV:">
623 <D:lockscope><D:exclusive/></D:lockscope>
624 <D:locktype><D:write/></D:locktype>
626 <D:href>http://example.org/~ejw/contact.html</D:href>
630 $this->server->httpRequest = $request;
631 $this->server->exec();
633 $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
634 $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
636 $this->assertEquals('HTTP/1.1 201 Created',$this->response->status);
639 'REQUEST_URI' => '/dir/child.txt',
640 'REQUEST_METHOD' => 'COPY',
641 'HTTP_DESTINATION' => '/dir/child2.txt',
644 $request = new Sabre_HTTP_Request($serverVars);
645 $this->server->httpRequest = $request;
646 $this->server->exec();
648 $this->assertEquals('HTTP/1.1 423 Locked',$this->response->status,'Copy must succeed if only the source is locked, but not the destination');
649 $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
656 function testLockMoveLockSourceLocked() {
659 'REQUEST_URI' => '/dir/child.txt',
660 'REQUEST_METHOD' => 'LOCK',
663 $request = new Sabre_HTTP_Request($serverVars);
664 $request->setBody('<?xml version="1.0"?>
665 <D:lockinfo xmlns:D="DAV:">
666 <D:lockscope><D:exclusive/></D:lockscope>
667 <D:locktype><D:write/></D:locktype>
669 <D:href>http://example.org/~ejw/contact.html</D:href>
673 $this->server->httpRequest = $request;
674 $this->server->exec();
676 $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
677 $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
679 $this->assertEquals('HTTP/1.1 200 OK',$this->response->status);
682 'REQUEST_URI' => '/dir/child.txt',
683 'REQUEST_METHOD' => 'MOVE',
684 'HTTP_DESTINATION' => '/dir/child2.txt',
687 $request = new Sabre_HTTP_Request($serverVars);
688 $this->server->httpRequest = $request;
689 $this->server->exec();
691 $this->assertEquals('HTTP/1.1 423 Locked',$this->response->status,'Copy must succeed if only the source is locked, but not the destination');
692 $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
699 function testLockMoveLockSourceSucceed() {
702 'REQUEST_URI' => '/dir/child.txt',
703 'REQUEST_METHOD' => 'LOCK',
706 $request = new Sabre_HTTP_Request($serverVars);
707 $request->setBody('<?xml version="1.0"?>
708 <D:lockinfo xmlns:D="DAV:">
709 <D:lockscope><D:exclusive/></D:lockscope>
710 <D:locktype><D:write/></D:locktype>
712 <D:href>http://example.org/~ejw/contact.html</D:href>
716 $this->server->httpRequest = $request;
717 $this->server->exec();
719 $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
720 $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
722 $this->assertEquals('HTTP/1.1 200 OK',$this->response->status);
725 'REQUEST_URI' => '/dir/child.txt',
726 'REQUEST_METHOD' => 'MOVE',
727 'HTTP_DESTINATION' => '/dir/child2.txt',
728 'HTTP_IF' => '(' . $this->response->headers['Lock-Token'] . ')',
731 $request = new Sabre_HTTP_Request($serverVars);
732 $this->server->httpRequest = $request;
733 $this->server->exec();
735 $this->assertEquals('HTTP/1.1 201 Created',$this->response->status,'A valid lock-token was provided for the source, so this MOVE operation must succeed. Full response body: ' . $this->response->body);
742 function testLockMoveLockDestination() {
745 'REQUEST_URI' => '/dir/child2.txt',
746 'REQUEST_METHOD' => 'LOCK',
749 $request = new Sabre_HTTP_Request($serverVars);
750 $request->setBody('<?xml version="1.0"?>
751 <D:lockinfo xmlns:D="DAV:">
752 <D:lockscope><D:exclusive/></D:lockscope>
753 <D:locktype><D:write/></D:locktype>
755 <D:href>http://example.org/~ejw/contact.html</D:href>
759 $this->server->httpRequest = $request;
760 $this->server->exec();
762 $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
763 $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
765 $this->assertEquals('HTTP/1.1 201 Created',$this->response->status);
768 'REQUEST_URI' => '/dir/child.txt',
769 'REQUEST_METHOD' => 'MOVE',
770 'HTTP_DESTINATION' => '/dir/child2.txt',
773 $request = new Sabre_HTTP_Request($serverVars);
774 $this->server->httpRequest = $request;
775 $this->server->exec();
777 $this->assertEquals('HTTP/1.1 423 Locked',$this->response->status,'Copy must succeed if only the source is locked, but not the destination');
778 $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
784 function testLockMoveLockParent() {
787 'REQUEST_URI' => '/dir',
788 'REQUEST_METHOD' => 'LOCK',
789 'HTTP_DEPTH' => 'infinite',
792 $request = new Sabre_HTTP_Request($serverVars);
793 $request->setBody('<?xml version="1.0"?>
794 <D:lockinfo xmlns:D="DAV:">
795 <D:lockscope><D:exclusive/></D:lockscope>
796 <D:locktype><D:write/></D:locktype>
798 <D:href>http://example.org/~ejw/contact.html</D:href>
802 $this->server->httpRequest = $request;
803 $this->server->exec();
805 $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
806 $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
808 $this->assertEquals('HTTP/1.1 200 OK',$this->response->status);
811 'REQUEST_URI' => '/dir/child.txt',
812 'REQUEST_METHOD' => 'MOVE',
813 'HTTP_DESTINATION' => '/dir/child2.txt',
814 'HTTP_IF' => '</dir> (' . $this->response->headers['Lock-Token'] . ')',
817 $request = new Sabre_HTTP_Request($serverVars);
818 $this->server->httpRequest = $request;
819 $this->server->exec();
821 $this->assertEquals('HTTP/1.1 201 Created',$this->response->status,'We locked the parent of both the source and destination, but the move didn\'t succeed.');
822 $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
829 function testLockPutGoodToken() {
832 'REQUEST_URI' => '/test.txt',
833 'REQUEST_METHOD' => 'LOCK',
836 $request = new Sabre_HTTP_Request($serverVars);
837 $request->setBody('<?xml version="1.0"?>
838 <D:lockinfo xmlns:D="DAV:">
839 <D:lockscope><D:exclusive/></D:lockscope>
840 <D:locktype><D:write/></D:locktype>
842 <D:href>http://example.org/~ejw/contact.html</D:href>
846 $this->server->httpRequest = $request;
847 $this->server->exec();
849 $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
850 $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
852 $this->assertEquals('HTTP/1.1 200 OK',$this->response->status);
855 'REQUEST_URI' => '/test.txt',
856 'REQUEST_METHOD' => 'PUT',
857 'HTTP_IF' => '('.$this->response->headers['Lock-Token'].')',
860 $request = new Sabre_HTTP_Request($serverVars);
861 $request->setBody('newbody');
862 $this->server->httpRequest = $request;
863 $this->server->exec();
865 $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']);
866 $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')');
868 $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status);
872 function testPutWithIncorrectETag() {
875 'REQUEST_URI' => '/test.txt',
876 'REQUEST_METHOD' => 'PUT',
877 'HTTP_IF' => '(["etag1"])',
880 $request = new Sabre_HTTP_Request($serverVars);
881 $request->setBody('newbody');
882 $this->server->httpRequest = $request;
883 $this->server->exec();
884 $this->assertEquals('HTTP/1.1 412 Precondition failed',$this->response->status);
889 * @depends testPutWithIncorrectETag
891 function testPutWithCorrectETag() {
893 // We need an etag-enabled file node.
894 $tree = new Sabre_DAV_ObjectTree(new Sabre_DAV_FSExt_Directory(SABRE_TEMPDIR));
895 $this->server->tree = $tree;
897 $etag = md5(file_get_contents(SABRE_TEMPDIR . '/test.txt'));
899 'REQUEST_URI' => '/test.txt',
900 'REQUEST_METHOD' => 'PUT',
901 'HTTP_IF' => '(["'.$etag.'"])',
904 $request = new Sabre_HTTP_Request($serverVars);
905 $request->setBody('newbody');
906 $this->server->httpRequest = $request;
907 $this->server->exec();
908 $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status, 'Incorrect status received. Full response body:' . $this->response->body);
912 function testGetTimeoutHeader() {
914 $request = new Sabre_HTTP_Request(array(
915 'HTTP_TIMEOUT' => 'second-100',
918 $this->server->httpRequest = $request;
919 $this->assertEquals(100, $this->locksPlugin->getTimeoutHeader());
924 function testGetTimeoutHeaderNotSet() {
926 $request = new Sabre_HTTP_Request(array(
929 $this->server->httpRequest = $request;
930 $this->assertEquals(0, $this->locksPlugin->getTimeoutHeader());
935 function testGetTimeoutHeaderInfinite() {
937 $request = new Sabre_HTTP_Request(array(
938 'HTTP_TIMEOUT' => 'infinite',
941 $this->server->httpRequest = $request;
942 $this->assertEquals(Sabre_DAV_Locks_LockInfo::TIMEOUT_INFINITE, $this->locksPlugin->getTimeoutHeader());
947 * @expectedException Sabre_DAV_Exception_BadRequest
949 function testGetTimeoutHeaderInvalid() {
951 $request = new Sabre_HTTP_Request(array(
952 'HTTP_TIMEOUT' => 'yourmom',
955 $this->server->httpRequest = $request;
956 $this->locksPlugin->getTimeoutHeader();