]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/CalDAV/CalendarObjectTest.php
Initial Release of the calendar plugin
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / CalDAV / CalendarObjectTest.php
1 <?php
2
3 require_once 'Sabre/CalDAV/TestUtil.php';
4 require_once 'Sabre/DAV/Auth/MockBackend.php';
5 require_once 'Sabre/DAVACL/MockPrincipalBackend.php';
6 require_once 'Sabre/CalDAV/Backend/Mock.php';
7
8 class Sabre_CalDAV_CalendarObjectTest extends PHPUnit_Framework_TestCase {
9
10     /**
11      * @var Sabre_CalDAV_Backend_PDO
12      */
13     protected $backend;
14     /**
15      * @var Sabre_CalDAV_Calendar
16      */
17     protected $calendar;
18     protected $principalBackend;
19
20     function setup() {
21
22         if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
23         $this->backend = Sabre_CalDAV_TestUtil::getBackend();
24         $this->principalBackend = new Sabre_DAVACL_MockPrincipalBackend;
25
26         $calendars = $this->backend->getCalendarsForUser('principals/user1');
27         $this->assertEquals(2,count($calendars));
28         $this->calendar = new Sabre_CalDAV_Calendar($this->principalBackend,$this->backend, $calendars[0]);
29
30     }
31
32     function teardown() {
33
34         unset($this->calendar);
35         unset($this->backend);
36
37     }
38
39     function testSetup() {
40
41         $children = $this->calendar->getChildren();
42         $this->assertTrue($children[0] instanceof Sabre_CalDAV_CalendarObject);
43
44         $this->assertInternalType('string',$children[0]->getName());
45         $this->assertInternalType('string',$children[0]->get());
46         $this->assertInternalType('string',$children[0]->getETag());
47         $this->assertEquals('text/calendar; charset=utf-8', $children[0]->getContentType());
48
49     }
50
51     /**
52      * @expectedException InvalidArgumentException
53      */
54     function testInvalidArg1() {
55
56         $obj = new Sabre_CalDAV_CalendarObject(
57             new Sabre_CalDAV_Backend_Mock(array(),array()),
58             array(),
59             array()
60         );
61
62     }
63
64     /**
65      * @expectedException InvalidArgumentException
66      */
67     function testInvalidArg2() {
68
69         $obj = new Sabre_CalDAV_CalendarObject(
70             new Sabre_CalDAV_Backend_Mock(array(),array()),
71             array(),
72             array('calendarid' => '1')
73         );
74
75     }
76
77     /**
78      * @depends testSetup
79      */
80     function testPut() {
81
82         $children = $this->calendar->getChildren();
83         $this->assertTrue($children[0] instanceof Sabre_CalDAV_CalendarObject);
84         $newData = Sabre_CalDAV_TestUtil::getTestCalendarData();
85
86         $children[0]->put($newData);
87         $this->assertEquals($newData, $children[0]->get());
88
89     }
90
91     /**
92      * @depends testSetup
93      */
94     function testPutStream() {
95
96         $children = $this->calendar->getChildren();
97         $this->assertTrue($children[0] instanceof Sabre_CalDAV_CalendarObject);
98         $newData = Sabre_CalDAV_TestUtil::getTestCalendarData();
99
100         $stream = fopen('php://temp','r+');
101         fwrite($stream, $newData);
102         rewind($stream);
103         $children[0]->put($stream);
104         $this->assertEquals($newData, $children[0]->get());
105
106     }
107
108
109     /**
110      * @depends testSetup
111      */
112     function testDelete() {
113
114         $children = $this->calendar->getChildren();
115         $this->assertTrue($children[0] instanceof Sabre_CalDAV_CalendarObject);
116
117         $obj = $children[0];
118         $obj->delete();
119
120         $children2 =  $this->calendar->getChildren();
121         $this->assertEquals(count($children)-1, count($children2));
122
123     }
124
125     /**
126      * @depends testSetup
127      */
128     function testGetLastModified() {
129
130         $children = $this->calendar->getChildren();
131         $this->assertTrue($children[0] instanceof Sabre_CalDAV_CalendarObject);
132
133         $obj = $children[0];
134
135         $lastMod = $obj->getLastModified();
136         $this->assertTrue(is_int($lastMod) || ctype_digit($lastMod));
137
138     }
139
140     /**
141      * @depends testSetup
142      */
143     function testGetSize() {
144
145         $children = $this->calendar->getChildren();
146         $this->assertTrue($children[0] instanceof Sabre_CalDAV_CalendarObject);
147
148         $obj = $children[0];
149
150         $size = $obj->getSize();
151         $this->assertInternalType('int', $size);
152
153     }
154
155     function testGetOwner() {
156
157         $children = $this->calendar->getChildren();
158         $this->assertTrue($children[0] instanceof Sabre_CalDAV_CalendarObject);
159
160         $obj = $children[0];
161         $this->assertEquals('principals/user1', $obj->getOwner());
162
163     }
164
165     function testGetGroup() {
166
167         $children = $this->calendar->getChildren();
168         $this->assertTrue($children[0] instanceof Sabre_CalDAV_CalendarObject);
169
170         $obj = $children[0];
171         $this->assertNull($obj->getGroup());
172
173     }
174
175     function testGetACL() {
176
177         $expected = array(
178             array(
179                 'privilege' => '{DAV:}read',
180                 'principal' => 'principals/user1',
181                 'protected' => true,
182             ),
183             array(
184                 'privilege' => '{DAV:}write',
185                 'principal' => 'principals/user1',
186                 'protected' => true,
187             ),
188             array(
189                 'privilege' => '{DAV:}read',
190                 'principal' => 'principals/user1/calendar-proxy-write',
191                 'protected' => true,
192             ),
193             array(
194                 'privilege' => '{DAV:}write',
195                 'principal' => 'principals/user1/calendar-proxy-write',
196                 'protected' => true,
197             ),
198             array(
199                 'privilege' => '{DAV:}read',
200                 'principal' => 'principals/user1/calendar-proxy-read',
201                 'protected' => true,
202             ),
203         );
204
205         $children = $this->calendar->getChildren();
206         $this->assertTrue($children[0] instanceof Sabre_CalDAV_CalendarObject);
207
208         $obj = $children[0];
209         $this->assertEquals($expected, $obj->getACL());
210
211     }
212
213     /**
214      * @expectedException Sabre_DAV_Exception_MethodNotAllowed
215      */
216     function testSetACL() {
217
218         $children = $this->calendar->getChildren();
219         $this->assertTrue($children[0] instanceof Sabre_CalDAV_CalendarObject);
220
221         $obj = $children[0];
222         $obj->setACL(array());
223
224     }
225
226     function testGet() {
227
228         $children = $this->calendar->getChildren();
229         $this->assertTrue($children[0] instanceof Sabre_CalDAV_CalendarObject);
230
231         $obj = $children[0];
232
233             $expected = "BEGIN:VCALENDAR
234 VERSION:2.0
235 PRODID:-//Apple Inc.//iCal 4.0.1//EN
236 CALSCALE:GREGORIAN
237 BEGIN:VTIMEZONE
238 TZID:Asia/Seoul
239 BEGIN:DAYLIGHT
240 TZOFFSETFROM:+0900
241 RRULE:FREQ=YEARLY;UNTIL=19880507T150000Z;BYMONTH=5;BYDAY=2SU
242 DTSTART:19870510T000000
243 TZNAME:GMT+09:00
244 TZOFFSETTO:+1000
245 END:DAYLIGHT
246 BEGIN:STANDARD
247 TZOFFSETFROM:+1000
248 DTSTART:19881009T000000
249 TZNAME:GMT+09:00
250 TZOFFSETTO:+0900
251 END:STANDARD
252 END:VTIMEZONE
253 BEGIN:VEVENT
254 CREATED:20100225T154229Z
255 UID:39A6B5ED-DD51-4AFE-A683-C35EE3749627
256 TRANSP:TRANSPARENT
257 SUMMARY:Something here
258 DTSTAMP:20100228T130202Z
259 DTSTART;TZID=Asia/Seoul:20100223T060000
260 DTEND;TZID=Asia/Seoul:20100223T070000
261 ATTENDEE;PARTSTAT=NEEDS-ACTION:mailto:lisa@example.com
262 SEQUENCE:2
263 END:VEVENT
264 END:VCALENDAR";
265
266
267
268         $this->assertEquals($expected, $obj->get());
269
270     }
271
272     function testGetRefetch() {
273
274         $backend = new Sabre_CalDAV_Backend_Mock(array(), array(
275             1 => array(
276                 'foo' => array(
277                     'calendardata' => 'foo',
278                     'uri' => 'foo'
279                 ),
280             )
281         ));
282         $obj = new Sabre_CalDAV_CalendarObject($backend, array(), array('calendarid' => 1, 'uri' => 'foo'));
283
284         $this->assertEquals('foo', $obj->get());
285
286     }
287
288     function testGetEtag1() {
289
290         $objectInfo = array(
291             'calendardata' => 'foo',
292             'uri' => 'foo',
293             'etag' => 'bar',
294             'calendarid' => 1
295         );
296
297         $backend = new Sabre_CalDAV_Backend_Mock(array(), array());
298         $obj = new Sabre_CalDAV_CalendarObject($backend, array(), $objectInfo);
299
300         $this->assertEquals('bar', $obj->getETag());
301
302     }
303
304     function testGetEtag2() {
305
306         $objectInfo = array(
307             'calendardata' => 'foo',
308             'uri' => 'foo',
309             'calendarid' => 1
310         );
311
312         $backend = new Sabre_CalDAV_Backend_Mock(array(), array());
313         $obj = new Sabre_CalDAV_CalendarObject($backend, array(), $objectInfo);
314
315         $this->assertEquals('"' . md5('foo') . '"', $obj->getETag());
316
317     }
318
319     function testGetSupportedPrivilegesSet() {
320
321         $objectInfo = array(
322             'calendardata' => 'foo',
323             'uri' => 'foo',
324             'calendarid' => 1
325         );
326
327         $backend = new Sabre_CalDAV_Backend_Mock(array(), array());
328         $obj = new Sabre_CalDAV_CalendarObject($backend, array(), $objectInfo);
329         $this->assertNull($obj->getSupportedPrivilegeSet());
330
331     }
332
333     function testGetSize1() {
334
335         $objectInfo = array(
336             'calendardata' => 'foo',
337             'uri' => 'foo',
338             'calendarid' => 1
339         );
340
341         $backend = new Sabre_CalDAV_Backend_Mock(array(), array());
342         $obj = new Sabre_CalDAV_CalendarObject($backend, array(), $objectInfo);
343         $this->assertEquals(3, $obj->getSize());
344
345     }
346
347     function testGetSize2() {
348
349         $objectInfo = array(
350             'uri' => 'foo',
351             'calendarid' => 1,
352             'size' => 4,
353         );
354
355         $backend = new Sabre_CalDAV_Backend_Mock(array(), array());
356         $obj = new Sabre_CalDAV_CalendarObject($backend, array(), $objectInfo);
357         $this->assertEquals(4, $obj->getSize());
358
359     }
360 }