1<?php
2
3namespace Sabre\VObject\Recur\EventIterator;
4
5use DateTime;
6use DateTimeZone;
7use Sabre\VObject\Reader;
8
9class ExpandFloatingTimesTest extends \PHPUnit_Framework_TestCase {
10
11    use \Sabre\VObject\PHPUnitAssertions;
12
13    function testExpand() {
14
15        $input = <<<ICS
16BEGIN:VCALENDAR
17VERSION:2.0
18BEGIN:VEVENT
19UID:foo
20DTSTART:20150109T090000
21DTEND:20150109T100000
22RRULE:FREQ=WEEKLY;INTERVAL=1;UNTIL=20191002T070000Z;BYDAY=FR
23END:VEVENT
24END:VCALENDAR
25ICS;
26
27        $vcal = Reader::read($input);
28        $this->assertInstanceOf('Sabre\\VObject\\Component\\VCalendar', $vcal);
29
30        $vcal = $vcal->expand(new DateTime('2015-01-01'), new DateTime('2015-01-31'));
31        $output = <<<ICS
32BEGIN:VCALENDAR
33VERSION:2.0
34BEGIN:VEVENT
35UID:foo
36DTSTART:20150109T090000Z
37DTEND:20150109T100000Z
38RECURRENCE-ID:20150109T090000Z
39END:VEVENT
40BEGIN:VEVENT
41UID:foo
42DTSTART:20150116T090000Z
43DTEND:20150116T100000Z
44RECURRENCE-ID:20150116T090000Z
45END:VEVENT
46BEGIN:VEVENT
47UID:foo
48DTSTART:20150123T090000Z
49DTEND:20150123T100000Z
50RECURRENCE-ID:20150123T090000Z
51END:VEVENT
52BEGIN:VEVENT
53UID:foo
54DTSTART:20150130T090000Z
55DTEND:20150130T100000Z
56RECURRENCE-ID:20150130T090000Z
57END:VEVENT
58END:VCALENDAR
59
60ICS;
61        $this->assertVObjectEqualsVObject($output, $vcal);
62
63    }
64
65    function testExpandWithReferenceTimezone() {
66
67        $input = <<<ICS
68BEGIN:VCALENDAR
69VERSION:2.0
70BEGIN:VEVENT
71UID:foo
72DTSTART:20150109T090000
73DTEND:20150109T100000
74RRULE:FREQ=WEEKLY;INTERVAL=1;UNTIL=20191002T070000Z;BYDAY=FR
75END:VEVENT
76END:VCALENDAR
77ICS;
78
79        $vcal = Reader::read($input);
80        $this->assertInstanceOf('Sabre\\VObject\\Component\\VCalendar', $vcal);
81
82        $vcal = $vcal->expand(
83            new DateTime('2015-01-01'),
84            new DateTime('2015-01-31'),
85            new DateTimeZone('Europe/Berlin')
86        );
87
88        $output = <<<ICS
89BEGIN:VCALENDAR
90VERSION:2.0
91BEGIN:VEVENT
92UID:foo
93DTSTART:20150109T080000Z
94DTEND:20150109T090000Z
95RECURRENCE-ID:20150109T080000Z
96END:VEVENT
97BEGIN:VEVENT
98UID:foo
99DTSTART:20150116T080000Z
100DTEND:20150116T090000Z
101RECURRENCE-ID:20150116T080000Z
102END:VEVENT
103BEGIN:VEVENT
104UID:foo
105DTSTART:20150123T080000Z
106DTEND:20150123T090000Z
107RECURRENCE-ID:20150123T080000Z
108END:VEVENT
109BEGIN:VEVENT
110UID:foo
111DTSTART:20150130T080000Z
112DTEND:20150130T090000Z
113RECURRENCE-ID:20150130T080000Z
114END:VEVENT
115END:VCALENDAR
116
117ICS;
118        $this->assertVObjectEqualsVObject($output, $vcal);
119
120    }
121
122}
123