ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
CalendarObjectTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\CalDAV;
4 
5 require_once 'Sabre/CalDAV/TestUtil.php';
6 
8 
12  protected $backend;
16  protected $calendar;
17  protected $principalBackend;
18 
19  function setup() {
20 
21  $this->backend = TestUtil::getBackend();
22 
23  $calendars = $this->backend->getCalendarsForUser('principals/user1');
24  $this->assertEquals(2, count($calendars));
25  $this->calendar = new Calendar($this->backend, $calendars[0]);
26 
27  }
28 
29  function teardown() {
30 
31  unset($this->calendar);
32  unset($this->backend);
33 
34  }
35 
36  function testSetup() {
37 
38  $children = $this->calendar->getChildren();
39  $this->assertTrue($children[0] instanceof CalendarObject);
40 
41  $this->assertInternalType('string', $children[0]->getName());
42  $this->assertInternalType('string', $children[0]->get());
43  $this->assertInternalType('string', $children[0]->getETag());
44  $this->assertEquals('text/calendar; charset=utf-8', $children[0]->getContentType());
45 
46  }
47 
51  function testInvalidArg1() {
52 
53  $obj = new CalendarObject(
54  new Backend\Mock([], []),
55  [],
56  []
57  );
58 
59  }
60 
64  function testInvalidArg2() {
65 
66  $obj = new CalendarObject(
67  new Backend\Mock([], []),
68  [],
69  ['calendarid' => '1']
70  );
71 
72  }
73 
77  function testPut() {
78 
79  $children = $this->calendar->getChildren();
80  $this->assertTrue($children[0] instanceof CalendarObject);
81  $newData = TestUtil::getTestCalendarData();
82 
83  $children[0]->put($newData);
84  $this->assertEquals($newData, $children[0]->get());
85 
86  }
87 
91  function testPutStream() {
92 
93  $children = $this->calendar->getChildren();
94  $this->assertTrue($children[0] instanceof CalendarObject);
95  $newData = TestUtil::getTestCalendarData();
96 
97  $stream = fopen('php://temp', 'r+');
98  fwrite($stream, $newData);
99  rewind($stream);
100  $children[0]->put($stream);
101  $this->assertEquals($newData, $children[0]->get());
102 
103  }
104 
105 
109  function testDelete() {
110 
111  $children = $this->calendar->getChildren();
112  $this->assertTrue($children[0] instanceof CalendarObject);
113 
114  $obj = $children[0];
115  $obj->delete();
116 
117  $children2 = $this->calendar->getChildren();
118  $this->assertEquals(count($children) - 1, count($children2));
119 
120  }
121 
125  function testGetLastModified() {
126 
127  $children = $this->calendar->getChildren();
128  $this->assertTrue($children[0] instanceof CalendarObject);
129 
130  $obj = $children[0];
131 
132  $lastMod = $obj->getLastModified();
133  $this->assertTrue(is_int($lastMod) || ctype_digit($lastMod) || is_null($lastMod));
134 
135  }
136 
140  function testGetSize() {
141 
142  $children = $this->calendar->getChildren();
143  $this->assertTrue($children[0] instanceof CalendarObject);
144 
145  $obj = $children[0];
146 
147  $size = $obj->getSize();
148  $this->assertInternalType('int', $size);
149 
150  }
151 
152  function testGetOwner() {
153 
154  $children = $this->calendar->getChildren();
155  $this->assertTrue($children[0] instanceof CalendarObject);
156 
157  $obj = $children[0];
158  $this->assertEquals('principals/user1', $obj->getOwner());
159 
160  }
161 
162  function testGetGroup() {
163 
164  $children = $this->calendar->getChildren();
165  $this->assertTrue($children[0] instanceof CalendarObject);
166 
167  $obj = $children[0];
168  $this->assertNull($obj->getGroup());
169 
170  }
171 
172  function testGetACL() {
173 
174  $expected = [
175  [
176  'privilege' => '{DAV:}read',
177  'principal' => 'principals/user1',
178  'protected' => true,
179  ],
180  [
181  'privilege' => '{DAV:}read',
182  'principal' => 'principals/user1/calendar-proxy-write',
183  'protected' => true,
184  ],
185  [
186  'privilege' => '{DAV:}read',
187  'principal' => 'principals/user1/calendar-proxy-read',
188  'protected' => true,
189  ],
190  [
191  'privilege' => '{DAV:}write',
192  'principal' => 'principals/user1',
193  'protected' => true,
194  ],
195  [
196  'privilege' => '{DAV:}write',
197  'principal' => 'principals/user1/calendar-proxy-write',
198  'protected' => true,
199  ],
200  ];
201 
202  $children = $this->calendar->getChildren();
203  $this->assertTrue($children[0] instanceof CalendarObject);
204 
205  $obj = $children[0];
206  $this->assertEquals($expected, $obj->getACL());
207 
208  }
209 
210  function testDefaultACL() {
211 
212  $backend = new Backend\Mock([], []);
213  $calendarObject = new CalendarObject($backend, ['principaluri' => 'principals/user1'], ['calendarid' => 1, 'uri' => 'foo']);
214  $expected = [
215  [
216  'privilege' => '{DAV:}all',
217  'principal' => 'principals/user1',
218  'protected' => true,
219  ],
220  [
221  'privilege' => '{DAV:}all',
222  'principal' => 'principals/user1/calendar-proxy-write',
223  'protected' => true,
224  ],
225  [
226  'privilege' => '{DAV:}read',
227  'principal' => 'principals/user1/calendar-proxy-read',
228  'protected' => true,
229  ],
230  ];
231  $this->assertEquals($expected, $calendarObject->getACL());
232 
233 
234  }
235 
239  function testSetACL() {
240 
241  $children = $this->calendar->getChildren();
242  $this->assertTrue($children[0] instanceof CalendarObject);
243 
244  $obj = $children[0];
245  $obj->setACL([]);
246 
247  }
248 
249  function testGet() {
250 
251  $children = $this->calendar->getChildren();
252  $this->assertTrue($children[0] instanceof CalendarObject);
253 
254  $obj = $children[0];
255 
256  $expected = "BEGIN:VCALENDAR
257 VERSION:2.0
258 PRODID:-//Apple Inc.//iCal 4.0.1//EN
259 CALSCALE:GREGORIAN
260 BEGIN:VTIMEZONE
261 TZID:Asia/Seoul
262 BEGIN:DAYLIGHT
263 TZOFFSETFROM:+0900
264 RRULE:FREQ=YEARLY;UNTIL=19880507T150000Z;BYMONTH=5;BYDAY=2SU
265 DTSTART:19870510T000000
266 TZNAME:GMT+09:00
267 TZOFFSETTO:+1000
268 END:DAYLIGHT
269 BEGIN:STANDARD
270 TZOFFSETFROM:+1000
271 DTSTART:19881009T000000
272 TZNAME:GMT+09:00
273 TZOFFSETTO:+0900
274 END:STANDARD
275 END:VTIMEZONE
276 BEGIN:VEVENT
277 CREATED:20100225T154229Z
278 UID:39A6B5ED-DD51-4AFE-A683-C35EE3749627
279 TRANSP:TRANSPARENT
280 SUMMARY:Something here
281 DTSTAMP:20100228T130202Z
282 DTSTART;TZID=Asia/Seoul:20100223T060000
283 DTEND;TZID=Asia/Seoul:20100223T070000
284 ATTENDEE;PARTSTAT=NEEDS-ACTION:mailto:lisa@example.com
285 SEQUENCE:2
286 END:VEVENT
287 END:VCALENDAR";
288 
289 
290 
291  $this->assertEquals($expected, $obj->get());
292 
293  }
294 
295  function testGetRefetch() {
296 
297  $backend = new Backend\Mock([], [
298  1 => [
299  'foo' => [
300  'calendardata' => 'foo',
301  'uri' => 'foo'
302  ],
303  ]
304  ]);
305  $obj = new CalendarObject($backend, ['id' => 1], ['uri' => 'foo']);
306 
307  $this->assertEquals('foo', $obj->get());
308 
309  }
310 
311  function testGetEtag1() {
312 
313  $objectInfo = [
314  'calendardata' => 'foo',
315  'uri' => 'foo',
316  'etag' => 'bar',
317  'calendarid' => 1
318  ];
319 
320  $backend = new Backend\Mock([], []);
321  $obj = new CalendarObject($backend, [], $objectInfo);
322 
323  $this->assertEquals('bar', $obj->getETag());
324 
325  }
326 
327  function testGetEtag2() {
328 
329  $objectInfo = [
330  'calendardata' => 'foo',
331  'uri' => 'foo',
332  'calendarid' => 1
333  ];
334 
335  $backend = new Backend\Mock([], []);
336  $obj = new CalendarObject($backend, [], $objectInfo);
337 
338  $this->assertEquals('"' . md5('foo') . '"', $obj->getETag());
339 
340  }
341 
343 
344  $objectInfo = [
345  'calendardata' => 'foo',
346  'uri' => 'foo',
347  'calendarid' => 1
348  ];
349 
350  $backend = new Backend\Mock([], []);
351  $obj = new CalendarObject($backend, [], $objectInfo);
352  $this->assertNull($obj->getSupportedPrivilegeSet());
353 
354  }
355 
356  function testGetSize1() {
357 
358  $objectInfo = [
359  'calendardata' => 'foo',
360  'uri' => 'foo',
361  'calendarid' => 1
362  ];
363 
364  $backend = new Backend\Mock([], []);
365  $obj = new CalendarObject($backend, [], $objectInfo);
366  $this->assertEquals(3, $obj->getSize());
367 
368  }
369 
370  function testGetSize2() {
371 
372  $objectInfo = [
373  'uri' => 'foo',
374  'calendarid' => 1,
375  'size' => 4,
376  ];
377 
378  $backend = new Backend\Mock([], []);
379  $obj = new CalendarObject($backend, [], $objectInfo);
380  $this->assertEquals(4, $obj->getSize());
381 
382  }
383 }
$size
Definition: RandomTest.php:84
static getTestCalendarData($type=1)
Definition: TestUtil.php:35
static getBackend()
Definition: TestUtil.php:7
The CalendarObject represents a single VEVENT or VTODO within a Calendar.
$stream
PHP stream implementation.
testInvalidArg1()
InvalidArgumentException
testInvalidArg2()
InvalidArgumentException
This object represents a CalDAV calendar.
Definition: Calendar.php:19