ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
VJournalTest.php
Go to the documentation of this file.
1<?php
2
4
5use PHPUnit\Framework\TestCase;
8
9class VJournalTest extends TestCase {
10
14 function testInTimeRange(VJournal $vtodo, $start, $end, $outcome) {
15
16 $this->assertEquals($outcome, $vtodo->isInTimeRange($start, $end));
17
18 }
19
20 function testValidate() {
21
22 $input = <<<HI
23BEGIN:VCALENDAR
24VERSION:2.0
25PRODID:YoYo
26BEGIN:VJOURNAL
27UID:12345678
28DTSTAMP:20140402T174100Z
29END:VJOURNAL
30END:VCALENDAR
31HI;
32
33 $obj = Reader::read($input);
34
35 $warnings = $obj->validate();
36 $messages = [];
37 foreach ($warnings as $warning) {
38 $messages[] = $warning['message'];
39 }
40
41 $this->assertEquals([], $messages);
42
43 }
44
45 function testValidateBroken() {
46
47 $input = <<<HI
48BEGIN:VCALENDAR
49VERSION:2.0
50PRODID:YoYo
51BEGIN:VJOURNAL
52UID:12345678
53DTSTAMP:20140402T174100Z
54URL:http://example.org/
55URL:http://example.com/
56END:VJOURNAL
57END:VCALENDAR
58HI;
59
60 $obj = Reader::read($input);
61
62 $warnings = $obj->validate();
63 $messages = [];
64 foreach ($warnings as $warning) {
65 $messages[] = $warning['message'];
66 }
67
68 $this->assertEquals(
69 ["URL MUST NOT appear more than once in a VJOURNAL component"],
71 );
72
73 }
74
75 function timeRangeTestData() {
76
77 $calendar = new VCalendar();
78
79 $tests = [];
80
81 $vjournal = $calendar->createComponent('VJOURNAL');
82 $vjournal->DTSTART = '20111223T120000Z';
83 $tests[] = [$vjournal, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true];
84 $tests[] = [$vjournal, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false];
85
86 $vjournal2 = $calendar->createComponent('VJOURNAL');
87 $vjournal2->DTSTART = '20111223';
88 $vjournal2->DTSTART['VALUE'] = 'DATE';
89 $tests[] = [$vjournal2, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true];
90 $tests[] = [$vjournal2, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false];
91
92 $vjournal3 = $calendar->createComponent('VJOURNAL');
93 $tests[] = [$vjournal3, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), false];
94 $tests[] = [$vjournal3, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false];
95
96 return $tests;
97 }
98
99
100
101}
$warning
Definition: X509warning.php:13
An exception for terminatinating execution or to throw for unit testing.
The VCalendar component.
Definition: VCalendar.php:23
testInTimeRange(VJournal $vtodo, $start, $end, $outcome)
@dataProvider timeRangeTestData
isInTimeRange(DateTimeInterface $start, DateTimeInterface $end)
Returns true or false depending on if the event falls in the specified time-range.
Definition: VJournal.php:31
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
$messages
Definition: en.php:5
$tests
Definition: bench.php:104
static http()
Fetches the global http state from ILIAS.
foreach($paths as $path) if($argc< 3) $input
$start
Definition: bench.php:8