CalendarQueryVAlarmTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace Sabre\CalDAV;
  3. use Sabre\VObject;
  4. class CalendarQueryVAlarmTest extends \PHPUnit_Framework_TestCase {
  5. /**
  6. * This test is specifically for a time-range query on a VALARM, contained
  7. * in a VEVENT that's recurring
  8. */
  9. function testValarm() {
  10. $vcalendar = new VObject\Component\VCalendar();
  11. $vevent = $vcalendar->createComponent('VEVENT');
  12. $vevent->RRULE = 'FREQ=MONTHLY';
  13. $vevent->DTSTART = '20120101T120000Z';
  14. $vevent->UID = 'bla';
  15. $valarm = $vcalendar->createComponent('VALARM');
  16. $valarm->TRIGGER = '-P15D';
  17. $vevent->add($valarm);
  18. $vcalendar->add($vevent);
  19. $filter = array(
  20. 'name' => 'VCALENDAR',
  21. 'is-not-defined' => false,
  22. 'time-range' => null,
  23. 'prop-filters' => array(),
  24. 'comp-filters' => array(
  25. array(
  26. 'name' => 'VEVENT',
  27. 'is-not-defined' => false,
  28. 'time-range' => null,
  29. 'prop-filters' => array(),
  30. 'comp-filters' => array(
  31. array(
  32. 'name' => 'VALARM',
  33. 'is-not-defined' => false,
  34. 'prop-filters' => array(),
  35. 'comp-filters' => array(),
  36. 'time-range' => array(
  37. 'start' => new \DateTime('2012-05-10'),
  38. 'end' => new \DateTime('2012-05-20'),
  39. ),
  40. ),
  41. ),
  42. ),
  43. ),
  44. );
  45. $validator = new CalendarQueryValidator();
  46. $this->assertTrue($validator->validate($vcalendar, $filter));
  47. $vcalendar = new VObject\Component\VCalendar();
  48. // A limited recurrence rule, should return false
  49. $vevent = $vcalendar->createComponent('VEVENT');
  50. $vevent->RRULE = 'FREQ=MONTHLY;COUNT=1';
  51. $vevent->DTSTART = '20120101T120000Z';
  52. $vevent->UID = 'bla';
  53. $valarm = $vcalendar->createComponent('VALARM');
  54. $valarm->TRIGGER = '-P15D';
  55. $vevent->add($valarm);
  56. $vcalendar->add($vevent);
  57. $this->assertFalse($validator->validate($vcalendar, $filter));
  58. }
  59. function testAlarmWayBefore() {
  60. $vcalendar = new VObject\Component\VCalendar();
  61. $vevent = $vcalendar->createComponent('VEVENT');
  62. $vevent->DTSTART = '20120101T120000Z';
  63. $vevent->UID = 'bla';
  64. $valarm = $vcalendar->createComponent('VALARM');
  65. $valarm->TRIGGER = '-P2W1D';
  66. $vevent->add($valarm);
  67. $vcalendar->add($vevent);
  68. $filter = array(
  69. 'name' => 'VCALENDAR',
  70. 'is-not-defined' => false,
  71. 'time-range' => null,
  72. 'prop-filters' => array(),
  73. 'comp-filters' => array(
  74. array(
  75. 'name' => 'VEVENT',
  76. 'is-not-defined' => false,
  77. 'time-range' => null,
  78. 'prop-filters' => array(),
  79. 'comp-filters' => array(
  80. array(
  81. 'name' => 'VALARM',
  82. 'is-not-defined' => false,
  83. 'prop-filters' => array(),
  84. 'comp-filters' => array(),
  85. 'time-range' => array(
  86. 'start' => new \DateTime('2011-12-10'),
  87. 'end' => new \DateTime('2011-12-20'),
  88. ),
  89. ),
  90. ),
  91. ),
  92. ),
  93. );
  94. $validator = new CalendarQueryValidator();
  95. $this->assertTrue($validator->validate($vcalendar, $filter));
  96. }
  97. }