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