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
|
<?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_CalendarEventTest 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/TestDataEventFeedSample1.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($value, $obj->$propGetter());
}
/**
* 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($value, $obj->$propGetter()->$secondGetter());
}
/**
* 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(10, $entryCount);
}
/**
* 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");
$this->assertTrue($feedAuthor[0]->getUri() instanceof Zend_Gdata_App_Extension_Uri);
$this->verifyProperty2($feedAuthor[0], "uri", "text", "http://test.address.invalid/");
// 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/full");
// 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[1];
$this->verifyProperty2($entry, "id", "text",
"http://www.google.com/calendar/feeds/default/private/full/2qt3ao5hbaq7m9igr5ak9esjo0");
}
/**
* 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[1];
$this->verifyProperty2($entry, "published", "text", "2007-03-20T21:26:04.000Z");
}
/**
* Check for the existence of an <atom:published> 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-03-20T21:29:57.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[1];
$this->verifyProperty2($entry, "updated", "text", "2007-03-20T21:28:46.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");
// 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[1];
$this->verifyProperty2($entry, "title", "text", "Afternoon at Dolores Park with Kim");
}
/**
* 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",
"Demo Feed");
}
/**
* 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 timezone is correct
$this->assertTrue($feed->getTimezone() instanceof Zend_Gdata_Calendar_Extension_Timezone);
$this->verifyProperty2($feed, "timezone", "value",
"America/Los_Angeles");
}
/**
* 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:content> and verify that it contains
* the expected value.
*/
public function testContent()
{
$feed = $this->eventFeed;
// Assert that all entry's have a content object
foreach ($feed as $entry) {
$this->assertTrue($entry->getContent() instanceof Zend_Gdata_App_Extension_Content);
}
// Assert one of the entry's values
$entry = $feed[1];
$this->verifyProperty2($entry, "content", "text", "This will be fun.");
}
/**
* 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[1];
$this->verifyProperty2($entry, "sendEventNotifications", "value", false);
}
/**
* Check for the existence of an <gd:eventStatus> and verify that it contains
* the expected value.
*/
public function testEventStatus()
{
$feed = $this->eventFeed;
// Assert that all entry's have a eventStatus object
foreach ($feed as $entry) {
$this->assertTrue($entry->getEventStatus() instanceof Zend_Gdata_Extension_EventStatus);
}
// Assert one of the entry's values
$entry = $feed[1];
$this->verifyProperty2($entry, "eventStatus", "value", "http://schemas.google.com/g/2005#event.confirmed");
}
/**
* 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 entry's commments links
$entry = $feed[1];
$this->assertTrue($entry->getComments() instanceof Zend_Gdata_Extension_Comments);
$this->verifyProperty2($entry->getComments(), "feedLink", "href", "http://www.google.com/calendar/feeds/default/private/full/2qt3ao5hbaq7m9igr5ak9esjo0/comments");
}
/**
* 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[1];
$this->verifyProperty2($entry, "visibility", "value", "http://schemas.google.com/g/2005#event.private");
}
/**
* 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[1];
$this->verifyProperty2($entry, "transparency", "value", "http://schemas.google.com/g/2005#event.opaque");
}
/**
* 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[1];
$when = $entry->getWhen();
$this->assertEquals($entry->getWhen(), $entry->when);
$this->assertEquals(1, count($when));
$w = $when[0];
$this->assertTrue($w instanceof Zend_Gdata_Extension_When);
$this->verifyProperty($w, "startTime", "2007-03-24T12:00:00.000-07:00");
$this->verifyProperty($w, "endTime", "2007-03-24T15:00:00.000-07:00");
// Assert that the associated reminders are correct
$reminders = $w->getReminders();
$this->assertEquals(1, count($reminders));
$this->verifyProperty($reminders[0], "minutes", "20");
$this->verifyProperty($reminders[0], "method", "alert");
}
/**
* 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[1];
$where = $entry->getWhere();
$this->assertEquals(1, count($where));
$this->assertTrue($where[0] instanceof Zend_Gdata_Extension_Where);
$this->verifyProperty($where[0], "valueString", "Dolores Park with Kim");
}
/**
* Check for the existence of an <gd:where> and verify that it contains
* the expected value.
*/
public function testWho()
{
$feed = $this->eventFeed;
// For one of the entries, make sure that all who entries are of the
// right kind
$entry = $feed[1];
$who = $entry->getWho();
foreach ($who as $w) {
$this->assertTrue($w instanceof Zend_Gdata_Extension_Who);
}
$this->assertEquals(2, count($who));
// Check one of the who entries to make sure the values are valid
$this->verifyProperty($who[0], "rel", "http://schemas.google.com/g/2005#event.organizer");
$this->verifyProperty($who[0], "valueString", "GData Ops Demo");
$this->verifyProperty($who[0], "email", "gdata.ops.demo@gmail.com");
$this->verifyProperty2($who[0], "attendeeStatus", "value", "http://schemas.google.com/g/2005#event.accepted");
}
/**
* 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");
$this->verifyProperty2($feed, "generator", "text", "Google Calendar");
}
/**
* Check for the existence of an <gd:quickadd> and verify that it contains
* the expected value.
*/
public function testQuickAdd()
{
$feed = $this->eventFeed;
// Assert that one of the event's QuickAdd entries is correct
$quickAdd = $feed->entry[1]->getQuickAdd();
$this->assertTrue($quickAdd instanceof Zend_Gdata_Calendar_Extension_QuickAdd);
$this->verifyProperty($quickAdd, "value", true);
}
}
|