3 class Sabre_DAVACL_ACLMethodTest extends PHPUnit_Framework_TestCase {
6 * @expectedException Sabre_DAV_Exception_BadRequest
8 function testCallback() {
10 $acl = new Sabre_DAVACL_Plugin();
11 $server = new Sabre_DAV_Server();
12 $server->addPlugin($acl);
14 $acl->unknownMethod('ACL','test');
18 function testCallbackPassthru() {
20 $acl = new Sabre_DAVACL_Plugin();
21 $server = new Sabre_DAV_Server();
22 $server->addPlugin($acl);
24 $this->assertNull($acl->unknownMethod('FOO','test'));
31 * @expectedException Sabre_DAV_Exception_MethodNotAllowed
33 function testNotSupportedByNode() {
36 new Sabre_DAV_SimpleCollection('test'),
38 $acl = new Sabre_DAVACL_Plugin();
39 $server = new Sabre_DAV_Server($tree);
40 $server->httpRequest = new Sabre_HTTP_Request();
41 $body = '<?xml version="1.0"?>
42 <d:acl xmlns:d="DAV:">
44 $server->httpRequest->setBody($body);
45 $server->addPlugin($acl);
47 $acl->httpACL('test');
51 function testSuccessSimple() {
54 new Sabre_DAVACL_MockACLNode('test',array()),
56 $acl = new Sabre_DAVACL_Plugin();
57 $server = new Sabre_DAV_Server($tree);
58 $server->httpRequest = new Sabre_HTTP_Request();
59 $body = '<?xml version="1.0"?>
60 <d:acl xmlns:d="DAV:">
62 $server->httpRequest->setBody($body);
63 $server->addPlugin($acl);
65 $this->assertNull($acl->httpACL('test'));
70 * @expectedException Sabre_DAVACL_Exception_NotRecognizedPrincipal
72 function testUnrecognizedPrincipal() {
75 new Sabre_DAVACL_MockACLNode('test',array()),
77 $acl = new Sabre_DAVACL_Plugin();
78 $server = new Sabre_DAV_Server($tree);
79 $server->httpRequest = new Sabre_HTTP_Request();
80 $body = '<?xml version="1.0"?>
81 <d:acl xmlns:d="DAV:">
83 <d:grant><d:privilege><d:read /></d:privilege></d:grant>
84 <d:principal><d:href>/principals/notfound</d:href></d:principal>
87 $server->httpRequest->setBody($body);
88 $server->addPlugin($acl);
90 $acl->httpACL('test');
95 * @expectedException Sabre_DAVACL_Exception_NotRecognizedPrincipal
97 function testUnrecognizedPrincipal2() {
100 new Sabre_DAVACL_MockACLNode('test',array()),
101 new Sabre_DAV_SimpleCollection('principals',array(
102 new Sabre_DAV_SimpleCollection('notaprincipal'),
105 $acl = new Sabre_DAVACL_Plugin();
106 $server = new Sabre_DAV_Server($tree);
107 $server->httpRequest = new Sabre_HTTP_Request();
108 $body = '<?xml version="1.0"?>
109 <d:acl xmlns:d="DAV:">
111 <d:grant><d:privilege><d:read /></d:privilege></d:grant>
112 <d:principal><d:href>/principals/notaprincipal</d:href></d:principal>
115 $server->httpRequest->setBody($body);
116 $server->addPlugin($acl);
118 $acl->httpACL('test');
123 * @expectedException Sabre_DAVACL_Exception_NotSupportedPrivilege
125 function testUnknownPrivilege() {
128 new Sabre_DAVACL_MockACLNode('test',array()),
130 $acl = new Sabre_DAVACL_Plugin();
131 $server = new Sabre_DAV_Server($tree);
132 $server->httpRequest = new Sabre_HTTP_Request();
133 $body = '<?xml version="1.0"?>
134 <d:acl xmlns:d="DAV:">
136 <d:grant><d:privilege><d:bananas /></d:privilege></d:grant>
137 <d:principal><d:href>/principals/notfound</d:href></d:principal>
140 $server->httpRequest->setBody($body);
141 $server->addPlugin($acl);
143 $acl->httpACL('test');
148 * @expectedException Sabre_DAVACL_Exception_NoAbstract
150 function testAbstractPrivilege() {
153 new Sabre_DAVACL_MockACLNode('test',array()),
155 $acl = new Sabre_DAVACL_Plugin();
156 $server = new Sabre_DAV_Server($tree);
157 $server->httpRequest = new Sabre_HTTP_Request();
158 $body = '<?xml version="1.0"?>
159 <d:acl xmlns:d="DAV:">
161 <d:grant><d:privilege><d:read-acl /></d:privilege></d:grant>
162 <d:principal><d:href>/principals/notfound</d:href></d:principal>
165 $server->httpRequest->setBody($body);
166 $server->addPlugin($acl);
168 $acl->httpACL('test');
173 * @expectedException Sabre_DAVACL_Exception_AceConflict
175 function testUpdateProtectedPrivilege() {
179 'principal' => 'principals/notfound',
180 'privilege' => '{DAV:}write',
186 new Sabre_DAVACL_MockACLNode('test',$oldACL),
188 $acl = new Sabre_DAVACL_Plugin();
189 $server = new Sabre_DAV_Server($tree);
190 $server->httpRequest = new Sabre_HTTP_Request();
191 $body = '<?xml version="1.0"?>
192 <d:acl xmlns:d="DAV:">
194 <d:grant><d:privilege><d:read /></d:privilege></d:grant>
195 <d:principal><d:href>/principals/notfound</d:href></d:principal>
198 $server->httpRequest->setBody($body);
199 $server->addPlugin($acl);
201 $acl->httpACL('test');
206 * @expectedException Sabre_DAVACL_Exception_AceConflict
208 function testUpdateProtectedPrivilege2() {
212 'principal' => 'principals/notfound',
213 'privilege' => '{DAV:}write',
219 new Sabre_DAVACL_MockACLNode('test',$oldACL),
221 $acl = new Sabre_DAVACL_Plugin();
222 $server = new Sabre_DAV_Server($tree);
223 $server->httpRequest = new Sabre_HTTP_Request();
224 $body = '<?xml version="1.0"?>
225 <d:acl xmlns:d="DAV:">
227 <d:grant><d:privilege><d:write /></d:privilege></d:grant>
228 <d:principal><d:href>/principals/foo</d:href></d:principal>
231 $server->httpRequest->setBody($body);
232 $server->addPlugin($acl);
234 $acl->httpACL('test');
239 * @expectedException Sabre_DAVACL_Exception_AceConflict
241 function testUpdateProtectedPrivilege3() {
245 'principal' => 'principals/notfound',
246 'privilege' => '{DAV:}write',
252 new Sabre_DAVACL_MockACLNode('test',$oldACL),
254 $acl = new Sabre_DAVACL_Plugin();
255 $server = new Sabre_DAV_Server($tree);
256 $server->httpRequest = new Sabre_HTTP_Request();
257 $body = '<?xml version="1.0"?>
258 <d:acl xmlns:d="DAV:">
260 <d:grant><d:privilege><d:write /></d:privilege></d:grant>
261 <d:principal><d:href>/principals/notfound</d:href></d:principal>
264 $server->httpRequest->setBody($body);
265 $server->addPlugin($acl);
267 $acl->httpACL('test');
271 function testSuccessComplex () {
275 'principal' => 'principals/foo',
276 'privilege' => '{DAV:}write',
280 'principal' => 'principals/bar',
281 'privilege' => '{DAV:}read',
286 $node = new Sabre_DAVACL_MockACLNode('test',$oldACL),
287 new Sabre_DAV_SimpleCollection('principals', array(
288 new Sabre_DAVACL_MockPrincipal('foo','principals/foo'),
289 new Sabre_DAVACL_MockPrincipal('baz','principals/baz'),
292 $acl = new Sabre_DAVACL_Plugin();
293 $server = new Sabre_DAV_Server($tree);
294 $server->httpRequest = new Sabre_HTTP_Request();
295 $body = '<?xml version="1.0"?>
296 <d:acl xmlns:d="DAV:">
298 <d:grant><d:privilege><d:write /></d:privilege></d:grant>
299 <d:principal><d:href>/principals/foo</d:href></d:principal>
303 <d:grant><d:privilege><d:write /></d:privilege></d:grant>
304 <d:principal><d:href>/principals/baz</d:href></d:principal>
307 $server->httpRequest->setBody($body);
308 $server->addPlugin($acl);
310 $this->assertFalse($acl->unknownMethod('ACL','test'));
312 $this->assertEquals(array(
314 'principal' => 'principals/foo',
315 'privilege' => '{DAV:}write',
319 'principal' => 'principals/baz',
320 'privilege' => '{DAV:}write',
321 'protected' => false,