2
0

CalendarOnlineTest.php 6.0 KB

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