1<?php
2
3namespace Sabre\DAVACL;
4
5use Sabre\DAV;
6use Sabre\HTTP;
7
8class AllowAccessTest extends \PHPUnit_Framework_TestCase {
9
10    /**
11     * @var DAV\Server
12     */
13    protected $server;
14
15    function setUp() {
16
17        $nodes = array(
18            new DAV\SimpleCollection('testdir'),
19        );
20
21        $this->server = new DAV\Server($nodes);
22        $aclPlugin = new Plugin();
23        $aclPlugin->allowAccessToNodesWithoutACL = true;
24        $this->server->addPlugin($aclPlugin);
25
26    }
27
28    function testGet() {
29
30        $this->server->httpRequest->setMethod('GET');
31        $this->server->httpRequest->setUrl('/testdir');
32
33        $this->assertTrue($this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse]));
34
35    }
36
37    function testGetDoesntExist() {
38
39        $this->server->httpRequest->setMethod('GET');
40        $this->server->httpRequest->setUrl('/foo');
41
42        $this->assertTrue($this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse]));
43
44    }
45
46    function testHEAD() {
47
48        $this->server->httpRequest->setMethod('HEAD');
49        $this->server->httpRequest->setUrl('/testdir');
50
51        $this->assertTrue($this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse]));
52
53    }
54
55    function testOPTIONS() {
56
57        $this->server->httpRequest->setMethod('OPTIONS');
58        $this->server->httpRequest->setUrl('/testdir');
59
60        $this->assertTrue($this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse]));
61
62    }
63
64    function testPUT() {
65
66        $this->server->httpRequest->setMethod('PUT');
67        $this->server->httpRequest->setUrl('/testdir');
68
69        $this->assertTrue($this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse]));
70
71    }
72
73    function testACL() {
74
75        $this->server->httpRequest->setMethod('ACL');
76        $this->server->httpRequest->setUrl('/testdir');
77
78        $this->assertTrue($this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse]));
79
80    }
81
82    function testPROPPATCH() {
83
84        $this->server->httpRequest->setMethod('PROPPATCH');
85        $this->server->httpRequest->setUrl('/testdir');
86
87        $this->assertTrue($this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse]));
88
89    }
90
91    function testCOPY() {
92
93        $this->server->httpRequest->setMethod('COPY');
94        $this->server->httpRequest->setUrl('/testdir');
95
96        $this->assertTrue($this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse]));
97
98    }
99
100    function testMOVE() {
101
102        $this->server->httpRequest->setMethod('MOVE');
103        $this->server->httpRequest->setUrl('/testdir');
104
105        $this->assertTrue($this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse]));
106
107    }
108
109    function testLOCK() {
110
111        $this->server->httpRequest->setMethod('LOCK');
112        $this->server->httpRequest->setUrl('/testdir');
113
114        $this->assertTrue($this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse]));
115
116    }
117
118    function testBeforeBind() {
119
120        $this->assertTrue($this->server->emit('beforeBind', ['testdir/file']));
121
122    }
123
124
125    function testBeforeUnbind() {
126
127        $this->assertTrue($this->server->emit('beforeUnbind', ['testdir']));
128
129    }
130
131}
132