Blame view

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