123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- <?php
- namespace Sabre\VObject\Splitter;
- use Sabre\VObject;
- class ICalendarTest 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
- DTSTAMP:20140122T233226Z
- DTSTART:20140101T070000Z
- 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());
- }
- /**
- * @expectedException Sabre\VObject\ParseException
- */
- function testICalendarImportWrongType() {
- $data = <<<EOT
- BEGIN:VCARD
- UID:foo1
- END:VCARD
- BEGIN:VCARD
- UID:foo2
- END:VCARD
- EOT;
- $tempFile = $this->createStream($data);
- $objects = new ICalendar($tempFile);
- }
- function testICalendarImportEndOfData() {
- $data = <<<EOT
- BEGIN:VCALENDAR
- BEGIN:VEVENT
- UID:foo
- DTSTAMP:20140122T233226Z
- 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
- DTSTAMP:20140122T233226Z
- DTSTART:20140101T050000Z
- END:VEVENT
- EOT;
- $event[] = <<<EOT
- BEGIN:VEVENT
- UID:foo2
- DTSTAMP:20140122T233226Z
- DTSTART:20140101T060000Z
- 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("\n", "\r\n", $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
- DTSTART:20140101T040000Z
- DTSTAMP:20140122T233226Z
- END:VEVENT
- END:VCALENDAR
- EOT;
- $tempFile = $this->createStream($data);
- $objects = new ICalendar($tempFile);
- $return = "";
- while($object=$objects->getNext()) {
- $return .= $object->serialize();
- }
- $messages = VObject\Reader::read($return)->validate();
- if ($messages) {
- $messages = array_map(
- function($item) { return $item['message']; },
- $messages
- );
- $this->fail('Validation errors: ' . implode("\n", $messages));
- } else {
- $this->assertEquals(array(), $messages);
- }
- }
- 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
- DTSTAMP:20140122T232710Z
- DTSTART:20140101T010000Z
- END:VEVENT
- EOT;
- $event[] = <<<EOT
- BEGIN:VEVENT
- UID:foo2
- DTSTAMP:20140122T232710Z
- DTSTART:20140101T020000Z
- END:VEVENT
- EOT;
- $event[] = <<<EOT
- BEGIN:VEVENT
- UID:foo3
- DTSTAMP:20140122T232710Z
- DTSTART:20140101T030000Z
- 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("\n", "\r\n", $expected);
- $this->assertEquals($expected, $object->serialize());
- $return .= $object->serialize();
- $i++;
- }
- $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();
- }
- $messages = VObject\Reader::read($return)->validate();
- $this->assertEquals(array(), $messages);
- }
- }
|