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