1<?php
2
3namespace Sabre\VObject\Recur\EventIterator;
4
5use DateTime;
6use DateTimeImmutable;
7use DateTimeZone;
8use Sabre\VObject\Reader;
9
10/**
11 * This is a unittest for Issue #53.
12 */
13class HandleRDateExpandTest extends \PHPUnit_Framework_TestCase {
14
15    function testExpand() {
16
17        $input = <<<ICS
18BEGIN:VCALENDAR
19VERSION:2.0
20BEGIN:VEVENT
21UID:2CD5887F7CF4600F7A3B1F8065099E40-240BDA7121B61224
22DTSTAMP;VALUE=DATE-TIME:20151014T110604Z
23CREATED;VALUE=DATE-TIME:20151014T110245Z
24LAST-MODIFIED;VALUE=DATE-TIME:20151014T110541Z
25DTSTART;VALUE=DATE-TIME;TZID=Europe/Berlin:20151012T020000
26DTEND;VALUE=DATE-TIME;TZID=Europe/Berlin:20151012T013000
27SUMMARY:Test
28SEQUENCE:2
29RDATE;VALUE=DATE-TIME;TZID=Europe/Berlin:20151015T020000,20151017T020000,20
30 151018T020000,20151020T020000
31TRANSP:OPAQUE
32CLASS:PUBLIC
33END:VEVENT
34END:VCALENDAR
35ICS;
36
37        $vcal = Reader::read($input);
38        $this->assertInstanceOf('Sabre\\VObject\\Component\\VCalendar', $vcal);
39
40        $vcal = $vcal->expand(new DateTime('2015-01-01'), new DateTime('2015-12-01'));
41
42        $result = iterator_to_array($vcal->VEVENT);
43
44        $this->assertEquals(5, count($result));
45
46        $utc = new DateTimeZone('UTC');
47        $expected = [
48            new DateTimeImmutable("2015-10-12", $utc),
49            new DateTimeImmutable("2015-10-15", $utc),
50            new DateTimeImmutable("2015-10-17", $utc),
51            new DateTimeImmutable("2015-10-18", $utc),
52            new DateTimeImmutable("2015-10-20", $utc),
53        ];
54
55        $result = array_map(function($ev) {return $ev->DTSTART->getDateTime();}, $result);
56        $this->assertEquals($expected, $result);
57
58    }
59
60}
61