version = VObject\Version::VERSION; } public function createStream($data) { $stream = fopen('php://memory', 'r+'); fwrite($stream, $data); rewind($stream); return $stream; } public function testICalendarImportValidEvent() { $data = <<createStream($data); $objects = new ICalendar($tempFile); $return = ''; while ($object = $objects->getNext()) { $return .= $object->serialize(); } $this->assertEquals([], VObject\Reader::read($return)->validate()); } /** * @expectedException \Sabre\VObject\ParseException */ public function testICalendarImportWrongType() { $data = <<createStream($data); $objects = new ICalendar($tempFile); } public function testICalendarImportEndOfData() { $data = <<createStream($data); $objects = new ICalendar($tempFile); $return = ''; while ($object = $objects->getNext()) { $return .= $object->serialize(); } $this->assertNull($object = $objects->getNext()); } /** * @expectedException \Sabre\VObject\ParseException */ public function testICalendarImportInvalidEvent() { $data = <<createStream($data); $objects = new ICalendar($tempFile); } public function testICalendarImportMultipleValidEvents() { $event[] = <<createStream($data); $objects = new ICalendar($tempFile); $return = ''; $i = 0; while ($object = $objects->getNext()) { $expected = <<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([], VObject\Reader::read($return)->validate()); } public function testICalendarImportEventWithoutUID() { $data = <<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([], $messages); } } public function testICalendarImportMultipleVTIMEZONESAndMultipleValidEvents() { $timezones = <<createStream($data); $objects = new ICalendar($tempFile); $return = ''; $i = 0; while ($object = $objects->getNext()) { $expected = <<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([], VObject\Reader::read($return)->validate()); } public function testICalendarImportWithOutVTIMEZONES() { $data = <<createStream($data); $objects = new ICalendar($tempFile); $return = ''; while ($object = $objects->getNext()) { $return .= $object->serialize(); } $messages = VObject\Reader::read($return)->validate(); $this->assertEquals([], $messages); } }