]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/VObject/RecurrenceIteratorInfiniteLoopProblemTest.php
Initial Release of the calendar plugin
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / VObject / RecurrenceIteratorInfiniteLoopProblemTest.php
1 <?php
2
3 class Sabre_VObject_RecurrenceIteratorInfiniteLoopProblemTest extends PHPUnit_Framework_TestCase {
4
5     /**
6      * This bug came from a Fruux customer. This would result in a never-ending
7      * request.
8      */
9     function testFastForwardTooFar() {
10
11         $ev = Sabre_VObject_Component::create('VEVENT');
12         $ev->DTSTART = '20090420T180000Z';
13         $ev->RRULE = 'FREQ=WEEKLY;BYDAY=MO;UNTIL=20090704T205959Z;INTERVAL=1';
14
15         $this->assertFalse($ev->isInTimeRange(new DateTime('2012-01-01 12:00:00'),new DateTime('3000-01-01 00:00:00')));
16
17     }
18
19     /**
20      * Different bug, also likely an infinite loop.
21      */
22     function testYearlyByMonthLoop() {
23
24         $ev = Sabre_VObject_Component::create('VEVENT');
25         $ev->UID = 'uuid';
26         $ev->DTSTART = '20120101T154500';
27         $ev->DTSTART['TZID'] = 'Europe/Berlin';
28         $ev->RRULE = 'FREQ=YEARLY;INTERVAL=1;UNTIL=20120203T225959Z;BYMONTH=2;BYSETPOS=1;BYDAY=SU,MO,TU,WE,TH,FR,SA';
29         $ev->DTEND = '20120101T164500';
30         $ev->DTEND['TZID'] = 'Europe/Berlin';
31
32         // This recurrence rule by itself is a yearly rule that should happen
33         // every february.
34         //
35         // The BYDAY part expands this to every day of the month, but the
36         // BYSETPOS limits this to only the 1st day of the month. Very crazy
37         // way to specify this, and could have certainly been a lot easier.
38         $cal = Sabre_VObject_Component::create('VCALENDAR');
39         $cal->add($ev);
40
41         $it = new Sabre_VObject_RecurrenceIterator($cal,'uuid');
42         $it->fastForward(new DateTime('2012-01-29 23:00:00', new DateTimeZone('UTC')));
43
44         $collect = array();
45
46         while($it->valid()) {
47             $collect[] = $it->getDTSTART();
48             if ($it->getDTSTART() > new DateTime('2013-02-05 22:59:59', new DateTimeZone('UTC'))) {
49                 break;
50             }
51             $it->next();
52
53         }
54
55         $this->assertEquals(
56             array(new DateTime('2012-02-01 15:45:00', new DateTimeZone('Europe/Berlin'))),
57             $collect
58         );
59
60     }
61
62
63 }