ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
MainTest.php
Go to the documentation of this file.
1 <?php
2 
4 
6 use DateTimeZone;
10 
11 class MainTest extends TestCase {
12 
13  function testValues() {
14 
15  $vcal = new VCalendar();
16  $ev = $vcal->createComponent('VEVENT');
17  $ev->UID = 'bla';
18  $ev->RRULE = 'FREQ=DAILY;BYHOUR=10;BYMINUTE=5;BYSECOND=16;BYWEEKNO=32;BYYEARDAY=100,200';
19  $dtStart = $vcal->createProperty('DTSTART');
20  $dtStart->setDateTime(new DateTimeImmutable('2011-10-07'));
21 
22  $ev->add($dtStart);
23 
24  $vcal->add($ev);
25 
26  $it = new EventIterator($vcal, (string)$ev->UID);
27 
28  $this->assertTrue($it->isInfinite());
29 
30  }
31 
36  function testInvalidFreq() {
37 
38  $vcal = new VCalendar();
39  $ev = $vcal->createComponent('VEVENT');
40  $ev->RRULE = 'FREQ=SMONTHLY;INTERVAL=3;UNTIL=20111025T000000Z';
41  $ev->UID = 'foo';
42  $dtStart = $vcal->createProperty('DTSTART');
43  $dtStart->setDateTime(new DateTimeImmutable('2011-10-07', new DateTimeZone('UTC')));
44 
45  $ev->add($dtStart);
46  $vcal->add($ev);
47 
48  $it = new EventIterator($vcal, (string)$ev->UID);
49 
50  }
51 
55  function testVCalendarNoUID() {
56 
57  $vcal = new VCalendar();
58  $it = new EventIterator($vcal);
59 
60  }
61 
66 
67  $vcal = new VCalendar();
68  $it = new EventIterator($vcal, 'foo');
69 
70  }
71 
75  function testHourly() {
76 
77  $vcal = new VCalendar();
78  $ev = $vcal->createComponent('VEVENT');
79 
80  $ev->UID = 'bla';
81  $ev->RRULE = 'FREQ=HOURLY;INTERVAL=3;UNTIL=20111025T000000Z';
82  $dtStart = $vcal->createProperty('DTSTART');
83  $dtStart->setDateTime(new DateTimeImmutable('2011-10-07 12:00:00', new DateTimeZone('UTC')));
84 
85  $ev->add($dtStart);
86  $vcal->add($ev);
87 
88  $it = new EventIterator($vcal, $ev->UID);
89 
90  // Max is to prevent overflow
91  $max = 12;
92  $result = [];
93  foreach ($it as $item) {
94 
95  $result[] = $item;
96  $max--;
97 
98  if (!$max) break;
99 
100  }
101 
102  $tz = new DateTimeZone('UTC');
103 
104  $this->assertEquals(
105  [
106  new DateTimeImmutable('2011-10-07 12:00:00', $tz),
107  new DateTimeImmutable('2011-10-07 15:00:00', $tz),
108  new DateTimeImmutable('2011-10-07 18:00:00', $tz),
109  new DateTimeImmutable('2011-10-07 21:00:00', $tz),
110  new DateTimeImmutable('2011-10-08 00:00:00', $tz),
111  new DateTimeImmutable('2011-10-08 03:00:00', $tz),
112  new DateTimeImmutable('2011-10-08 06:00:00', $tz),
113  new DateTimeImmutable('2011-10-08 09:00:00', $tz),
114  new DateTimeImmutable('2011-10-08 12:00:00', $tz),
115  new DateTimeImmutable('2011-10-08 15:00:00', $tz),
116  new DateTimeImmutable('2011-10-08 18:00:00', $tz),
117  new DateTimeImmutable('2011-10-08 21:00:00', $tz),
118  ],
119  $result
120  );
121 
122  }
123 
127  function testDaily() {
128 
129  $vcal = new VCalendar();
130  $ev = $vcal->createComponent('VEVENT');
131 
132  $ev->UID = 'bla';
133  $ev->RRULE = 'FREQ=DAILY;INTERVAL=3;UNTIL=20111025T000000Z';
134  $dtStart = $vcal->createProperty('DTSTART');
135  $dtStart->setDateTime(new DateTimeImmutable('2011-10-07', new DateTimeZone('UTC')));
136 
137  $ev->add($dtStart);
138 
139  $vcal->add($ev);
140 
141  $it = new EventIterator($vcal, $ev->UID);
142 
143  // Max is to prevent overflow
144  $max = 12;
145  $result = [];
146  foreach ($it as $item) {
147 
148  $result[] = $item;
149  $max--;
150 
151  if (!$max) break;
152 
153  }
154 
155  $tz = new DateTimeZone('UTC');
156 
157  $this->assertEquals(
158  [
159  new DateTimeImmutable('2011-10-07', $tz),
160  new DateTimeImmutable('2011-10-10', $tz),
161  new DateTimeImmutable('2011-10-13', $tz),
162  new DateTimeImmutable('2011-10-16', $tz),
163  new DateTimeImmutable('2011-10-19', $tz),
164  new DateTimeImmutable('2011-10-22', $tz),
165  new DateTimeImmutable('2011-10-25', $tz),
166  ],
167  $result
168  );
169 
170  }
171 
175  function testNoRRULE() {
176 
177  $vcal = new VCalendar();
178  $ev = $vcal->createComponent('VEVENT');
179 
180  $ev->UID = 'bla';
181  $dtStart = $vcal->createProperty('DTSTART');
182  $dtStart->setDateTime(new DateTimeImmutable('2011-10-07', new DateTimeZone('UTC')));
183 
184  $ev->add($dtStart);
185 
186  $vcal->add($ev);
187 
188  $it = new EventIterator($vcal, $ev->UID);
189 
190  // Max is to prevent overflow
191  $max = 12;
192  $result = [];
193  foreach ($it as $item) {
194 
195  $result[] = $item;
196  $max--;
197 
198  if (!$max) break;
199 
200  }
201 
202  $tz = new DateTimeZone('UTC');
203 
204  $this->assertEquals(
205  [
206  new DateTimeImmutable('2011-10-07', $tz),
207  ],
208  $result
209  );
210 
211  }
212 
216  function testDailyByDayByHour() {
217 
218  $vcal = new VCalendar();
219  $ev = $vcal->createComponent('VEVENT');
220 
221  $ev->UID = 'bla';
222  $ev->RRULE = 'FREQ=DAILY;BYDAY=SA,SU;BYHOUR=6,7';
223  $dtStart = $vcal->createProperty('DTSTART');
224  $dtStart->setDateTime(new DateTimeImmutable('2011-10-08 06:00:00', new DateTimeZone('UTC')));
225 
226  $ev->add($dtStart);
227 
228  $vcal->add($ev);
229 
230  $it = new EventIterator($vcal, (string)$ev->UID);
231 
232  // Grabbing the next 12 items
233  $max = 12;
234  $result = [];
235  foreach ($it as $item) {
236 
237  $result[] = $item;
238  $max--;
239 
240  if (!$max) break;
241 
242  }
243 
244  $tz = new DateTimeZone('UTC');
245 
246  $this->assertEquals(
247  [
248  new DateTimeImmutable('2011-10-08 06:00:00', $tz),
249  new DateTimeImmutable('2011-10-08 07:00:00', $tz),
250  new DateTimeImmutable('2011-10-09 06:00:00', $tz),
251  new DateTimeImmutable('2011-10-09 07:00:00', $tz),
252  new DateTimeImmutable('2011-10-15 06:00:00', $tz),
253  new DateTimeImmutable('2011-10-15 07:00:00', $tz),
254  new DateTimeImmutable('2011-10-16 06:00:00', $tz),
255  new DateTimeImmutable('2011-10-16 07:00:00', $tz),
256  new DateTimeImmutable('2011-10-22 06:00:00', $tz),
257  new DateTimeImmutable('2011-10-22 07:00:00', $tz),
258  new DateTimeImmutable('2011-10-23 06:00:00', $tz),
259  new DateTimeImmutable('2011-10-23 07:00:00', $tz),
260  ],
261  $result
262  );
263 
264  }
265 
269  function testDailyByHour() {
270 
271  $vcal = new VCalendar();
272  $ev = $vcal->createComponent('VEVENT');
273 
274  $ev->UID = 'bla';
275  $ev->RRULE = 'FREQ=DAILY;INTERVAL=2;BYHOUR=10,11,12,13,14,15';
276  $dtStart = $vcal->createProperty('DTSTART');
277  $dtStart->setDateTime(new DateTimeImmutable('2012-10-11 12:00:00', new DateTimeZone('UTC')));
278 
279  $ev->add($dtStart);
280 
281  $vcal->add($ev);
282 
283  $it = new EventIterator($vcal, (string)$ev->UID);
284 
285  // Grabbing the next 12 items
286  $max = 12;
287  $result = [];
288  foreach ($it as $item) {
289 
290  $result[] = $item;
291  $max--;
292 
293  if (!$max) break;
294 
295  }
296 
297  $tz = new DateTimeZone('UTC');
298 
299  $this->assertEquals(
300  [
301  new DateTimeImmutable('2012-10-11 12:00:00', $tz),
302  new DateTimeImmutable('2012-10-11 13:00:00', $tz),
303  new DateTimeImmutable('2012-10-11 14:00:00', $tz),
304  new DateTimeImmutable('2012-10-11 15:00:00', $tz),
305  new DateTimeImmutable('2012-10-13 10:00:00', $tz),
306  new DateTimeImmutable('2012-10-13 11:00:00', $tz),
307  new DateTimeImmutable('2012-10-13 12:00:00', $tz),
308  new DateTimeImmutable('2012-10-13 13:00:00', $tz),
309  new DateTimeImmutable('2012-10-13 14:00:00', $tz),
310  new DateTimeImmutable('2012-10-13 15:00:00', $tz),
311  new DateTimeImmutable('2012-10-15 10:00:00', $tz),
312  new DateTimeImmutable('2012-10-15 11:00:00', $tz),
313  ],
314  $result
315  );
316 
317  }
318 
322  function testDailyByDay() {
323 
324  $vcal = new VCalendar();
325  $ev = $vcal->createComponent('VEVENT');
326 
327  $ev->UID = 'bla';
328  $ev->RRULE = 'FREQ=DAILY;INTERVAL=2;BYDAY=TU,WE,FR';
329  $dtStart = $vcal->createProperty('DTSTART');
330  $dtStart->setDateTime(new DateTimeImmutable('2011-10-07', new DateTimeZone('UTC')));
331 
332  $ev->add($dtStart);
333 
334  $vcal->add($ev);
335 
336  $it = new EventIterator($vcal, (string)$ev->UID);
337 
338  // Grabbing the next 12 items
339  $max = 12;
340  $result = [];
341  foreach ($it as $item) {
342 
343  $result[] = $item;
344  $max--;
345 
346  if (!$max) break;
347 
348  }
349 
350  $tz = new DateTimeZone('UTC');
351 
352  $this->assertEquals(
353  [
354  new DateTimeImmutable('2011-10-07', $tz),
355  new DateTimeImmutable('2011-10-11', $tz),
356  new DateTimeImmutable('2011-10-19', $tz),
357  new DateTimeImmutable('2011-10-21', $tz),
358  new DateTimeImmutable('2011-10-25', $tz),
359  new DateTimeImmutable('2011-11-02', $tz),
360  new DateTimeImmutable('2011-11-04', $tz),
361  new DateTimeImmutable('2011-11-08', $tz),
362  new DateTimeImmutable('2011-11-16', $tz),
363  new DateTimeImmutable('2011-11-18', $tz),
364  new DateTimeImmutable('2011-11-22', $tz),
365  new DateTimeImmutable('2011-11-30', $tz),
366  ],
367  $result
368  );
369 
370  }
371 
375  function testWeekly() {
376 
377  $vcal = new VCalendar();
378  $ev = $vcal->createComponent('VEVENT');
379 
380  $ev->UID = 'bla';
381  $ev->RRULE = 'FREQ=WEEKLY;INTERVAL=2;COUNT=10';
382  $dtStart = $vcal->createProperty('DTSTART');
383  $dtStart->setDateTime(new DateTimeImmutable('2011-10-07', new DateTimeZone('UTC')));
384 
385  $ev->add($dtStart);
386 
387  $vcal->add($ev);
388 
389  $it = new EventIterator($vcal, (string)$ev->UID);
390 
391  // Max is to prevent overflow
392  $max = 12;
393  $result = [];
394  foreach ($it as $item) {
395 
396  $result[] = $item;
397  $max--;
398 
399  if (!$max) break;
400 
401  }
402 
403  $tz = new DateTimeZone('UTC');
404 
405  $this->assertEquals(
406  [
407  new DateTimeImmutable('2011-10-07', $tz),
408  new DateTimeImmutable('2011-10-21', $tz),
409  new DateTimeImmutable('2011-11-04', $tz),
410  new DateTimeImmutable('2011-11-18', $tz),
411  new DateTimeImmutable('2011-12-02', $tz),
412  new DateTimeImmutable('2011-12-16', $tz),
413  new DateTimeImmutable('2011-12-30', $tz),
414  new DateTimeImmutable('2012-01-13', $tz),
415  new DateTimeImmutable('2012-01-27', $tz),
416  new DateTimeImmutable('2012-02-10', $tz),
417  ],
418  $result
419  );
420 
421  }
422 
427 
428  $vcal = new VCalendar();
429  $ev = $vcal->createComponent('VEVENT');
430 
431  $ev->UID = 'bla';
432  $ev->RRULE = 'FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,WE,FR;WKST=MO;BYHOUR=8,9,10';
433  $dtStart = $vcal->createProperty('DTSTART');
434  $dtStart->setDateTime(new DateTimeImmutable('2011-10-07 08:00:00', new DateTimeZone('UTC')));
435 
436  $ev->add($dtStart);
437 
438  $vcal->add($ev);
439 
440  $it = new EventIterator($vcal, (string)$ev->UID);
441 
442  // Grabbing the next 12 items
443  $max = 15;
444  $result = [];
445  foreach ($it as $item) {
446 
447  $result[] = $item;
448  $max--;
449 
450  if (!$max) break;
451 
452  }
453 
454  $tz = new DateTimeZone('UTC');
455 
456  $this->assertEquals(
457  [
458  new DateTimeImmutable('2011-10-07 08:00:00', $tz),
459  new DateTimeImmutable('2011-10-07 09:00:00', $tz),
460  new DateTimeImmutable('2011-10-07 10:00:00', $tz),
461  new DateTimeImmutable('2011-10-18 08:00:00', $tz),
462  new DateTimeImmutable('2011-10-18 09:00:00', $tz),
463  new DateTimeImmutable('2011-10-18 10:00:00', $tz),
464  new DateTimeImmutable('2011-10-19 08:00:00', $tz),
465  new DateTimeImmutable('2011-10-19 09:00:00', $tz),
466  new DateTimeImmutable('2011-10-19 10:00:00', $tz),
467  new DateTimeImmutable('2011-10-21 08:00:00', $tz),
468  new DateTimeImmutable('2011-10-21 09:00:00', $tz),
469  new DateTimeImmutable('2011-10-21 10:00:00', $tz),
470  new DateTimeImmutable('2011-11-01 08:00:00', $tz),
471  new DateTimeImmutable('2011-11-01 09:00:00', $tz),
472  new DateTimeImmutable('2011-11-01 10:00:00', $tz),
473  ],
474  $result
475  );
476 
477  }
478 
483 
484  $vcal = new VCalendar();
485  $ev = $vcal->createComponent('VEVENT');
486 
487  $ev->UID = 'bla';
488  $ev->RRULE = 'FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,WE,FR;WKST=SU';
489  $dtStart = $vcal->createProperty('DTSTART');
490  $dtStart->setDateTime(new DateTimeImmutable('2011-10-07 18:00:00', new DateTimeZone('UTC')));
491 
492  $ev->add($dtStart);
493 
494  $vcal->add($ev);
495 
496  $it = new EventIterator($vcal, (string)$ev->UID);
497 
498  // Grabbing the next 12 items
499  $max = 12;
500  $result = [];
501  foreach ($it as $item) {
502 
503  $result[] = $item;
504  $max--;
505 
506  if (!$max) break;
507 
508  }
509 
510  $tz = new DateTimeZone('UTC');
511 
512  $this->assertEquals(
513  [
514  new DateTimeImmutable('2011-10-07 18:00:00', $tz),
515  new DateTimeImmutable('2011-10-18 18:00:00', $tz),
516  new DateTimeImmutable('2011-10-19 18:00:00', $tz),
517  new DateTimeImmutable('2011-10-21 18:00:00', $tz),
518  new DateTimeImmutable('2011-11-01 18:00:00', $tz),
519  new DateTimeImmutable('2011-11-02 18:00:00', $tz),
520  new DateTimeImmutable('2011-11-04 18:00:00', $tz),
521  new DateTimeImmutable('2011-11-15 18:00:00', $tz),
522  new DateTimeImmutable('2011-11-16 18:00:00', $tz),
523  new DateTimeImmutable('2011-11-18 18:00:00', $tz),
524  new DateTimeImmutable('2011-11-29 18:00:00', $tz),
525  new DateTimeImmutable('2011-11-30 18:00:00', $tz),
526  ],
527  $result
528  );
529 
530  }
531 
535  function testWeeklyByDay() {
536 
537  $vcal = new VCalendar();
538  $ev = $vcal->createComponent('VEVENT');
539 
540  $ev->UID = 'bla';
541  $ev->RRULE = 'FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,WE,FR;WKST=SU';
542  $dtStart = $vcal->createProperty('DTSTART');
543  $dtStart->setDateTime(new DateTimeImmutable('2011-10-07', new DateTimeZone('UTC')));
544 
545  $ev->add($dtStart);
546 
547  $vcal->add($ev);
548 
549  $it = new EventIterator($vcal, (string)$ev->UID);
550 
551  // Grabbing the next 12 items
552  $max = 12;
553  $result = [];
554  foreach ($it as $item) {
555 
556  $result[] = $item;
557  $max--;
558 
559  if (!$max) break;
560 
561  }
562 
563  $tz = new DateTimeZone('UTC');
564 
565  $this->assertEquals(
566  [
567  new DateTimeImmutable('2011-10-07', $tz),
568  new DateTimeImmutable('2011-10-18', $tz),
569  new DateTimeImmutable('2011-10-19', $tz),
570  new DateTimeImmutable('2011-10-21', $tz),
571  new DateTimeImmutable('2011-11-01', $tz),
572  new DateTimeImmutable('2011-11-02', $tz),
573  new DateTimeImmutable('2011-11-04', $tz),
574  new DateTimeImmutable('2011-11-15', $tz),
575  new DateTimeImmutable('2011-11-16', $tz),
576  new DateTimeImmutable('2011-11-18', $tz),
577  new DateTimeImmutable('2011-11-29', $tz),
578  new DateTimeImmutable('2011-11-30', $tz),
579  ],
580  $result
581  );
582 
583  }
584 
588  function testMonthly() {
589 
590  $vcal = new VCalendar();
591  $ev = $vcal->createComponent('VEVENT');
592 
593  $ev->UID = 'bla';
594  $ev->RRULE = 'FREQ=MONTHLY;INTERVAL=3;COUNT=5';
595  $dtStart = $vcal->createProperty('DTSTART');
596  $dtStart->setDateTime(new DateTimeImmutable('2011-12-05', new DateTimeZone('UTC')));
597 
598  $ev->add($dtStart);
599 
600  $vcal->add($ev);
601 
602  $it = new EventIterator($vcal, (string)$ev->UID);
603 
604  $max = 14;
605  $result = [];
606  foreach ($it as $item) {
607 
608  $result[] = $item;
609  $max--;
610 
611  if (!$max) break;
612 
613  }
614 
615  $tz = new DateTimeZone('UTC');
616 
617  $this->assertEquals(
618  [
619  new DateTimeImmutable('2011-12-05', $tz),
620  new DateTimeImmutable('2012-03-05', $tz),
621  new DateTimeImmutable('2012-06-05', $tz),
622  new DateTimeImmutable('2012-09-05', $tz),
623  new DateTimeImmutable('2012-12-05', $tz),
624  ],
625  $result
626  );
627 
628 
629  }
630 
635 
636  $vcal = new VCalendar();
637  $ev = $vcal->createComponent('VEVENT');
638 
639  $ev->UID = 'bla';
640  $ev->RRULE = 'FREQ=MONTHLY;INTERVAL=2;COUNT=12';
641  $dtStart = $vcal->createProperty('DTSTART');
642  $dtStart->setDateTime(new DateTimeImmutable('2011-12-31', new DateTimeZone('UTC')));
643 
644  $ev->add($dtStart);
645 
646  $vcal->add($ev);
647 
648  $it = new EventIterator($vcal, (string)$ev->UID);
649 
650  $max = 14;
651  $result = [];
652  foreach ($it as $item) {
653 
654  $result[] = $item;
655  $max--;
656 
657  if (!$max) break;
658 
659  }
660 
661  $tz = new DateTimeZone('UTC');
662 
663  $this->assertEquals(
664  [
665  new DateTimeImmutable('2011-12-31', $tz),
666  new DateTimeImmutable('2012-08-31', $tz),
667  new DateTimeImmutable('2012-10-31', $tz),
668  new DateTimeImmutable('2012-12-31', $tz),
669  new DateTimeImmutable('2013-08-31', $tz),
670  new DateTimeImmutable('2013-10-31', $tz),
671  new DateTimeImmutable('2013-12-31', $tz),
672  new DateTimeImmutable('2014-08-31', $tz),
673  new DateTimeImmutable('2014-10-31', $tz),
674  new DateTimeImmutable('2014-12-31', $tz),
675  new DateTimeImmutable('2015-08-31', $tz),
676  new DateTimeImmutable('2015-10-31', $tz),
677  ],
678  $result
679  );
680 
681 
682  }
683 
688 
689  $vcal = new VCalendar();
690  $ev = $vcal->createComponent('VEVENT');
691 
692  $ev->UID = 'bla';
693  $ev->RRULE = 'FREQ=MONTHLY;INTERVAL=5;COUNT=9;BYMONTHDAY=1,31,-7';
694  $dtStart = $vcal->createProperty('DTSTART');
695  $dtStart->setDateTime(new DateTimeImmutable('2011-01-01', new DateTimeZone('UTC')));
696 
697  $ev->add($dtStart);
698 
699  $vcal->add($ev);
700 
701  $it = new EventIterator($vcal, (string)$ev->UID);
702 
703  $max = 14;
704  $result = [];
705  foreach ($it as $item) {
706 
707  $result[] = $item;
708  $max--;
709 
710  if (!$max) break;
711 
712  }
713 
714  $tz = new DateTimeZone('UTC');
715 
716  $this->assertEquals(
717  [
718  new DateTimeImmutable('2011-01-01', $tz),
719  new DateTimeImmutable('2011-01-25', $tz),
720  new DateTimeImmutable('2011-01-31', $tz),
721  new DateTimeImmutable('2011-06-01', $tz),
722  new DateTimeImmutable('2011-06-24', $tz),
723  new DateTimeImmutable('2011-11-01', $tz),
724  new DateTimeImmutable('2011-11-24', $tz),
725  new DateTimeImmutable('2012-04-01', $tz),
726  new DateTimeImmutable('2012-04-24', $tz),
727  ],
728  $result
729  );
730 
731  }
732 
740  function testMonthlyByDay() {
741 
742  $vcal = new VCalendar();
743  $ev = $vcal->createComponent('VEVENT');
744 
745  $ev->UID = 'bla';
746  $ev->RRULE = 'FREQ=MONTHLY;INTERVAL=2;COUNT=16;BYDAY=MO,-2TU,+1WE,3TH';
747  $dtStart = $vcal->createProperty('DTSTART');
748  $dtStart->setDateTime(new DateTimeImmutable('2011-01-03', new DateTimeZone('UTC')));
749 
750  $ev->add($dtStart);
751 
752  $vcal->add($ev);
753 
754  $it = new EventIterator($vcal, (string)$ev->UID);
755 
756  $max = 20;
757  $result = [];
758  foreach ($it as $item) {
759 
760  $result[] = $item;
761  $max--;
762 
763  if (!$max) break;
764 
765  }
766 
767  $tz = new DateTimeZone('UTC');
768 
769  $this->assertEquals(
770  [
771  new DateTimeImmutable('2011-01-03', $tz),
772  new DateTimeImmutable('2011-01-05', $tz),
773  new DateTimeImmutable('2011-01-10', $tz),
774  new DateTimeImmutable('2011-01-17', $tz),
775  new DateTimeImmutable('2011-01-18', $tz),
776  new DateTimeImmutable('2011-01-20', $tz),
777  new DateTimeImmutable('2011-01-24', $tz),
778  new DateTimeImmutable('2011-01-31', $tz),
779  new DateTimeImmutable('2011-03-02', $tz),
780  new DateTimeImmutable('2011-03-07', $tz),
781  new DateTimeImmutable('2011-03-14', $tz),
782  new DateTimeImmutable('2011-03-17', $tz),
783  new DateTimeImmutable('2011-03-21', $tz),
784  new DateTimeImmutable('2011-03-22', $tz),
785  new DateTimeImmutable('2011-03-28', $tz),
786  new DateTimeImmutable('2011-05-02', $tz),
787  ],
788  $result
789  );
790 
791  }
792 
797 
798  $vcal = new VCalendar();
799  $ev = $vcal->createComponent('VEVENT');
800 
801  $ev->UID = 'bla';
802  $ev->RRULE = 'FREQ=MONTHLY;COUNT=10;BYDAY=MO;BYMONTHDAY=1';
803  $dtStart = $vcal->createProperty('DTSTART');
804  $dtStart->setDateTime(new DateTimeImmutable('2011-08-01', new DateTimeZone('UTC')));
805 
806  $ev->add($dtStart);
807 
808  $vcal->add($ev);
809 
810  $it = new EventIterator($vcal, (string)$ev->UID);
811 
812  $max = 20;
813  $result = [];
814  foreach ($it as $item) {
815 
816  $result[] = $item;
817  $max--;
818 
819  if (!$max) break;
820 
821  }
822 
823  $tz = new DateTimeZone('UTC');
824 
825  $this->assertEquals(
826  [
827  new DateTimeImmutable('2011-08-01', $tz),
828  new DateTimeImmutable('2012-10-01', $tz),
829  new DateTimeImmutable('2013-04-01', $tz),
830  new DateTimeImmutable('2013-07-01', $tz),
831  new DateTimeImmutable('2014-09-01', $tz),
832  new DateTimeImmutable('2014-12-01', $tz),
833  new DateTimeImmutable('2015-06-01', $tz),
834  new DateTimeImmutable('2016-02-01', $tz),
835  new DateTimeImmutable('2016-08-01', $tz),
836  new DateTimeImmutable('2017-05-01', $tz),
837  ],
838  $result
839  );
840 
841  }
842 
847 
848  $vcal = new VCalendar();
849  $ev = $vcal->createComponent('VEVENT');
850 
851  $ev->UID = 'bla';
852  $ev->RRULE = 'FREQ=MONTHLY;COUNT=10;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=1,-1';
853  $dtStart = $vcal->createProperty('DTSTART');
854  $dtStart->setDateTime(new DateTimeImmutable('2011-01-03', new DateTimeZone('UTC')));
855 
856  $ev->add($dtStart);
857 
858  $vcal->add($ev);
859 
860  $it = new EventIterator($vcal, (string)$ev->UID);
861 
862  $max = 20;
863  $result = [];
864  foreach ($it as $item) {
865 
866  $result[] = $item;
867  $max--;
868 
869  if (!$max) break;
870 
871  }
872 
873  $tz = new DateTimeZone('UTC');
874 
875  $this->assertEquals(
876  [
877  new DateTimeImmutable('2011-01-03', $tz),
878  new DateTimeImmutable('2011-01-31', $tz),
879  new DateTimeImmutable('2011-02-01', $tz),
880  new DateTimeImmutable('2011-02-28', $tz),
881  new DateTimeImmutable('2011-03-01', $tz),
882  new DateTimeImmutable('2011-03-31', $tz),
883  new DateTimeImmutable('2011-04-01', $tz),
884  new DateTimeImmutable('2011-04-29', $tz),
885  new DateTimeImmutable('2011-05-02', $tz),
886  new DateTimeImmutable('2011-05-31', $tz),
887  ],
888  $result
889  );
890 
891  }
892 
896  function testYearly() {
897 
898  $vcal = new VCalendar();
899  $ev = $vcal->createComponent('VEVENT');
900 
901  $ev->UID = 'bla';
902  $ev->RRULE = 'FREQ=YEARLY;COUNT=10;INTERVAL=3';
903  $dtStart = $vcal->createProperty('DTSTART');
904  $dtStart->setDateTime(new DateTimeImmutable('2011-01-01', new DateTimeZone('UTC')));
905 
906  $ev->add($dtStart);
907 
908  $vcal->add($ev);
909 
910  $it = new EventIterator($vcal, (string)$ev->UID);
911 
912  $max = 20;
913  $result = [];
914  foreach ($it as $item) {
915 
916  $result[] = $item;
917  $max--;
918 
919  if (!$max) break;
920 
921  }
922 
923  $tz = new DateTimeZone('UTC');
924 
925  $this->assertEquals(
926  [
927  new DateTimeImmutable('2011-01-01', $tz),
928  new DateTimeImmutable('2014-01-01', $tz),
929  new DateTimeImmutable('2017-01-01', $tz),
930  new DateTimeImmutable('2020-01-01', $tz),
931  new DateTimeImmutable('2023-01-01', $tz),
932  new DateTimeImmutable('2026-01-01', $tz),
933  new DateTimeImmutable('2029-01-01', $tz),
934  new DateTimeImmutable('2032-01-01', $tz),
935  new DateTimeImmutable('2035-01-01', $tz),
936  new DateTimeImmutable('2038-01-01', $tz),
937  ],
938  $result
939  );
940 
941  }
942 
946  function testYearlyLeapYear() {
947 
948  $vcal = new VCalendar();
949  $ev = $vcal->createComponent('VEVENT');
950 
951  $ev->UID = 'bla';
952  $ev->RRULE = 'FREQ=YEARLY;COUNT=3';
953  $dtStart = $vcal->createProperty('DTSTART');
954  $dtStart->setDateTime(new DateTimeImmutable('2012-02-29', new DateTimeZone('UTC')));
955 
956  $ev->add($dtStart);
957 
958  $vcal->add($ev);
959 
960  $it = new EventIterator($vcal, (string)$ev->UID);
961 
962  $max = 20;
963  $result = [];
964  foreach ($it as $item) {
965 
966  $result[] = $item;
967  $max--;
968 
969  if (!$max) break;
970 
971  }
972 
973  $tz = new DateTimeZone('UTC');
974 
975  $this->assertEquals(
976  [
977  new DateTimeImmutable('2012-02-29', $tz),
978  new DateTimeImmutable('2016-02-29', $tz),
979  new DateTimeImmutable('2020-02-29', $tz),
980  ],
981  $result
982  );
983 
984  }
985 
989  function testYearlyByMonth() {
990 
991  $vcal = new VCalendar();
992  $ev = $vcal->createComponent('VEVENT');
993 
994  $ev->UID = 'bla';
995  $ev->RRULE = 'FREQ=YEARLY;COUNT=8;INTERVAL=4;BYMONTH=4,10';
996  $dtStart = $vcal->createProperty('DTSTART');
997  $dtStart->setDateTime(new DateTimeImmutable('2011-04-07', new DateTimeZone('UTC')));
998 
999  $ev->add($dtStart);
1000 
1001  $vcal->add($ev);
1002 
1003  $it = new EventIterator($vcal, (string)$ev->UID);
1004 
1005  $max = 20;
1006  $result = [];
1007  foreach ($it as $item) {
1008 
1009  $result[] = $item;
1010  $max--;
1011 
1012  if (!$max) break;
1013 
1014  }
1015 
1016  $tz = new DateTimeZone('UTC');
1017 
1018  $this->assertEquals(
1019  [
1020  new DateTimeImmutable('2011-04-07', $tz),
1021  new DateTimeImmutable('2011-10-07', $tz),
1022  new DateTimeImmutable('2015-04-07', $tz),
1023  new DateTimeImmutable('2015-10-07', $tz),
1024  new DateTimeImmutable('2019-04-07', $tz),
1025  new DateTimeImmutable('2019-10-07', $tz),
1026  new DateTimeImmutable('2023-04-07', $tz),
1027  new DateTimeImmutable('2023-10-07', $tz),
1028  ],
1029  $result
1030  );
1031 
1032  }
1033 
1038 
1039  $vcal = new VCalendar();
1040  $ev = $vcal->createComponent('VEVENT');
1041 
1042  $ev->UID = 'bla';
1043  $ev->RRULE = 'FREQ=YEARLY;COUNT=8;INTERVAL=5;BYMONTH=4,10;BYDAY=1MO,-1SU';
1044  $dtStart = $vcal->createProperty('DTSTART');
1045  $dtStart->setDateTime(new DateTimeImmutable('2011-04-04', new DateTimeZone('UTC')));
1046 
1047  $ev->add($dtStart);
1048 
1049  $vcal->add($ev);
1050 
1051  $it = new EventIterator($vcal, (string)$ev->UID);
1052 
1053  $max = 20;
1054  $result = [];
1055  foreach ($it as $item) {
1056 
1057  $result[] = $item;
1058  $max--;
1059 
1060  if (!$max) break;
1061 
1062  }
1063 
1064  $tz = new DateTimeZone('UTC');
1065 
1066  $this->assertEquals(
1067  [
1068  new DateTimeImmutable('2011-04-04', $tz),
1069  new DateTimeImmutable('2011-04-24', $tz),
1070  new DateTimeImmutable('2011-10-03', $tz),
1071  new DateTimeImmutable('2011-10-30', $tz),
1072  new DateTimeImmutable('2016-04-04', $tz),
1073  new DateTimeImmutable('2016-04-24', $tz),
1074  new DateTimeImmutable('2016-10-03', $tz),
1075  new DateTimeImmutable('2016-10-30', $tz),
1076  ],
1077  $result
1078  );
1079 
1080  }
1081 
1085  function testFastForward() {
1086 
1087  $vcal = new VCalendar();
1088  $ev = $vcal->createComponent('VEVENT');
1089 
1090  $ev->UID = 'bla';
1091  $ev->RRULE = 'FREQ=YEARLY;COUNT=8;INTERVAL=5;BYMONTH=4,10;BYDAY=1MO,-1SU';
1092  $dtStart = $vcal->createProperty('DTSTART');
1093  $dtStart->setDateTime(new DateTimeImmutable('2011-04-04', new DateTimeZone('UTC')));
1094 
1095  $ev->add($dtStart);
1096 
1097  $vcal->add($ev);
1098 
1099  $it = new EventIterator($vcal, (string)$ev->UID);
1100 
1101  // The idea is that we're fast-forwarding too far in the future, so
1102  // there will be no results left.
1103  $it->fastForward(new DateTimeImmutable('2020-05-05', new DateTimeZone('UTC')));
1104 
1105  $max = 20;
1106  $result = [];
1107  while ($item = $it->current()) {
1108 
1109  $result[] = $item;
1110  $max--;
1111 
1112  if (!$max) break;
1113  $it->next();
1114 
1115  }
1116 
1117  $this->assertEquals([], $result);
1118 
1119  }
1120 
1125  $vcal = new VCalendar();
1126  $ev = $vcal->createComponent('VEVENT');
1127 
1128  $ev->UID = 'bla';
1129  $ev->RRULE = 'FREQ=DAILY';
1130 
1131  $dtStart = $vcal->createProperty('DTSTART');
1132  $dtStart->setDateTime(new DateTimeImmutable('2011-04-04', new DateTimeZone('UTC')));
1133  $ev->add($dtStart);
1134 
1135  $dtEnd = $vcal->createProperty('DTSTART');
1136  $dtEnd->setDateTime(new DateTimeImmutable('2011-04-05', new DateTimeZone('UTC')));
1137  $ev->add($dtEnd);
1138 
1139  $vcal->add($ev);
1140 
1141  $it = new EventIterator($vcal, (string)$ev->UID);
1142 
1143  $it->fastForward(new DateTimeImmutable('2011-04-05T000000', new DateTimeZone('UTC')));
1144 
1145  $this->assertEquals(new DateTimeImmutable('2011-04-06'), $it->getDTStart());
1146  }
1147 
1152 
1153  $vcal = new VCalendar();
1154  $ev = $vcal->createComponent('VEVENT');
1155 
1156  $ev->UID = 'bla';
1157  $ev->RRULE = 'FREQ=YEARLY;COUNT=10';
1158  $dtStart = $vcal->createProperty('DTSTART');
1159 
1160  $tz = new DateTimeZone('Canada/Eastern');
1161  $dtStart->setDateTime(new DateTimeImmutable('2011-01-01 13:50:20', $tz));
1162 
1163  $exDate1 = $vcal->createProperty('EXDATE');
1164  $exDate1->setDateTimes([new DateTimeImmutable('2012-01-01 13:50:20', $tz), new DateTimeImmutable('2014-01-01 13:50:20', $tz)]);
1165  $exDate2 = $vcal->createProperty('EXDATE');
1166  $exDate2->setDateTimes([new DateTimeImmutable('2016-01-01 13:50:20', $tz)]);
1167 
1168  $ev->add($dtStart);
1169  $ev->add($exDate1);
1170  $ev->add($exDate2);
1171 
1172  $vcal->add($ev);
1173 
1174  $it = new EventIterator($vcal, (string)$ev->UID);
1175 
1176  $max = 20;
1177  $result = [];
1178  foreach ($it as $item) {
1179 
1180  $result[] = $item;
1181  $max--;
1182 
1183  if (!$max) break;
1184 
1185  }
1186 
1187  $this->assertEquals(
1188  [
1189  new DateTimeImmutable('2011-01-01 13:50:20', $tz),
1190  new DateTimeImmutable('2013-01-01 13:50:20', $tz),
1191  new DateTimeImmutable('2015-01-01 13:50:20', $tz),
1192  new DateTimeImmutable('2017-01-01 13:50:20', $tz),
1193  new DateTimeImmutable('2018-01-01 13:50:20', $tz),
1194  new DateTimeImmutable('2019-01-01 13:50:20', $tz),
1195  new DateTimeImmutable('2020-01-01 13:50:20', $tz),
1196  ],
1197  $result
1198  );
1199 
1200  }
1201 
1205  function testOverridenEvent() {
1206 
1207  $vcal = new VCalendar();
1208 
1209  $ev1 = $vcal->createComponent('VEVENT');
1210  $ev1->UID = 'overridden';
1211  $ev1->RRULE = 'FREQ=DAILY;COUNT=10';
1212  $ev1->DTSTART = '20120107T120000Z';
1213  $ev1->SUMMARY = 'baseEvent';
1214 
1215  $vcal->add($ev1);
1216 
1217  // ev2 overrides an event, and puts it on 2pm instead.
1218  $ev2 = $vcal->createComponent('VEVENT');
1219  $ev2->UID = 'overridden';
1220  $ev2->{'RECURRENCE-ID'} = '20120110T120000Z';
1221  $ev2->DTSTART = '20120110T140000Z';
1222  $ev2->SUMMARY = 'Event 2';
1223 
1224  $vcal->add($ev2);
1225 
1226  // ev3 overrides an event, and puts it 2 days and 2 hours later
1227  $ev3 = $vcal->createComponent('VEVENT');
1228  $ev3->UID = 'overridden';
1229  $ev3->{'RECURRENCE-ID'} = '20120113T120000Z';
1230  $ev3->DTSTART = '20120115T140000Z';
1231  $ev3->SUMMARY = 'Event 3';
1232 
1233  $vcal->add($ev3);
1234 
1235  $it = new EventIterator($vcal, 'overridden');
1236 
1237  $dates = [];
1238  $summaries = [];
1239  while ($it->valid()) {
1240 
1241  $dates[] = $it->getDTStart();
1242  $summaries[] = (string)$it->getEventObject()->SUMMARY;
1243  $it->next();
1244 
1245  }
1246 
1247  $tz = new DateTimeZone('UTC');
1248  $this->assertEquals([
1249  new DateTimeImmutable('2012-01-07 12:00:00', $tz),
1250  new DateTimeImmutable('2012-01-08 12:00:00', $tz),
1251  new DateTimeImmutable('2012-01-09 12:00:00', $tz),
1252  new DateTimeImmutable('2012-01-10 14:00:00', $tz),
1253  new DateTimeImmutable('2012-01-11 12:00:00', $tz),
1254  new DateTimeImmutable('2012-01-12 12:00:00', $tz),
1255  new DateTimeImmutable('2012-01-14 12:00:00', $tz),
1256  new DateTimeImmutable('2012-01-15 12:00:00', $tz),
1257  new DateTimeImmutable('2012-01-15 14:00:00', $tz),
1258  new DateTimeImmutable('2012-01-16 12:00:00', $tz),
1259  ], $dates);
1260 
1261  $this->assertEquals([
1262  'baseEvent',
1263  'baseEvent',
1264  'baseEvent',
1265  'Event 2',
1266  'baseEvent',
1267  'baseEvent',
1268  'baseEvent',
1269  'baseEvent',
1270  'Event 3',
1271  'baseEvent',
1272  ], $summaries);
1273 
1274  }
1275 
1279  function testOverridenEvent2() {
1280 
1281  $vcal = new VCalendar();
1282 
1283  $ev1 = $vcal->createComponent('VEVENT');
1284  $ev1->UID = 'overridden';
1285  $ev1->RRULE = 'FREQ=WEEKLY;COUNT=3';
1286  $ev1->DTSTART = '20120112T120000Z';
1287  $ev1->SUMMARY = 'baseEvent';
1288 
1289  $vcal->add($ev1);
1290 
1291  // ev2 overrides an event, and puts it 6 days earlier instead.
1292  $ev2 = $vcal->createComponent('VEVENT');
1293  $ev2->UID = 'overridden';
1294  $ev2->{'RECURRENCE-ID'} = '20120119T120000Z';
1295  $ev2->DTSTART = '20120113T120000Z';
1296  $ev2->SUMMARY = 'Override!';
1297 
1298  $vcal->add($ev2);
1299 
1300  $it = new EventIterator($vcal, 'overridden');
1301 
1302  $dates = [];
1303  $summaries = [];
1304  while ($it->valid()) {
1305 
1306  $dates[] = $it->getDTStart();
1307  $summaries[] = (string)$it->getEventObject()->SUMMARY;
1308  $it->next();
1309 
1310  }
1311 
1312  $tz = new DateTimeZone('UTC');
1313  $this->assertEquals([
1314  new DateTimeImmutable('2012-01-12 12:00:00', $tz),
1315  new DateTimeImmutable('2012-01-13 12:00:00', $tz),
1316  new DateTimeImmutable('2012-01-26 12:00:00', $tz),
1317 
1318  ], $dates);
1319 
1320  $this->assertEquals([
1321  'baseEvent',
1322  'Override!',
1323  'baseEvent',
1324  ], $summaries);
1325 
1326  }
1327 
1332 
1333  $vcal = new VCalendar();
1334  $ev1 = $vcal->createComponent('VEVENT');
1335 
1336  $ev1->UID = 'overridden';
1337  $ev1->RRULE = 'FREQ=WEEKLY;COUNT=3';
1338  $ev1->DTSTART = '20120124T120000Z';
1339  $ev1->SUMMARY = 'baseEvent';
1340 
1341  $vcal->add($ev1);
1342 
1343  // ev2 overrides an event, and puts it 6 days earlier instead.
1344  $ev2 = $vcal->createComponent('VEVENT');
1345  $ev2->UID = 'overridden';
1346  $ev2->{'RECURRENCE-ID'} = '20120131T120000Z';
1347  $ev2->DTSTART = '20120125T120000Z';
1348  $ev2->SUMMARY = 'Override!';
1349 
1350  $vcal->add($ev2);
1351 
1352  $it = new EventIterator($vcal, 'overridden');
1353 
1354  $dates = [];
1355  $summaries = [];
1356 
1357  // The reported problem was specifically related to the VCALENDAR
1358  // expansion. In this parcitular case, we had to forward to the 28th of
1359  // january.
1360  $it->fastForward(new DateTimeImmutable('2012-01-28 23:00:00'));
1361 
1362  // We stop the loop when it hits the 6th of februari. Normally this
1363  // iterator would hit 24, 25 (overriden from 31) and 7 feb but because
1364  // we 'filter' from the 28th till the 6th, we should get 0 results.
1365  while ($it->valid() && $it->getDTStart() < new DateTimeImmutable('2012-02-06 23:00:00')) {
1366 
1367  $dates[] = $it->getDTStart();
1368  $summaries[] = (string)$it->getEventObject()->SUMMARY;
1369  $it->next();
1370 
1371  }
1372 
1373  $this->assertEquals([], $dates);
1374  $this->assertEquals([], $summaries);
1375 
1376  }
1377 
1381  function testRDATE() {
1382 
1383  $vcal = new VCalendar();
1384  $ev = $vcal->createComponent('VEVENT');
1385 
1386  $ev->UID = 'bla';
1387  $ev->RDATE = [
1388  new DateTimeImmutable('2014-08-07', new DateTimeZone('UTC')),
1389  new DateTimeImmutable('2014-08-08', new DateTimeZone('UTC')),
1390  ];
1391  $dtStart = $vcal->createProperty('DTSTART');
1392  $dtStart->setDateTime(new DateTimeImmutable('2011-10-07', new DateTimeZone('UTC')));
1393 
1394  $ev->add($dtStart);
1395 
1396  $vcal->add($ev);
1397 
1398  $it = new EventIterator($vcal, $ev->UID);
1399 
1400  // Max is to prevent overflow
1401  $max = 12;
1402  $result = [];
1403  foreach ($it as $item) {
1404 
1405  $result[] = $item;
1406  $max--;
1407 
1408  if (!$max) break;
1409 
1410  }
1411 
1412  $tz = new DateTimeZone('UTC');
1413 
1414  $this->assertEquals(
1415  [
1416  new DateTimeImmutable('2011-10-07', $tz),
1417  new DateTimeImmutable('2014-08-07', $tz),
1418  new DateTimeImmutable('2014-08-08', $tz),
1419  ],
1420  $result
1421  );
1422 
1423  }
1424 
1429  function testNoMasterBadUID() {
1430 
1431  $vcal = new VCalendar();
1432  // ev2 overrides an event, and puts it on 2pm instead.
1433  $ev2 = $vcal->createComponent('VEVENT');
1434  $ev2->UID = 'overridden';
1435  $ev2->{'RECURRENCE-ID'} = '20120110T120000Z';
1436  $ev2->DTSTART = '20120110T140000Z';
1437  $ev2->SUMMARY = 'Event 2';
1438 
1439  $vcal->add($ev2);
1440 
1441  // ev3 overrides an event, and puts it 2 days and 2 hours later
1442  $ev3 = $vcal->createComponent('VEVENT');
1443  $ev3->UID = 'overridden';
1444  $ev3->{'RECURRENCE-ID'} = '20120113T120000Z';
1445  $ev3->DTSTART = '20120115T140000Z';
1446  $ev3->SUMMARY = 'Event 3';
1447 
1448  $vcal->add($ev3);
1449 
1450  $it = new EventIterator($vcal, 'broken');
1451 
1452  }
1453 }
testMonthlyByDay()
A pretty slow test.
Definition: MainTest.php:740
$result
testFastForwardAllDayEventThatStopAtTheStartTime()
testValues
Definition: MainTest.php:1124
The VCalendar component.
Definition: VCalendar.php:23
testVCalendarInvalidUID()
InvalidArgumentException
Definition: MainTest.php:65
This class is used to determine new for a recurring event, when the next events occur.
testVCalendarNoUID()
InvalidArgumentException
Definition: MainTest.php:55