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