xref: /plugin/davcal/vendor/sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php (revision a1a3b6794e0e143a4a8b51d3185ce2d339be61ab)
1*a1a3b679SAndreas Boehler<?php
2*a1a3b679SAndreas Boehler
3*a1a3b679SAndreas Boehlernamespace Sabre\DAV\Locks;
4*a1a3b679SAndreas Boehler
5*a1a3b679SAndreas Boehleruse Sabre\HTTP;
6*a1a3b679SAndreas Boehleruse Sabre\DAV;
7*a1a3b679SAndreas Boehler
8*a1a3b679SAndreas Boehlerrequire_once 'Sabre/DAV/AbstractServer.php';
9*a1a3b679SAndreas Boehler
10*a1a3b679SAndreas Boehlerclass PluginTest extends DAV\AbstractServer {
11*a1a3b679SAndreas Boehler
12*a1a3b679SAndreas Boehler    /**
13*a1a3b679SAndreas Boehler     * @var Sabre\DAV\Locks\Plugin
14*a1a3b679SAndreas Boehler     */
15*a1a3b679SAndreas Boehler    protected $locksPlugin;
16*a1a3b679SAndreas Boehler
17*a1a3b679SAndreas Boehler    function setUp() {
18*a1a3b679SAndreas Boehler
19*a1a3b679SAndreas Boehler        parent::setUp();
20*a1a3b679SAndreas Boehler        $locksBackend = new Backend\File(SABRE_TEMPDIR . '/locksdb');
21*a1a3b679SAndreas Boehler        $locksPlugin = new Plugin($locksBackend);
22*a1a3b679SAndreas Boehler        $this->server->addPlugin($locksPlugin);
23*a1a3b679SAndreas Boehler        $this->locksPlugin = $locksPlugin;
24*a1a3b679SAndreas Boehler
25*a1a3b679SAndreas Boehler    }
26*a1a3b679SAndreas Boehler
27*a1a3b679SAndreas Boehler    function testGetFeatures() {
28*a1a3b679SAndreas Boehler
29*a1a3b679SAndreas Boehler        $this->assertEquals(array(2),$this->locksPlugin->getFeatures());
30*a1a3b679SAndreas Boehler
31*a1a3b679SAndreas Boehler    }
32*a1a3b679SAndreas Boehler
33*a1a3b679SAndreas Boehler    function testGetHTTPMethods() {
34*a1a3b679SAndreas Boehler
35*a1a3b679SAndreas Boehler        $this->assertEquals(array('LOCK','UNLOCK'),$this->locksPlugin->getHTTPMethods(''));
36*a1a3b679SAndreas Boehler
37*a1a3b679SAndreas Boehler    }
38*a1a3b679SAndreas Boehler
39*a1a3b679SAndreas Boehler    function testLockNoBody() {
40*a1a3b679SAndreas Boehler
41*a1a3b679SAndreas Boehler        $request = new HTTP\Request('LOCK', '/test.txt');
42*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
43*a1a3b679SAndreas Boehler        $this->server->exec();
44*a1a3b679SAndreas Boehler
45*a1a3b679SAndreas Boehler        $this->assertEquals(array(
46*a1a3b679SAndreas Boehler            'X-Sabre-Version' => [DAV\Version::VERSION],
47*a1a3b679SAndreas Boehler            'Content-Type' => ['application/xml; charset=utf-8'],
48*a1a3b679SAndreas Boehler            ),
49*a1a3b679SAndreas Boehler            $this->response->getHeaders()
50*a1a3b679SAndreas Boehler         );
51*a1a3b679SAndreas Boehler
52*a1a3b679SAndreas Boehler        $this->assertEquals(400, $this->response->status);
53*a1a3b679SAndreas Boehler
54*a1a3b679SAndreas Boehler    }
55*a1a3b679SAndreas Boehler
56*a1a3b679SAndreas Boehler    function testLock() {
57*a1a3b679SAndreas Boehler
58*a1a3b679SAndreas Boehler        $request = new HTTP\Request('LOCK', '/test.txt');
59*a1a3b679SAndreas Boehler        $request->setBody('<?xml version="1.0"?>
60*a1a3b679SAndreas Boehler<D:lockinfo xmlns:D="DAV:">
61*a1a3b679SAndreas Boehler    <D:lockscope><D:exclusive/></D:lockscope>
62*a1a3b679SAndreas Boehler    <D:locktype><D:write/></D:locktype>
63*a1a3b679SAndreas Boehler    <D:owner>
64*a1a3b679SAndreas Boehler        <D:href>http://example.org/~ejw/contact.html</D:href>
65*a1a3b679SAndreas Boehler    </D:owner>
66*a1a3b679SAndreas Boehler</D:lockinfo>');
67*a1a3b679SAndreas Boehler
68*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
69*a1a3b679SAndreas Boehler        $this->server->exec();
70*a1a3b679SAndreas Boehler
71*a1a3b679SAndreas Boehler        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
72*a1a3b679SAndreas Boehler        $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')');
73*a1a3b679SAndreas Boehler
74*a1a3b679SAndreas Boehler        $this->assertEquals(200, $this->response->status,'Got an incorrect status back. Response body: ' . $this->response->body);
75*a1a3b679SAndreas Boehler
76*a1a3b679SAndreas Boehler        $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/","xmlns\\1=\"urn:DAV\"",$this->response->body);
77*a1a3b679SAndreas Boehler        $xml = simplexml_load_string($body);
78*a1a3b679SAndreas Boehler        $xml->registerXPathNamespace('d','urn:DAV');
79*a1a3b679SAndreas Boehler
80*a1a3b679SAndreas Boehler        $elements = array(
81*a1a3b679SAndreas Boehler            '/d:prop',
82*a1a3b679SAndreas Boehler            '/d:prop/d:lockdiscovery',
83*a1a3b679SAndreas Boehler            '/d:prop/d:lockdiscovery/d:activelock',
84*a1a3b679SAndreas Boehler            '/d:prop/d:lockdiscovery/d:activelock/d:locktype',
85*a1a3b679SAndreas Boehler            '/d:prop/d:lockdiscovery/d:activelock/d:lockroot',
86*a1a3b679SAndreas Boehler            '/d:prop/d:lockdiscovery/d:activelock/d:lockroot/d:href',
87*a1a3b679SAndreas Boehler            '/d:prop/d:lockdiscovery/d:activelock/d:locktype/d:write',
88*a1a3b679SAndreas Boehler            '/d:prop/d:lockdiscovery/d:activelock/d:lockscope',
89*a1a3b679SAndreas Boehler            '/d:prop/d:lockdiscovery/d:activelock/d:lockscope/d:exclusive',
90*a1a3b679SAndreas Boehler            '/d:prop/d:lockdiscovery/d:activelock/d:depth',
91*a1a3b679SAndreas Boehler            '/d:prop/d:lockdiscovery/d:activelock/d:owner',
92*a1a3b679SAndreas Boehler            '/d:prop/d:lockdiscovery/d:activelock/d:timeout',
93*a1a3b679SAndreas Boehler            '/d:prop/d:lockdiscovery/d:activelock/d:locktoken',
94*a1a3b679SAndreas Boehler            '/d:prop/d:lockdiscovery/d:activelock/d:locktoken/d:href',
95*a1a3b679SAndreas Boehler        );
96*a1a3b679SAndreas Boehler
97*a1a3b679SAndreas Boehler        foreach($elements as $elem) {
98*a1a3b679SAndreas Boehler            $data = $xml->xpath($elem);
99*a1a3b679SAndreas Boehler            $this->assertEquals(1,count($data),'We expected 1 match for the xpath expression "' . $elem . '". ' . count($data) . ' were found. Full response body: ' . $this->response->body);
100*a1a3b679SAndreas Boehler        }
101*a1a3b679SAndreas Boehler
102*a1a3b679SAndreas Boehler        $depth = $xml->xpath('/d:prop/d:lockdiscovery/d:activelock/d:depth');
103*a1a3b679SAndreas Boehler        $this->assertEquals('infinity',(string)$depth[0]);
104*a1a3b679SAndreas Boehler
105*a1a3b679SAndreas Boehler        $token = $xml->xpath('/d:prop/d:lockdiscovery/d:activelock/d:locktoken/d:href');
106*a1a3b679SAndreas Boehler        $this->assertEquals($this->response->getHeader('Lock-Token'),'<' . (string)$token[0] . '>','Token in response body didn\'t match token in response header.');
107*a1a3b679SAndreas Boehler
108*a1a3b679SAndreas Boehler    }
109*a1a3b679SAndreas Boehler
110*a1a3b679SAndreas Boehler    /**
111*a1a3b679SAndreas Boehler     * @depends testLock
112*a1a3b679SAndreas Boehler     */
113*a1a3b679SAndreas Boehler    function testDoubleLock() {
114*a1a3b679SAndreas Boehler
115*a1a3b679SAndreas Boehler        $request = new HTTP\Request('LOCK', '/test.txt');
116*a1a3b679SAndreas Boehler        $request->setBody('<?xml version="1.0"?>
117*a1a3b679SAndreas Boehler<D:lockinfo xmlns:D="DAV:">
118*a1a3b679SAndreas Boehler    <D:lockscope><D:exclusive/></D:lockscope>
119*a1a3b679SAndreas Boehler    <D:locktype><D:write/></D:locktype>
120*a1a3b679SAndreas Boehler    <D:owner>
121*a1a3b679SAndreas Boehler        <D:href>http://example.org/~ejw/contact.html</D:href>
122*a1a3b679SAndreas Boehler    </D:owner>
123*a1a3b679SAndreas Boehler</D:lockinfo>');
124*a1a3b679SAndreas Boehler
125*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
126*a1a3b679SAndreas Boehler        $this->server->exec();
127*a1a3b679SAndreas Boehler
128*a1a3b679SAndreas Boehler        $this->response = new HTTP\ResponseMock();
129*a1a3b679SAndreas Boehler        $this->server->httpResponse = $this->response;
130*a1a3b679SAndreas Boehler
131*a1a3b679SAndreas Boehler        $this->server->exec();
132*a1a3b679SAndreas Boehler
133*a1a3b679SAndreas Boehler        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
134*a1a3b679SAndreas Boehler
135*a1a3b679SAndreas Boehler        $this->assertEquals(423, $this->response->status, 'Full response: ' . $this->response->body);
136*a1a3b679SAndreas Boehler
137*a1a3b679SAndreas Boehler    }
138*a1a3b679SAndreas Boehler
139*a1a3b679SAndreas Boehler    /**
140*a1a3b679SAndreas Boehler     * @depends testLock
141*a1a3b679SAndreas Boehler     */
142*a1a3b679SAndreas Boehler    function testLockRefresh() {
143*a1a3b679SAndreas Boehler
144*a1a3b679SAndreas Boehler        $request = new HTTP\Request('LOCK', '/test.txt');
145*a1a3b679SAndreas Boehler        $request->setBody('<?xml version="1.0"?>
146*a1a3b679SAndreas Boehler<D:lockinfo xmlns:D="DAV:">
147*a1a3b679SAndreas Boehler    <D:lockscope><D:exclusive/></D:lockscope>
148*a1a3b679SAndreas Boehler    <D:locktype><D:write/></D:locktype>
149*a1a3b679SAndreas Boehler    <D:owner>
150*a1a3b679SAndreas Boehler        <D:href>http://example.org/~ejw/contact.html</D:href>
151*a1a3b679SAndreas Boehler    </D:owner>
152*a1a3b679SAndreas Boehler</D:lockinfo>');
153*a1a3b679SAndreas Boehler
154*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
155*a1a3b679SAndreas Boehler        $this->server->exec();
156*a1a3b679SAndreas Boehler
157*a1a3b679SAndreas Boehler        $lockToken = $this->response->getHeader('Lock-Token');
158*a1a3b679SAndreas Boehler
159*a1a3b679SAndreas Boehler        $this->response = new HTTP\ResponseMock();
160*a1a3b679SAndreas Boehler        $this->server->httpResponse = $this->response;
161*a1a3b679SAndreas Boehler
162*a1a3b679SAndreas Boehler        $request = new HTTP\Request('LOCK', '/test.txt', ['If' => '(' . $lockToken . ')' ]);
163*a1a3b679SAndreas Boehler        $request->setBody('');
164*a1a3b679SAndreas Boehler
165*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
166*a1a3b679SAndreas Boehler        $this->server->exec();
167*a1a3b679SAndreas Boehler
168*a1a3b679SAndreas Boehler        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
169*a1a3b679SAndreas Boehler
170*a1a3b679SAndreas Boehler        $this->assertEquals(200, $this->response->status,'We received an incorrect status code. Full response body: ' . $this->response->getBody());
171*a1a3b679SAndreas Boehler
172*a1a3b679SAndreas Boehler    }
173*a1a3b679SAndreas Boehler
174*a1a3b679SAndreas Boehler    /**
175*a1a3b679SAndreas Boehler     * @depends testLock
176*a1a3b679SAndreas Boehler     */
177*a1a3b679SAndreas Boehler    function testLockRefreshBadToken() {
178*a1a3b679SAndreas Boehler
179*a1a3b679SAndreas Boehler        $request = new HTTP\Request('LOCK', '/test.txt');
180*a1a3b679SAndreas Boehler        $request->setBody('<?xml version="1.0"?>
181*a1a3b679SAndreas Boehler<D:lockinfo xmlns:D="DAV:">
182*a1a3b679SAndreas Boehler    <D:lockscope><D:exclusive/></D:lockscope>
183*a1a3b679SAndreas Boehler    <D:locktype><D:write/></D:locktype>
184*a1a3b679SAndreas Boehler    <D:owner>
185*a1a3b679SAndreas Boehler        <D:href>http://example.org/~ejw/contact.html</D:href>
186*a1a3b679SAndreas Boehler    </D:owner>
187*a1a3b679SAndreas Boehler</D:lockinfo>');
188*a1a3b679SAndreas Boehler
189*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
190*a1a3b679SAndreas Boehler        $this->server->exec();
191*a1a3b679SAndreas Boehler
192*a1a3b679SAndreas Boehler        $lockToken = $this->response->getHeader('Lock-Token');
193*a1a3b679SAndreas Boehler
194*a1a3b679SAndreas Boehler        $this->response = new HTTP\ResponseMock();
195*a1a3b679SAndreas Boehler        $this->server->httpResponse = $this->response;
196*a1a3b679SAndreas Boehler
197*a1a3b679SAndreas Boehler        $request = new HTTP\Request('LOCK', '/test.txt', ['If' => '(' . $lockToken . 'foobar) (<opaquelocktoken:anotherbadtoken>)' ]);
198*a1a3b679SAndreas Boehler        $request->setBody('');
199*a1a3b679SAndreas Boehler
200*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
201*a1a3b679SAndreas Boehler        $this->server->exec();
202*a1a3b679SAndreas Boehler
203*a1a3b679SAndreas Boehler        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
204*a1a3b679SAndreas Boehler
205*a1a3b679SAndreas Boehler        $this->assertEquals(423, $this->response->getStatus(),'We received an incorrect status code. Full response body: ' . $this->response->getBody());
206*a1a3b679SAndreas Boehler
207*a1a3b679SAndreas Boehler    }
208*a1a3b679SAndreas Boehler
209*a1a3b679SAndreas Boehler    /**
210*a1a3b679SAndreas Boehler     * @depends testLock
211*a1a3b679SAndreas Boehler     */
212*a1a3b679SAndreas Boehler    function testLockNoFile() {
213*a1a3b679SAndreas Boehler
214*a1a3b679SAndreas Boehler        $request = new HTTP\Request('LOCK', '/notfound.txt');
215*a1a3b679SAndreas Boehler        $request->setBody('<?xml version="1.0"?>
216*a1a3b679SAndreas Boehler<D:lockinfo xmlns:D="DAV:">
217*a1a3b679SAndreas Boehler    <D:lockscope><D:exclusive/></D:lockscope>
218*a1a3b679SAndreas Boehler    <D:locktype><D:write/></D:locktype>
219*a1a3b679SAndreas Boehler    <D:owner>
220*a1a3b679SAndreas Boehler        <D:href>http://example.org/~ejw/contact.html</D:href>
221*a1a3b679SAndreas Boehler    </D:owner>
222*a1a3b679SAndreas Boehler</D:lockinfo>');
223*a1a3b679SAndreas Boehler
224*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
225*a1a3b679SAndreas Boehler        $this->server->exec();
226*a1a3b679SAndreas Boehler
227*a1a3b679SAndreas Boehler        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
228*a1a3b679SAndreas Boehler        $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')');
229*a1a3b679SAndreas Boehler
230*a1a3b679SAndreas Boehler        $this->assertEquals(201, $this->response->status);
231*a1a3b679SAndreas Boehler
232*a1a3b679SAndreas Boehler    }
233*a1a3b679SAndreas Boehler
234*a1a3b679SAndreas Boehler    /**
235*a1a3b679SAndreas Boehler     * @depends testLock
236*a1a3b679SAndreas Boehler     */
237*a1a3b679SAndreas Boehler    function testUnlockNoToken() {
238*a1a3b679SAndreas Boehler
239*a1a3b679SAndreas Boehler        $request = new HTTP\Request('UNLOCK', '/test.txt');
240*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
241*a1a3b679SAndreas Boehler        $this->server->exec();
242*a1a3b679SAndreas Boehler
243*a1a3b679SAndreas Boehler        $this->assertEquals([
244*a1a3b679SAndreas Boehler            'X-Sabre-Version' => [DAV\Version::VERSION],
245*a1a3b679SAndreas Boehler            'Content-Type' => ['application/xml; charset=utf-8'],
246*a1a3b679SAndreas Boehler            ],
247*a1a3b679SAndreas Boehler            $this->response->getHeaders()
248*a1a3b679SAndreas Boehler         );
249*a1a3b679SAndreas Boehler
250*a1a3b679SAndreas Boehler        $this->assertEquals(400, $this->response->status);
251*a1a3b679SAndreas Boehler
252*a1a3b679SAndreas Boehler    }
253*a1a3b679SAndreas Boehler
254*a1a3b679SAndreas Boehler    /**
255*a1a3b679SAndreas Boehler     * @depends testLock
256*a1a3b679SAndreas Boehler     */
257*a1a3b679SAndreas Boehler    function testUnlockBadToken() {
258*a1a3b679SAndreas Boehler
259*a1a3b679SAndreas Boehler        $request = new HTTP\Request('UNLOCK', '/test.txt', ['Lock-Token' => '<opaquelocktoken:blablabla>']);
260*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
261*a1a3b679SAndreas Boehler        $this->server->exec();
262*a1a3b679SAndreas Boehler
263*a1a3b679SAndreas Boehler        $this->assertEquals([
264*a1a3b679SAndreas Boehler            'X-Sabre-Version' => [DAV\Version::VERSION],
265*a1a3b679SAndreas Boehler            'Content-Type' => ['application/xml; charset=utf-8'],
266*a1a3b679SAndreas Boehler            ],
267*a1a3b679SAndreas Boehler            $this->response->getHeaders()
268*a1a3b679SAndreas Boehler         );
269*a1a3b679SAndreas Boehler
270*a1a3b679SAndreas Boehler        $this->assertEquals(409, $this->response->status, 'Got an incorrect status code. Full response body: ' . $this->response->body);
271*a1a3b679SAndreas Boehler
272*a1a3b679SAndreas Boehler    }
273*a1a3b679SAndreas Boehler
274*a1a3b679SAndreas Boehler    /**
275*a1a3b679SAndreas Boehler     * @depends testLock
276*a1a3b679SAndreas Boehler     */
277*a1a3b679SAndreas Boehler    function testLockPutNoToken() {
278*a1a3b679SAndreas Boehler
279*a1a3b679SAndreas Boehler        $request = new HTTP\Request('LOCK', '/test.txt');
280*a1a3b679SAndreas Boehler        $request->setBody('<?xml version="1.0"?>
281*a1a3b679SAndreas Boehler<D:lockinfo xmlns:D="DAV:">
282*a1a3b679SAndreas Boehler    <D:lockscope><D:exclusive/></D:lockscope>
283*a1a3b679SAndreas Boehler    <D:locktype><D:write/></D:locktype>
284*a1a3b679SAndreas Boehler    <D:owner>
285*a1a3b679SAndreas Boehler        <D:href>http://example.org/~ejw/contact.html</D:href>
286*a1a3b679SAndreas Boehler    </D:owner>
287*a1a3b679SAndreas Boehler</D:lockinfo>');
288*a1a3b679SAndreas Boehler
289*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
290*a1a3b679SAndreas Boehler        $this->server->exec();
291*a1a3b679SAndreas Boehler
292*a1a3b679SAndreas Boehler        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
293*a1a3b679SAndreas Boehler        $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')');
294*a1a3b679SAndreas Boehler
295*a1a3b679SAndreas Boehler        $this->assertEquals(200, $this->response->status);
296*a1a3b679SAndreas Boehler
297*a1a3b679SAndreas Boehler        $request = new HTTP\Request('PUT', '/test.txt');
298*a1a3b679SAndreas Boehler        $request->setBody('newbody');
299*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
300*a1a3b679SAndreas Boehler        $this->server->exec();
301*a1a3b679SAndreas Boehler
302*a1a3b679SAndreas Boehler        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
303*a1a3b679SAndreas Boehler        $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')');
304*a1a3b679SAndreas Boehler
305*a1a3b679SAndreas Boehler        $this->assertEquals(423, $this->response->status);
306*a1a3b679SAndreas Boehler
307*a1a3b679SAndreas Boehler    }
308*a1a3b679SAndreas Boehler
309*a1a3b679SAndreas Boehler    /**
310*a1a3b679SAndreas Boehler     * @depends testLock
311*a1a3b679SAndreas Boehler     */
312*a1a3b679SAndreas Boehler    function testUnlock() {
313*a1a3b679SAndreas Boehler
314*a1a3b679SAndreas Boehler        $request = new HTTP\Request('LOCK', '/test.txt');
315*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
316*a1a3b679SAndreas Boehler
317*a1a3b679SAndreas Boehler        $request->setBody('<?xml version="1.0"?>
318*a1a3b679SAndreas Boehler<D:lockinfo xmlns:D="DAV:">
319*a1a3b679SAndreas Boehler    <D:lockscope><D:exclusive/></D:lockscope>
320*a1a3b679SAndreas Boehler    <D:locktype><D:write/></D:locktype>
321*a1a3b679SAndreas Boehler    <D:owner>
322*a1a3b679SAndreas Boehler        <D:href>http://example.org/~ejw/contact.html</D:href>
323*a1a3b679SAndreas Boehler    </D:owner>
324*a1a3b679SAndreas Boehler</D:lockinfo>');
325*a1a3b679SAndreas Boehler
326*a1a3b679SAndreas Boehler        $this->server->invokeMethod($request, $this->server->httpResponse);
327*a1a3b679SAndreas Boehler        $lockToken = $this->server->httpResponse->getHeader('Lock-Token');
328*a1a3b679SAndreas Boehler
329*a1a3b679SAndreas Boehler        $request = new HTTP\Request('UNLOCK', '/test.txt', ['Lock-Token' => $lockToken]);
330*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
331*a1a3b679SAndreas Boehler        $this->server->httpResponse = new HTTP\ResponseMock();
332*a1a3b679SAndreas Boehler        $this->server->invokeMethod($request, $this->server->httpResponse);
333*a1a3b679SAndreas Boehler
334*a1a3b679SAndreas Boehler        $this->assertEquals(204,$this->server->httpResponse->status,'Got an incorrect status code. Full response body: ' . $this->response->body);
335*a1a3b679SAndreas Boehler        $this->assertEquals([
336*a1a3b679SAndreas Boehler            'X-Sabre-Version' => [DAV\Version::VERSION],
337*a1a3b679SAndreas Boehler            'Content-Length' => ['0'],
338*a1a3b679SAndreas Boehler            ],
339*a1a3b679SAndreas Boehler            $this->server->httpResponse->getHeaders()
340*a1a3b679SAndreas Boehler         );
341*a1a3b679SAndreas Boehler
342*a1a3b679SAndreas Boehler
343*a1a3b679SAndreas Boehler    }
344*a1a3b679SAndreas Boehler
345*a1a3b679SAndreas Boehler    /**
346*a1a3b679SAndreas Boehler     * @depends testLock
347*a1a3b679SAndreas Boehler     */
348*a1a3b679SAndreas Boehler    function testUnlockWindowsBug() {
349*a1a3b679SAndreas Boehler
350*a1a3b679SAndreas Boehler        $request = new HTTP\Request('LOCK', '/test.txt');
351*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
352*a1a3b679SAndreas Boehler
353*a1a3b679SAndreas Boehler        $request->setBody('<?xml version="1.0"?>
354*a1a3b679SAndreas Boehler<D:lockinfo xmlns:D="DAV:">
355*a1a3b679SAndreas Boehler    <D:lockscope><D:exclusive/></D:lockscope>
356*a1a3b679SAndreas Boehler    <D:locktype><D:write/></D:locktype>
357*a1a3b679SAndreas Boehler    <D:owner>
358*a1a3b679SAndreas Boehler        <D:href>http://example.org/~ejw/contact.html</D:href>
359*a1a3b679SAndreas Boehler    </D:owner>
360*a1a3b679SAndreas Boehler</D:lockinfo>');
361*a1a3b679SAndreas Boehler
362*a1a3b679SAndreas Boehler        $this->server->invokeMethod($request, $this->server->httpResponse);
363*a1a3b679SAndreas Boehler        $lockToken = $this->server->httpResponse->getHeader('Lock-Token');
364*a1a3b679SAndreas Boehler
365*a1a3b679SAndreas Boehler        // See Issue 123
366*a1a3b679SAndreas Boehler        $lockToken = trim($lockToken,'<>');
367*a1a3b679SAndreas Boehler
368*a1a3b679SAndreas Boehler        $request = new HTTP\Request('UNLOCK', '/test.txt', ['Lock-Token' => $lockToken]);
369*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
370*a1a3b679SAndreas Boehler        $this->server->httpResponse = new HTTP\ResponseMock();
371*a1a3b679SAndreas Boehler        $this->server->invokeMethod($request, $this->server->httpResponse);
372*a1a3b679SAndreas Boehler
373*a1a3b679SAndreas Boehler        $this->assertEquals(204, $this->server->httpResponse->status,'Got an incorrect status code. Full response body: ' . $this->response->body);
374*a1a3b679SAndreas Boehler        $this->assertEquals([
375*a1a3b679SAndreas Boehler            'X-Sabre-Version' => [DAV\Version::VERSION],
376*a1a3b679SAndreas Boehler            'Content-Length' => ['0'],
377*a1a3b679SAndreas Boehler            ],
378*a1a3b679SAndreas Boehler            $this->server->httpResponse->getHeaders()
379*a1a3b679SAndreas Boehler         );
380*a1a3b679SAndreas Boehler
381*a1a3b679SAndreas Boehler
382*a1a3b679SAndreas Boehler    }
383*a1a3b679SAndreas Boehler
384*a1a3b679SAndreas Boehler    /**
385*a1a3b679SAndreas Boehler     * @depends testLock
386*a1a3b679SAndreas Boehler     */
387*a1a3b679SAndreas Boehler    function testLockRetainOwner() {
388*a1a3b679SAndreas Boehler
389*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray([
390*a1a3b679SAndreas Boehler            'REQUEST_URI' => '/test.txt',
391*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'LOCK',
392*a1a3b679SAndreas Boehler        ]);
393*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
394*a1a3b679SAndreas Boehler
395*a1a3b679SAndreas Boehler        $request->setBody('<?xml version="1.0"?>
396*a1a3b679SAndreas Boehler<D:lockinfo xmlns:D="DAV:">
397*a1a3b679SAndreas Boehler    <D:lockscope><D:exclusive/></D:lockscope>
398*a1a3b679SAndreas Boehler    <D:locktype><D:write/></D:locktype>
399*a1a3b679SAndreas Boehler    <D:owner>Evert</D:owner>
400*a1a3b679SAndreas Boehler</D:lockinfo>');
401*a1a3b679SAndreas Boehler
402*a1a3b679SAndreas Boehler        $this->server->invokeMethod($request, $this->server->httpResponse);
403*a1a3b679SAndreas Boehler        $lockToken = $this->server->httpResponse->getHeader('Lock-Token');
404*a1a3b679SAndreas Boehler
405*a1a3b679SAndreas Boehler        $locks = $this->locksPlugin->getLocks('test.txt');
406*a1a3b679SAndreas Boehler        $this->assertEquals(1,count($locks));
407*a1a3b679SAndreas Boehler        $this->assertEquals('Evert',$locks[0]->owner);
408*a1a3b679SAndreas Boehler
409*a1a3b679SAndreas Boehler
410*a1a3b679SAndreas Boehler    }
411*a1a3b679SAndreas Boehler
412*a1a3b679SAndreas Boehler    /**
413*a1a3b679SAndreas Boehler     * @depends testLock
414*a1a3b679SAndreas Boehler     */
415*a1a3b679SAndreas Boehler    function testLockPutBadToken() {
416*a1a3b679SAndreas Boehler
417*a1a3b679SAndreas Boehler        $serverVars = array(
418*a1a3b679SAndreas Boehler            'REQUEST_URI'    => '/test.txt',
419*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'LOCK',
420*a1a3b679SAndreas Boehler        );
421*a1a3b679SAndreas Boehler
422*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray($serverVars);
423*a1a3b679SAndreas Boehler        $request->setBody('<?xml version="1.0"?>
424*a1a3b679SAndreas Boehler<D:lockinfo xmlns:D="DAV:">
425*a1a3b679SAndreas Boehler    <D:lockscope><D:exclusive/></D:lockscope>
426*a1a3b679SAndreas Boehler    <D:locktype><D:write/></D:locktype>
427*a1a3b679SAndreas Boehler    <D:owner>
428*a1a3b679SAndreas Boehler        <D:href>http://example.org/~ejw/contact.html</D:href>
429*a1a3b679SAndreas Boehler    </D:owner>
430*a1a3b679SAndreas Boehler</D:lockinfo>');
431*a1a3b679SAndreas Boehler
432*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
433*a1a3b679SAndreas Boehler        $this->server->exec();
434*a1a3b679SAndreas Boehler
435*a1a3b679SAndreas Boehler        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
436*a1a3b679SAndreas Boehler        $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')');
437*a1a3b679SAndreas Boehler
438*a1a3b679SAndreas Boehler        $this->assertEquals(200, $this->response->status);
439*a1a3b679SAndreas Boehler
440*a1a3b679SAndreas Boehler        $serverVars = array(
441*a1a3b679SAndreas Boehler            'REQUEST_URI'    => '/test.txt',
442*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'PUT',
443*a1a3b679SAndreas Boehler            'HTTP_IF' => '(<opaquelocktoken:token1>)',
444*a1a3b679SAndreas Boehler        );
445*a1a3b679SAndreas Boehler
446*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray($serverVars);
447*a1a3b679SAndreas Boehler        $request->setBody('newbody');
448*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
449*a1a3b679SAndreas Boehler        $this->server->exec();
450*a1a3b679SAndreas Boehler
451*a1a3b679SAndreas Boehler        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
452*a1a3b679SAndreas Boehler        $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')');
453*a1a3b679SAndreas Boehler
454*a1a3b679SAndreas Boehler        // $this->assertEquals('412 Precondition failed',$this->response->status);
455*a1a3b679SAndreas Boehler        $this->assertEquals(423, $this->response->status);
456*a1a3b679SAndreas Boehler
457*a1a3b679SAndreas Boehler    }
458*a1a3b679SAndreas Boehler
459*a1a3b679SAndreas Boehler    /**
460*a1a3b679SAndreas Boehler     * @depends testLock
461*a1a3b679SAndreas Boehler     */
462*a1a3b679SAndreas Boehler    function testLockDeleteParent() {
463*a1a3b679SAndreas Boehler
464*a1a3b679SAndreas Boehler        $serverVars = array(
465*a1a3b679SAndreas Boehler            'REQUEST_URI'    => '/dir/child.txt',
466*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'LOCK',
467*a1a3b679SAndreas Boehler        );
468*a1a3b679SAndreas Boehler
469*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray($serverVars);
470*a1a3b679SAndreas Boehler        $request->setBody('<?xml version="1.0"?>
471*a1a3b679SAndreas Boehler<D:lockinfo xmlns:D="DAV:">
472*a1a3b679SAndreas Boehler    <D:lockscope><D:exclusive/></D:lockscope>
473*a1a3b679SAndreas Boehler    <D:locktype><D:write/></D:locktype>
474*a1a3b679SAndreas Boehler    <D:owner>
475*a1a3b679SAndreas Boehler        <D:href>http://example.org/~ejw/contact.html</D:href>
476*a1a3b679SAndreas Boehler    </D:owner>
477*a1a3b679SAndreas Boehler</D:lockinfo>');
478*a1a3b679SAndreas Boehler
479*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
480*a1a3b679SAndreas Boehler        $this->server->exec();
481*a1a3b679SAndreas Boehler
482*a1a3b679SAndreas Boehler        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
483*a1a3b679SAndreas Boehler        $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')');
484*a1a3b679SAndreas Boehler
485*a1a3b679SAndreas Boehler        $this->assertEquals(200, $this->response->status);
486*a1a3b679SAndreas Boehler
487*a1a3b679SAndreas Boehler        $serverVars = array(
488*a1a3b679SAndreas Boehler            'REQUEST_URI'    => '/dir',
489*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'DELETE',
490*a1a3b679SAndreas Boehler        );
491*a1a3b679SAndreas Boehler
492*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray($serverVars);
493*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
494*a1a3b679SAndreas Boehler        $this->server->exec();
495*a1a3b679SAndreas Boehler
496*a1a3b679SAndreas Boehler        $this->assertEquals(423, $this->response->status);
497*a1a3b679SAndreas Boehler        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
498*a1a3b679SAndreas Boehler
499*a1a3b679SAndreas Boehler    }
500*a1a3b679SAndreas Boehler    /**
501*a1a3b679SAndreas Boehler     * @depends testLock
502*a1a3b679SAndreas Boehler     */
503*a1a3b679SAndreas Boehler    function testLockDeleteSucceed() {
504*a1a3b679SAndreas Boehler
505*a1a3b679SAndreas Boehler        $serverVars = array(
506*a1a3b679SAndreas Boehler            'REQUEST_URI'    => '/dir/child.txt',
507*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'LOCK',
508*a1a3b679SAndreas Boehler        );
509*a1a3b679SAndreas Boehler
510*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray($serverVars);
511*a1a3b679SAndreas Boehler        $request->setBody('<?xml version="1.0"?>
512*a1a3b679SAndreas Boehler<D:lockinfo xmlns:D="DAV:">
513*a1a3b679SAndreas Boehler    <D:lockscope><D:exclusive/></D:lockscope>
514*a1a3b679SAndreas Boehler    <D:locktype><D:write/></D:locktype>
515*a1a3b679SAndreas Boehler    <D:owner>
516*a1a3b679SAndreas Boehler        <D:href>http://example.org/~ejw/contact.html</D:href>
517*a1a3b679SAndreas Boehler    </D:owner>
518*a1a3b679SAndreas Boehler</D:lockinfo>');
519*a1a3b679SAndreas Boehler
520*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
521*a1a3b679SAndreas Boehler        $this->server->exec();
522*a1a3b679SAndreas Boehler
523*a1a3b679SAndreas Boehler        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
524*a1a3b679SAndreas Boehler        $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')');
525*a1a3b679SAndreas Boehler
526*a1a3b679SAndreas Boehler        $this->assertEquals(200, $this->response->status);
527*a1a3b679SAndreas Boehler
528*a1a3b679SAndreas Boehler        $serverVars = array(
529*a1a3b679SAndreas Boehler            'REQUEST_URI'    => '/dir/child.txt',
530*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'DELETE',
531*a1a3b679SAndreas Boehler            'HTTP_IF' => '(' . $this->response->getHeader('Lock-Token') . ')',
532*a1a3b679SAndreas Boehler        );
533*a1a3b679SAndreas Boehler
534*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray($serverVars);
535*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
536*a1a3b679SAndreas Boehler        $this->server->exec();
537*a1a3b679SAndreas Boehler
538*a1a3b679SAndreas Boehler        $this->assertEquals(204, $this->response->status);
539*a1a3b679SAndreas Boehler        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
540*a1a3b679SAndreas Boehler
541*a1a3b679SAndreas Boehler    }
542*a1a3b679SAndreas Boehler
543*a1a3b679SAndreas Boehler    /**
544*a1a3b679SAndreas Boehler     * @depends testLock
545*a1a3b679SAndreas Boehler     */
546*a1a3b679SAndreas Boehler    function testLockCopyLockSource() {
547*a1a3b679SAndreas Boehler
548*a1a3b679SAndreas Boehler        $serverVars = array(
549*a1a3b679SAndreas Boehler            'REQUEST_URI'    => '/dir/child.txt',
550*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'LOCK',
551*a1a3b679SAndreas Boehler        );
552*a1a3b679SAndreas Boehler
553*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray($serverVars);
554*a1a3b679SAndreas Boehler        $request->setBody('<?xml version="1.0"?>
555*a1a3b679SAndreas Boehler<D:lockinfo xmlns:D="DAV:">
556*a1a3b679SAndreas Boehler    <D:lockscope><D:exclusive/></D:lockscope>
557*a1a3b679SAndreas Boehler    <D:locktype><D:write/></D:locktype>
558*a1a3b679SAndreas Boehler    <D:owner>
559*a1a3b679SAndreas Boehler        <D:href>http://example.org/~ejw/contact.html</D:href>
560*a1a3b679SAndreas Boehler    </D:owner>
561*a1a3b679SAndreas Boehler</D:lockinfo>');
562*a1a3b679SAndreas Boehler
563*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
564*a1a3b679SAndreas Boehler        $this->server->exec();
565*a1a3b679SAndreas Boehler
566*a1a3b679SAndreas Boehler        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
567*a1a3b679SAndreas Boehler        $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')');
568*a1a3b679SAndreas Boehler
569*a1a3b679SAndreas Boehler        $this->assertEquals(200, $this->response->status);
570*a1a3b679SAndreas Boehler
571*a1a3b679SAndreas Boehler        $serverVars = array(
572*a1a3b679SAndreas Boehler            'REQUEST_URI'    => '/dir/child.txt',
573*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'COPY',
574*a1a3b679SAndreas Boehler            'HTTP_DESTINATION' => '/dir/child2.txt',
575*a1a3b679SAndreas Boehler        );
576*a1a3b679SAndreas Boehler
577*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray($serverVars);
578*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
579*a1a3b679SAndreas Boehler        $this->server->exec();
580*a1a3b679SAndreas Boehler
581*a1a3b679SAndreas Boehler        $this->assertEquals(201, $this->response->status,'Copy must succeed if only the source is locked, but not the destination');
582*a1a3b679SAndreas Boehler        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
583*a1a3b679SAndreas Boehler
584*a1a3b679SAndreas Boehler    }
585*a1a3b679SAndreas Boehler    /**
586*a1a3b679SAndreas Boehler     * @depends testLock
587*a1a3b679SAndreas Boehler     */
588*a1a3b679SAndreas Boehler    function testLockCopyLockDestination() {
589*a1a3b679SAndreas Boehler
590*a1a3b679SAndreas Boehler        $serverVars = array(
591*a1a3b679SAndreas Boehler            'REQUEST_URI'    => '/dir/child2.txt',
592*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'LOCK',
593*a1a3b679SAndreas Boehler        );
594*a1a3b679SAndreas Boehler
595*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray($serverVars);
596*a1a3b679SAndreas Boehler        $request->setBody('<?xml version="1.0"?>
597*a1a3b679SAndreas Boehler<D:lockinfo xmlns:D="DAV:">
598*a1a3b679SAndreas Boehler    <D:lockscope><D:exclusive/></D:lockscope>
599*a1a3b679SAndreas Boehler    <D:locktype><D:write/></D:locktype>
600*a1a3b679SAndreas Boehler    <D:owner>
601*a1a3b679SAndreas Boehler        <D:href>http://example.org/~ejw/contact.html</D:href>
602*a1a3b679SAndreas Boehler    </D:owner>
603*a1a3b679SAndreas Boehler</D:lockinfo>');
604*a1a3b679SAndreas Boehler
605*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
606*a1a3b679SAndreas Boehler        $this->server->exec();
607*a1a3b679SAndreas Boehler
608*a1a3b679SAndreas Boehler        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
609*a1a3b679SAndreas Boehler        $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')');
610*a1a3b679SAndreas Boehler
611*a1a3b679SAndreas Boehler        $this->assertEquals(201, $this->response->status);
612*a1a3b679SAndreas Boehler
613*a1a3b679SAndreas Boehler        $serverVars = array(
614*a1a3b679SAndreas Boehler            'REQUEST_URI'    => '/dir/child.txt',
615*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'COPY',
616*a1a3b679SAndreas Boehler            'HTTP_DESTINATION' => '/dir/child2.txt',
617*a1a3b679SAndreas Boehler        );
618*a1a3b679SAndreas Boehler
619*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray($serverVars);
620*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
621*a1a3b679SAndreas Boehler        $this->server->exec();
622*a1a3b679SAndreas Boehler
623*a1a3b679SAndreas Boehler        $this->assertEquals(423, $this->response->status,'Copy must succeed if only the source is locked, but not the destination');
624*a1a3b679SAndreas Boehler        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
625*a1a3b679SAndreas Boehler
626*a1a3b679SAndreas Boehler    }
627*a1a3b679SAndreas Boehler
628*a1a3b679SAndreas Boehler    /**
629*a1a3b679SAndreas Boehler     * @depends testLock
630*a1a3b679SAndreas Boehler     */
631*a1a3b679SAndreas Boehler    function testLockMoveLockSourceLocked() {
632*a1a3b679SAndreas Boehler
633*a1a3b679SAndreas Boehler        $serverVars = array(
634*a1a3b679SAndreas Boehler            'REQUEST_URI'    => '/dir/child.txt',
635*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'LOCK',
636*a1a3b679SAndreas Boehler        );
637*a1a3b679SAndreas Boehler
638*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray($serverVars);
639*a1a3b679SAndreas Boehler        $request->setBody('<?xml version="1.0"?>
640*a1a3b679SAndreas Boehler<D:lockinfo xmlns:D="DAV:">
641*a1a3b679SAndreas Boehler    <D:lockscope><D:exclusive/></D:lockscope>
642*a1a3b679SAndreas Boehler    <D:locktype><D:write/></D:locktype>
643*a1a3b679SAndreas Boehler    <D:owner>
644*a1a3b679SAndreas Boehler        <D:href>http://example.org/~ejw/contact.html</D:href>
645*a1a3b679SAndreas Boehler    </D:owner>
646*a1a3b679SAndreas Boehler</D:lockinfo>');
647*a1a3b679SAndreas Boehler
648*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
649*a1a3b679SAndreas Boehler        $this->server->exec();
650*a1a3b679SAndreas Boehler
651*a1a3b679SAndreas Boehler        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
652*a1a3b679SAndreas Boehler        $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')');
653*a1a3b679SAndreas Boehler
654*a1a3b679SAndreas Boehler        $this->assertEquals(200, $this->response->status);
655*a1a3b679SAndreas Boehler
656*a1a3b679SAndreas Boehler        $serverVars = array(
657*a1a3b679SAndreas Boehler            'REQUEST_URI'    => '/dir/child.txt',
658*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'MOVE',
659*a1a3b679SAndreas Boehler            'HTTP_DESTINATION' => '/dir/child2.txt',
660*a1a3b679SAndreas Boehler        );
661*a1a3b679SAndreas Boehler
662*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray($serverVars);
663*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
664*a1a3b679SAndreas Boehler        $this->server->exec();
665*a1a3b679SAndreas Boehler
666*a1a3b679SAndreas Boehler        $this->assertEquals(423, $this->response->status,'Copy must succeed if only the source is locked, but not the destination');
667*a1a3b679SAndreas Boehler        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
668*a1a3b679SAndreas Boehler
669*a1a3b679SAndreas Boehler    }
670*a1a3b679SAndreas Boehler
671*a1a3b679SAndreas Boehler    /**
672*a1a3b679SAndreas Boehler     * @depends testLock
673*a1a3b679SAndreas Boehler     */
674*a1a3b679SAndreas Boehler    function testLockMoveLockSourceSucceed() {
675*a1a3b679SAndreas Boehler
676*a1a3b679SAndreas Boehler        $serverVars = array(
677*a1a3b679SAndreas Boehler            'REQUEST_URI'    => '/dir/child.txt',
678*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'LOCK',
679*a1a3b679SAndreas Boehler        );
680*a1a3b679SAndreas Boehler
681*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray($serverVars);
682*a1a3b679SAndreas Boehler        $request->setBody('<?xml version="1.0"?>
683*a1a3b679SAndreas Boehler<D:lockinfo xmlns:D="DAV:">
684*a1a3b679SAndreas Boehler    <D:lockscope><D:exclusive/></D:lockscope>
685*a1a3b679SAndreas Boehler    <D:locktype><D:write/></D:locktype>
686*a1a3b679SAndreas Boehler    <D:owner>
687*a1a3b679SAndreas Boehler        <D:href>http://example.org/~ejw/contact.html</D:href>
688*a1a3b679SAndreas Boehler    </D:owner>
689*a1a3b679SAndreas Boehler</D:lockinfo>');
690*a1a3b679SAndreas Boehler
691*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
692*a1a3b679SAndreas Boehler        $this->server->exec();
693*a1a3b679SAndreas Boehler
694*a1a3b679SAndreas Boehler        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
695*a1a3b679SAndreas Boehler        $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')');
696*a1a3b679SAndreas Boehler
697*a1a3b679SAndreas Boehler        $this->assertEquals(200, $this->response->status);
698*a1a3b679SAndreas Boehler
699*a1a3b679SAndreas Boehler        $serverVars = array(
700*a1a3b679SAndreas Boehler            'REQUEST_URI'    => '/dir/child.txt',
701*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'MOVE',
702*a1a3b679SAndreas Boehler            'HTTP_DESTINATION' => '/dir/child2.txt',
703*a1a3b679SAndreas Boehler            'HTTP_IF' => '(' . $this->response->getHeader('Lock-Token') . ')',
704*a1a3b679SAndreas Boehler        );
705*a1a3b679SAndreas Boehler
706*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray($serverVars);
707*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
708*a1a3b679SAndreas Boehler        $this->server->exec();
709*a1a3b679SAndreas Boehler
710*a1a3b679SAndreas Boehler        $this->assertEquals(201, $this->response->status,'A valid lock-token was provided for the source, so this MOVE operation must succeed. Full response body: ' . $this->response->body);
711*a1a3b679SAndreas Boehler
712*a1a3b679SAndreas Boehler    }
713*a1a3b679SAndreas Boehler
714*a1a3b679SAndreas Boehler    /**
715*a1a3b679SAndreas Boehler     * @depends testLock
716*a1a3b679SAndreas Boehler     */
717*a1a3b679SAndreas Boehler    function testLockMoveLockDestination() {
718*a1a3b679SAndreas Boehler
719*a1a3b679SAndreas Boehler        $serverVars = array(
720*a1a3b679SAndreas Boehler            'REQUEST_URI'    => '/dir/child2.txt',
721*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'LOCK',
722*a1a3b679SAndreas Boehler        );
723*a1a3b679SAndreas Boehler
724*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray($serverVars);
725*a1a3b679SAndreas Boehler        $request->setBody('<?xml version="1.0"?>
726*a1a3b679SAndreas Boehler<D:lockinfo xmlns:D="DAV:">
727*a1a3b679SAndreas Boehler    <D:lockscope><D:exclusive/></D:lockscope>
728*a1a3b679SAndreas Boehler    <D:locktype><D:write/></D:locktype>
729*a1a3b679SAndreas Boehler    <D:owner>
730*a1a3b679SAndreas Boehler        <D:href>http://example.org/~ejw/contact.html</D:href>
731*a1a3b679SAndreas Boehler    </D:owner>
732*a1a3b679SAndreas Boehler</D:lockinfo>');
733*a1a3b679SAndreas Boehler
734*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
735*a1a3b679SAndreas Boehler        $this->server->exec();
736*a1a3b679SAndreas Boehler
737*a1a3b679SAndreas Boehler        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
738*a1a3b679SAndreas Boehler        $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')');
739*a1a3b679SAndreas Boehler
740*a1a3b679SAndreas Boehler        $this->assertEquals(201, $this->response->status);
741*a1a3b679SAndreas Boehler
742*a1a3b679SAndreas Boehler        $serverVars = array(
743*a1a3b679SAndreas Boehler            'REQUEST_URI'    => '/dir/child.txt',
744*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'MOVE',
745*a1a3b679SAndreas Boehler            'HTTP_DESTINATION' => '/dir/child2.txt',
746*a1a3b679SAndreas Boehler        );
747*a1a3b679SAndreas Boehler
748*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray($serverVars);
749*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
750*a1a3b679SAndreas Boehler        $this->server->exec();
751*a1a3b679SAndreas Boehler
752*a1a3b679SAndreas Boehler        $this->assertEquals(423, $this->response->status,'Copy must succeed if only the source is locked, but not the destination');
753*a1a3b679SAndreas Boehler        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
754*a1a3b679SAndreas Boehler
755*a1a3b679SAndreas Boehler    }
756*a1a3b679SAndreas Boehler    /**
757*a1a3b679SAndreas Boehler     * @depends testLock
758*a1a3b679SAndreas Boehler     */
759*a1a3b679SAndreas Boehler    function testLockMoveLockParent() {
760*a1a3b679SAndreas Boehler
761*a1a3b679SAndreas Boehler        $serverVars = array(
762*a1a3b679SAndreas Boehler            'REQUEST_URI'    => '/dir',
763*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'LOCK',
764*a1a3b679SAndreas Boehler            'HTTP_DEPTH' => 'infinite',
765*a1a3b679SAndreas Boehler        );
766*a1a3b679SAndreas Boehler
767*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray($serverVars);
768*a1a3b679SAndreas Boehler        $request->setBody('<?xml version="1.0"?>
769*a1a3b679SAndreas Boehler<D:lockinfo xmlns:D="DAV:">
770*a1a3b679SAndreas Boehler    <D:lockscope><D:exclusive/></D:lockscope>
771*a1a3b679SAndreas Boehler    <D:locktype><D:write/></D:locktype>
772*a1a3b679SAndreas Boehler    <D:owner>
773*a1a3b679SAndreas Boehler        <D:href>http://example.org/~ejw/contact.html</D:href>
774*a1a3b679SAndreas Boehler    </D:owner>
775*a1a3b679SAndreas Boehler</D:lockinfo>');
776*a1a3b679SAndreas Boehler
777*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
778*a1a3b679SAndreas Boehler        $this->server->exec();
779*a1a3b679SAndreas Boehler
780*a1a3b679SAndreas Boehler        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
781*a1a3b679SAndreas Boehler        $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')');
782*a1a3b679SAndreas Boehler
783*a1a3b679SAndreas Boehler        $this->assertEquals(200,$this->response->status);
784*a1a3b679SAndreas Boehler
785*a1a3b679SAndreas Boehler        $serverVars = array(
786*a1a3b679SAndreas Boehler            'REQUEST_URI'    => '/dir/child.txt',
787*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'MOVE',
788*a1a3b679SAndreas Boehler            'HTTP_DESTINATION' => '/dir/child2.txt',
789*a1a3b679SAndreas Boehler            'HTTP_IF' => '</dir> (' . $this->response->getHeader('Lock-Token') . ')',
790*a1a3b679SAndreas Boehler        );
791*a1a3b679SAndreas Boehler
792*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray($serverVars);
793*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
794*a1a3b679SAndreas Boehler        $this->server->exec();
795*a1a3b679SAndreas Boehler
796*a1a3b679SAndreas Boehler        $this->assertEquals(201, $this->response->status,'We locked the parent of both the source and destination, but the move didn\'t succeed.');
797*a1a3b679SAndreas Boehler        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
798*a1a3b679SAndreas Boehler
799*a1a3b679SAndreas Boehler    }
800*a1a3b679SAndreas Boehler
801*a1a3b679SAndreas Boehler    /**
802*a1a3b679SAndreas Boehler     * @depends testLock
803*a1a3b679SAndreas Boehler     */
804*a1a3b679SAndreas Boehler    function testLockPutGoodToken() {
805*a1a3b679SAndreas Boehler
806*a1a3b679SAndreas Boehler        $serverVars = array(
807*a1a3b679SAndreas Boehler            'REQUEST_URI'    => '/test.txt',
808*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'LOCK',
809*a1a3b679SAndreas Boehler        );
810*a1a3b679SAndreas Boehler
811*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray($serverVars);
812*a1a3b679SAndreas Boehler        $request->setBody('<?xml version="1.0"?>
813*a1a3b679SAndreas Boehler<D:lockinfo xmlns:D="DAV:">
814*a1a3b679SAndreas Boehler    <D:lockscope><D:exclusive/></D:lockscope>
815*a1a3b679SAndreas Boehler    <D:locktype><D:write/></D:locktype>
816*a1a3b679SAndreas Boehler    <D:owner>
817*a1a3b679SAndreas Boehler        <D:href>http://example.org/~ejw/contact.html</D:href>
818*a1a3b679SAndreas Boehler    </D:owner>
819*a1a3b679SAndreas Boehler</D:lockinfo>');
820*a1a3b679SAndreas Boehler
821*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
822*a1a3b679SAndreas Boehler        $this->server->exec();
823*a1a3b679SAndreas Boehler
824*a1a3b679SAndreas Boehler        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
825*a1a3b679SAndreas Boehler        $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')');
826*a1a3b679SAndreas Boehler
827*a1a3b679SAndreas Boehler        $this->assertEquals(200, $this->response->status);
828*a1a3b679SAndreas Boehler
829*a1a3b679SAndreas Boehler        $serverVars = array(
830*a1a3b679SAndreas Boehler            'REQUEST_URI'    => '/test.txt',
831*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'PUT',
832*a1a3b679SAndreas Boehler            'HTTP_IF' => '('.$this->response->getHeader('Lock-Token').')',
833*a1a3b679SAndreas Boehler        );
834*a1a3b679SAndreas Boehler
835*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray($serverVars);
836*a1a3b679SAndreas Boehler        $request->setBody('newbody');
837*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
838*a1a3b679SAndreas Boehler        $this->server->exec();
839*a1a3b679SAndreas Boehler
840*a1a3b679SAndreas Boehler        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
841*a1a3b679SAndreas Boehler        $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')');
842*a1a3b679SAndreas Boehler
843*a1a3b679SAndreas Boehler        $this->assertEquals(204, $this->response->status);
844*a1a3b679SAndreas Boehler
845*a1a3b679SAndreas Boehler    }
846*a1a3b679SAndreas Boehler
847*a1a3b679SAndreas Boehler    /**
848*a1a3b679SAndreas Boehler     * @depends testLock
849*a1a3b679SAndreas Boehler     */
850*a1a3b679SAndreas Boehler    function testLockPutUnrelatedToken() {
851*a1a3b679SAndreas Boehler
852*a1a3b679SAndreas Boehler        $request = new HTTP\Request('LOCK', '/unrelated.txt');
853*a1a3b679SAndreas Boehler        $request->setBody('<?xml version="1.0"?>
854*a1a3b679SAndreas Boehler<D:lockinfo xmlns:D="DAV:">
855*a1a3b679SAndreas Boehler    <D:lockscope><D:exclusive/></D:lockscope>
856*a1a3b679SAndreas Boehler    <D:locktype><D:write/></D:locktype>
857*a1a3b679SAndreas Boehler    <D:owner>
858*a1a3b679SAndreas Boehler        <D:href>http://example.org/~ejw/contact.html</D:href>
859*a1a3b679SAndreas Boehler    </D:owner>
860*a1a3b679SAndreas Boehler</D:lockinfo>');
861*a1a3b679SAndreas Boehler
862*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
863*a1a3b679SAndreas Boehler        $this->server->exec();
864*a1a3b679SAndreas Boehler
865*a1a3b679SAndreas Boehler        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
866*a1a3b679SAndreas Boehler        $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')');
867*a1a3b679SAndreas Boehler
868*a1a3b679SAndreas Boehler        $this->assertEquals(201, $this->response->getStatus());
869*a1a3b679SAndreas Boehler
870*a1a3b679SAndreas Boehler        $request = new HTTP\Request(
871*a1a3b679SAndreas Boehler            'PUT',
872*a1a3b679SAndreas Boehler            '/test.txt',
873*a1a3b679SAndreas Boehler            ['If' => '</unrelated.txt> ('.$this->response->getHeader('Lock-Token').')']
874*a1a3b679SAndreas Boehler        );
875*a1a3b679SAndreas Boehler        $request->setBody('newbody');
876*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
877*a1a3b679SAndreas Boehler        $this->server->exec();
878*a1a3b679SAndreas Boehler
879*a1a3b679SAndreas Boehler        $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type'));
880*a1a3b679SAndreas Boehler        $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')');
881*a1a3b679SAndreas Boehler
882*a1a3b679SAndreas Boehler        $this->assertEquals(204, $this->response->status);
883*a1a3b679SAndreas Boehler
884*a1a3b679SAndreas Boehler    }
885*a1a3b679SAndreas Boehler
886*a1a3b679SAndreas Boehler    function testPutWithIncorrectETag() {
887*a1a3b679SAndreas Boehler
888*a1a3b679SAndreas Boehler        $serverVars = array(
889*a1a3b679SAndreas Boehler            'REQUEST_URI'    => '/test.txt',
890*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'PUT',
891*a1a3b679SAndreas Boehler            'HTTP_IF' => '(["etag1"])',
892*a1a3b679SAndreas Boehler        );
893*a1a3b679SAndreas Boehler
894*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray($serverVars);
895*a1a3b679SAndreas Boehler        $request->setBody('newbody');
896*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
897*a1a3b679SAndreas Boehler        $this->server->exec();
898*a1a3b679SAndreas Boehler        $this->assertEquals(412, $this->response->status);
899*a1a3b679SAndreas Boehler
900*a1a3b679SAndreas Boehler    }
901*a1a3b679SAndreas Boehler
902*a1a3b679SAndreas Boehler    /**
903*a1a3b679SAndreas Boehler     * @depends testPutWithIncorrectETag
904*a1a3b679SAndreas Boehler     */
905*a1a3b679SAndreas Boehler    function testPutWithCorrectETag() {
906*a1a3b679SAndreas Boehler
907*a1a3b679SAndreas Boehler        // We need an ETag-enabled file node.
908*a1a3b679SAndreas Boehler        $tree = new DAV\Tree(new DAV\FSExt\Directory(SABRE_TEMPDIR));
909*a1a3b679SAndreas Boehler        $this->server->tree = $tree;
910*a1a3b679SAndreas Boehler
911*a1a3b679SAndreas Boehler        $filename = SABRE_TEMPDIR . '/test.txt';
912*a1a3b679SAndreas Boehler        $etag = sha1(
913*a1a3b679SAndreas Boehler            fileinode($filename) .
914*a1a3b679SAndreas Boehler            filesize($filename ) .
915*a1a3b679SAndreas Boehler            filemtime($filename)
916*a1a3b679SAndreas Boehler        );
917*a1a3b679SAndreas Boehler        $serverVars = array(
918*a1a3b679SAndreas Boehler            'REQUEST_URI'    => '/test.txt',
919*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'PUT',
920*a1a3b679SAndreas Boehler            'HTTP_IF' => '(["'.$etag.'"])',
921*a1a3b679SAndreas Boehler        );
922*a1a3b679SAndreas Boehler
923*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray($serverVars);
924*a1a3b679SAndreas Boehler        $request->setBody('newbody');
925*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
926*a1a3b679SAndreas Boehler        $this->server->exec();
927*a1a3b679SAndreas Boehler        $this->assertEquals(204, $this->response->status, 'Incorrect status received. Full response body:' . $this->response->body);
928*a1a3b679SAndreas Boehler
929*a1a3b679SAndreas Boehler    }
930*a1a3b679SAndreas Boehler
931*a1a3b679SAndreas Boehler    function testDeleteWithETagOnCollection() {
932*a1a3b679SAndreas Boehler
933*a1a3b679SAndreas Boehler        $serverVars = array(
934*a1a3b679SAndreas Boehler            'REQUEST_URI'    => '/dir',
935*a1a3b679SAndreas Boehler            'REQUEST_METHOD' => 'DELETE',
936*a1a3b679SAndreas Boehler            'HTTP_IF' => '(["etag1"])',
937*a1a3b679SAndreas Boehler        );
938*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray($serverVars);
939*a1a3b679SAndreas Boehler
940*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
941*a1a3b679SAndreas Boehler        $this->server->exec();
942*a1a3b679SAndreas Boehler        $this->assertEquals(412, $this->response->status);
943*a1a3b679SAndreas Boehler
944*a1a3b679SAndreas Boehler    }
945*a1a3b679SAndreas Boehler
946*a1a3b679SAndreas Boehler    function testGetTimeoutHeader() {
947*a1a3b679SAndreas Boehler
948*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray(array(
949*a1a3b679SAndreas Boehler            'HTTP_TIMEOUT' => 'second-100',
950*a1a3b679SAndreas Boehler        ));
951*a1a3b679SAndreas Boehler
952*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
953*a1a3b679SAndreas Boehler        $this->assertEquals(100, $this->locksPlugin->getTimeoutHeader());
954*a1a3b679SAndreas Boehler
955*a1a3b679SAndreas Boehler    }
956*a1a3b679SAndreas Boehler
957*a1a3b679SAndreas Boehler    function testGetTimeoutHeaderTwoItems() {
958*a1a3b679SAndreas Boehler
959*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray(array(
960*a1a3b679SAndreas Boehler            'HTTP_TIMEOUT' => 'second-5, infinite',
961*a1a3b679SAndreas Boehler        ));
962*a1a3b679SAndreas Boehler
963*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
964*a1a3b679SAndreas Boehler        $this->assertEquals(5, $this->locksPlugin->getTimeoutHeader());
965*a1a3b679SAndreas Boehler
966*a1a3b679SAndreas Boehler    }
967*a1a3b679SAndreas Boehler
968*a1a3b679SAndreas Boehler    function testGetTimeoutHeaderInfinite() {
969*a1a3b679SAndreas Boehler
970*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray(array(
971*a1a3b679SAndreas Boehler            'HTTP_TIMEOUT' => 'infinite, second-5',
972*a1a3b679SAndreas Boehler        ));
973*a1a3b679SAndreas Boehler
974*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
975*a1a3b679SAndreas Boehler        $this->assertEquals(LockInfo::TIMEOUT_INFINITE, $this->locksPlugin->getTimeoutHeader());
976*a1a3b679SAndreas Boehler
977*a1a3b679SAndreas Boehler    }
978*a1a3b679SAndreas Boehler
979*a1a3b679SAndreas Boehler    /**
980*a1a3b679SAndreas Boehler     * @expectedException Sabre\DAV\Exception\BadRequest
981*a1a3b679SAndreas Boehler     */
982*a1a3b679SAndreas Boehler    function testGetTimeoutHeaderInvalid() {
983*a1a3b679SAndreas Boehler
984*a1a3b679SAndreas Boehler        $request = HTTP\Sapi::createFromServerArray(array(
985*a1a3b679SAndreas Boehler            'HTTP_TIMEOUT' => 'yourmom',
986*a1a3b679SAndreas Boehler        ));
987*a1a3b679SAndreas Boehler
988*a1a3b679SAndreas Boehler        $this->server->httpRequest = $request;
989*a1a3b679SAndreas Boehler        $this->locksPlugin->getTimeoutHeader();
990*a1a3b679SAndreas Boehler
991*a1a3b679SAndreas Boehler    }
992*a1a3b679SAndreas Boehler
993*a1a3b679SAndreas Boehler
994*a1a3b679SAndreas Boehler}
995