1<?php
2
3namespace Sabre\DAV\Locks;
4
5use Sabre\HTTP\Request;
6
7class Plugin2Test extends \Sabre\DAVServerTest {
8
9    public $setupLocks = true;
10
11    function setUpTree() {
12
13        $this->tree = new \Sabre\DAV\FS\Directory(SABRE_TEMPDIR);
14
15    }
16
17    function tearDown() {
18
19        \Sabre\TestUtil::clearTempDir();
20
21    }
22
23    /**
24     * This test first creates a file with LOCK and then deletes it.
25     *
26     * After deleting the file, the lock should no longer be in the lock
27     * backend.
28     *
29     * Reported in ticket #487
30     */
31    function testUnlockAfterDelete() {
32
33        $body = '<?xml version="1.0"?>
34<D:lockinfo xmlns:D="DAV:">
35    <D:lockscope><D:exclusive/></D:lockscope>
36    <D:locktype><D:write/></D:locktype>
37</D:lockinfo>';
38
39        $request = new Request(
40            'LOCK',
41            '/file.txt',
42            [],
43            $body
44        );
45        $response = $this->request($request);
46        $this->assertEquals(201, $response->getStatus(), $response->getBodyAsString());
47
48        $this->assertEquals(
49            1,
50            count($this->locksBackend->getLocks('file.txt', true))
51        );
52
53        $request = new Request(
54            'DELETE',
55            '/file.txt',
56            [
57                'If' => '(' . $response->getHeader('Lock-Token') . ')',
58            ]
59        );
60        $response = $this->request($request);
61        $this->assertEquals(204, $response->getStatus(), $response->getBodyAsString());
62
63        $this->assertEquals(
64            0,
65            count($this->locksBackend->getLocks('file.txt', true))
66        );
67    }
68
69}
70