File: CalendarFeedCompositeTest.php

package info (click to toggle)
zendframework 1.12.9%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 133,584 kB
  • sloc: xml: 1,311,829; php: 570,173; sh: 170; makefile: 125; sql: 121
file content (509 lines) | stat: -rw-r--r-- 18,947 bytes parent folder | download | duplicates (2)
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Gdata_Calendar
 * @subpackage UnitTests
 * @copyright  Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id $
 */

require_once 'Zend/Gdata/Calendar.php';
require_once 'Zend/Gdata/Calendar/EventFeed.php';
require_once 'Zend/Http/Client.php';
require_once 'Zend/Http/Client/Adapter/Test.php';

/**
 * @category   Zend
 * @package    Zend_Gdata_Calendar
 * @subpackage UnitTests
 * @copyright  Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @group      Zend_Gdata
 * @group      Zend_Gdata_Calendar
 */
class Zend_Gdata_CalendarFeedCompositeTest extends PHPUnit_Framework_TestCase
{
    protected $eventFeed = null;

    /**
      * Called before each test to setup any fixtures.
      */
    public function setUp()
    {
        $eventFeedText = file_get_contents(
                'Zend/Gdata/Calendar/_files/EventFeedCompositeSample1.xml',
                true);
        $this->eventFeed = new Zend_Gdata_Calendar_EventFeed($eventFeedText);
    }

    /**
      * Verify that a given property is set to a specific value
      * and that the getter and magic variable return the same value.
      *
      * @param object $obj The object to be interrogated.
      * @param string $name The name of the property to be verified.
      * @param object $value The expected value of the property.
      */
    protected function verifyProperty($obj, $name, $value)
    {
        $propName = $name;
        $propGetter = "get" . ucfirst($name);

        $this->assertEquals($obj->$propGetter(), $obj->$propName);
        $this->assertEquals($obj->$propGetter(), $value);
    }

    /**
      * Verify that a given property is set to a specific value
      * and that the getter and magic variable return the same value.
      *
      * @param object $obj The object to be interrogated.
      * @param string $name The name of the property to be verified.
      * @param string $secondName 2nd level accessor function name
      * @param object $value The expected value of the property.
      */
    protected function verifyProperty2($obj, $name, $secondName, $value)
    {
        $propName = $name;
        $propGetter = "get" . ucfirst($name);
        $secondGetter = "get" . ucfirst($secondName);

        $this->assertEquals($obj->$propGetter(), $obj->$propName);
        $this->assertEquals($obj->$propGetter()->$secondGetter(), $value);
    }

    /**
      * Convert sample feed to XML then back to objects. Ensure that
      * all objects are instances of EventEntry and object count matches.
      */
    public function testEventFeedToAndFromString()
    {
        $entryCount = 0;
        foreach ($this->eventFeed as $entry) {
            $entryCount++;
            $this->assertTrue($entry instanceof Zend_Gdata_Calendar_EventEntry);
        }
        $this->assertTrue($entryCount > 0);

        /* Grab XML from $this->eventFeed and convert back to objects */
        $newEventFeed = new Zend_Gdata_Calendar_EventFeed(
                $this->eventFeed->saveXML());
        $newEntryCount = 0;
        foreach ($newEventFeed as $entry) {
            $newEntryCount++;
            $this->assertTrue($entry instanceof Zend_Gdata_Calendar_EventEntry);
        }
        $this->assertEquals($entryCount, $newEntryCount);
    }

    /**
      * Ensure that there number of lsit feeds equals the number
      * of calendars defined in the sample file.
      */
    public function testEntryCount()
    {
        //TODO feeds implementing ArrayAccess would be helpful here
        $entryCount = 0;
        foreach ($this->eventFeed as $entry) {
            $entryCount++;
        }
        $this->assertEquals(7, $entryCount);
        $this->assertEquals($entryCount, $this->eventFeed->totalResults->text);
    }

    /**
      * Check for the existence of an <atom:author> and verify that they
      * contain the expected values.
      */
    public function testAuthor()
    {
        $feed = $this->eventFeed;

        // Assert that the feed's author is correct
        $feedAuthor = $feed->getAuthor();
        $this->assertEquals($feedAuthor, $feed->author);
        $this->assertEquals(1, count($feedAuthor));
        $this->assertTrue($feedAuthor[0] instanceof Zend_Gdata_App_Extension_Author);
        $this->verifyProperty2($feedAuthor[0], "name", "text", "GData Ops Demo");
        $this->verifyProperty2($feedAuthor[0], "email", "text", "gdata.ops.demo@gmail.com");

        // Assert that each entry has valid author data
        foreach ($feed as $entry) {
            $entryAuthor = $entry->getAuthor();
            $this->assertEquals(1, count($entryAuthor));
            $this->verifyProperty2($entryAuthor[0], "name", "text", "GData Ops Demo");
            $this->verifyProperty2($entryAuthor[0], "email", "text", "gdata.ops.demo@gmail.com");
            $this->verifyProperty($entryAuthor[0], "uri", null);
        }
    }

