1<?php 2 3namespace Sabre\CalDAV; 4 5class TestUtil { 6 7 static function getBackend() { 8 9 $backend = new Backend\PDO(self::getSQLiteDB()); 10 return $backend; 11 12 } 13 14 static function getSQLiteDB() { 15 16 if (file_exists(SABRE_TEMPDIR . '/testdb.sqlite')) 17 unlink(SABRE_TEMPDIR . '/testdb.sqlite'); 18 19 $pdo = new \PDO('sqlite:' . SABRE_TEMPDIR . '/testdb.sqlite'); 20 $pdo->setAttribute(\PDO::ATTR_ERRMODE,\PDO::ERRMODE_EXCEPTION); 21 22 // Yup this is definitely not 'fool proof', but good enough for now. 23 $queries = explode(';', file_get_contents(__DIR__ . '/../../../examples/sql/sqlite.calendars.sql')); 24 foreach($queries as $query) { 25 $pdo->exec($query); 26 } 27 // Inserting events through a backend class. 28 $backend = new Backend\PDO($pdo); 29 $calendarId = $backend->createCalendar( 30 'principals/user1', 31 'UUID-123467', 32 array( 33 '{DAV:}displayname' => 'user1 calendar', 34 '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar description', 35 '{http://apple.com/ns/ical/}calendar-order' => '1', 36 '{http://apple.com/ns/ical/}calendar-color' => '#FF0000', 37 ) 38 ); 39 $backend->createCalendar( 40 'principals/user1', 41 'UUID-123468', 42 array( 43 '{DAV:}displayname' => 'user1 calendar2', 44 '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar description', 45 '{http://apple.com/ns/ical/}calendar-order' => '1', 46 '{http://apple.com/ns/ical/}calendar-color' => '#FF0000', 47 ) 48 ); 49 $backend->createCalendarObject($calendarId, 'UUID-2345', self::getTestCalendarData()); 50 return $pdo; 51 52 } 53 54 static function getTestCalendarData($type = 1) { 55 56 $calendarData = 'BEGIN:VCALENDAR 57VERSION:2.0 58PRODID:-//Apple Inc.//iCal 4.0.1//EN 59CALSCALE:GREGORIAN 60BEGIN:VTIMEZONE 61TZID:Asia/Seoul 62BEGIN:DAYLIGHT 63TZOFFSETFROM:+0900 64RRULE:FREQ=YEARLY;UNTIL=19880507T150000Z;BYMONTH=5;BYDAY=2SU 65DTSTART:19870510T000000 66TZNAME:GMT+09:00 67TZOFFSETTO:+1000 68END:DAYLIGHT 69BEGIN:STANDARD 70TZOFFSETFROM:+1000 71DTSTART:19881009T000000 72TZNAME:GMT+09:00 73TZOFFSETTO:+0900 74END:STANDARD 75END:VTIMEZONE 76BEGIN:VEVENT 77CREATED:20100225T154229Z 78UID:39A6B5ED-DD51-4AFE-A683-C35EE3749627 79TRANSP:TRANSPARENT 80SUMMARY:Something here 81DTSTAMP:20100228T130202Z'; 82 83 switch($type) { 84 case 1 : 85 $calendarData.="\nDTSTART;TZID=Asia/Seoul:20100223T060000\nDTEND;TZID=Asia/Seoul:20100223T070000\n"; 86 break; 87 case 2 : 88 $calendarData.="\nDTSTART:20100223T060000\nDTEND:20100223T070000\n"; 89 break; 90 case 3 : 91 $calendarData.="\nDTSTART;VALUE=DATE:20100223\nDTEND;VALUE=DATE:20100223\n"; 92 break; 93 case 4 : 94 $calendarData.="\nDTSTART;TZID=Asia/Seoul:20100223T060000\nDURATION:PT1H\n"; 95 break; 96 case 5 : 97 $calendarData.="\nDTSTART;TZID=Asia/Seoul:20100223T060000\nDURATION:-P5D\n"; 98 break; 99 case 6 : 100 $calendarData.="\nDTSTART;VALUE=DATE:20100223\n"; 101 break; 102 case 7 : 103 $calendarData.="\nDTSTART;VALUE=DATETIME:20100223T060000\n"; 104 break; 105 106 // No DTSTART, so intentionally broken 107 case 'X' : 108 $calendarData.="\n"; 109 break; 110 } 111 112 113 $calendarData.='ATTENDEE;PARTSTAT=NEEDS-ACTION:mailto:lisa@example.com 114SEQUENCE:2 115END:VEVENT 116END:VCALENDAR'; 117 118 return $calendarData; 119 120 } 121 122 static function getTestTODO($type = 'due') { 123 124 switch($type) { 125 126 case 'due' : 127 $extra = "DUE:20100104T000000Z"; 128 break; 129 case 'due2' : 130 $extra = "DUE:20060104T000000Z"; 131 break; 132 case 'due_date' : 133 $extra = "DUE;VALUE=DATE:20060104"; 134 break; 135 case 'due_tz' : 136 $extra = "DUE;TZID=Asia/Seoul:20060104T000000Z"; 137 break; 138 case 'due_dtstart' : 139 $extra = "DTSTART:20050223T060000Z\nDUE:20060104T000000Z"; 140 break; 141 case 'due_dtstart2' : 142 $extra = "DTSTART:20090223T060000Z\nDUE:20100104T000000Z"; 143 break; 144 case 'dtstart' : 145 $extra = 'DTSTART:20100223T060000Z'; 146 break; 147 case 'dtstart2' : 148 $extra = 'DTSTART:20060223T060000Z'; 149 break; 150 case 'dtstart_date' : 151 $extra = 'DTSTART;VALUE=DATE:20100223'; 152 break; 153 case 'dtstart_tz' : 154 $extra = 'DTSTART;TZID=Asia/Seoul:20100223T060000Z'; 155 break; 156 case 'dtstart_duration' : 157 $extra = "DTSTART:20061023T060000Z\nDURATION:PT1H"; 158 break; 159 case 'dtstart_duration2' : 160 $extra = "DTSTART:20101023T060000Z\nDURATION:PT1H"; 161 break; 162 case 'completed' : 163 $extra = 'COMPLETED:20060601T000000Z'; 164 break; 165 case 'completed2' : 166 $extra = 'COMPLETED:20090601T000000Z'; 167 break; 168 case 'created' : 169 $extra = 'CREATED:20060601T000000Z'; 170 break; 171 case 'created2' : 172 $extra = 'CREATED:20090601T000000Z'; 173 break; 174 case 'completedcreated' : 175 $extra = "CREATED:20060601T000000Z\nCOMPLETED:20070101T000000Z"; 176 break; 177 case 'completedcreated2' : 178 $extra = "CREATED:20090601T000000Z\nCOMPLETED:20100101T000000Z"; 179 break; 180 case 'notime' : 181 $extra = 'X-FILLER:oh hello'; 182 break; 183 default : 184 throw new Exception('Unknown type: ' . $type); 185 186 } 187 188 $todo = 'BEGIN:VCALENDAR 189VERSION:2.0 190PRODID:-//Example Corp.//CalDAV Client//EN 191BEGIN:VTODO 192DTSTAMP:20060205T235335Z 193' . $extra . ' 194STATUS:NEEDS-ACTION 195SUMMARY:Task #1 196UID:DDDEEB7915FA61233B861457@example.com 197BEGIN:VALARM 198ACTION:AUDIO 199TRIGGER;RELATED=START:-PT10M 200END:VALARM 201END:VTODO 202END:VCALENDAR'; 203 204 return $todo; 205 206 } 207 208} 209