]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/VObject/FreeBusyGeneratorTest.php
Move friendica-specific parts into an own subdirectory
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / VObject / FreeBusyGeneratorTest.php
1 <?php
2
3 class Sabre_VObject_FreeBusyGeneratorTest extends PHPUnit_Framework_TestCase {
4
5     function getInput() {
6
7         // shows up
8 $blob1 = <<<ICS
9 BEGIN:VCALENDAR
10 BEGIN:VEVENT
11 DTSTART:20110101T120000Z
12 DTEND:20110101T130000Z
13 END:VEVENT
14 END:VCALENDAR
15 ICS;
16
17     // opaque, shows up
18 $blob2 = <<<ICS
19 BEGIN:VCALENDAR
20 BEGIN:VEVENT
21 TRANSP:OPAQUE
22 DTSTART:20110101T130000Z
23 DTEND:20110101T140000Z
24 END:VEVENT
25 END:VCALENDAR
26 ICS;
27
28     // transparent, hidden
29 $blob3 = <<<ICS
30 BEGIN:VCALENDAR
31 BEGIN:VEVENT
32 TRANSP:TRANSPARENT
33 DTSTART:20110101T140000Z
34 DTEND:20110101T150000Z
35 END:VEVENT
36 END:VCALENDAR
37 ICS;
38
39     // cancelled, hidden
40 $blob4 = <<<ICS
41 BEGIN:VCALENDAR
42 BEGIN:VEVENT
43 STATUS:CANCELLED
44 DTSTART:20110101T160000Z
45 DTEND:20110101T170000Z
46 END:VEVENT
47 END:VCALENDAR
48 ICS;
49
50     // tentative, shows up
51 $blob5 = <<<ICS
52 BEGIN:VCALENDAR
53 BEGIN:VEVENT
54 STATUS:TENTATIVE
55 DTSTART:20110101T180000Z
56 DTEND:20110101T190000Z
57 END:VEVENT
58 END:VCALENDAR
59 ICS;
60
61     // outside of time-range, hidden
62 $blob6 = <<<ICS
63 BEGIN:VCALENDAR
64 BEGIN:VEVENT
65 DTSTART:20110101T090000Z
66 DTEND:20110101T100000Z
67 END:VEVENT
68 END:VCALENDAR
69 ICS;
70
71     // outside of time-range, hidden
72 $blob7 = <<<ICS
73 BEGIN:VCALENDAR
74 BEGIN:VEVENT
75 DTSTART:20110104T090000Z
76 DTEND:20110104T100000Z
77 END:VEVENT
78 END:VCALENDAR
79 ICS;
80
81     // using duration, shows up
82 $blob8 = <<<ICS
83 BEGIN:VCALENDAR
84 BEGIN:VEVENT
85 DTSTART:20110101T190000Z
86 DURATION:PT1H
87 END:VEVENT
88 END:VCALENDAR
89 ICS;
90
91     // Day-long event, shows up
92 $blob9 = <<<ICS
93 BEGIN:VCALENDAR
94 BEGIN:VEVENT
95 DTSTART;TYPE=DATE:20110102
96 END:VEVENT
97 END:VCALENDAR
98 ICS;
99
100 // No duration, does not show up
101 $blob10 = <<<ICS
102 BEGIN:VCALENDAR
103 BEGIN:VEVENT
104 DTSTART:20110101T200000Z
105 END:VEVENT
106 END:VCALENDAR
107 ICS;
108
109 // encoded as object, shows up
110 $blob11 = <<<ICS
111 BEGIN:VCALENDAR
112 BEGIN:VEVENT
113 DTSTART:20110101T210000Z
114 DURATION:PT1H
115 END:VEVENT
116 END:VCALENDAR
117 ICS;
118
119 // Freebusy. Some parts show up
120 $blob12 = <<<ICS
121 BEGIN:VCALENDAR
122 BEGIN:VFREEBUSY
123 FREEBUSY:20110103T010000Z/20110103T020000Z
124 FREEBUSY;FBTYPE=FREE:20110103T020000Z/20110103T030000Z
125 FREEBUSY:20110103T030000Z/20110103T040000Z,20110103T040000Z/20110103T050000Z
126 FREEBUSY:20120101T000000Z/20120101T010000Z
127 FREEBUSY:20110103T050000Z/PT1H
128 END:VFREEBUSY
129 END:VCALENDAR
130 ICS;
131
132 // Yearly recurrence rule, shows up
133 $blob13 = <<<ICS
134 BEGIN:VCALENDAR
135 BEGIN:VEVENT
136 DTSTART:20100101T220000Z
137 DTEND:20100101T230000Z
138 RRULE:FREQ=YEARLY
139 END:VEVENT
140 END:VCALENDAR
141 ICS;
142
143 // Yearly recurrence rule + duration, shows up
144 $blob14 = <<<ICS
145 BEGIN:VCALENDAR
146 BEGIN:VEVENT
147 DTSTART:20100101T230000Z
148 DURATION:PT1H
149 RRULE:FREQ=YEARLY
150 END:VEVENT
151 END:VCALENDAR
152 ICS;
153
154
155         return array(
156             $blob1,
157             $blob2,
158             $blob3,
159             $blob4,
160             $blob5,
161             $blob6,
162             $blob7,
163             $blob8,
164             $blob9,
165             $blob10,
166             Sabre_VObject_Reader::read($blob11),
167             $blob12,
168             $blob13,
169             $blob14,
170         );
171
172     }
173
174     function testGenerator() {
175
176         $gen = new Sabre_VObject_FreeBusyGenerator();
177         $gen->setObjects($this->getInput());
178         $gen->setTimeRange(
179             new DateTime('20110101T110000Z'),
180             new DateTime('20110103T110000Z')
181         );
182
183         $result = $gen->getResult();
184
185         $expected = array(
186             '20110101T120000Z/20110101T130000Z',
187             '20110101T130000Z/20110101T140000Z',
188             '20110101T180000Z/20110101T190000Z',
189             '20110101T190000Z/20110101T200000Z',
190             '20110102T000000Z/20110103T000000Z',
191             '20110101T210000Z/20110101T220000Z',
192
193             '20110103T010000Z/20110103T020000Z',
194             '20110103T030000Z/20110103T040000Z',
195             '20110103T040000Z/20110103T050000Z',
196             '20110103T050000Z/20110103T060000Z',
197
198             '20110101T220000Z/20110101T230000Z',
199             '20110101T230000Z/20110102T000000Z',
200         );
201
202         foreach($result->VFREEBUSY->FREEBUSY as $fb) {
203
204             $this->assertContains((string)$fb, $expected);
205
206             $k = array_search((string)$fb, $expected);
207             unset($expected[$k]);
208
209         }
210         if (count($expected)>0) {
211             $this->fail('There were elements in the expected array that were not found in the output: ' . "\n"  . print_r($expected,true) . "\n" . $result->serialize());
212
213         }
214
215     }
216
217     function testGeneratorBaseObject() {
218
219         $obj = new Sabre_VObject_Component('VCALENDAR');
220         $obj->METHOD = 'PUBLISH';
221
222         $gen = new Sabre_VObject_FreeBusyGenerator();
223         $gen->setObjects(array());
224         $gen->setBaseObject($obj);
225
226         $result = $gen->getResult();
227
228         $this->assertEquals('PUBLISH', $result->METHOD->value);
229
230     }
231     function testGeneratorNoVersion() {
232
233         $v = Sabre_DAV_Server::$exposeVersion;
234         Sabre_DAV_Server::$exposeVersion = false;
235
236         $gen = new Sabre_VObject_FreeBusyGenerator();
237         $gen->setObjects(array());
238
239         $result = $gen->getResult();
240         Sabre_DAV_Server::$exposeVersion = $v;
241
242         $this->assertFalse(strpos($result->PRODID->value, Sabre_VObject_Version::VERSION));
243
244     }
245
246     /**
247      * @expectedException InvalidArgumentException
248      */
249     function testInvalidArg() {
250
251         $gen = new Sabre_VObject_FreeBusyGenerator();
252         $gen->setObjects(array(new StdClass()));
253
254     }
255
256 }