1<?php
2
3namespace Sabre\VObject\Component;
4
5use Sabre\VObject;
6
7class VEventTest extends \PHPUnit_Framework_TestCase {
8
9    /**
10     * @dataProvider timeRangeTestData
11     */
12    public function testInTimeRange(VEvent $vevent,$start,$end,$outcome) {
13
14        $this->assertEquals($outcome, $vevent->isInTimeRange($start, $end));
15
16    }
17
18    public function timeRangeTestData() {
19
20        $tests = array();
21
22        $calendar = new VCalendar();
23
24        $vevent = $calendar->createComponent('VEVENT');
25        $vevent->DTSTART = '20111223T120000Z';
26        $tests[] = array($vevent, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
27        $tests[] = array($vevent, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
28
29        $vevent2 = clone $vevent;
30        $vevent2->DTEND = '20111225T120000Z';
31        $tests[] = array($vevent2, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
32        $tests[] = array($vevent2, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
33
34        $vevent3 = clone $vevent;
35        $vevent3->DURATION = 'P1D';
36        $tests[] = array($vevent3, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
37        $tests[] = array($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[] = array($vevent4, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
43        $tests[] = array($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[] = array($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[] = array($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[] = array($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[] = array($vevent5, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
55        $tests[] = array($vevent5, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
56        $tests[] = array($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[] = array($vevent6, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
65        $tests[] = array($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[] = array($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
76        // Added this test to check recurring events that have no instances.
77        $vevent8 = clone $vevent;
78        $vevent8->DTSTART = '20130329T140000';
79        $vevent8->DTEND = '20130329T153000';
80        $vevent8->RRULE = array('FREQ' => 'WEEKLY', 'BYDAY' => array('FR'), 'UNTIL' => '20130412T115959Z');
81        $vevent8->add('EXDATE', '20130405T140000');
82        $vevent8->add('EXDATE', '20130329T140000');
83        $tests[] = array($vevent8, new \DateTime('2013-03-01'), new \DateTime('2013-04-01'), false);
84
85        return $tests;
86
87    }
88
89}
90
91