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