CalendarOnlineTest.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Gdata_Calendar
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id $
  21. */
  22. require_once 'Zend/Gdata/Calendar.php';
  23. require_once 'Zend/Gdata/Calendar/EventEntry.php';
  24. require_once 'Zend/Gdata/ClientLogin.php';
  25. require_once 'Zend/Http/Client.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Gdata_Calendar
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Gdata
  33. * @group Zend_Gdata_Calendar
  34. */
  35. class Zend_Gdata_CalendarOnlineTest extends PHPUnit_Framework_TestCase
  36. {
  37. const GOOGLE_DEVELOPER_CALENDAR = 'developer-calendar@google.com';
  38. const ZEND_CONFERENCE_EVENT = 'bn2h4o4mc3a03ci4t48j3m56pg';
  39. public function setUp()
  40. {
  41. $user = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL');
  42. $pass = constant('TESTS_ZEND_GDATA_CLIENTLOGIN_PASSWORD');
  43. $service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
  44. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
  45. $this->gdata = new Zend_Gdata_Calendar($client);
  46. }
  47. public function testCalendarListFeed()
  48. {
  49. $calFeed = $this->gdata->getCalendarListFeed();
  50. $this->assertTrue(strpos($calFeed->title->text, 'Calendar List')
  51. !== false);
  52. $calCount = 0;
  53. foreach ($calFeed as $calendar) {
  54. $calCount++;
  55. }
  56. $this->assertTrue($calCount > 0);
  57. }
  58. /**
  59. * @see ZF-1701
  60. */
  61. /*
  62. public function testCalendarOnlineFeed()
  63. {
  64. $eventFeed = $this->gdata->getCalendarEventFeed();
  65. foreach ($eventFeed as $event) {
  66. $title = $event->title;
  67. $times = $event->when;
  68. $location = $event->where;
  69. $recurrence = $event->recurrence;
  70. }
  71. }
  72. */
  73. function getEvent($eventId)
  74. {
  75. $query = $this->gdata->newEventQuery();
  76. $query->setUser('default');
  77. $query->setVisibility('private');
  78. $query->setProjection('full');
  79. $query->setEvent($eventId);
  80. $eventEntry = $this->gdata->getCalendarEventEntry($query);
  81. $this->assertTrue(
  82. $eventEntry instanceof Zend_Gdata_Calendar_EventEntry);
  83. return $eventEntry;
  84. }
  85. public function createEvent(
  86. $title = 'Tennis with Beth',
  87. $desc='Meet for a quick lesson', $where = 'On the courts',
  88. $startDate = '2008-01-20', $startTime = '10:00',
  89. $endDate = '2008-01-20', $endTime = '11:00', $tzOffset = '-08')
  90. {
  91. $newEntry = $this->gdata->newEventEntry();
  92. $newEntry->title = $this->gdata->newTitle(trim($title));
  93. $newEntry->where = array($this->gdata->newWhere($where));
  94. $newEntry->content = $this->gdata->newContent($desc);
  95. $newEntry->content->type = 'text';
  96. $when = $this->gdata->newWhen();
  97. $when->startTime = "{$startDate}T{$startTime}:00.000{$tzOffset}:00";
  98. $when->endTime = "{$endDate}T{$endTime}:00.000{$tzOffset}:00";
  99. $reminder = $this->gdata->newReminder();
  100. $reminder->minutes = '30';
  101. $reminder->method = 'email';
  102. $when->reminders = array($reminder);
  103. $newEntry->when = array($when);
  104. $createdEntry = $this->gdata->insertEvent($newEntry);
  105. $this->assertEquals('email in 30 minutes', $reminder->__toString());
  106. $this->assertEquals($title, $createdEntry->title->text);
  107. $this->assertEquals($desc, $createdEntry->content->text);
  108. $this->assertEquals(strtotime($when->startTime),
  109. strtotime($createdEntry->when[0]->startTime));
  110. $this->assertEquals(strtotime($when->endTime),
  111. strtotime($createdEntry->when[0]->endTime));
  112. $this->assertEquals($reminder->method,
  113. $createdEntry->when[0]->reminders[0]->method);
  114. $this->assertEquals($reminder->minutes,
  115. $createdEntry->when[0]->reminders[0]->minutes);
  116. $this->assertEquals($where, $createdEntry->where[0]->valueString);
  117. return $createdEntry;
  118. }
  119. function updateEvent ($eventId, $newTitle)
  120. {
  121. $eventOld = $this->getEvent($eventId);
  122. $eventOld->title = $this->gdata->newTitle($newTitle);
  123. $eventOld->save();
  124. $eventNew = $this->getEvent($eventId);
  125. $this->assertEquals($newTitle, $eventNew->title->text);
  126. return $eventNew;
  127. }
  128. public function testCreateEvent()
  129. {
  130. $createdEntry = $this->createEvent();
  131. }
  132. public function testCreateAndUpdateEvent()
  133. {
  134. $newTitle = 'my new title';
  135. $createdEntry = $this->createEvent();
  136. preg_match('#.*/([A-Za-z0-9]+)$#', $createdEntry->id->text, $matches);
  137. $id = $matches[1];
  138. $updatedEvent = $this->updateEvent($id, $newTitle);
  139. $this->assertEquals($newTitle, $updatedEvent->title->text);
  140. }
  141. public function testCreateAndDeleteEvent()
  142. {
  143. /* deletion can be performed in several different ways-- test all */
  144. $createdEntry = $this->createEvent();
  145. $createdEntry->delete();
  146. $createdEntry2 = $this->createEvent();
  147. $this->gdata->delete($createdEntry2);
  148. $createdEntry3 = $this->createEvent();
  149. $this->gdata->delete($createdEntry3->getEditLink()->href);
  150. }
  151. }