~ubuntu-branches/ubuntu/vivid/php-horde-icalendar/vivid-proposed

« back to all changes in this revision

Viewing changes to Horde_Icalendar-2.0.5/test/Horde/Icalendar/ParseTest.php

  • Committer: Package Import Robot
  • Author(s): Mathieu Parent
  • Date: 2013-05-14 20:46:43 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130514204643-xq5x2ezjku3om1um
Tags: 2.0.5-1
New upstream version 2.0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * @category   Horde
 
4
 * @package    Icalendar
 
5
 * @subpackage UnitTests
 
6
 */
 
7
 
 
8
/**
 
9
 * @category   Horde
 
10
 * @package    Icalendar
 
11
 * @subpackage UnitTests
 
12
 */
 
13
class Horde_Icalendar_ParseTest extends Horde_Test_Case
 
14
{
 
15
    public function testEmptyData()
 
16
    {
 
17
        $ical = new Horde_Icalendar();
 
18
        $ical->parsevCalendar(file_get_contents(__DIR__ . '/fixtures/empty.ics'));
 
19
        $this->assertEquals(
 
20
            array(),
 
21
            $ical->getComponents()
 
22
        );
 
23
        $ical->parsevCalendar('');
 
24
        $this->assertEquals(
 
25
            array(),
 
26
            $ical->getComponents()
 
27
        );
 
28
    }
 
29
 
 
30
    public function testEscapes()
 
31
    {
 
32
        $ical = new Horde_Icalendar();
 
33
        $ical->parsevCalendar(file_get_contents(__DIR__ . '/fixtures/escapes1.ics'));
 
34
        $this->assertEquals(
 
35
            array('There is a comma (escaped with a baskslash) in this sentence and some important words after it, see anything here?'),
 
36
            $ical->getComponent(0)->getAttributeValues('DESCRIPTION')
 
37
        );
 
38
        $this->assertEquals(
 
39
            array('There are important words after this dash - see anything here or have the words gone?'),
 
40
            $ical->getComponent(1)->getAttributeValues('DESCRIPTION')
 
41
        );
 
42
        $this->assertEquals(
 
43
            array('mailto:a@b.c'),
 
44
            $ical->getComponent(1)->getAttributeValues('ORGANIZER')
 
45
        );
 
46
    }
 
47
 
 
48
    public function testQuotedParameters()
 
49
    {
 
50
        $ical = new Horde_Icalendar();
 
51
        $ical->parsevCalendar(file_get_contents(__DIR__ . '/fixtures/quoted-params.ics'));
 
52
        $attr = $ical->getComponent(0)->getAttribute('ORGANIZER', true);
 
53
        $this->assertEquals(
 
54
            'Klä,rchen; Mül:ler',
 
55
            $attr[0]['CN']
 
56
        );
 
57
    }
 
58
 
 
59
    public function testVcalendar20()
 
60
    {
 
61
        $ical = new Horde_Icalendar();
 
62
        $ical->parsevCalendar(file_get_contents(__DIR__ . '/fixtures/vcal20.ics'));
 
63
 
 
64
        $this->assertEquals(
 
65
            array(
 
66
              0 => 
 
67
              array(
 
68
                'name' => 'PRODID',
 
69
                'params' => 
 
70
                array(
 
71
                ),
 
72
                'value' => '-//Google Inc//Google Calendar 70.9054//EN',
 
73
                'values' => 
 
74
                array(
 
75
                  0 => '-//Google Inc//Google Calendar 70.9054//EN',
 
76
                ),
 
77
              ),
 
78
              1 => 
 
79
              array(
 
80
                'name' => 'VERSION',
 
81
                'params' => 
 
82
                array(
 
83
                ),
 
84
                'value' => '2.0',
 
85
                'values' => 
 
86
                array(
 
87
                  0 => '2.0',
 
88
                ),
 
89
              ),
 
90
              2 => 
 
91
              array(
 
92
                'name' => 'CALSCALE',
 
93
                'params' => 
 
94
                array(
 
95
                ),
 
96
                'value' => 'GREGORIAN',
 
97
                'values' => 
 
98
                array(
 
99
                  0 => 'GREGORIAN',
 
100
                ),
 
101
              ),
 
102
              3 => 
 
103
              array(
 
104
                'name' => 'METHOD',
 
105
                'params' => 
 
106
                array(
 
107
                ),
 
108
                'value' => 'PUBLISH',
 
109
                'values' => 
 
110
                array(
 
111
                  0 => 'PUBLISH',
 
112
                ),
 
113
              ),
 
114
              4 => 
 
115
              array(
 
116
                'name' => 'X-WR-CALNAME',
 
117
                'params' => 
 
118
                array(
 
119
                ),
 
120
                'value' => 'PEAR - PHP Extension and Application Repository',
 
121
                'values' => 
 
122
                array(
 
123
                  0 => 'PEAR - PHP Extension and Application Repository',
 
124
                ),
 
125
              ),
 
126
              5 => 
 
127
              array(
 
128
                'name' => 'X-WR-TIMEZONE',
 
129
                'params' => 
 
130
                array(
 
131
                ),
 
132
                'value' => 'Atlantic/Reykjavik',
 
133
                'values' => 
 
134
                array(
 
135
                  0 => 'Atlantic/Reykjavik',
 
136
                ),
 
137
              ),
 
138
              6 => 
 
139
              array(
 
140
                'name' => 'X-WR-CALDESC',
 
141
                'params' => 
 
142
                array(
 
143
                ),
 
144
                'value' => 'pear.php.net activity calendar, bug triage, group meetings, qa, conferences or similar',
 
145
                'values' => 
 
146
                array(
 
147
                  0 => 'pear.php.net activity calendar, bug triage, group meetings, qa, conferences or similar',
 
148
                ),
 
149
              ),
 
150
            ),
 
151
            $ical->getAllAttributes()
 
152
        );
 
153
 
 
154
        $this->assertEquals(
 
155
            array(
 
156
              0 => 
 
157
              array(
 
158
                'name' => 'DTSTART',
 
159
                'params' => 
 
160
                array(
 
161
                ),
 
162
                'value' => 1224950400,
 
163
                'values' => 
 
164
                array(
 
165
                  0 => 1224950400,
 
166
                ),
 
167
              ),
 
168
              1 => 
 
169
              array(
 
170
                'name' => 'DTEND',
 
171
                'params' => 
 
172
                array(
 
173
                ),
 
174
                'value' => 1224968400,
 
175
                'values' => 
 
176
                array(
 
177
                  0 => 1224968400,
 
178
                ),
 
179
              ),
 
180
              2 => 
 
181
              array(
 
182
                'name' => 'DTSTAMP',
 
183
                'params' => 
 
184
                array(
 
185
                ),
 
186
                'value' => 1219138073,
 
187
                'values' => 
 
188
                array(
 
189
                  0 => 1219138073,
 
190
                ),
 
191
              ),
 
192
              3 => 
 
193
              array(
 
194
                'name' => 'UID',
 
195
                'params' => 
 
196
                array(
 
197
                ),
 
198
                'value' => 'ntnrt4go4482q2trk18bt62c0o@google.com',
 
199
                'values' => 
 
200
                array(
 
201
                  0 => 'ntnrt4go4482q2trk18bt62c0o@google.com',
 
202
                ),
 
203
              ),
 
204
              4 => 
 
205
              array(
 
206
                'name' => 'RECURRENCE-ID',
 
207
                'params' => 
 
208
                array(
 
209
                ),
 
210
                'value' => 1224950400,
 
211
                'values' => 
 
212
                array(
 
213
                  0 => 1224950400,
 
214
                ),
 
215
              ),
 
216
              5 => 
 
217
              array(
 
218
                'name' => 'CLASS',
 
219
                'params' => 
 
220
                array(
 
221
                ),
 
222
                'value' => 'PUBLIC',
 
223
                'values' => 
 
224
                array(
 
225
                  0 => 'PUBLIC',
 
226
                ),
 
227
              ),
 
228
              6 => 
 
229
              array(
 
230
                'name' => 'CREATED',
 
231
                'params' => 
 
232
                array(
 
233
                ),
 
234
                'value' => 1204763165,
 
235
                'values' => 
 
236
                array(
 
237
                  0 => 1204763165,
 
238
                ),
 
239
              ),
 
240
              7 => 
 
241
              array(
 
242
                'name' => 'DESCRIPTION',
 
243
                'params' => 
 
244
                array(
 
245
                ),
 
246
                'value' => 'Bug Triage session
 
247
 
 
248
Not been invited ? Want to attend ? Let us know and we\'ll add you!',
 
249
                'values' => 
 
250
                array(
 
251
                  0 => 'Bug Triage session
 
252
 
 
253
Not been invited ? Want to attend ? Let us know and we\'ll add you!',
 
254
                ),
 
255
              ),
 
256
              8 => 
 
257
              array(
 
258
                'name' => 'LAST-MODIFIED',
 
259
                'params' => 
 
260
                array(
 
261
                ),
 
262
                'value' => 1216413606,
 
263
                'values' => 
 
264
                array(
 
265
                  0 => 1216413606,
 
266
                ),
 
267
              ),
 
268
              9 => 
 
269
              array(
 
270
                'name' => 'LOCATION',
 
271
                'params' => 
 
272
                array(
 
273
                ),
 
274
                'value' => '#pear-bugs Efnet',
 
275
                'values' => 
 
276
                array(
 
277
                  0 => '#pear-bugs Efnet',
 
278
                ),
 
279
              ),
 
280
              10 => 
 
281
              array(
 
282
                'name' => 'SEQUENCE',
 
283
                'params' => 
 
284
                array(
 
285
                ),
 
286
                'value' => 2,
 
287
                'values' => 
 
288
                array(
 
289
                  0 => 2,
 
290
                ),
 
291
              ),
 
292
              11 => 
 
293
              array(
 
294
                'name' => 'STATUS',
 
295
                'params' => 
 
296
                array(
 
297
                ),
 
298
                'value' => 'CONFIRMED',
 
299
                'values' => 
 
300
                array(
 
301
                  0 => 'CONFIRMED',
 
302
                ),
 
303
              ),
 
304
              12 => 
 
305
              array(
 
306
                'name' => 'SUMMARY',
 
307
                'params' => 
 
308
                array(
 
309
                ),
 
310
                'value' => 'Bug Triage',
 
311
                'values' => 
 
312
                array(
 
313
                  0 => 'Bug Triage',
 
314
                ),
 
315
              ),
 
316
              13 => 
 
317
              array(
 
318
                'name' => 'TRANSP',
 
319
                'params' => 
 
320
                array(
 
321
                ),
 
322
                'value' => 'OPAQUE',
 
323
                'values' => 
 
324
                array(
 
325
                  0 => 'OPAQUE',
 
326
                ),
 
327
              ),
 
328
              14 => 
 
329
              array(
 
330
                'name' => 'CATEGORIES',
 
331
                'params' => 
 
332
                array(
 
333
                ),
 
334
                'value' => 'foo,bar,fuz buz,blah, blah',
 
335
                'values' => 
 
336
                array(
 
337
                  0 => 'foo',
 
338
                  1 => 'bar',
 
339
                  2 => 'fuz buz',
 
340
                  3 => 'blah, blah',
 
341
                ),
 
342
              ),
 
343
            ),
 
344
            $ical->getComponent(0)->getAllAttributes()
 
345
        );
 
346
    }
 
347
 
 
348
    public function testBug7423()
 
349
    {
 
350
        $ical = new Horde_Icalendar();
 
351
        $ical->parsevCalendar(file_get_contents(__DIR__ . '/fixtures/bug7423.ics'));
 
352
        $this->assertEquals(
 
353
            array('SUMMARY' => 'birthday'),
 
354
            $ical->getComponent(0)->toHash(true)
 
355
        );
 
356
    }
 
357
}