ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
SchedulingObjectTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\CalDAV\Schedule;
4 
6 
8 
12  protected $backend;
16  protected $calendar;
17  protected $principalBackend;
18 
19  protected $data;
20  protected $data2;
21 
22  function setup() {
23 
24  if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
25  $this->backend = new Backend\MockScheduling();
26 
27  $this->data = <<<ICS
28 BEGIN:VCALENDAR
29 METHOD:REQUEST
30 BEGIN:VEVENT
31 SEQUENCE:1
32 END:VEVENT
33 END:VCALENDAR
34 ICS;
35  $this->data = <<<ICS
36 BEGIN:VCALENDAR
37 METHOD:REQUEST
38 BEGIN:VEVENT
39 SEQUENCE:2
40 END:VEVENT
41 END:VCALENDAR
42 ICS;
43 
44  $this->inbox = new Inbox($this->backend, 'principals/user1');
45  $this->inbox->createFile('item1.ics', $this->data);
46 
47  }
48 
49  function teardown() {
50 
51  unset($this->inbox);
52  unset($this->backend);
53 
54  }
55 
56  function testSetup() {
57 
58  $children = $this->inbox->getChildren();
59  $this->assertTrue($children[0] instanceof SchedulingObject);
60 
61  $this->assertInternalType('string', $children[0]->getName());
62  $this->assertInternalType('string', $children[0]->get());
63  $this->assertInternalType('string', $children[0]->getETag());
64  $this->assertEquals('text/calendar; charset=utf-8', $children[0]->getContentType());
65 
66  }
67 
71  function testInvalidArg1() {
72 
73  $obj = new SchedulingObject(
74  new Backend\MockScheduling([], []),
75  [],
76  []
77  );
78 
79  }
80 
84  function testInvalidArg2() {
85 
86  $obj = new SchedulingObject(
87  new Backend\MockScheduling([], []),
88  [],
89  ['calendarid' => '1']
90  );
91 
92  }
93 
98  function testPut() {
99 
100  $children = $this->inbox->getChildren();
101  $this->assertTrue($children[0] instanceof SchedulingObject);
102 
103  $children[0]->put('');
104 
105  }
106 
110  function testDelete() {
111 
112  $children = $this->inbox->getChildren();
113  $this->assertTrue($children[0] instanceof SchedulingObject);
114 
115  $obj = $children[0];
116  $obj->delete();
117 
118  $children2 = $this->inbox->getChildren();
119  $this->assertEquals(count($children) - 1, count($children2));
120 
121  }
122 
126  function testGetLastModified() {
127 
128  $children = $this->inbox->getChildren();
129  $this->assertTrue($children[0] instanceof SchedulingObject);
130 
131  $obj = $children[0];
132 
133  $lastMod = $obj->getLastModified();
134  $this->assertTrue(is_int($lastMod) || ctype_digit($lastMod) || is_null($lastMod));
135 
136  }
137 
141  function testGetSize() {
142 
143  $children = $this->inbox->getChildren();
144  $this->assertTrue($children[0] instanceof SchedulingObject);
145 
146  $obj = $children[0];
147 
148  $size = $obj->getSize();
149  $this->assertInternalType('int', $size);
150 
151  }
152 
153  function testGetOwner() {
154 
155  $children = $this->inbox->getChildren();
156  $this->assertTrue($children[0] instanceof SchedulingObject);
157 
158  $obj = $children[0];
159  $this->assertEquals('principals/user1', $obj->getOwner());
160 
161  }
162 
163  function testGetGroup() {
164 
165  $children = $this->inbox->getChildren();
166  $this->assertTrue($children[0] instanceof SchedulingObject);
167 
168  $obj = $children[0];
169  $this->assertNull($obj->getGroup());
170 
171  }
172 
173  function testGetACL() {
174 
175  $expected = [
176  [
177  'privilege' => '{DAV:}all',
178  'principal' => '{DAV:}owner',
179  'protected' => true,
180  ],
181  [
182  'privilege' => '{DAV:}all',
183  'principal' => 'principals/user1/calendar-proxy-write',
184  'protected' => true,
185  ],
186  [
187  'privilege' => '{DAV:}read',
188  'principal' => 'principals/user1/calendar-proxy-read',
189  'protected' => true,
190  ],
191  ];
192 
193  $children = $this->inbox->getChildren();
194  $this->assertTrue($children[0] instanceof SchedulingObject);
195 
196  $obj = $children[0];
197  $this->assertEquals($expected, $obj->getACL());
198 
199  }
200 
201  function testDefaultACL() {
202 
203  $backend = new Backend\MockScheduling([], []);
204  $calendarObject = new SchedulingObject($backend, ['calendarid' => 1, 'uri' => 'foo', 'principaluri' => 'principals/user1']);
205  $expected = [
206  [
207  'privilege' => '{DAV:}all',
208  'principal' => '{DAV:}owner',
209  'protected' => true,
210  ],
211  [
212  'privilege' => '{DAV:}all',
213  'principal' => 'principals/user1/calendar-proxy-write',
214  'protected' => true,
215  ],
216  [
217  'privilege' => '{DAV:}read',
218  'principal' => 'principals/user1/calendar-proxy-read',
219  'protected' => true,
220  ],
221  ];
222  $this->assertEquals($expected, $calendarObject->getACL());
223 
224 
225  }
226 
230  function testSetACL() {
231 
232  $children = $this->inbox->getChildren();
233  $this->assertTrue($children[0] instanceof SchedulingObject);
234 
235  $obj = $children[0];
236  $obj->setACL([]);
237 
238  }
239 
240  function testGet() {
241 
242  $children = $this->inbox->getChildren();
243  $this->assertTrue($children[0] instanceof SchedulingObject);
244 
245  $obj = $children[0];
246 
247  $this->assertEquals($this->data, $obj->get());
248 
249  }
250 
251  function testGetRefetch() {
252 
254  $backend->createSchedulingObject('principals/user1', 'foo', 'foo');
255 
256  $obj = new SchedulingObject($backend, [
257  'calendarid' => 1,
258  'uri' => 'foo',
259  'principaluri' => 'principals/user1',
260  ]);
261 
262  $this->assertEquals('foo', $obj->get());
263 
264  }
265 
266  function testGetEtag1() {
267 
268  $objectInfo = [
269  'calendardata' => 'foo',
270  'uri' => 'foo',
271  'etag' => 'bar',
272  'calendarid' => 1
273  ];
274 
275  $backend = new Backend\MockScheduling([], []);
276  $obj = new SchedulingObject($backend, $objectInfo);
277 
278  $this->assertEquals('bar', $obj->getETag());
279 
280  }
281 
282  function testGetEtag2() {
283 
284  $objectInfo = [
285  'calendardata' => 'foo',
286  'uri' => 'foo',
287  'calendarid' => 1
288  ];
289 
290  $backend = new Backend\MockScheduling([], []);
291  $obj = new SchedulingObject($backend, $objectInfo);
292 
293  $this->assertEquals('"' . md5('foo') . '"', $obj->getETag());
294 
295  }
296 
298 
299  $objectInfo = [
300  'calendardata' => 'foo',
301  'uri' => 'foo',
302  'calendarid' => 1
303  ];
304 
305  $backend = new Backend\MockScheduling([], []);
306  $obj = new SchedulingObject($backend, $objectInfo);
307  $this->assertNull($obj->getSupportedPrivilegeSet());
308 
309  }
310 
311  function testGetSize1() {
312 
313  $objectInfo = [
314  'calendardata' => 'foo',
315  'uri' => 'foo',
316  'calendarid' => 1
317  ];
318 
319  $backend = new Backend\MockScheduling([], []);
320  $obj = new SchedulingObject($backend, $objectInfo);
321  $this->assertEquals(3, $obj->getSize());
322 
323  }
324 
325  function testGetSize2() {
326 
327  $objectInfo = [
328  'uri' => 'foo',
329  'calendarid' => 1,
330  'size' => 4,
331  ];
332 
333  $backend = new Backend\MockScheduling([], []);
334  $obj = new SchedulingObject($backend, $objectInfo);
335  $this->assertEquals(4, $obj->getSize());
336 
337  }
338 
339  function testGetContentType() {
340 
341  $objectInfo = [
342  'uri' => 'foo',
343  'calendarid' => 1,
344  ];
345 
346  $backend = new Backend\MockScheduling([], []);
347  $obj = new SchedulingObject($backend, $objectInfo);
348  $this->assertEquals('text/calendar; charset=utf-8', $obj->getContentType());
349 
350  }
351 
352  function testGetContentType2() {
353 
354  $objectInfo = [
355  'uri' => 'foo',
356  'calendarid' => 1,
357  'component' => 'VEVENT',
358  ];
359 
360  $backend = new Backend\MockScheduling([], []);
361  $obj = new SchedulingObject($backend, $objectInfo);
362  $this->assertEquals('text/calendar; charset=utf-8; component=VEVENT', $obj->getContentType());
363 
364  }
365  function testGetACL2() {
366 
367  $objectInfo = [
368  'uri' => 'foo',
369  'calendarid' => 1,
370  'acl' => [],
371  ];
372 
373  $backend = new Backend\MockScheduling([], []);
374  $obj = new SchedulingObject($backend, $objectInfo);
375  $this->assertEquals([], $obj->getACL());
376 
377  }
378 }
$size
Definition: RandomTest.php:84
The CalDAV scheduling inbox.
Definition: Inbox.php:18
$this data['403_header']
The SchedulingObject represents a scheduling object in the Inbox collection.