45e362ff0694a84ca0bffa982be5dcfaedb47573
[tine20] / tests / tine20 / Calendar / Convert / Event / VCalendar / GenericTest.php
1 <?php
2 /**
3  * Tine 2.0 - http://www.tine20.org
4  * 
5  * @package     Calendar
6  * @license     http://www.gnu.org/licenses/agpl.html
7  * @copyright   Copyright (c) 2011-2012 Metaways Infosystems GmbH (http://www.metaways.de)
8  * @author      Lars Kneschke <l.kneschke@metaways.de>
9  */
10
11 /**
12  * Test helper
13  */
14 require_once dirname(dirname(dirname(dirname(dirname(__FILE__))))) . DIRECTORY_SEPARATOR . 'TestHelper.php';
15
16 /**
17  * Test class for Calendar_Convert_Event_VCalendar_Generic
18  */
19 class Calendar_Convert_Event_VCalendar_GenericTest extends PHPUnit_Framework_TestCase
20 {
21     /**
22      * @var array test objects
23      */
24     protected $objects = array();
25     
26     /**
27      * Runs the test methods of this class.
28      *
29      * @access public
30      * @static
31      */
32     public static function main()
33     {
34         $suite  = new PHPUnit_Framework_TestSuite('Tine 2.0 Calendar WebDAV Generic Event Tests');
35         PHPUnit_TextUI_TestRunner::run($suite);
36     }
37
38     /**
39      * Sets up the fixture.
40      * This method is called before a test is executed.
41      *
42      * @access protected
43      */
44     protected function setUp()
45     {
46         Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb());
47     }
48
49     /**
50      * Tears down the fixture
51      * This method is called after a test is executed.
52      *
53      * @access protected
54      */
55     protected function tearDown()
56     {
57         Tinebase_TransactionManager::getInstance()->rollBack();
58     }
59     
60     /**
61      * test converting vcard from lighting to Calendar_Model_Event
62      * 
63      * @return Calendar_Model_Event
64      */
65     public function testConvertToTine20Model()
66     {
67         $event = $this->_convertHelper(dirname(__FILE__) . '/../../../Import/files/lightning.ics');
68         //var_dump($event->toArray());
69         
70         $this->assertEquals(Calendar_Model_Event::CLASS_PRIVATE, $event->class);
71         $this->assertEquals('Hamburg',                           $event->location);
72         $this->assertEquals('Europe/Berlin',                     $event->originator_tz);
73         $this->assertEquals("2011-10-04 10:00:00",               (string)$event->dtend);
74         $this->assertEquals("2011-10-04 08:00:00",               (string)$event->dtstart);
75         $this->assertEquals("2011-10-04 06:45:00",               (string)$event->alarms[0]->alarm_time);
76         $this->assertEquals("75",                                (string)$event->alarms[0]->minutes_before);
77         $this->assertEquals("This is a descpription\nwith a linebreak and a ; , and :", $event->description);
78         $this->assertEquals(2, count($event->attendee));
79         $this->assertEquals(1, count($event->alarms));
80         
81         return $event;
82     }
83     
84     /**
85      * convert helper
86      * 
87      * @param string $filename
88      * @return Calendar_Model_Event
89      */
90     protected function _convertHelper($filename)
91     {
92         $vcalendar = Calendar_Frontend_WebDAV_EventTest::getVCalendar($filename);
93         $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC);
94         $event = $converter->toTine20Model($vcalendar);
95         
96         return $event;
97     }
98     
99     /**
100      * test converting vcalendar from iCloud to Calendar_Model_Event
101      *
102      * @return Calendar_Model_Event
103      */
104     public function testConvertToTine20ModelFromICloud()
105     {
106         $vcalendar = Calendar_Frontend_WebDAV_EventTest::getVCalendar(dirname(__FILE__) . '/../../../Import/files/calendarserver_external_invitation.ics');
107         $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC);
108         $event = $converter->toTine20Model($vcalendar);
109     
110         //var_dump($event->toArray());
111     
112         $this->assertEquals(Calendar_Model_Event::CLASS_PUBLIC,     $event->class);
113         $this->assertEquals('9320E052-6AF0-45E7-9352-04BBEC898D47', $event->uid);
114         $this->assertEquals(2, count($event->attendee));
115         $this->assertTrue(!empty($event->organizer));
116     
117         return $event;
118     }
119     
120     /**
121      * test converting vcalendar from Lotus Notes to Calendar_Model_Event
122      *
123      * @return Calendar_Model_Event
124      */
125     public function testConvertToTine20ModelFromLotusNotes()
126     {
127         $vcalendar = Calendar_Frontend_WebDAV_EventTest::getVCalendar(dirname(__FILE__) . '/../../../Import/files/lotusnotes_external_invitation.ics');
128         $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC);
129         $event = $converter->toTine20Model($vcalendar);
130     
131         //var_dump($event->toArray());
132     
133         $this->assertEquals(Calendar_Model_Event::CLASS_PUBLIC,     $event->class);
134         $this->assertEquals('A5C4058C8C5926C8C12579B100622D66-Lotus_Notes_Generated', $event->uid);
135         $this->assertEquals(3, count($event->attendee));
136         $this->assertTrue(!empty($event->organizer));
137     
138         return $event;
139     }
140     
141     /**
142     * test converting vcard from lighting to Calendar_Model_Event (with unrecognized timezone)
143     */
144     public function testConvertToTine20ModelWithBadTZ()
145     {
146         $vcalendarStream = Calendar_Frontend_WebDAV_EventTest::getVCalendar(dirname(__FILE__) . '/../../../Import/files/lightning_badTZ.ics', 'r');
147         $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC);
148         $event = $converter->toTine20Model($vcalendarStream);
149         
150         $this->assertEquals('Europe/Berlin', $event->originator_tz);
151     }
152     
153     /**
154      * test converting vcard from lighting to Calendar_Model_Event
155      *
156      * @return Calendar_Model_Event
157      */
158     public function testConvertToTine20ModelWithGroupInvitation()
159     {
160         $smtpConfig = Tinebase_Config::getInstance()->get(Tinebase_Model_Config::SMTP, new Tinebase_Config_Struct())->toArray();
161         if (!isset($smtpConfig['primarydomain'])) {
162             $this->markTestSkipped('no primary smtp domain configured');
163         }
164         
165         $vcalendar = Calendar_Frontend_WebDAV_EventTest::getVCalendar(dirname(__FILE__) . '/../../../Import/files/lightning.ics');
166     
167         $vcalendar = preg_replace('/lars@kneschke.de/', 'users@' . $smtpConfig['primarydomain'], $vcalendar);
168     
169         $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC);
170         $event = $converter->toTine20Model($vcalendar);
171     
172         #var_dump($event->attendee->toArray());
173     
174         $this->assertEquals(2, count($event->attendee));
175         $this->assertContains('group', $event->attendee->user_type);
176     
177         return $event;
178     }
179     
180    /**
181     * test converting vcard with status
182     */
183     public function testConvertToTine20ModelWithStatus()
184     {
185         $vcalendar = Calendar_Frontend_WebDAV_EventTest::getVCalendar(dirname(__FILE__) . '/../../../Import/files/lightning.ics', 'r');
186         $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC);
187         
188         $vcalendar = str_replace('LOCATION:Hamburg', 'STATUS:CONFIRMED', $vcalendar);
189         $event = $converter->toTine20Model($vcalendar);
190         $this->assertEquals(Calendar_Model_Event::STATUS_CONFIRMED, $event->status);
191         
192         $vcalendar = str_replace('STATUS:CONFIRMED', 'STATUS:TENTATIVE', $vcalendar);
193         $event = $converter->toTine20Model($vcalendar);
194         $this->assertEquals(Calendar_Model_Event::STATUS_TENTATIVE, $event->status);
195         
196         $vcalendar = str_replace('STATUS:TENTATIVE', 'STATUS:CANCELED', $vcalendar);
197         $event = $converter->toTine20Model($vcalendar);
198         $this->assertEquals(Calendar_Model_Event::STATUS_CANCELED, $event->status);
199     }
200     
201     /**
202      * test converting vcard from sogo connector to Calendar_Model_Event
203      * @return Calendar_Model_Event
204      */
205     public function _testConvertFromIcalToTine20Model()
206     {
207         $vcalendarStream = Calendar_Frontend_WebDAV_EventTest::getVCalendar(dirname(__FILE__) . '/../../../Import/files/lightning.ics', 'r');
208     
209         $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC);
210     
211         $event = $converter->toTine20Model($vcalendarStream);
212     
213         #var_dump($event->toArray());
214     
215         $this->assertEquals(Calendar_Model_Event::CLASS_PRIVATE, $event->class);
216         $this->assertEquals('Hamburg',                           $event->location);
217         $this->assertEquals('Europe/Berlin',                     $event->originator_tz);
218         $this->assertEquals("2011-10-04 10:00:00",               (string)$event->dtend);
219         $this->assertEquals("2011-10-04 08:00:00",               (string)$event->dtstart);
220         $this->assertEquals("2011-10-04 06:45:00",               (string)$event->alarms[0]->alarm_time);
221         $this->assertEquals("75",                                (string)$event->alarms[0]->minutes_before);
222     
223         return $event;
224     }
225     
226     /**
227      * test converting vcard from sogo connector to Calendar_Model_Event
228      * @return Calendar_Model_Event
229      */
230     public function testConvertAllDayEventToTine20Model()
231     {
232         $vcalendarStream = Calendar_Frontend_WebDAV_EventTest::getVCalendar(dirname(__FILE__) . '/../../../Import/files/lightning_allday.ics', 'r');
233     
234         $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC);
235     
236         $event = $converter->toTine20Model($vcalendarStream);
237         
238         #var_dump($event->toArray());
239         #var_dump($event->dtend);
240         
241         $this->assertEquals(Calendar_Model_Event::CLASS_PRIVATE, $event->class);
242         $this->assertEquals('Hamburg',                           $event->location);
243         $this->assertEquals("2011-10-19 21:59:59",               (string)$event->dtend   , 'DTEND mismatch');
244         $this->assertEquals("2011-10-18 22:00:00",               (string)$event->dtstart , 'DTSTART mismatch');
245         $this->assertTrue($event->is_all_day_event , 'All day event mismatch');
246         $this->assertEquals("2011-10-19 00:00:00",               (string)$event->alarms[0]->alarm_time);
247     
248         return $event;
249     }
250     
251     /**
252      * test converting vcard with daily repeating event to Calendar_Model_Event
253      * @return Calendar_Model_Event
254      */
255     public function testConvertRepeatingDailyEventToTine20Model()
256     {
257         $vcalendarStream = Calendar_Frontend_WebDAV_EventTest::getVCalendar(dirname(__FILE__) . '/../../../Import/files/lightning_repeating_daily.ics', 'r');
258     
259         $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC);
260     
261         $event = $converter->toTine20Model($vcalendarStream);
262     
263         #var_dump($event->exdate[3]->recurid->format('hm'));
264         #var_dump($event->dtstart->format('hm'));
265     
266         $this->assertEquals('FREQ=DAILY;UNTIL=2011-10-30 06:00:00', $event->rrule);
267         $this->assertEquals(4, count($event->exdate));
268         $this->assertEquals($event->uid,            $event->exdate[3]->uid);
269         $this->assertEquals("2011-10-08 13:00:00",  (string)$event->exdate[3]->dtend   , 'DTEND mismatch');
270         $this->assertEquals("2011-10-08 11:00:00",  (string)$event->exdate[3]->dtstart , 'DTSTART mismatch');
271         $this->assertEquals($event->dtstart->format('hm'),  $event->exdate[3]->recurid->format('hm') , 'Recurid mismatch');
272         
273         return $event;
274     }
275     
276     /**
277      * test converting vcard with daily repeating event to Calendar_Model_Event
278      * @return Calendar_Model_Event
279      */
280     public function testConvertRepeatingAllDayDailyEventToTine20Model()
281     {
282         $vcalendarStream = Calendar_Frontend_WebDAV_EventTest::getVCalendar(dirname(__FILE__) . '/../../../Import/files/apple_caldendar_repeating_allday.ics', 'r');
283     
284         $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC);
285     
286         $event = $converter->toTine20Model($vcalendarStream);
287     
288         #var_dump($event->exdate->toArray());
289         #var_dump($event->dtstart->format('hm'));
290         
291         $this->assertEquals('FREQ=DAILY;UNTIL=2011-11-11 23:00:00;INTERVAL=1', $event->rrule, 'until must be converted');
292         $this->assertEquals(TRUE, $event->is_all_day_event);
293         $this->assertEquals('TRANSPARENT', $event->transp);
294         $this->assertEquals('PUBLIC', $event->class);
295         $this->assertEquals("2011-11-07 23:00:00", (string) $event->dtstart, 'DTEND mismatch');
296         $this->assertEquals("2011-11-08 22:59:59", (string) $event->dtend,   'DTSTART mismatch');
297         $this->assertEquals("2011-11-10 23:00:00", (string) $event->exdate[0]->recurid, 'RECURID mismatch');
298         
299         return $event;
300     }
301     
302     /**
303      * test converting vcard with daily repeating event to Calendar_Model_Event
304      * @return Calendar_Model_Event
305      */
306     public function testConvertRepeatingAllDayDailyEventFromTine20Model()
307     {
308         $event = $this->testConvertRepeatingAllDayDailyEventToTine20Model();
309         $event->creation_time      = new Tinebase_DateTime('2011-11-11 11:11', 'UTC');
310         $event->last_modified_time = new Tinebase_DateTime('2011-11-11 12:12', 'UTC');
311         $event->organizer          = Tinebase_Core::getUser()->contact_id;
312         
313         $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC);
314         
315         $vevent = $converter->fromTine20Model($event)->serialize();
316         
317         //var_dump($vevent);
318         $this->assertContains('VERSION:2.0',                                    $vevent, $vevent);
319         $this->assertContains('PRODID:-//tine20.org//Tine 2.0 Calendar V',      $vevent, $vevent);
320         $this->assertContains('CREATED;VALUE=DATE-TIME:20111111T111100Z',       $vevent, $vevent);
321         $this->assertContains('LAST-MODIFIED;VALUE=DATE-TIME:20111111T121200Z', $vevent, $vevent);
322         $this->assertContains('DTSTAMP;VALUE=DATE-TIME:',                       $vevent, $vevent);
323         $this->assertContains('RRULE:FREQ=DAILY;UNTIL=20111112;INTERVAL=1',     $vevent, $vevent);
324         $this->assertContains('EXDATE;VALUE=DATE:20111111',                     $vevent, $vevent);
325         $this->assertContains('ORGANIZER;CN="' . Tinebase_Core::getUser()->accountDisplayName . '";EMAIL=' . Tinebase_Core::getUser()->accountEmailAddress . ':', $vevent, $vevent);
326     }
327     
328     /**
329      * test converting vcard with daily repeating event to Calendar_Model_Event
330      * and merge with existing event
331      * @return Calendar_Model_Event
332      */
333     public function disabled_testConvertRepeatingDailyEventToTine20ModelWithMerge()
334     {
335         $event = $this->testConvertRepeatingDailyEventToTine20Model();
336         
337         $vcalendarStream = Calendar_Frontend_WebDAV_EventTest::getVCalendar(dirname(__FILE__) . '/../../../Import/files/lightning_repeating_daily.ics', 'r');
338     
339         $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC);
340         
341         $event->exdate[3]->attendee[0]->status_authkey = 'TestMe';
342         
343         $updatedEvent = $converter->toTine20Model($vcalendarStream, clone $event);
344     
345         //var_dump($event->exdate->toArray());
346         #var_dump($updatedEvent->exdate[3]->attendee->toArray());
347         #var_dump($event->dtstart->format('hm'));
348     
349         $this->assertTrue(! empty($updatedEvent->exdate[3]->attendee[0]->status_authkey));
350         $this->assertEquals($event->exdate[3]->attendee[0]->status_authkey, $updatedEvent->exdate[3]->attendee[0]->status_authkey);
351     
352         return $event;
353     }
354     
355     /**
356      * test converting vcard from sogo connector to Calendar_Model_Event 
357      */
358     public function testConvertToTine20ModelWithUpdate()
359     {
360         $vcalendarStream = Calendar_Frontend_WebDAV_EventTest::getVCalendar(dirname(__FILE__) . '/../../../Import/files/lightning.ics', 'r');
361         
362         $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC);
363         
364         $event = $converter->toTine20Model($vcalendarStream);
365         
366         // status_authkey must be kept after second convert
367         $event->attendee[0]->quantity = 10;
368         
369         $vcalendar = Calendar_Frontend_WebDAV_EventTest::getVCalendar(dirname(__FILE__) . '/../../../Import/files/lightning.ics');
370         // remove alarm part from vcalendar
371         $vcalendar = preg_replace('/BEGIN:VALARM.*END:VALARM(\n|\r\n)/s', null, $vcalendar);
372         
373         $event = $converter->toTine20Model($vcalendar, $event);
374         
375         $this->assertEquals(10, $event->attendee[0]->quantity);
376         $this->assertTrue($event->alarms instanceof Tinebase_Record_RecordSet);
377         $this->assertEquals(0, count($event->alarms));
378     }    
379
380     /**
381      * @depends testConvertToTine20Model
382      */
383     public function testConvertFromTine20Model()
384     {
385         $event = $this->testConvertToTine20Model();
386         $event->creation_time      = new Tinebase_DateTime('2011-11-11 11:11', 'UTC');
387         $event->last_modified_time = new Tinebase_DateTime('2011-11-11 12:12', 'UTC');
388         $event->attendee = new Tinebase_Record_RecordSet('Calendar_Model_Attender');
389         
390         $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC);
391         
392         $vevent = $converter->fromTine20Model($event)->serialize();
393         // var_dump($vevent);
394         // required fields
395         $this->assertContains('VERSION:2.0',                                    $vevent, $vevent);
396         $this->assertContains('PRODID:-//tine20.org//Tine 2.0 Calendar V',      $vevent, $vevent);
397         $this->assertContains('CREATED;VALUE=DATE-TIME:20111111T111100Z',       $vevent, $vevent);
398         $this->assertContains('LAST-MODIFIED;VALUE=DATE-TIME:20111111T121200Z', $vevent, $vevent);
399         $this->assertContains('DTSTAMP;VALUE=DATE-TIME:',                       $vevent, $vevent);
400         $this->assertContains('TZID:Europe/Berlin',               $vevent, $vevent);
401         $this->assertContains('UID:' . $event->uid,               $vevent, $vevent);
402         $this->assertContains('LOCATION:' . $event->location,     $vevent, $vevent);
403         $this->assertContains('CLASS:PRIVATE',                    $vevent, $vevent);
404         $this->assertContains('TZOFFSETFROM:+0100',  $vevent, $vevent);
405         $this->assertContains('TZOFFSETTO:+0200',  $vevent, $vevent);
406         $this->assertContains('TZNAME:CEST',  $vevent, $vevent);
407         $this->assertContains('TZOFFSETFROM:+0200',  $vevent, $vevent);
408         $this->assertContains('TZOFFSETTO:+0100',  $vevent, $vevent);
409         $this->assertContains('TZNAME:CET',  $vevent, $vevent);
410         
411     }
412     
413     /**
414      * @depends testConvertToTine20Model
415      */
416     public function testConvertFromTine20ModelWithCurrentUserAsAttendee()
417     {
418         $event = $this->testConvertToTine20Model();
419         $event->creation_time      = new Tinebase_DateTime('2011-11-11 11:11', 'UTC');
420         $event->last_modified_time = new Tinebase_DateTime('2011-11-11 12:12', 'UTC');
421         $event->attendee->addRecord(new Calendar_Model_Attender(array(
422             'user_id'   => Tinebase_Core::getUser()->contact_id,
423             'user_type' => Calendar_Model_Attender::USERTYPE_USER,
424             'role'      => Calendar_Model_Attender::ROLE_REQUIRED,
425             'status'    => Calendar_Model_Attender::STATUS_ACCEPTED
426         )));
427         
428         $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC);
429         
430         $vevent = $converter->fromTine20Model($event)->serialize();
431         // var_dump($vevent);
432         // required fields
433         $this->assertContains('VERSION:2.0',                                    $vevent, $vevent);
434         $this->assertContains('PRODID:-//tine20.org//Tine 2.0 Calendar V',      $vevent, $vevent);
435         $this->assertContains('CREATED;VALUE=DATE-TIME:20111111T111100Z',       $vevent, $vevent);
436         $this->assertContains('LAST-MODIFIED;VALUE=DATE-TIME:20111111T121200Z', $vevent, $vevent);
437         $this->assertContains('DTSTAMP;VALUE=DATE-TIME:',         $vevent, $vevent);
438         $this->assertContains('TZID:Europe/Berlin',               $vevent, $vevent);
439         $this->assertContains('UID:' . $event->uid,               $vevent, $vevent);
440         $this->assertContains('LOCATION:' . $event->location,     $vevent, $vevent);
441         $this->assertContains('CLASS:PRIVATE',                    $vevent, $vevent);
442         $this->assertContains('TRIGGER;VALUE=DURATION:-PT1H15M',  $vevent, $vevent);
443         $this->assertContains('TZOFFSETFROM:+0100',  $vevent, $vevent);
444         $this->assertContains('TZOFFSETTO:+0200',  $vevent, $vevent);
445         $this->assertContains('TZNAME:CEST',  $vevent, $vevent);
446         $this->assertContains('TZOFFSETFROM:+0200',  $vevent, $vevent);
447         $this->assertContains('TZOFFSETTO:+0100',  $vevent, $vevent);
448         $this->assertContains('TZNAME:CET',  $vevent, $vevent);
449         
450     }
451     
452     /**
453      * 
454      * @depends testConvertAllDayEventToTine20Model
455      */
456     public function testConvertFromAllDayEventTine20Model()
457     {
458         $event = $this->testConvertAllDayEventToTine20Model();
459         $event->creation_time      = new Tinebase_DateTime('2011-11-11 11:11', 'UTC');
460         $event->last_modified_time = new Tinebase_DateTime('2011-11-11 12:12', 'UTC');
461         $event->attendee->addRecord(new Calendar_Model_Attender(array(
462             'user_id'   => Tinebase_Core::getUser()->contact_id,
463             'user_type' => Calendar_Model_Attender::USERTYPE_USER,
464             'role'      => Calendar_Model_Attender::ROLE_REQUIRED,
465             'status'    => Calendar_Model_Attender::STATUS_ACCEPTED
466         )));
467         
468         $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC);
469         
470         $vevent = $converter->fromTine20Model($event)->serialize();
471         // var_dump($vevent);
472         // required fields
473         $this->assertContains('VERSION:2.0',                                    $vevent, $vevent);
474         $this->assertContains('PRODID:-//tine20.org//Tine 2.0 Calendar V',      $vevent, $vevent);
475         $this->assertContains('CREATED;VALUE=DATE-TIME:20111111T111100Z',       $vevent, $vevent);
476         $this->assertContains('LAST-MODIFIED;VALUE=DATE-TIME:20111111T121200Z', $vevent, $vevent);
477         $this->assertContains('DTSTAMP;VALUE=DATE-TIME:',         $vevent, $vevent);
478         $this->assertContains('DTSTART;VALUE=DATE:20111019',      $vevent, $vevent);
479         $this->assertContains('DTEND;VALUE=DATE:20111020',        $vevent, $vevent);
480         $this->assertContains('TZID:Europe/Berlin',               $vevent, $vevent);
481         $this->assertContains('UID:' . $event->uid,               $vevent, $vevent);
482         $this->assertContains('LOCATION:' . $event->location,     $vevent, $vevent);
483         $this->assertContains('CLASS:PRIVATE',                    $vevent, $vevent);
484         $this->assertContains('TRIGGER;VALUE=DATE-TIME:20111019T000000Z',  $vevent, $vevent);
485         $this->assertContains('TZOFFSETFROM:+0100',  $vevent, $vevent);
486         $this->assertContains('TZOFFSETTO:+0200',    $vevent, $vevent);
487         $this->assertContains('TZNAME:CEST',         $vevent, $vevent);
488         $this->assertContains('TZOFFSETFROM:+0200',  $vevent, $vevent);
489         $this->assertContains('TZOFFSETTO:+0100',    $vevent, $vevent);
490         $this->assertContains('TZNAME:CET',          $vevent, $vevent);
491         
492     }
493     
494     /**
495      * 
496      * @depends testConvertToTine20Model
497      */
498     public function testConvertRepeatingEventFromTine20Model()
499     {
500         $event = $this->testConvertRepeatingDailyEventToTine20Model();
501         $event->creation_time          = new Tinebase_DateTime('2011-11-11 11:11', 'UTC');
502         $event->last_modified_time     = new Tinebase_DateTime('2011-11-11 12:12', 'UTC');
503         $event->exdate->creation_time  = new Tinebase_DateTime('2011-11-11 11:11', 'UTC');
504         
505         $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC);
506         
507         $vevent = $converter->fromTine20Model($event)->serialize();
508         #var_dump($vevent);
509         // required fields
510         $this->assertContains('VERSION:2.0', $vevent, $vevent);
511         $this->assertContains('PRODID:-//tine20.org//Tine 2.0 Calendar V',      $vevent, $vevent);
512         $this->assertContains('CREATED;VALUE=DATE-TIME:20111111T111100Z',       $vevent, $vevent);
513         $this->assertContains('LAST-MODIFIED;VALUE=DATE-TIME:20111111T121200Z', $vevent, $vevent);
514         $this->assertContains('DTSTAMP;VALUE=DATE-TIME:',                       $vevent, $vevent);
515         $this->assertContains('RRULE:FREQ=DAILY;UNTIL=20111030T060000Z',        $vevent, $vevent);
516         $this->assertContains('EXDATE;VALUE=DATE-TIME:20111005T080000Z',        $vevent, $vevent);
517         $this->assertContains('EXDATE;VALUE=DATE-TIME:20111006T080000Z',        $vevent, $vevent);
518         $this->assertContains('EXDATE;VALUE=DATE-TIME:20111007T080000Z',        $vevent, $vevent);
519         $this->assertContains('TZID:Europe/Berlin',           $vevent, $vevent);
520         $this->assertContains('UID:' . $event->uid,           $vevent, $vevent);
521         $this->assertContains('LOCATION:' . $event->location, $vevent, $vevent);
522         $this->assertContains('CLASS:PRIVATE',                $vevent, $vevent);
523     }
524     
525     public function testConvertFromTine20ModelWithCustomAlarm()
526     {
527         $event = $this->testConvertToTine20Model();
528         $event->creation_time      = new Tinebase_DateTime('2011-11-11 11:11', 'UTC');
529         $event->last_modified_time = new Tinebase_DateTime('2011-11-11 12:12', 'UTC');
530         $event->organizer          = Tinebase_Core::getUser()->contact_id;
531         
532         $event->alarms = new Tinebase_Record_RecordSet('Tinebase_Model_Alarm', array(array(
533             'model'            => 'Calendar_Model_Event',
534             'alarm_time'       => '2011-10-04 07:10:00',
535             'minutes_before'   => Tinebase_Model_Alarm::OPTION_CUSTOM
536         )));
537         
538         $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC);
539         
540         $vevent = $converter->fromTine20Model($event)->serialize();
541         #var_dump($vevent);
542         $this->assertContains('TRIGGER;VALUE=DATE-TIME:20111004T071000Z',        $vevent, $vevent);
543     }
544     
545     public function testConvertFromTine20ModelWithStatus()
546     {
547         $event = $this->testConvertToTine20Model();
548         $event->creation_time      = new Tinebase_DateTime('2011-11-11 11:11', 'UTC');
549         $event->last_modified_time = new Tinebase_DateTime('2011-11-11 12:12', 'UTC');
550         $event->organizer          = Tinebase_Core::getUser()->contact_id;
551         $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC);
552         
553         $event->status = Calendar_Model_Event::STATUS_CONFIRMED;
554         $vevent = $converter->fromTine20Model($event)->serialize();
555         #var_dump($vevent);
556         $this->assertContains('STATUS:CONFIRMED',        $vevent, $vevent);
557         
558         $event->is_deleted = 1;
559         $vevent = $converter->fromTine20Model($event)->serialize();
560         #var_dump($vevent);
561         $this->assertContains('STATUS:CANCELED',        $vevent, $vevent);
562     }
563     
564     public function testConvertToTine20ModelWithCustomAlarm()
565     {
566         $vcalendar = Calendar_Frontend_WebDAV_EventTest::getVCalendar(dirname(__FILE__) . '/../../../Import/files/event_with_custom_alarm.ics');
567         
568         $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC);
569         
570         $event = $converter->toTine20Model($vcalendar);
571         
572         $this->assertTrue($event->alarms instanceof Tinebase_Record_RecordSet);
573         $this->assertEquals(1, count($event->alarms));
574         
575         $alarm = $event->alarms->getFirstRecord();
576         
577         $this->assertEquals(Tinebase_Model_Alarm::OPTION_CUSTOM, $alarm->minutes_before);
578         $this->assertEquals('2012-02-14 17:00:00', $alarm->alarm_time->toString());
579     }
580     
581     /**
582      * testConvertFromGoogleToTine20Model
583      * 
584      * @see 0006110: handle iMIP messages from outlook
585      */
586     public function testConvertFromGoogleToTine20Model()
587     {
588         $event = $this->_convertHelper(dirname(__FILE__) . '/../../../Import/files/invite_google.ics');
589         
590         $this->assertEquals('133st5tjius426l9n1k1sil5rk@google.com', $event->uid);
591         $this->assertEquals('Test-Termin aus Google an Tine20', $event->summary);
592     }
593 }