    /**
      * Check for the existence of an <atom:id> and verify that it contains
      * the expected value.
      */
    public function testId()
    {
        $feed = $this->eventFeed;

        // Assert that the feed's ID is correct
        $this->assertTrue($feed->getId() instanceof Zend_Gdata_App_Extension_Id);
        $this->verifyProperty2($feed, "id", "text",
                "http://www.google.com/calendar/feeds/default/private/composite");

        // Assert that all entry's have an Atom ID object
        foreach ($feed as $entry) {
            $this->assertTrue($entry->getId() instanceof Zend_Gdata_App_Extension_Id);
        }

        // Assert one of the entry's IDs
        $entry = $feed[2];
        $this->verifyProperty2($entry, "id", "text",
                "http://www.google.com/calendar/feeds/default/private/composite/lq2ai6imsbq209q3aeturho50g");
    }

    /**
      * Check for the existence of an <atom:published> and verify that it contains
      * the expected value.
      */
    public function testPublished()
    {
        $feed = $this->eventFeed;

        // Assert that all entry's have an Atom Published object
        foreach ($feed as $entry) {
            $this->assertTrue($entry->getPublished() instanceof Zend_Gdata_App_Extension_Published);
        }

        // Assert one of the entry's Published dates
        $entry = $feed[2];
        $this->verifyProperty2($entry, "published", "text", "2007-05-09T16:44:38.000Z");
    }

    /**
      * Check for the existence of an <atom:updated> and verify that it contains
      * the expected value.
      */
    public function testUpdated()
    {
        $feed = $this->eventFeed;

        // Assert that the feed's updated date is correct
        $this->assertTrue($feed->getUpdated() instanceof Zend_Gdata_App_Extension_Updated);
        $this->verifyProperty2($feed, "updated", "text",
                "2007-05-31T01:15:00.000Z");

        // Assert that all entry's have an Atom Published object
        foreach ($feed as $entry) {
            $this->assertTrue($entry->getUpdated() instanceof Zend_Gdata_App_Extension_Updated);
        }

        // Assert one of the entry's Published dates
        $entry = $feed[2];
        $this->verifyProperty2($entry, "updated", "text", "2007-05-17T10:33:49.000Z");
    }

    /**
      * Check for the existence of an <atom:title> and verify that it contains
      * the expected value.
      */
    public function testTitle()
    {
        $feed = $this->eventFeed;

        // Assert that the feed's title is correct
        $this->assertTrue($feed->getTitle() instanceof Zend_Gdata_App_Extension_Title);
        $this->verifyProperty2($feed, "title", "text",
                "GData Ops Demo's Composite View");

        // Assert that all entry's have an Atom ID object
        foreach ($feed as $entry) {
            $this->assertTrue($entry->getTitle() instanceof Zend_Gdata_App_Extension_Title);
        }

        // Assert one of the entry's Titles
        $entry = $feed[2];
        $this->verifyProperty2($entry, "title", "text", "all day event may 24");
    }

    /**
      * Check for the existence of an <atom:subtitle> and verify that it contains
      * the expected value.
      */
    public function testSubtitle()
    {
        $feed = $this->eventFeed;

        // Assert that the feed's title is correct
        $this->assertTrue($feed->getSubtitle() instanceof Zend_Gdata_App_Extension_Subtitle);
        $this->verifyProperty2($feed, "subtitle", "text",
                "GData Is Awesome");
    }

    /**
      * Check for the existence of an <gCal:timezone> and verify that it contains
      * the expected value.
      */
    public function testTimezone()
    {
        $feed = $this->eventFeed;

        // Assert that the feed's title is correct
        $this->assertTrue($feed->getTimezone() instanceof Zend_Gdata_Calendar_Extension_Timezone);
        $this->verifyProperty2($feed, "timezone", "value",
                "America/Chicago");
    }


