]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/DAVACL/ACLMethodTest.php
Initial Release of the calendar plugin
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / DAVACL / ACLMethodTest.php
1 <?php
2
3 class Sabre_DAVACL_ACLMethodTest extends PHPUnit_Framework_TestCase {
4
5     /**
6      * @expectedException Sabre_DAV_Exception_BadRequest
7      */
8     function testCallback() {
9
10         $acl = new Sabre_DAVACL_Plugin();
11         $server = new Sabre_DAV_Server();
12         $server->addPlugin($acl);
13
14         $acl->unknownMethod('ACL','test');
15
16     }
17
18     function testCallbackPassthru() {
19
20         $acl = new Sabre_DAVACL_Plugin();
21         $server = new Sabre_DAV_Server();
22         $server->addPlugin($acl);
23
24         $this->assertNull($acl->unknownMethod('FOO','test'));
25
26     }
27
28     /**
29
30     /**
31      * @expectedException Sabre_DAV_Exception_MethodNotAllowed
32      */
33     function testNotSupportedByNode() {
34
35         $tree = array(
36             new Sabre_DAV_SimpleCollection('test'),
37         );
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:">
43 </d:acl>';
44         $server->httpRequest->setBody($body);
45         $server->addPlugin($acl);
46
47         $acl->httpACL('test');
48
49     }
50
51     function testSuccessSimple() {
52
53         $tree = array(
54             new Sabre_DAVACL_MockACLNode('test',array()),
55         );
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:">
61 </d:acl>';
62         $server->httpRequest->setBody($body);
63         $server->addPlugin($acl);
64
65         $this->assertNull($acl->httpACL('test'));
66
67     }
68
69     /**
70      * @expectedException Sabre_DAVACL_Exception_NotRecognizedPrincipal
71      */
72     function testUnrecognizedPrincipal() {
73
74         $tree = array(
75             new Sabre_DAVACL_MockACLNode('test',array()),
76         );
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:">
82     <d:ace>
83         <d:grant><d:privilege><d:read /></d:privilege></d:grant>
84         <d:principal><d:href>/principals/notfound</d:href></d:principal>
85     </d:ace>
86 </d:acl>';
87         $server->httpRequest->setBody($body);
88         $server->addPlugin($acl);
89
90         $acl->httpACL('test');
91
92     }
93
94     /**
95      * @expectedException Sabre_DAVACL_Exception_NotRecognizedPrincipal
96      */
97     function testUnrecognizedPrincipal2() {
98
99         $tree = array(
100             new Sabre_DAVACL_MockACLNode('test',array()),
101             new Sabre_DAV_SimpleCollection('principals',array(
102                 new Sabre_DAV_SimpleCollection('notaprincipal'),
103             )),
104         );
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:">
110     <d:ace>
111         <d:grant><d:privilege><d:read /></d:privilege></d:grant>
112         <d:principal><d:href>/principals/notaprincipal</d:href></d:principal>
113     </d:ace>
114 </d:acl>';
115         $server->httpRequest->setBody($body);
116         $server->addPlugin($acl);
117
118         $acl->httpACL('test');
119
120     }
121
122     /**
123      * @expectedException Sabre_DAVACL_Exception_NotSupportedPrivilege
124      */
125     function testUnknownPrivilege() {
126
127         $tree = array(
128             new Sabre_DAVACL_MockACLNode('test',array()),
129         );
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:">
135     <d:ace>
136         <d:grant><d:privilege><d:bananas /></d:privilege></d:grant>
137         <d:principal><d:href>/principals/notfound</d:href></d:principal>
138     </d:ace>
139 </d:acl>';
140         $server->httpRequest->setBody($body);
141         $server->addPlugin($acl);
142
143         $acl->httpACL('test');
144
145     }
146
147     /**
148      * @expectedException Sabre_DAVACL_Exception_NoAbstract
149      */
150     function testAbstractPrivilege() {
151
152         $tree = array(
153             new Sabre_DAVACL_MockACLNode('test',array()),
154         );
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:">
160     <d:ace>
161         <d:grant><d:privilege><d:read-acl /></d:privilege></d:grant>
162         <d:principal><d:href>/principals/notfound</d:href></d:principal>
163     </d:ace>
164 </d:acl>';
165         $server->httpRequest->setBody($body);
166         $server->addPlugin($acl);
167
168         $acl->httpACL('test');
169
170     }
171
172     /**
173      * @expectedException Sabre_DAVACL_Exception_AceConflict
174      */
175     function testUpdateProtectedPrivilege() {
176
177         $oldACL = array(
178             array(
179                 'principal' => 'principals/notfound',
180                 'privilege' => '{DAV:}write',
181                 'protected' => true,
182             ),
183         );
184
185         $tree = array(
186             new Sabre_DAVACL_MockACLNode('test',$oldACL),
187         );
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:">
193     <d:ace>
194         <d:grant><d:privilege><d:read /></d:privilege></d:grant>
195         <d:principal><d:href>/principals/notfound</d:href></d:principal>
196     </d:ace>
197 </d:acl>';
198         $server->httpRequest->setBody($body);
199         $server->addPlugin($acl);
200
201         $acl->httpACL('test');
202
203     }
204
205     /**
206      * @expectedException Sabre_DAVACL_Exception_AceConflict
207      */
208     function testUpdateProtectedPrivilege2() {
209
210         $oldACL = array(
211             array(
212                 'principal' => 'principals/notfound',
213                 'privilege' => '{DAV:}write',
214                 'protected' => true,
215             ),
216         );
217
218         $tree = array(
219             new Sabre_DAVACL_MockACLNode('test',$oldACL),
220         );
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:">
226     <d:ace>
227         <d:grant><d:privilege><d:write /></d:privilege></d:grant>
228         <d:principal><d:href>/principals/foo</d:href></d:principal>
229     </d:ace>
230 </d:acl>';
231         $server->httpRequest->setBody($body);
232         $server->addPlugin($acl);
233
234         $acl->httpACL('test');
235
236     }
237
238     /**
239      * @expectedException Sabre_DAVACL_Exception_AceConflict
240      */
241     function testUpdateProtectedPrivilege3() {
242
243         $oldACL = array(
244             array(
245                 'principal' => 'principals/notfound',
246                 'privilege' => '{DAV:}write',
247                 'protected' => true,
248             ),
249         );
250
251         $tree = array(
252             new Sabre_DAVACL_MockACLNode('test',$oldACL),
253         );
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:">
259     <d:ace>
260         <d:grant><d:privilege><d:write /></d:privilege></d:grant>
261         <d:principal><d:href>/principals/notfound</d:href></d:principal>
262     </d:ace>
263 </d:acl>';
264         $server->httpRequest->setBody($body);
265         $server->addPlugin($acl);
266
267         $acl->httpACL('test');
268
269     }
270
271     function testSuccessComplex () {
272
273         $oldACL = array(
274             array(
275                 'principal' => 'principals/foo',
276                 'privilege' => '{DAV:}write',
277                 'protected' => true,
278             ),
279             array(
280                 'principal' => 'principals/bar',
281                 'privilege' => '{DAV:}read',
282             ),
283         );
284
285         $tree = array(
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'),
290             )),
291         );
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:">
297     <d:ace>
298         <d:grant><d:privilege><d:write /></d:privilege></d:grant>
299         <d:principal><d:href>/principals/foo</d:href></d:principal>
300         <d:protected />
301     </d:ace>
302     <d:ace>
303         <d:grant><d:privilege><d:write /></d:privilege></d:grant>
304         <d:principal><d:href>/principals/baz</d:href></d:principal>
305     </d:ace>
306 </d:acl>';
307         $server->httpRequest->setBody($body);
308         $server->addPlugin($acl);
309
310         $this->assertFalse($acl->unknownMethod('ACL','test'));
311
312         $this->assertEquals(array(
313             array(
314                 'principal' => 'principals/foo',
315                 'privilege' => '{DAV:}write',
316                 'protected' => true,
317             ),
318             array(
319                 'principal' => 'principals/baz',
320                 'privilege' => '{DAV:}write',
321                 'protected' => false,
322             ),
323         ), $node->getACL());
324
325     }
326 }