1<?php
2
3namespace Sabre\VObject\Recur;
4
5use
6    Sabre\VObject\Reader,
7    DateTime;
8
9class BySetPosHangTest extends \PHPUnit_Framework_TestCase {
10
11    /**
12     * Using this iCalendar object, including BYSETPOS=-2 causes the iterator
13     * to hang, as reported in ticket #212.
14     *
15     * See: https://github.com/fruux/sabre-vobject/issues/212
16     */
17    function testExpand() {
18
19        $ics = <<<ICS
20BEGIN:VCALENDAR
21VERSION:2.0
22PRODID:-//Sabre//Sabre VObject 3.4.2//EN
23CALSCALE:GREGORIAN
24BEGIN:VEVENT
25SUMMARY:Test event 1
26DTSTART;TZID=Europe/Copenhagen:20150101T170000
27RRULE:FREQ=MONTHLY;BYDAY=TH;BYSETPOS=-2
28UID:b4071499-6fe4-418a-83b8-2b8d5ebb38e4
29END:VEVENT
30END:VCALENDAR
31ICS;
32
33        $vcal = Reader::read($ics);
34        $this->assertInstanceOf('Sabre\\VObject\\Component\\VCalendar', $vcal);
35
36        $vcal->expand(new DateTime('2015-01-01'), new DateTime('2016-01-01'));
37
38        foreach ($vcal->VEVENT as $event) {
39            $dates[] = $event->DTSTART->getValue();
40        }
41
42        $expectedDates = array(
43            "20150101T160000Z",
44            "20150122T160000Z",
45            "20150219T160000Z",
46            "20150319T160000Z",
47            "20150423T150000Z",
48            "20150521T150000Z",
49            "20150618T150000Z",
50            "20150723T150000Z",
51            "20150820T150000Z",
52            "20150917T150000Z",
53            "20151022T150000Z",
54            "20151119T160000Z",
55            "20151224T160000Z",
56        );
57
58        $this->assertEquals($expectedDates, $dates);
59    }
60
61}
62