VEventTest.php 4.0 KB

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