    /**
      * Check for the existence of an <gCal:eventStatus> and verify that it contains
      * the expected value.
      */
    public function testEventStatus()
    {
        $feed = $this->eventFeed;

        // Assert that all entry's have an eventStatus object
        foreach ($feed as $entry) {
            $this->assertTrue($entry->getEventStatus() instanceof Zend_Gdata_Extension_EventStatus);
        }

        // Assert one of the entries values
        $entry = $feed[2];
        $this->verifyProperty2($entry, "eventStatus", "value", "http://schemas.google.com/g/2005#event.confirmed");
    }

    /**
      * Check for the existence of an <gCal:visibility> and verify that it contains
      * the expected value.
      */
    public function testVisibility()
    {
        $feed = $this->eventFeed;

        // Assert that all entry's have a visibility object
        foreach ($feed as $entry) {
            $this->assertTrue($entry->getVisibility() instanceof Zend_Gdata_Extension_Visibility);
        }

        // Assert one of the entries values
        $entry = $feed[2];
        $this->verifyProperty2($entry, "visibility", "value", "http://schemas.google.com/g/2005#event.default");
    }

    /**
      * Check for the existence of an <gCal:transparency> and verify that it contains
      * the expected value.
      */
    public function testTransparency()
    {
        $feed = $this->eventFeed;

        // Assert that all entry's have a transparency object
        foreach ($feed as $entry) {
            $this->assertTrue($entry->getTransparency() instanceof Zend_Gdata_Extension_Transparency);
        }

        // Assert one of the entries values
        $entry = $feed[2];
        $this->verifyProperty2($entry, "transparency", "value", "http://schemas.google.com/g/2005#event.transparent");
    }

    /**
      * Check for the existence of an <gCal:sendEventNotifications> and verify that it contains
      * the expected value.
      */
    public function testSendEventNotifications()
    {
        $feed = $this->eventFeed;

        // Assert that all entry's have a sendEventNotifications object
        foreach ($feed as $entry) {
            $this->assertTrue($entry->getSendEventNotifications() instanceof Zend_Gdata_Calendar_Extension_SendEventNotifications);
        }

        // Assert one of the entry's values
        $entry = $feed[2];
        $this->verifyProperty2($entry, "sendEventNotifications", "value", false);
    }

    /**
      * Check for the existence of an <gd:when> and verify that it contains
      * the expected value.
      */
    public function testWhen()
    {
        $feed = $this->eventFeed;

        // Assert one of the entry's values
        $entry = $feed[2];
        $when = $entry->getWhen();
        $this->assertEquals($entry->getWhen(), $entry->when);
        $this->assertEquals(1, count($when));
        $this->assertTrue($when[0] instanceof Zend_Gdata_Extension_When);
        $this->verifyProperty($when[0], "startTime", "2007-05-24");
        $this->verifyProperty($when[0], "endTime", "2007-05-25");

        // Verify that the reminders show up
        $reminders = $when[0]->getReminders();
        $this->assertEquals(2, count($reminders));
        $this->assertTrue($reminders[0] instanceof Zend_Gdata_Extension_Reminder);
        $this->assertTrue($reminders[1] instanceof Zend_Gdata_Extension_Reminder);
        $this->verifyProperty($reminders[0], "minutes", "10");
        $this->verifyProperty($reminders[0], "method", "alert");
        $this->verifyProperty($reminders[1], "minutes", "10");
        $this->verifyProperty($reminders[1], "method", "email");
    }

    /**
      * Check for the existence of an <gd:where> and verify that it contains
      * the expected value.
      */
    public function testWhere()
    {
        $feed = $this->eventFeed;

        // Assert one of the entry's values
        $entry = $feed[2];
        $where = $entry->getWhere();
        $this->assertEquals(1, count($where));
        $this->assertTrue($where[0] instanceof Zend_Gdata_Extension_Where);
        $this->verifyProperty($where[0], "valueString", "Mountain View, California");
    }

