ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
VEventTest.php
Go to the documentation of this file.
1 <?php
2 
4 
6 
7 class VEventTest extends TestCase {
8 
12  function testInTimeRange(VEvent $vevent, $start, $end, $outcome) {
13 
14  $this->assertEquals($outcome, $vevent->isInTimeRange($start, $end));
15 
16  }
17 
18  function timeRangeTestData() {
19 
20  $tests = [];
21 
22  $calendar = new VCalendar();
23 
24  $vevent = $calendar->createComponent('VEVENT');
25  $vevent->DTSTART = '20111223T120000Z';
26  $tests[] = [$vevent, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true];
27  $tests[] = [$vevent, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false];
28 
29  $vevent2 = clone $vevent;
30  $vevent2->DTEND = '20111225T120000Z';
31  $tests[] = [$vevent2, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true];
32  $tests[] = [$vevent2, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false];
33 
34  $vevent3 = clone $vevent;
35  $vevent3->DURATION = 'P1D';
36  $tests[] = [$vevent3, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true];
37  $tests[] = [$vevent3, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false];
38 
39  $vevent4 = clone $vevent;
40  $vevent4->DTSTART = '20111225';
41  $vevent4->DTSTART['VALUE'] = 'DATE';
42  $tests[] = [$vevent4, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true];
43  $tests[] = [$vevent4, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false];
44  // Event with no end date should be treated as lasting the entire day.
45  $tests[] = [$vevent4, new \DateTime('2011-12-25 16:00:00'), new \DateTime('2011-12-25 17:00:00'), true];
46  // DTEND is non inclusive so all day events should not be returned on the next day.
47  $tests[] = [$vevent4, new \DateTime('2011-12-26 00:00:00'), new \DateTime('2011-12-26 17:00:00'), false];
48  // The timezone of timerange in question also needs to be considered.
49  $tests[] = [$vevent4, new \DateTime('2011-12-26 00:00:00', new \DateTimeZone('Europe/Berlin')), new \DateTime('2011-12-26 17:00:00', new \DateTimeZone('Europe/Berlin')), false];
50 
51  $vevent5 = clone $vevent;
52  $vevent5->DURATION = 'P1D';
53  $vevent5->RRULE = 'FREQ=YEARLY';
54  $tests[] = [$vevent5, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true];
55  $tests[] = [$vevent5, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false];
56  $tests[] = [$vevent5, new \DateTime('2013-12-01'), new \DateTime('2013-12-31'), true];
57 
58  $vevent6 = clone $vevent;
59  $vevent6->DTSTART = '20111225';
60  $vevent6->DTSTART['VALUE'] = 'DATE';
61  $vevent6->DTEND = '20111225';
62  $vevent6->DTEND['VALUE'] = 'DATE';
63 
64  $tests[] = [$vevent6, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true];
65  $tests[] = [$vevent6, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false];
66 
67  // Added this test to ensure that recurrence rules with no DTEND also
68  // get checked for the entire day.
69  $vevent7 = clone $vevent;
70  $vevent7->DTSTART = '20120101';
71  $vevent7->DTSTART['VALUE'] = 'DATE';
72  $vevent7->RRULE = 'FREQ=MONTHLY';
73  $tests[] = [$vevent7, new \DateTime('2012-02-01 15:00:00'), new \DateTime('2012-02-02'), true];
74  // The timezone of timerange in question should also be considered.
75  $tests[] = [$vevent7, new \DateTime('2012-02-02 00:00:00', new \DateTimeZone('Europe/Berlin')), new \DateTime('2012-02-03 00:00:00', new \DateTimeZone('Europe/Berlin')), false];
76 
77  // Added this test to check recurring events that have no instances.
78  $vevent8 = clone $vevent;
79  $vevent8->DTSTART = '20130329T140000';
80  $vevent8->DTEND = '20130329T153000';
81  $vevent8->RRULE = ['FREQ' => 'WEEKLY', 'BYDAY' => ['FR'], 'UNTIL' => '20130412T115959Z'];
82  $vevent8->add('EXDATE', '20130405T140000');
83  $vevent8->add('EXDATE', '20130329T140000');
84  $tests[] = [$vevent8, new \DateTime('2013-03-01'), new \DateTime('2013-04-01'), false];
85 
86  // Added this test to check recurring all day event that repeat every day
87  $vevent9 = clone $vevent;
88  $vevent9->DTSTART = '20161027';
89  $vevent9->DTEND = '20161028';
90  $vevent9->RRULE = 'FREQ=DAILY';
91  $tests[] = [$vevent9, new \DateTime('2016-10-31'), new \DateTime('2016-12-12'), true];
92 
93  return $tests;
94 
95  }
96 
97 }
testInTimeRange(VEvent $vevent, $start, $end, $outcome)
timeRangeTestData
Definition: VEventTest.php:12
VEvent component.
Definition: VEvent.php:19
The VCalendar component.
Definition: VCalendar.php:23
$start
Definition: bench.php:8
$tests
Definition: bench.php:104
isInTimeRange(DateTimeInterface $start, DateTimeInterface $end)
Returns true or false depending on if the event falls in the specified time-range.
Definition: VEvent.php:33