ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
VAlarmTest.php
Go to the documentation of this file.
1<?php
2
4
5use DateTime;
6use PHPUnit\Framework\TestCase;
8
9class VAlarmTest extends TestCase {
10
14 function testInTimeRange(VAlarm $valarm, $start, $end, $outcome) {
15
16 $this->assertEquals($outcome, $valarm->isInTimeRange($start, $end));
17
18 }
19
20 function timeRangeTestData() {
21
22 $tests = [];
23
24 $calendar = new VCalendar();
25
26 // Hard date and time
27 $valarm1 = $calendar->createComponent('VALARM');
28 $valarm1->add(
29 $calendar->createProperty('TRIGGER', '20120312T130000Z', ['VALUE' => 'DATE-TIME'])
30 );
31
32 $tests[] = [$valarm1, new DateTime('2012-03-01 01:00:00'), new DateTime('2012-04-01 01:00:00'), true];
33 $tests[] = [$valarm1, new DateTime('2012-03-01 01:00:00'), new DateTime('2012-03-10 01:00:00'), false];
34
35 // Relation to start time of event
36 $valarm2 = $calendar->createComponent('VALARM');
37 $valarm2->add(
38 $calendar->createProperty('TRIGGER', '-P1D', ['VALUE' => 'DURATION'])
39 );
40
41 $vevent2 = $calendar->createComponent('VEVENT');
42 $vevent2->DTSTART = '20120313T130000Z';
43 $vevent2->add($valarm2);
44
45 $tests[] = [$valarm2, new DateTime('2012-03-01 01:00:00'), new DateTime('2012-04-01 01:00:00'), true];
46 $tests[] = [$valarm2, new DateTime('2012-03-01 01:00:00'), new DateTime('2012-03-10 01:00:00'), false];
47
48 // Relation to end time of event
49 $valarm3 = $calendar->createComponent('VALARM');
50 $valarm3->add($calendar->createProperty('TRIGGER', '-P1D', ['VALUE' => 'DURATION', 'RELATED' => 'END']));
51
52 $vevent3 = $calendar->createComponent('VEVENT');
53 $vevent3->DTSTART = '20120301T130000Z';
54 $vevent3->DTEND = '20120401T130000Z';
55 $vevent3->add($valarm3);
56
57 $tests[] = [$valarm3, new DateTime('2012-02-25 01:00:00'), new DateTime('2012-03-05 01:00:00'), false];
58 $tests[] = [$valarm3, new DateTime('2012-03-25 01:00:00'), new DateTime('2012-04-05 01:00:00'), true];
59
60 // Relation to end time of todo
61 $valarm4 = $calendar->createComponent('VALARM');
62 $valarm4->TRIGGER = '-P1D';
63 $valarm4->TRIGGER['VALUE'] = 'DURATION';
64 $valarm4->TRIGGER['RELATED'] = 'END';
65
66 $vtodo4 = $calendar->createComponent('VTODO');
67 $vtodo4->DTSTART = '20120301T130000Z';
68 $vtodo4->DUE = '20120401T130000Z';
69 $vtodo4->add($valarm4);
70
71 $tests[] = [$valarm4, new DateTime('2012-02-25 01:00:00'), new DateTime('2012-03-05 01:00:00'), false];
72 $tests[] = [$valarm4, new DateTime('2012-03-25 01:00:00'), new DateTime('2012-04-05 01:00:00'), true];
73
74 // Relation to start time of event + repeat
75 $valarm5 = $calendar->createComponent('VALARM');
76 $valarm5->TRIGGER = '-P1D';
77 $valarm5->TRIGGER['VALUE'] = 'DURATION';
78 $valarm5->REPEAT = 10;
79 $valarm5->DURATION = 'P1D';
80
81 $vevent5 = $calendar->createComponent('VEVENT');
82 $vevent5->DTSTART = '20120301T130000Z';
83 $vevent5->add($valarm5);
84
85 $tests[] = [$valarm5, new DateTime('2012-03-09 01:00:00'), new DateTime('2012-03-10 01:00:00'), true];
86
87 // Relation to start time of event + duration, but no repeat
88 $valarm6 = $calendar->createComponent('VALARM');
89 $valarm6->TRIGGER = '-P1D';
90 $valarm6->TRIGGER['VALUE'] = 'DURATION';
91 $valarm6->DURATION = 'P1D';
92
93 $vevent6 = $calendar->createComponent('VEVENT');
94 $vevent6->DTSTART = '20120313T130000Z';
95 $vevent6->add($valarm6);
96
97 $tests[] = [$valarm6, new DateTime('2012-03-01 01:00:00'), new DateTime('2012-04-01 01:00:00'), true];
98 $tests[] = [$valarm6, new DateTime('2012-03-01 01:00:00'), new DateTime('2012-03-10 01:00:00'), false];
99
100
101 // Relation to end time of event (DURATION instead of DTEND)
102 $valarm7 = $calendar->createComponent('VALARM');
103 $valarm7->TRIGGER = '-P1D';
104 $valarm7->TRIGGER['VALUE'] = 'DURATION';
105 $valarm7->TRIGGER['RELATED'] = 'END';
106
107 $vevent7 = $calendar->createComponent('VEVENT');
108 $vevent7->DTSTART = '20120301T130000Z';
109 $vevent7->DURATION = 'P30D';
110 $vevent7->add($valarm7);
111
112 $tests[] = [$valarm7, new DateTime('2012-02-25 01:00:00'), new DateTime('2012-03-05 01:00:00'), false];
113 $tests[] = [$valarm7, new DateTime('2012-03-25 01:00:00'), new DateTime('2012-04-05 01:00:00'), true];
114
115 // Relation to end time of event (No DTEND or DURATION)
116 $valarm7 = $calendar->createComponent('VALARM');
117 $valarm7->TRIGGER = '-P1D';
118 $valarm7->TRIGGER['VALUE'] = 'DURATION';
119 $valarm7->TRIGGER['RELATED'] = 'END';
120
121 $vevent7 = $calendar->createComponent('VEVENT');
122 $vevent7->DTSTART = '20120301T130000Z';
123 $vevent7->add($valarm7);
124
125 $tests[] = [$valarm7, new DateTime('2012-02-25 01:00:00'), new DateTime('2012-03-05 01:00:00'), true];
126 $tests[] = [$valarm7, new DateTime('2012-03-25 01:00:00'), new DateTime('2012-04-05 01:00:00'), false];
127
128
129 return $tests;
130 }
131
136
137 $calendar = new VCalendar();
138 $valarm = $calendar->createComponent('VALARM');
139 $valarm->TRIGGER = '-P1D';
140 $valarm->TRIGGER['RELATED'] = 'END';
141
142 $vjournal = $calendar->createComponent('VJOURNAL');
143 $vjournal->add($valarm);
144
145 $valarm->isInTimeRange(new DateTime('2012-02-25 01:00:00'), new DateTime('2012-03-05 01:00:00'));
146
147 }
148
153
154$input = <<<BLA
155BEGIN:VCALENDAR
156BEGIN:VTODO
157DTSTAMP:20121003T064931Z
158UID:b848cb9a7bb16e464a06c222ca1f8102@examle.com
159STATUS:NEEDS-ACTION
160DUE:20121005T000000Z
161SUMMARY:Task 1
162CATEGORIES:AlarmCategory
163BEGIN:VALARM
164TRIGGER:-PT10M
165ACTION:DISPLAY
166DESCRIPTION:Task 1
167END:VALARM
168END:VTODO
169END:VCALENDAR
170BLA;
171
173
174 $this->assertTrue($vobj->VTODO->VALARM->isInTimeRange(new \DateTime('2012-10-01 00:00:00'), new \DateTime('2012-11-01 00:00:00')));
175
176 }
177
178}
An exception for terminatinating execution or to throw for unit testing.
testInTimeRangeBuggy()
This bug was found and reported on the mailing list.
Definition: VAlarmTest.php:152
testInTimeRangeInvalidComponent()
@expectedException \Sabre\VObject\InvalidDataException
Definition: VAlarmTest.php:135
testInTimeRange(VAlarm $valarm, $start, $end, $outcome)
@dataProvider timeRangeTestData
Definition: VAlarmTest.php:14
VAlarm component.
Definition: VAlarm.php:19
isInTimeRange(DateTimeInterface $start, DateTimeInterface $end)
Returns true or false depending on if the event falls in the specified time-range.
Definition: VAlarm.php:87
The VCalendar component.
Definition: VCalendar.php:23
iCalendar/vCard/jCal/jCard/xCal/xCard reader object.
Definition: Reader.php:15
static read($data, $options=0, $charset='UTF-8')
Parses a vCard or iCalendar object, and returns the top component.
Definition: Reader.php:42
$tests
Definition: bench.php:104
foreach($paths as $path) if($argc< 3) $input
$vobj
Definition: rrulebench.php:21
$start
Definition: bench.php:8