ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
SharingPluginTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\CalDAV;
4 
5 use Sabre\DAV;
7 use Sabre\HTTP;
8 
10 
11  protected $setupCalDAV = true;
12  protected $setupCalDAVSharing = true;
13  protected $setupACL = true;
14  protected $autoLogin = 'user1';
15 
16  function setUp() {
17 
18  $this->caldavCalendars = [
19  [
20  'principaluri' => 'principals/user1',
21  'id' => 1,
22  'uri' => 'cal1',
23  ],
24  [
25  'principaluri' => 'principals/user1',
26  'id' => 2,
27  'uri' => 'cal2',
29  ],
30  [
31  'principaluri' => 'principals/user1',
32  'id' => 3,
33  'uri' => 'cal3',
34  ],
35  ];
36 
37  parent::setUp();
38 
39  // Making the logged in user an admin, for full access:
40  $this->aclPlugin->adminPrincipals[] = 'principals/user2';
41 
42  }
43 
44  function testSimple() {
45 
46  $this->assertInstanceOf('Sabre\\CalDAV\\SharingPlugin', $this->server->getPlugin('caldav-sharing'));
47  $this->assertEquals(
48  'caldav-sharing',
49  $this->caldavSharingPlugin->getPluginInfo()['name']
50  );
51 
52  }
53 
58 
59  $server = new DAV\Server();
60  $server->addPlugin(
61  new SharingPlugin()
62  );
63 
64  }
65 
66  function testGetFeatures() {
67 
68  $this->assertEquals(['calendarserver-sharing'], $this->caldavSharingPlugin->getFeatures());
69 
70  }
71 
73 
74  // Forcing the server to authenticate:
75  $this->authPlugin->beforeMethod(new HTTP\Request(), new HTTP\Response());
76  $props = $this->server->getProperties('calendars/user1/cal1', [
77  '{' . Plugin::NS_CALENDARSERVER . '}invite',
78  '{' . Plugin::NS_CALENDARSERVER . '}allowed-sharing-modes',
79  ]);
80 
81  $this->assertInstanceOf('Sabre\\CalDAV\\Xml\\Property\\Invite', $props['{' . Plugin::NS_CALENDARSERVER . '}invite']);
82  $this->assertInstanceOf('Sabre\\CalDAV\\Xml\\Property\\AllowedSharingModes', $props['{' . Plugin::NS_CALENDARSERVER . '}allowed-sharing-modes']);
83 
84  }
85 
87 
88  $props = $this->server->getProperties('calendars/user1/cal2', [
89  '{' . Plugin::NS_CALENDARSERVER . '}shared-url',
90  '{' . Plugin::NS_CALENDARSERVER . '}invite',
91  ]);
92 
93  $this->assertInstanceOf('Sabre\\CalDAV\\Xml\\Property\\Invite', $props['{' . Plugin::NS_CALENDARSERVER . '}invite']);
94  //$this->assertInstanceOf('Sabre\\DAV\\Xml\\Property\\Href', $props['{' . Plugin::NS_CALENDARSERVER . '}shared-url']);
95 
96  }
97 
99 
100  $this->caldavBackend->updateInvites(1,
101  [
102  new Sharee([
103  'href' => 'mailto:joe@example.org',
104  ])
105  ]
106  );
107  $result = $this->server->updateProperties('calendars/user1/cal1', [
108  '{DAV:}resourcetype' => new DAV\Xml\Property\ResourceType(['{DAV:}collection'])
109  ]);
110 
111  $this->assertEquals([
112  '{DAV:}resourcetype' => 200
113  ], $result);
114 
115  $this->assertEquals(0, count($this->caldavBackend->getInvites(1)));
116 
117  }
118 
120 
121  $result = $this->server->updateProperties('calendars/user1/cal3', [
122  '{DAV:}foo' => 'bar',
123  ]);
124 
125  $this->assertEquals([
126  '{DAV:}foo' => 200,
127  ], $result);
128 
129  }
130 
132 
134  'REQUEST_METHOD' => 'PATCH',
135  'REQUEST_URI' => '/',
136  ]);
137 
138  $response = $this->request($request);
139 
140  $this->assertEquals(501, $response->status, $response->body);
141 
142  }
143 
145 
147  'REQUEST_METHOD' => 'POST',
148  'REQUEST_URI' => '/',
149  'CONTENT_TYPE' => 'text/plain',
150  ]);
151 
152  $response = $this->request($request);
153 
154  $this->assertEquals(501, $response->status, $response->body);
155 
156  }
157 
159 
161  'REQUEST_METHOD' => 'POST',
162  'REQUEST_URI' => '/foo',
163  'CONTENT_TYPE' => 'text/xml',
164  ]);
165 
166  $response = $this->request($request);
167 
168  $this->assertEquals(501, $response->status, $response->body);
169 
170  }
171 
172  function testShareRequest() {
173 
174  $request = new HTTP\Request('POST', '/calendars/user1/cal1', ['Content-Type' => 'text/xml']);
175 
176  $xml = <<<RRR
177 <?xml version="1.0"?>
178 <cs:share xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:">
179  <cs:set>
180  <d:href>mailto:joe@example.org</d:href>
181  <cs:common-name>Joe Shmoe</cs:common-name>
182  <cs:read-write />
183  </cs:set>
184  <cs:remove>
185  <d:href>mailto:nancy@example.org</d:href>
186  </cs:remove>
187 </cs:share>
188 RRR;
189 
190  $request->setBody($xml);
191 
192  $response = $this->request($request, 200);
193 
194  $this->assertEquals(
195  [
196  new Sharee([
197  'href' => 'mailto:joe@example.org',
198  'properties' => [
199  '{DAV:}displayname' => 'Joe Shmoe',
200  ],
201  'access' => \Sabre\DAV\Sharing\Plugin::ACCESS_READWRITE,
202  'inviteStatus' => \Sabre\DAV\Sharing\Plugin::INVITE_NORESPONSE,
203  'comment' => '',
204  ]),
205  ],
206  $this->caldavBackend->getInvites(1)
207  );
208 
209  // Wiping out tree cache
210  $this->server->tree->markDirty('');
211 
212  // Verifying that the calendar is now marked shared.
213  $props = $this->server->getProperties('calendars/user1/cal1', ['{DAV:}resourcetype']);
214  $this->assertTrue(
215  $props['{DAV:}resourcetype']->is('{http://calendarserver.org/ns/}shared-owner')
216  );
217 
218  }
219 
221 
222  $request = new HTTP\Request(
223  'POST',
224  '/calendars/user1/cal2',
225  ['Content-Type' => 'text/xml']
226  );
227 
228  $xml = '<?xml version="1.0"?>
229 <cs:share xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:">
230  <cs:set>
231  <d:href>mailto:joe@example.org</d:href>
232  <cs:common-name>Joe Shmoe</cs:common-name>
233  <cs:read-write />
234  </cs:set>
235  <cs:remove>
236  <d:href>mailto:nancy@example.org</d:href>
237  </cs:remove>
238 </cs:share>
239 ';
240 
241  $request->setBody($xml);
242 
243  $response = $this->request($request, 403);
244 
245  }
246 
247  function testInviteReply() {
248 
250  'REQUEST_METHOD' => 'POST',
251  'REQUEST_URI' => '/calendars/user1',
252  'CONTENT_TYPE' => 'text/xml',
253  ]);
254 
255  $xml = '<?xml version="1.0"?>
256 <cs:invite-reply xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:">
257  <cs:hosturl><d:href>/principals/owner</d:href></cs:hosturl>
258  <cs:invite-accepted />
259 </cs:invite-reply>
260 ';
261 
262  $request->setBody($xml);
263  $response = $this->request($request);
264  $this->assertEquals(200, $response->status, $response->body);
265 
266  }
267 
268  function testInviteBadXML() {
269 
271  'REQUEST_METHOD' => 'POST',
272  'REQUEST_URI' => '/calendars/user1',
273  'CONTENT_TYPE' => 'text/xml',
274  ]);
275 
276  $xml = '<?xml version="1.0"?>
277 <cs:invite-reply xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:">
278 </cs:invite-reply>
279 ';
280  $request->setBody($xml);
281  $response = $this->request($request);
282  $this->assertEquals(400, $response->status, $response->body);
283 
284  }
285 
286  function testInviteWrongUrl() {
287 
289  'REQUEST_METHOD' => 'POST',
290  'REQUEST_URI' => '/calendars/user1/cal1',
291  'CONTENT_TYPE' => 'text/xml',
292  ]);
293 
294  $xml = '<?xml version="1.0"?>
295 <cs:invite-reply xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:">
296  <cs:hosturl><d:href>/principals/owner</d:href></cs:hosturl>
297 </cs:invite-reply>
298 ';
299  $request->setBody($xml);
300  $response = $this->request($request);
301  $this->assertEquals(501, $response->status, $response->body);
302 
303  // If the plugin did not handle this request, it must ensure that the
304  // body is still accessible by other plugins.
305  $this->assertEquals($xml, $request->getBody(true));
306 
307  }
308 
309  function testPublish() {
310 
311  $request = new HTTP\Request('POST', '/calendars/user1/cal1', ['Content-Type' => 'text/xml']);
312 
313  $xml = '<?xml version="1.0"?>
314 <cs:publish-calendar xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:" />
315 ';
316 
317  $request->setBody($xml);
318 
319  $response = $this->request($request);
320  $this->assertEquals(202, $response->status, $response->body);
321 
322  }
323 
324 
325  function testUnpublish() {
326 
327  $request = new HTTP\Request(
328  'POST',
329  '/calendars/user1/cal1',
330  ['Content-Type' => 'text/xml']
331  );
332 
333  $xml = '<?xml version="1.0"?>
334 <cs:unpublish-calendar xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:" />
335 ';
336 
337  $request->setBody($xml);
338 
339  $response = $this->request($request);
340  $this->assertEquals(200, $response->status, $response->body);
341 
342  }
343 
344  function testPublishWrongUrl() {
345 
346  $request = new HTTP\Request(
347  'POST',
348  '/calendars/user1',
349  ['Content-Type' => 'text/xml']
350  );
351 
352  $xml = '<?xml version="1.0"?>
353 <cs:publish-calendar xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:" />
354 ';
355 
356  $request->setBody($xml);
357  $this->request($request, 501);
358 
359  }
360 
362 
363  $request = new HTTP\Request(
364  'POST',
365  '/calendars/user1',
366  ['Content-Type' => 'text/xml']
367  );
368  $xml = '<?xml version="1.0"?>
369 <cs:unpublish-calendar xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:" />
370 ';
371 
372  $request->setBody($xml);
373 
374  $this->request($request, 501);
375 
376  }
377 
378  function testUnknownXmlDoc() {
379 
380 
381  $request = new HTTP\Request(
382  'POST',
383  '/calendars/user1/cal2',
384  ['Content-Type' => 'text/xml']
385  );
386 
387  $xml = '<?xml version="1.0"?>
388 <cs:foo-bar xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:" />';
389 
390  $request->setBody($xml);
391 
392  $response = $this->request($request);
393  $this->assertEquals(501, $response->status, $response->body);
394 
395  }
396 }
This class represents the {DAV:}sharee element.
Definition: Sharee.php:21
$result
foreach($paths as $path) $request
Definition: asyncclient.php:32
The Request class represents a single HTTP request.
Definition: Request.php:18
{DAV:}resourcetype property
const NS_CALENDARSERVER
This is the namespace for the proprietary calendarserver extensions.
Definition: Plugin.php:38
This class represents a single HTTP response.
Definition: Response.php:12
This class may be used as a basis for other webdav-related unittests.
Main DAV server class.
Definition: Server.php:23
request($request, $expectedStatus=null)
Makes a request, and returns a response object.
static createFromServerArray(array $serverArray)
This static method will create a new Request object, based on a PHP $_SERVER array.
Definition: Sapi.php:107
$response