2
0

CalendarOnlineTest.php 5.6 KB

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