ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
RecurTest.php
Go to the documentation of this file.
1 <?php
2 
4 
9 
10 class RecurTest extends TestCase {
11 
12  use \Sabre\VObject\PHPUnitAssertions;
13 
14  function testParts() {
15 
16  $vcal = new VCalendar();
17  $recur = $vcal->add('RRULE', 'FREQ=Daily');
18 
19  $this->assertInstanceOf('Sabre\VObject\Property\ICalendar\Recur', $recur);
20 
21  $this->assertEquals(['FREQ' => 'DAILY'], $recur->getParts());
22  $recur->setParts(['freq' => 'MONTHLY']);
23 
24  $this->assertEquals(['FREQ' => 'MONTHLY'], $recur->getParts());
25 
26  }
27 
31  function testSetValueBadVal() {
32 
33  $vcal = new VCalendar();
34  $recur = $vcal->add('RRULE', 'FREQ=Daily');
35  $recur->setValue(new \Exception());
36 
37  }
38 
39  function testSetValueWithCount() {
40  $vcal = new VCalendar();
41  $recur = $vcal->add('RRULE', 'FREQ=Daily');
42  $recur->setValue(['COUNT' => 3]);
43  $this->assertEquals($recur->getParts()['COUNT'], 3);
44  }
45 
46  function testGetJSONWithCount() {
47  $input = 'BEGIN:VCALENDAR
48 BEGIN:VEVENT
49 UID:908d53c0-e1a3-4883-b69f-530954d6bd62
50 TRANSP:OPAQUE
51 DTSTART;TZID=Europe/Berlin:20160301T150000
52 DTEND;TZID=Europe/Berlin:20160301T170000
53 SUMMARY:test
54 RRULE:FREQ=DAILY;COUNT=3
55 ORGANIZER;CN=robert pipo:mailto:robert@example.org
56 END:VEVENT
57 END:VCALENDAR
58 ';
59 
61  $rrule = $vcal->VEVENT->RRULE;
62  $count = $rrule->getJsonValue()[0]['count'];
63  $this->assertTrue(is_int($count));
64  $this->assertEquals(3, $count);
65  }
66 
67  function testSetSubParts() {
68 
69  $vcal = new VCalendar();
70  $recur = $vcal->add('RRULE', ['FREQ' => 'DAILY', 'BYDAY' => 'mo,tu', 'BYMONTH' => [0, 1]]);
71 
72  $this->assertEquals([
73  'FREQ' => 'DAILY',
74  'BYDAY' => ['MO', 'TU'],
75  'BYMONTH' => [0, 1],
76  ], $recur->getParts());
77 
78  }
79 
80  function testGetJSONWithUntil() {
81  $input = 'BEGIN:VCALENDAR
82 BEGIN:VEVENT
83 UID:908d53c0-e1a3-4883-b69f-530954d6bd62
84 TRANSP:OPAQUE
85 DTSTART;TZID=Europe/Berlin:20160301T150000
86 DTEND;TZID=Europe/Berlin:20160301T170000
87 SUMMARY:test
88 RRULE:FREQ=DAILY;UNTIL=20160305T230000Z
89 ORGANIZER;CN=robert pipo:mailto:robert@example.org
90 END:VEVENT
91 END:VCALENDAR
92 ';
93 
95  $rrule = $vcal->VEVENT->RRULE;
96  $untilJsonString = $rrule->getJsonValue()[0]['until'];
97  $this->assertEquals('2016-03-05T23:00:00Z', $untilJsonString);
98  }
99 
100 
102 
103  $input = 'BEGIN:VCALENDAR
104 VERSION:2.0
105 PRODID:foobar
106 BEGIN:VEVENT
107 UID:908d53c0-e1a3-4883-b69f-530954d6bd62
108 TRANSP:OPAQUE
109 DTSTART;TZID=Europe/Berlin:20160301T150000
110 DTEND;TZID=Europe/Berlin:20160301T170000
111 SUMMARY:test
112 RRULE:FREQ=DAILY;BYMONTH=;UNTIL=20160305T230000Z
113 ORGANIZER;CN=robert pipo:mailto:robert@example.org
114 DTSTAMP:20160312T183800Z
115 END:VEVENT
116 END:VCALENDAR
117 ';
118 
120  $this->assertEquals(
121  1,
122  count($vcal->validate())
123  );
124  $this->assertEquals(
125  1,
126  count($vcal->validate($vcal::REPAIR))
127  );
128 
129  $expected = 'BEGIN:VCALENDAR
130 VERSION:2.0
131 PRODID:foobar
132 BEGIN:VEVENT
133 UID:908d53c0-e1a3-4883-b69f-530954d6bd62
134 TRANSP:OPAQUE
135 DTSTART;TZID=Europe/Berlin:20160301T150000
136 DTEND;TZID=Europe/Berlin:20160301T170000
137 SUMMARY:test
138 RRULE:FREQ=DAILY;UNTIL=20160305T230000Z
139 ORGANIZER;CN=robert pipo:mailto:robert@example.org
140 DTSTAMP:20160312T183800Z
141 END:VEVENT
142 END:VCALENDAR
143 ';
144 
145  $this->assertVObjectEqualsVObject(
146  $expected,
147  $vcal
148  );
149 
150  }
151 
153 
154  $input = 'BEGIN:VCALENDAR
155 VERSION:2.0
156 PRODID:foobar
157 BEGIN:VEVENT
158 UID:908d53c0-e1a3-4883-b69f-530954d6bd62
159 TRANSP:OPAQUE
160 DTSTART;TZID=Europe/Berlin:20160301T150000
161 DTEND;TZID=Europe/Berlin:20160301T170000
162 SUMMARY:test
163 RRULE:UNTIL=20160305T230000Z
164 ORGANIZER;CN=robert pipo:mailto:robert@example.org
165 DTSTAMP:20160312T183800Z
166 END:VEVENT
167 END:VCALENDAR
168 ';
169 
171  $this->assertEquals(
172  1,
173  count($vcal->validate())
174  );
175  $this->assertEquals(
176  1,
177  count($vcal->validate($vcal::REPAIR))
178  );
179 
180  $expected = 'BEGIN:VCALENDAR
181 VERSION:2.0
182 PRODID:foobar
183 BEGIN:VEVENT
184 UID:908d53c0-e1a3-4883-b69f-530954d6bd62
185 TRANSP:OPAQUE
186 DTSTART;TZID=Europe/Berlin:20160301T150000
187 DTEND;TZID=Europe/Berlin:20160301T170000
188 SUMMARY:test
189 ORGANIZER;CN=robert pipo:mailto:robert@example.org
190 DTSTAMP:20160312T183800Z
191 END:VEVENT
192 END:VCALENDAR
193 ';
194 
195  $this->assertVObjectEqualsVObject(
196  $expected,
197  $vcal
198  );
199 
200  }
201 
203 
204  $calendar = new VCalendar();
205  $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=0');
206  $result = $property->validate(Node::REPAIR);
207 
208  $this->assertCount(1, $result);
209  $this->assertEquals('BYMONTH in RRULE must have value(s) between 1 and 12!', $result[0]['message']);
210  $this->assertEquals(1, $result[0]['level']);
211  $this->assertEquals('FREQ=YEARLY;COUNT=6;BYMONTHDAY=24', $property->getValue());
212 
213  }
214 
216 
217  $calendar = new VCalendar();
218  $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=0');
219  $result = $property->validate();
220 
221  $this->assertCount(1, $result);
222  $this->assertEquals('BYMONTH in RRULE must have value(s) between 1 and 12!', $result[0]['message']);
223  $this->assertEquals(3, $result[0]['level']);
224  $this->assertEquals('FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=0', $property->getValue());
225 
226  }
227 
229 
230  $calendar = new VCalendar();
231  $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=bla');
232  $result = $property->validate(Node::REPAIR);
233 
234  $this->assertCount(1, $result);
235  $this->assertEquals('BYMONTH in RRULE must have value(s) between 1 and 12!', $result[0]['message']);
236  $this->assertEquals(1, $result[0]['level']);
237  $this->assertEquals('FREQ=YEARLY;COUNT=6;BYMONTHDAY=24', $property->getValue());
238 
239  }
240 
242 
243  $calendar = new VCalendar();
244  $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=bla');
245  $result = $property->validate();
246 
247  $this->assertCount(1, $result);
248  $this->assertEquals('BYMONTH in RRULE must have value(s) between 1 and 12!', $result[0]['message']);
249  $this->assertEquals(3, $result[0]['level']);
250  // Without repair the invalid BYMONTH is still there, but the value is changed to uppercase
251  $this->assertEquals('FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=BLA', $property->getValue());
252 
253  }
254 
256 
257  $calendar = new VCalendar();
258  $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=14');
259  $result = $property->validate(Node::REPAIR);
260 
261  $this->assertCount(1, $result);
262  $this->assertEquals('BYMONTH in RRULE must have value(s) between 1 and 12!', $result[0]['message']);
263  $this->assertEquals(1, $result[0]['level']);
264  $this->assertEquals('FREQ=YEARLY;COUNT=6;BYMONTHDAY=24', $property->getValue());
265 
266  }
267 
269 
270  $calendar = new VCalendar();
271  $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=0,1,2,3,4,14');
272  $result = $property->validate(Node::REPAIR);
273 
274  $this->assertCount(2, $result);
275  $this->assertEquals('BYMONTH in RRULE must have value(s) between 1 and 12!', $result[0]['message']);
276  $this->assertEquals(1, $result[0]['level']);
277  $this->assertEquals('BYMONTH in RRULE must have value(s) between 1 and 12!', $result[1]['message']);
278  $this->assertEquals(1, $result[1]['level']);
279  $this->assertEquals('FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=1,2,3,4', $property->getValue());
280 
281  }
282 
284 
285  $calendar = new VCalendar();
286  $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=bla,3,foo');
287  $result = $property->validate(Node::REPAIR);
288 
289  $this->assertCount(2, $result);
290  $this->assertEquals('BYMONTH in RRULE must have value(s) between 1 and 12!', $result[0]['message']);
291  $this->assertEquals(1, $result[0]['level']);
292  $this->assertEquals('BYMONTH in RRULE must have value(s) between 1 and 12!', $result[1]['message']);
293  $this->assertEquals(1, $result[1]['level']);
294  $this->assertEquals('FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=3', $property->getValue());
295 
296  }
297 
299 
300  $calendar = new VCalendar();
301  $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=2,3');
302  $this->assertEquals('FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=2,3', $property->getValue());
303 
304  }
305 
310 
311  $calendar = new VCalendar();
312  $property = $calendar->createProperty('RRULE', 'FREQ=DAILY;BYHOUR=10;BYMINUTE=30;BYSECOND=0;UNTIL=20150616T153000Z');
313  $result = $property->validate(Node::REPAIR);
314 
315  // There should be 0 warnings and the value should be unchanged
316  $this->assertEmpty($result);
317  $this->assertEquals('FREQ=DAILY;BYHOUR=10;BYMINUTE=30;BYSECOND=0;UNTIL=20150616T153000Z', $property->getValue());
318 
319  }
320 
322 
323  $calendar = new VCalendar();
324  $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYWEEKNO=11');
325  $result = $property->validate(Node::REPAIR);
326 
327  $this->assertCount(0, $result);
328  $this->assertEquals('FREQ=YEARLY;COUNT=6;BYWEEKNO=11', $property->getValue());
329 
330  }
331 
333 
334  $calendar = new VCalendar();
335  $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYWEEKNO=55;BYDAY=WE');
336  $result = $property->validate(Node::REPAIR);
337 
338  $this->assertCount(1, $result);
339  $this->assertEquals('BYWEEKNO in RRULE must have value(s) from -53 to -1, or 1 to 53!', $result[0]['message']);
340  $this->assertEquals(1, $result[0]['level']);
341  $this->assertEquals('FREQ=YEARLY;COUNT=6;BYDAY=WE', $property->getValue());
342 
343  }
344 
346 
347  $calendar = new VCalendar();
348  $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYWEEKNO=55,2,-80;BYDAY=WE');
349  $result = $property->validate(Node::REPAIR);
350 
351  $this->assertCount(2, $result);
352  $this->assertEquals('BYWEEKNO in RRULE must have value(s) from -53 to -1, or 1 to 53!', $result[0]['message']);
353  $this->assertEquals(1, $result[0]['level']);
354  $this->assertEquals('BYWEEKNO in RRULE must have value(s) from -53 to -1, or 1 to 53!', $result[1]['message']);
355  $this->assertEquals(1, $result[1]['level']);
356  $this->assertEquals('FREQ=YEARLY;COUNT=6;BYWEEKNO=2;BYDAY=WE', $property->getValue());
357 
358  }
359 
361 
362  $calendar = new VCalendar();
363  $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYWEEKNO=55,-80;BYDAY=WE');
364  $result = $property->validate(Node::REPAIR);
365 
366  $this->assertCount(2, $result);
367  $this->assertEquals('BYWEEKNO in RRULE must have value(s) from -53 to -1, or 1 to 53!', $result[0]['message']);
368  $this->assertEquals(1, $result[0]['level']);
369  $this->assertEquals('BYWEEKNO in RRULE must have value(s) from -53 to -1, or 1 to 53!', $result[1]['message']);
370  $this->assertEquals(1, $result[1]['level']);
371  $this->assertEquals('FREQ=YEARLY;COUNT=6;BYDAY=WE', $property->getValue());
372 
373  }
374 
376 
377  $calendar = new VCalendar();
378  $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYWEEKNO=55;BYDAY=WE');
379  $result = $property->validate();
380 
381  $this->assertCount(1, $result);
382  $this->assertEquals('BYWEEKNO in RRULE must have value(s) from -53 to -1, or 1 to 53!', $result[0]['message']);
383  $this->assertEquals(3, $result[0]['level']);
384  $this->assertEquals('FREQ=YEARLY;COUNT=6;BYWEEKNO=55;BYDAY=WE', $property->getValue());
385 
386  }
387 
389 
390  $calendar = new VCalendar();
391  $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYYEARDAY=119');
392  $result = $property->validate(Node::REPAIR);
393 
394  $this->assertCount(0, $result);
395  $this->assertEquals('FREQ=YEARLY;COUNT=6;BYYEARDAY=119', $property->getValue());
396 
397  }
398 
400 
401  $calendar = new VCalendar();
402  $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYYEARDAY=367;BYDAY=WE');
403  $result = $property->validate(Node::REPAIR);
404 
405  $this->assertCount(1, $result);
406  $this->assertEquals('BYYEARDAY in RRULE must have value(s) from -366 to -1, or 1 to 366!', $result[0]['message']);
407  $this->assertEquals(1, $result[0]['level']);
408  $this->assertEquals('FREQ=YEARLY;COUNT=6;BYDAY=WE', $property->getValue());
409 
410  }
411 
413 
414  $calendar = new VCalendar();
415  $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYYEARDAY=380,2,-390;BYDAY=WE');
416  $result = $property->validate(Node::REPAIR);
417 
418  $this->assertCount(2, $result);
419  $this->assertEquals('BYYEARDAY in RRULE must have value(s) from -366 to -1, or 1 to 366!', $result[0]['message']);
420  $this->assertEquals(1, $result[0]['level']);
421  $this->assertEquals('BYYEARDAY in RRULE must have value(s) from -366 to -1, or 1 to 366!', $result[1]['message']);
422  $this->assertEquals(1, $result[1]['level']);
423  $this->assertEquals('FREQ=YEARLY;COUNT=6;BYYEARDAY=2;BYDAY=WE', $property->getValue());
424 
425  }
426 
428 
429  $calendar = new VCalendar();
430  $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYYEARDAY=455,-480;BYDAY=WE');
431  $result = $property->validate(Node::REPAIR);
432 
433  $this->assertCount(2, $result);
434  $this->assertEquals('BYYEARDAY in RRULE must have value(s) from -366 to -1, or 1 to 366!', $result[0]['message']);
435  $this->assertEquals(1, $result[0]['level']);
436  $this->assertEquals('BYYEARDAY in RRULE must have value(s) from -366 to -1, or 1 to 366!', $result[1]['message']);
437  $this->assertEquals(1, $result[1]['level']);
438  $this->assertEquals('FREQ=YEARLY;COUNT=6;BYDAY=WE', $property->getValue());
439 
440  }
441 
443 
444  $calendar = new VCalendar();
445  $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYYEARDAY=380;BYDAY=WE');
446  $result = $property->validate();
447 
448  $this->assertCount(1, $result);
449  $this->assertEquals('BYYEARDAY in RRULE must have value(s) from -366 to -1, or 1 to 366!', $result[0]['message']);
450  $this->assertEquals(3, $result[0]['level']);
451  $this->assertEquals('FREQ=YEARLY;COUNT=6;BYYEARDAY=380;BYDAY=WE', $property->getValue());
452 
453  }
454 }
$result
if($argc< 3) $input
testValidateRruleBySecondZero()
test for issue #336
Definition: RecurTest.php:309
The VCalendar component.
Definition: VCalendar.php:23
const REPAIR
The following constants are used by the validate() method.
Definition: Node.php:27
count()
Returns the number of elements.
Definition: Node.php:177
static read($data, $options=0, $charset='UTF-8')
Parses a vCard or iCalendar object, and returns the top component.
Definition: Reader.php:42