CalendarOnlineTest.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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-2015 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-2015 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. * @group ZF-1701
  60. */
  61. public function testCalendarOnlineFeed()
  62. {
  63. $eventFeed = $this->gdata->getCalendarEventFeed();
  64. $this->assertTrue(strpos($eventFeed->title->text, TESTS_ZEND_GDATA_CLIENTLOGIN_EMAIL)
  65. !== false);
  66. $eventCount = 0;
  67. foreach ( $eventFeed as $event ) {
  68. $this->assertTrue($event instanceof Zend_Gdata_Calendar_EventEntry);
  69. $eventCount++;
  70. }
  71. $this->assertTrue($eventCount > 0 );
  72. $this->assertTrue(count($eventFeed) == $eventCount);
  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. }