ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
CalendarObjectTest.php
Go to the documentation of this file.
1<?php
2
3namespace Sabre\CalDAV;
4
5require_once 'Sabre/CalDAV/TestUtil.php';
6
8
12 protected $backend;
16 protected $calendar;
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);
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);
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
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
257VERSION:2.0
258PRODID:-//Apple Inc.//iCal 4.0.1//EN
259CALSCALE:GREGORIAN
260BEGIN:VTIMEZONE
261TZID:Asia/Seoul
262BEGIN:DAYLIGHT
263TZOFFSETFROM:+0900
264RRULE:FREQ=YEARLY;UNTIL=19880507T150000Z;BYMONTH=5;BYDAY=2SU
265DTSTART:19870510T000000
266TZNAME:GMT+09:00
267TZOFFSETTO:+1000
268END:DAYLIGHT
269BEGIN:STANDARD
270TZOFFSETFROM:+1000
271DTSTART:19881009T000000
272TZNAME:GMT+09:00
273TZOFFSETTO:+0900
274END:STANDARD
275END:VTIMEZONE
276BEGIN:VEVENT
277CREATED:20100225T154229Z
278UID:39A6B5ED-DD51-4AFE-A683-C35EE3749627
279TRANSP:TRANSPARENT
280SUMMARY:Something here
281DTSTAMP:20100228T130202Z
282DTSTART;TZID=Asia/Seoul:20100223T060000
283DTEND;TZID=Asia/Seoul:20100223T070000
284ATTENDEE;PARTSTAT=NEEDS-ACTION:mailto:lisa@example.com
285SEQUENCE:2
286END:VEVENT
287END: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
An exception for terminatinating execution or to throw for unit testing.
testInvalidArg2()
@expectedException InvalidArgumentException
testSetACL()
@expectedException \Sabre\DAV\Exception\Forbidden
testInvalidArg1()
@expectedException InvalidArgumentException
The CalendarObject represents a single VEVENT or VTODO within a Calendar.
This object represents a CalDAV calendar.
Definition: Calendar.php:19
static getTestCalendarData($type=1)
Definition: TestUtil.php:35
static getBackend()
Definition: TestUtil.php:7
$stream
PHP stream implementation.