workaround 10.10 allday event rrule until timezone bug
[tine20] / tests / tine20 / Calendar / Convert / Event / VCalendar / MacOSXTest.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-2015 Metaways Infosystems GmbH (http://www.metaways.de)
8  * @author      Lars Kneschke <l.kneschke@metaways.de>
9  */
10
11 /**
12  * Test class for Calendar_Convert_Event_VCalendar_MacOSX
13  */
14 class Calendar_Convert_Event_VCalendar_MacOSXTest extends Calendar_TestCase
15 {
16     /**
17      * @var array test objects
18      */
19     protected $objects = array();
20
21     /**
22      * testBackslashInDescription
23      *
24      * @see 0009176: iCal adds another backslash to description field
25      */
26     public function testBackslashInDescription()
27     {
28         $event = new Calendar_Model_Event(array(
29             'summary' => 'CalDAV test',
30             'dtstart' => Tinebase_DateTime::now(),
31             'dtend' => Tinebase_DateTime::now()->addHour(1),
32             'description' => 'lalala \\\\',
33             'originator_tz' => 'Europe/Berlin',
34             'creation_time' => Tinebase_DateTime::now(),
35             'uid' => Tinebase_Record_Abstract::generateUID(),
36             'seq' => 1,
37         ));
38
39         $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_MACOSX);
40         $vevent = $converter->fromTine20Model($event)->serialize();
41
42         $convertedEvent = $converter->toTine20Model($vevent);
43
44         $this->assertEquals($event->description, $convertedEvent->description);
45     }
46
47     /**
48      * test converting vcard from apple iCal to Calendar_Model_Event
49      */
50     public function testConvertToTine20Model()
51     {
52         $vcalendarStream = fopen(dirname(__FILE__) . '/../../../Import/files/apple_caldendar_mavericks_organizer_only.ics', 'r');
53
54         $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_MACOSX, '10.9');
55
56         $event = $converter->toTine20Model($vcalendarStream);
57
58         // assert testuser is not attendee
59         $this->assertEquals(1, $event->attendee->count(), 'there sould only be one attendee');
60         $this->assertNotEquals($event->organizer, $event->attendee[0]->user_id, 'organizer should not attend');
61
62         // assert alarm
63         $this->assertEquals(1, $event->alarms->count(), 'there should be exactly one alarm');
64         $this->assertFalse((bool)$event->alarms->getFirstRecord()->getOption('custom'), 'alarm should be duration alarm');
65         $this->assertEquals(15, $event->alarms->getFirstRecord()->minutes_before, 'alarm should be 15 min. before');
66         $this->assertEquals('2013-11-15 11:47:23', Calendar_Controller_Alarm::getAcknowledgeTime($event->alarms->getFirstRecord())->format(Tinebase_Record_Abstract::ISO8601LONG), 'ACKNOWLEDGED was not imported properly');
67     }
68
69     public function testConvertToTine20ModelXCalendarAccess()
70     {
71         $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_MACOSX, '10.10.2');
72
73         $vcalendarStream = fopen(dirname(__FILE__) . '/../../../Import/files/apple_calendar_lion_access_private.ics', 'r');
74         $event = $converter->toTine20Model($vcalendarStream);
75         $this->assertEquals(Calendar_Model_Event::CLASS_PRIVATE, $event->class);
76
77         $vcalendarStream = fopen(dirname(__FILE__) . '/../../../Import/files/apple_calendar_lion_access_attendee.ics', 'r');
78         $event = $converter->toTine20Model($vcalendarStream);
79         $this->assertEquals(Calendar_Model_Event::CLASS_PUBLIC, $event->class);
80
81         $iosPrivateIcs = dirname(__FILE__) . '/../../../Import/files/ios_private.ics';
82         $vcalendarStream = fopen($iosPrivateIcs, 'r');
83         $event = $converter->toTine20Model($vcalendarStream);
84         $this->assertEquals(Calendar_Model_Event::CLASS_PRIVATE, $event->class);
85
86         // try again with ios user agent
87         $iosUserAgent = 'iOS/8.2 (12D508) dataaccessd/1.0';
88         list($backend, $version) = Calendar_Convert_Event_VCalendar_Factory::parseUserAgent($iosUserAgent);
89         $converter = Calendar_Convert_Event_VCalendar_Factory::factory($backend, $version);
90         $vcalendarStream = fopen($iosPrivateIcs, 'r');
91         $event = $converter->toTine20Model($vcalendarStream);
92         $this->assertEquals(Calendar_Model_Event::CLASS_PRIVATE, $event->class);
93     }
94
95     /**
96      * testConvertAllDayEventWithExdate
97      *
98      * - exdate is the base event
99      */
100     public function testConvertAllDayEventWithExdate()
101     {
102         $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_MACOSX, '10.10.2');
103
104         $vcalendarStream = fopen(dirname(__FILE__) . '/../../../Import/files/apple_calendar_birthday.ics', 'r');
105         $updateEvent = $converter->toTine20Model($vcalendarStream);
106         $eventWithExdateOnBaseEvent = Calendar_Controller_MSEventFacade::getInstance()->create($updateEvent);
107
108         $this->assertEquals(1, count($eventWithExdateOnBaseEvent->exdate));
109
110         // refetch existing event here and pass it to converter
111         $eventWithExdateOnBaseEvent = Calendar_Controller_Event::getInstance()->get($eventWithExdateOnBaseEvent->getId());
112
113         $vcalendarStream2 = fopen(dirname(__FILE__) . '/../../../Import/files/apple_calendar_birthday2.ics', 'r');
114         $updateEvent2 = $converter->toTine20Model($vcalendarStream2, $eventWithExdateOnBaseEvent);
115
116         $this->assertEquals(1, count($updateEvent2->exdate), print_r($updateEvent2->toArray(), true));
117         $this->assertEquals('2015-04-27 22:00:00', $updateEvent2->rrule_until);
118     }
119
120     public function testConvertToTine20ModelYosemiteRecurringAllDayWithUntil()
121     {
122         $converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_MACOSX, '10.10.5');
123
124         $vcalendarStream = fopen(dirname(__FILE__) . '/../../../Import/files/apple_calendar_10.10_birthday02-PUT-quit-old.ics', 'r');
125         $event = $converter->toTine20Model($vcalendarStream);
126
127         $this->assertEquals('FREQ=YEARLY;INTERVAL=1;UNTIL=2016-09-17 22:00:00', $event->rrule);
128     }
129 }