Blame view
sources/3rdparty/sabre/vobject/tests/Sabre/VObject/Splitter/ICalendarTest.php
5.62 KB
|
6d9380f96
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
<?php
namespace Sabre\VObject\Splitter;
use Sabre\VObject;
class ICalendarSplitterTest extends \PHPUnit_Framework_TestCase {
protected $version;
function setup() {
$this->version = VObject\Version::VERSION;
}
function createStream($data) {
$stream = fopen('php://memory','r+');
fwrite($stream, $data);
rewind($stream);
return $stream;
}
function testICalendarImportValidEvent() {
$data = <<<EOT
BEGIN:VCALENDAR
BEGIN:VEVENT
UID:foo
END:VEVENT
END:VCALENDAR
EOT;
$tempFile = $this->createStream($data);
$objects = new ICalendar($tempFile);
$return = "";
while($object=$objects->getNext()) {
$return .= $object->serialize();
}
$this->assertEquals(array(), VObject\Reader::read($return)->validate());
}
function testICalendarImportEndOfData() {
$data = <<<EOT
BEGIN:VCALENDAR
BEGIN:VEVENT
UID:foo
END:VEVENT
END:VCALENDAR
EOT;
$tempFile = $this->createStream($data);
$objects = new ICalendar($tempFile);
$return = "";
while($object=$objects->getNext()) {
$return .= $object->serialize();
}
$this->assertNull($object=$objects->getNext());
}
/**
* @expectedException Sabre\VObject\ParseException
*/
function testICalendarImportInvalidEvent() {
$data = <<<EOT
EOT;
$tempFile = $this->createStream($data);
$objects = new ICalendar($tempFile);
}
function testICalendarImportMultipleValidEvents() {
$event[] = <<<EOT
BEGIN:VEVENT
UID:foo1
END:VEVENT
EOT;
$event[] = <<<EOT
BEGIN:VEVENT
UID:foo2
END:VEVENT
EOT;
$data = <<<EOT
BEGIN:VCALENDAR
$event[0]
$event[1]
END:VCALENDAR
EOT;
$tempFile = $this->createStream($data);
$objects = new ICalendar($tempFile);
$return = "";
$i = 0;
while($object=$objects->getNext()) {
$expected = <<<EOT
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Sabre//Sabre VObject $this->version//EN
CALSCALE:GREGORIAN
$event[$i]
END:VCALENDAR
EOT;
$return .= $object->serialize();
$expected = str_replace("
", "\r
", $expected);
$this->assertEquals($expected, $object->serialize());
$i++;
}
$this->assertEquals(array(), VObject\Reader::read($return)->validate());
}
function testICalendarImportEventWithoutUID() {
$data = <<<EOT
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Sabre//Sabre VObject $this->version//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
END:VEVENT
END:VCALENDAR
EOT;
$tempFile = $this->createStream($data);
$objects = new ICalendar($tempFile);
$return = "";
while($object=$objects->getNext()) {
$expected = str_replace("
", "\r
", $data);
$this->assertEquals($expected, $object->serialize());
$return .= $object->serialize();
}
$this->assertEquals(array(), VObject\Reader::read($return)->validate());
}
function testICalendarImportMultipleVTIMEZONESAndMultipleValidEvents() {
$timezones = <<<EOT
BEGIN:VTIMEZONE
TZID:Europe/Berlin
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
DTSTART:19810329T020000
TZNAME:MESZ
TZOFFSETTO:+0200
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
DTSTART:19961027T030000
TZNAME:MEZ
TZOFFSETTO:+0100
END:STANDARD
END:VTIMEZONE
BEGIN:VTIMEZONE
TZID:Europe/London
BEGIN:DAYLIGHT
TZOFFSETFROM:+0000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
DTSTART:19810329T010000
TZNAME:GMT+01:00
TZOFFSETTO:+0100
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0100
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
DTSTART:19961027T020000
TZNAME:GMT
TZOFFSETTO:+0000
END:STANDARD
END:VTIMEZONE
EOT;
$event[] = <<<EOT
BEGIN:VEVENT
UID:foo1
END:VEVENT
EOT;
$event[] = <<<EOT
BEGIN:VEVENT
UID:foo2
END:VEVENT
EOT;
$event[] = <<<EOT
BEGIN:VEVENT
UID:foo3
END:VEVENT
EOT;
$data = <<<EOT
BEGIN:VCALENDAR
$timezones
$event[0]
$event[1]
$event[2]
END:VCALENDAR
EOT;
$tempFile = $this->createStream($data);
$objects = new ICalendar($tempFile);
$return = "";
$i = 0;
while($object=$objects->getNext()) {
$expected = <<<EOT
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Sabre//Sabre VObject $this->version//EN
CALSCALE:GREGORIAN
$timezones
$event[$i]
END:VCALENDAR
EOT;
$expected = str_replace("
", "\r
", $expected);
$this->assertEquals($expected, $object->serialize());
$return .= $object->serialize();
$i++;
}
$this->assertEquals(array(), VObject\Reader::read($return)->validate());
$this->assertEquals(array(), VObject\Reader::read($return)->validate());
}
function testICalendarImportWithOutVTIMEZONES() {
$data = <<<EOT
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Apple Inc.//Mac OS X 10.8//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
CREATED:20120605T072109Z
UID:D6716295-C10F-4B20-82F9-E1A3026C7DCF
DTEND;VALUE=DATE:20120717
TRANSP:TRANSPARENT
SUMMARY:Start Vorbereitung
DTSTART;VALUE=DATE:20120716
DTSTAMP:20120605T072115Z
SEQUENCE:2
BEGIN:VALARM
X-WR-ALARMUID:A99EDA6A-35EB-4446-B8BC-CDA3C60C627D
UID:A99EDA6A-35EB-4446-B8BC-CDA3C60C627D
TRIGGER:-PT15H
X-APPLE-DEFAULT-ALARM:TRUE
ATTACH;VALUE=URI:Basso
ACTION:AUDIO
END:VALARM
END:VEVENT
END:VCALENDAR
EOT;
$tempFile = $this->createStream($data);
$objects = new ICalendar($tempFile);
$return = "";
while($object=$objects->getNext()) {
$return .= $object->serialize();
}
$this->assertEquals(array(), VObject\Reader::read($return)->validate());
}
}
|