1<?php
2
3namespace Sabre\VObject\RecurrenceIterator;
4
5use Sabre\VObject\Reader;
6use DateTime;
7
8class OverrideFirstEventTest extends \PHPUnit_Framework_TestCase {
9
10    function testOverrideFirstEvent() {
11
12        $input =  <<<ICS
13BEGIN:VCALENDAR
14BEGIN:VEVENT
15UID:foobar
16DTSTART:20140803T120000Z
17RRULE:FREQ=WEEKLY
18SUMMARY:Original
19END:VEVENT
20BEGIN:VEVENT
21UID:foobar
22RECURRENCE-ID:20140803T120000Z
23DTSTART:20140803T120000Z
24SUMMARY:Overridden
25END:VEVENT
26END:VCALENDAR
27ICS;
28
29        $vcal = Reader::read($input);
30        $vcal->expand(new DateTime('2014-08-01'), new DateTime('2014-09-01'));
31
32        $expected = <<<ICS
33BEGIN:VCALENDAR
34BEGIN:VEVENT
35UID:foobar
36RECURRENCE-ID:20140803T120000Z
37DTSTART:20140803T120000Z
38SUMMARY:Overridden
39END:VEVENT
40BEGIN:VEVENT
41UID:foobar
42DTSTART:20140810T120000Z
43SUMMARY:Original
44RECURRENCE-ID:20140810T120000Z
45END:VEVENT
46BEGIN:VEVENT
47UID:foobar
48DTSTART:20140817T120000Z
49SUMMARY:Original
50RECURRENCE-ID:20140817T120000Z
51END:VEVENT
52BEGIN:VEVENT
53UID:foobar
54DTSTART:20140824T120000Z
55SUMMARY:Original
56RECURRENCE-ID:20140824T120000Z
57END:VEVENT
58BEGIN:VEVENT
59UID:foobar
60DTSTART:20140831T120000Z
61SUMMARY:Original
62RECURRENCE-ID:20140831T120000Z
63END:VEVENT
64END:VCALENDAR
65
66ICS;
67
68        $newIcs = $vcal->serialize();
69        $newIcs = str_replace("\r\n","\n", $newIcs);
70        $this->assertEquals(
71            $expected,
72            $newIcs
73        );
74
75
76    }
77
78    function testRemoveFirstEvent() {
79
80        $input =  <<<ICS
81BEGIN:VCALENDAR
82BEGIN:VEVENT
83UID:foobar
84DTSTART:20140803T120000Z
85RRULE:FREQ=WEEKLY
86EXDATE:20140803T120000Z
87SUMMARY:Original
88END:VEVENT
89END:VCALENDAR
90ICS;
91
92        $vcal = Reader::read($input);
93        $vcal->expand(new DateTime('2014-08-01'), new DateTime('2014-08-19'));
94
95        $expected = <<<ICS
96BEGIN:VCALENDAR
97BEGIN:VEVENT
98UID:foobar
99DTSTART:20140810T120000Z
100SUMMARY:Original
101RECURRENCE-ID:20140810T120000Z
102END:VEVENT
103BEGIN:VEVENT
104UID:foobar
105DTSTART:20140817T120000Z
106SUMMARY:Original
107RECURRENCE-ID:20140817T120000Z
108END:VEVENT
109END:VCALENDAR
110
111ICS;
112
113        $newIcs = $vcal->serialize();
114        $newIcs = str_replace("\r\n","\n", $newIcs);
115        $this->assertEquals(
116            $expected,
117            $newIcs
118        );
119
120
121    }
122}
123