    /**
      * Check for the existence of an <gd:comments> and verify that it contains
      * the expected value.
      */
    public function testComments()
    {
        $feed = $this->eventFeed;


        // Assert one of the entries has the correct values
        // Make sure the comment element looks right
        $entry = $feed[2];
        $c = $entry->getComments();
        $this->assertEquals($c, $entry->comments);
        $this->assertTrue($c instanceof Zend_Gdata_Extension_Comments);

        // Make sure that the feedLink looks right
        $fl = $c->getFeedLink();
        $this->assertTrue($fl instanceof Zend_Gdata_Extension_FeedLink);
        $this->assertEquals($fl, $c->feedLink);
        $this->verifyProperty($fl, "href", "http://www.google.com/calendar/feeds/default/private/full/lq2ai6imsbq209q3aeturho50g/comments");

        // Make sure the embedded feed looks right
        $cFeed = $fl->getFeed();
        $this->assertTrue($cFeed instanceof Zend_Gdata_App_Feed);
        $this->assertEquals($cFeed, $fl->feed);

        // Verify the remainder of the comment feed metadata
        $this->assertTrue($cFeed->getUpdated() instanceof Zend_Gdata_App_Extension_Updated);
        $this->verifyProperty2($cFeed, "updated", "text", "2007-05-31T01:15:13.249Z");

        $this->assertTrue($cFeed->getTitle() instanceof Zend_Gdata_App_Extension_Title);
        $this->verifyProperty2($cFeed, "title", "text", "Comments for: all day event may 24");

        // Verify that the comments appear to be good
        $commentCount = 0;
        foreach ($cFeed as $entry)
        {
            $this->assertTrue($entry instanceof Zend_Gdata_Entry);
            $commentCount++;
        }
        $this->assertEquals(2, $commentCount);

        // Closely examine one of the comments
        $comment = $cFeed[1];

        $this->assertTrue($comment->getId() instanceof Zend_Gdata_App_Extension_Id);
        $this->verifyProperty2($comment, "id", "text", "i9q87onko1uphfs7i21elnnb4g");

        $this->assertTrue($comment->getPublished() instanceof Zend_Gdata_App_Extension_Published);
        $this->verifyProperty2($comment, "published", "text", "2007-06-01T21:21:47.000Z");

        $this->assertTrue($comment->getUpdated() instanceof Zend_Gdata_App_Extension_Updated);
        $this->verifyProperty2($comment, "updated", "text", "2007-06-01T21:21:47.000Z");

        $this->assertEquals(1, count($comment->author));
        $this->assertTrue($comment->author[0] instanceof Zend_Gdata_App_Extension_Author);
        $this->assertTrue($comment->author[0]->getName() instanceof Zend_Gdata_App_Extension_Name);
        $this->assertTrue($comment->author[0]->getEmail() instanceof Zend_Gdata_App_Extension_Email);
        $this->verifyProperty2($comment->author[0], "name", "text", "User 2");
        $this->verifyProperty2($comment->author[0], "email", "text", "user2@nowhere.invalid");

        $this->assertTrue($comment->getContent() instanceof Zend_Gdata_App_Extension_Content);
        $this->verifyProperty($comment->getContent(), "type", "html");
        $this->assertEquals('<p>This is a user supplied comment.</p>', $comment->getContent()->text);
    }

    /**
      * Check for the existence of an <gd:where> and verify that it contains
      * the expected value.
      */
    public function testRecurrence()
    {
        $feed = $this->eventFeed;

        // Assert one of the entry's values
        $entry = $feed[1];
        $this->assertTrue($entry->getRecurrence() instanceof Zend_Gdata_Extension_Recurrence);
        $this->verifyProperty2($entry, "recurrence", "text",
                "DTSTART;VALUE=DATE:20070501 DTEND;VALUE=DATE:20070502 RRULE:FREQ=WEEKLY;BYDAY=Tu;UNTIL=20070904");
    }

    /**
      * Check for the existence of an <openSearch:startIndex> and verify that it contains
      * the expected value.
      */
    public function testStartIndex()
    {
        $feed = $this->eventFeed;

        // Assert that the feed's startIndex is correct
        $this->assertTrue($feed->getStartIndex() instanceof Zend_Gdata_Extension_OpenSearchStartIndex);
        $this->verifyProperty2($feed, "startIndex", "text", "1");
    }

    /**
      * Check for the existence of an <openSearch:itemsPerPage> and verify that it contains
      * the expected value.
      */
    public function testItemsPerPage()
    {
        $feed = $this->eventFeed;

        // Assert that the feed's itemsPerPage is correct
        $this->assertTrue($feed->getItemsPerPage() instanceof Zend_Gdata_Extension_OpenSearchItemsPerPage);
        $this->verifyProperty2($feed, "itemsPerPage", "text", "25");
    }

    /**
      * Check for the existence of an <atom:generator> and verify that it contains
      * the expected value.
      */
    public function testGenerator()
    {
        $feed = $this->eventFeed;

        // Assert that the feed's generator is correct
        $this->assertTrue($feed->getGenerator() instanceof Zend_Gdata_App_Extension_Generator);
        $this->verifyProperty2($feed, "generator", "version", "1.0");
        $this->verifyProperty2($feed, "generator", "uri", "http://www.google.com/calendar");
    }


}