CalendarEventTest.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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 'Zend/Gdata/Calendar.php';
  22. require_once 'Zend/Gdata/Calendar/EventFeed.php';
  23. require_once 'Zend/Http/Client.php';
  24. require_once 'Zend/Http/Client/Adapter/Test.php';
  25. /**
  26. * @package Zend_Gdata
  27. * @subpackage UnitTests
  28. */
  29. class Zend_Gdata_CalendarEventTest extends PHPUnit_Framework_TestCase
  30. {
  31. protected $eventFeed = null;
  32. /**
  33. * Called before each test to setup any fixtures.
  34. */
  35. public function setUp()
  36. {
  37. $eventFeedText = file_get_contents(
  38. 'Zend/Gdata/Calendar/_files/TestDataEventFeedSample1.xml',
  39. true);
  40. $this->eventFeed = new Zend_Gdata_Calendar_EventFeed($eventFeedText);
  41. }
  42. /**
  43. * Verify that a given property is set to a specific value
  44. * and that the getter and magic variable return the same value.
  45. *
  46. * @param object $obj The object to be interrogated.
  47. * @param string $name The name of the property to be verified.
  48. * @param object $value The expected value of the property.
  49. */
  50. protected function verifyProperty($obj, $name, $value)
  51. {
  52. $propName = $name;
  53. $propGetter = "get" . ucfirst($name);
  54. $this->assertEquals($obj->$propGetter(), $obj->$propName);
  55. $this->assertEquals($value, $obj->$propGetter());
  56. }
  57. /**
  58. * Verify that a given property is set to a specific value
  59. * and that the getter and magic variable return the same value.
  60. *
  61. * @param object $obj The object to be interrogated.
  62. * @param string $name The name of the property to be verified.
  63. * @param string $secondName 2nd level accessor function name
  64. * @param object $value The expected value of the property.
  65. */
  66. protected function verifyProperty2($obj, $name, $secondName, $value)
  67. {
  68. $propName = $name;
  69. $propGetter = "get" . ucfirst($name);
  70. $secondGetter = "get" . ucfirst($secondName);
  71. $this->assertEquals($obj->$propGetter(), $obj->$propName);
  72. $this->assertEquals($value, $obj->$propGetter()->$secondGetter());
  73. }
  74. /**
  75. * Convert sample feed to XML then back to objects. Ensure that
  76. * all objects are instances of EventEntry and object count matches.
  77. */
  78. public function testEventFeedToAndFromString()
  79. {
  80. $entryCount = 0;
  81. foreach ($this->eventFeed as $entry) {
  82. $entryCount++;
  83. $this->assertTrue($entry instanceof Zend_Gdata_Calendar_EventEntry);
  84. }
  85. $this->assertTrue($entryCount > 0);
  86. /* Grab XML from $this->eventFeed and convert back to objects */
  87. $newEventFeed = new Zend_Gdata_Calendar_EventFeed(
  88. $this->eventFeed->saveXML());
  89. $newEntryCount = 0;
  90. foreach ($newEventFeed as $entry) {
  91. $newEntryCount++;
  92. $this->assertTrue($entry instanceof Zend_Gdata_Calendar_EventEntry);
  93. }
  94. $this->assertEquals($entryCount, $newEntryCount);
  95. }
  96. /**
  97. * Ensure that there number of lsit feeds equals the number
  98. * of calendars defined in the sample file.
  99. */
  100. public function testEntryCount()
  101. {
  102. //TODO feeds implementing ArrayAccess would be helpful here
  103. $entryCount = 0;
  104. foreach ($this->eventFeed as $entry) {
  105. $entryCount++;
  106. }
  107. $this->assertEquals(10, $entryCount);
  108. }
  109. /**
  110. * Check for the existence of an <atom:author> and verify that they
  111. * contain the expected values.
  112. */
  113. public function testAuthor()
  114. {
  115. $feed = $this->eventFeed;
  116. // Assert that the feed's author is correct
  117. $feedAuthor = $feed->getAuthor();
  118. $this->assertEquals($feedAuthor, $feed->author);
  119. $this->assertEquals(1, count($feedAuthor));
  120. $this->assertTrue($feedAuthor[0] instanceof Zend_Gdata_App_Extension_Author);
  121. $this->verifyProperty2($feedAuthor[0], "name", "text", "GData Ops Demo");
  122. $this->verifyProperty2($feedAuthor[0], "email", "text", "gdata.ops.demo@gmail.com");
  123. $this->assertTrue($feedAuthor[0]->getUri() instanceof Zend_Gdata_App_Extension_Uri);
  124. $this->verifyProperty2($feedAuthor[0], "uri", "text", "http://test.address.invalid/");
  125. // Assert that each entry has valid author data
  126. foreach ($feed as $entry) {
  127. $entryAuthor = $entry->getAuthor();
  128. $this->assertEquals(1, count($entryAuthor));
  129. $this->verifyProperty2($entryAuthor[0], "name", "text", "GData Ops Demo");
  130. $this->verifyProperty2($entryAuthor[0], "email", "text", "gdata.ops.demo@gmail.com");
  131. $this->verifyProperty($entryAuthor[0], "uri", null);
  132. }
  133. }
  134. /**
  135. * Check for the existence of an <atom:id> and verify that it contains
  136. * the expected value.
  137. */
  138. public function testId()
  139. {
  140. $feed = $this->eventFeed;
  141. // Assert that the feed's ID is correct
  142. $this->assertTrue($feed->getId() instanceof Zend_Gdata_App_Extension_Id);
  143. $this->verifyProperty2($feed, "id", "text",
  144. "http://www.google.com/calendar/feeds/default/private/full");
  145. // Assert that all entry's have an Atom ID object
  146. foreach ($feed as $entry) {
  147. $this->assertTrue($entry->getId() instanceof Zend_Gdata_App_Extension_Id);
  148. }
  149. // Assert one of the entry's IDs
  150. $entry = $feed[1];
  151. $this->verifyProperty2($entry, "id", "text",
  152. "http://www.google.com/calendar/feeds/default/private/full/2qt3ao5hbaq7m9igr5ak9esjo0");
  153. }
  154. /**
  155. * Check for the existence of an <atom:published> and verify that it contains
  156. * the expected value.
  157. */
  158. public function testPublished()
  159. {
  160. $feed = $this->eventFeed;
  161. // Assert that all entry's have an Atom Published object
  162. foreach ($feed as $entry) {
  163. $this->assertTrue($entry->getPublished() instanceof Zend_Gdata_App_Extension_Published);
  164. }
  165. // Assert one of the entry's Published dates
  166. $entry = $feed[1];
  167. $this->verifyProperty2($entry, "published", "text", "2007-03-20T21:26:04.000Z");
  168. }
  169. /**
  170. * Check for the existence of an <atom:published> and verify that it contains
  171. * the expected value.
  172. */
  173. public function testUpdated()
  174. {
  175. $feed = $this->eventFeed;
  176. // Assert that the feed's updated date is correct
  177. $this->assertTrue($feed->getUpdated() instanceof Zend_Gdata_App_Extension_Updated);
  178. $this->verifyProperty2($feed, "updated", "text",
  179. "2007-03-20T21:29:57.000Z");
  180. // Assert that all entry's have an Atom Published object
  181. foreach ($feed as $entry) {
  182. $this->assertTrue($entry->getUpdated() instanceof Zend_Gdata_App_Extension_Updated);
  183. }
  184. // Assert one of the entry's Published dates
  185. $entry = $feed[1];
  186. $this->verifyProperty2($entry, "updated", "text", "2007-03-20T21:28:46.000Z");
  187. }
  188. /**
  189. * Check for the existence of an <atom:title> and verify that it contains
  190. * the expected value.
  191. */
  192. public function testTitle()
  193. {
  194. $feed = $this->eventFeed;
  195. // Assert that the feed's title is correct
  196. $this->assertTrue($feed->getTitle() instanceof Zend_Gdata_App_Extension_Title);
  197. $this->verifyProperty2($feed, "title", "text",
  198. "GData Ops Demo");
  199. // Assert that all entry's have an Atom ID object
  200. foreach ($feed as $entry) {
  201. $this->assertTrue($entry->getTitle() instanceof Zend_Gdata_App_Extension_Title);
  202. }
  203. // Assert one of the entry's Titles
  204. $entry = $feed[1];
  205. $this->verifyProperty2($entry, "title", "text", "Afternoon at Dolores Park with Kim");
  206. }
  207. /**
  208. * Check for the existence of an <atom:subtitle> and verify that it contains
  209. * the expected value.
  210. */
  211. public function testSubtitle()
  212. {
  213. $feed = $this->eventFeed;
  214. // Assert that the feed's title is correct
  215. $this->assertTrue($feed->getSubtitle() instanceof Zend_Gdata_App_Extension_Subtitle);
  216. $this->verifyProperty2($feed, "subtitle", "text",
  217. "Demo Feed");
  218. }
  219. /**
  220. * Check for the existence of an <gCal:timezone> and verify that it contains
  221. * the expected value.
  222. */
  223. public function testTimezone()
  224. {
  225. $feed = $this->eventFeed;
  226. // Assert that the feed's timezone is correct
  227. $this->assertTrue($feed->getTimezone() instanceof Zend_Gdata_Calendar_Extension_Timezone);
  228. $this->verifyProperty2($feed, "timezone", "value",
  229. "America/Los_Angeles");
  230. }
  231. /**
  232. * Check for the existence of an <openSearch:startIndex> and verify that it contains
  233. * the expected value.
  234. */
  235. public function testStartIndex()
  236. {
  237. $feed = $this->eventFeed;
  238. // Assert that the feed's startIndex is correct
  239. $this->assertTrue($feed->getStartIndex() instanceof Zend_Gdata_Extension_OpenSearchStartIndex);
  240. $this->verifyProperty2($feed, "startIndex", "text", "1");
  241. }
  242. /**
  243. * Check for the existence of an <openSearch:itemsPerPage> and verify that it contains
  244. * the expected value.
  245. */
  246. public function testItemsPerPage()
  247. {
  248. $feed = $this->eventFeed;
  249. // Assert that the feed's itemsPerPage is correct
  250. $this->assertTrue($feed->getItemsPerPage() instanceof Zend_Gdata_Extension_OpenSearchItemsPerPage);
  251. $this->verifyProperty2($feed, "itemsPerPage", "text", "25");
  252. }
  253. /**
  254. * Check for the existence of an <atom:content> and verify that it contains
  255. * the expected value.
  256. */
  257. public function testContent()
  258. {
  259. $feed = $this->eventFeed;
  260. // Assert that all entry's have a content object
  261. foreach ($feed as $entry) {
  262. $this->assertTrue($entry->getContent() instanceof Zend_Gdata_App_Extension_Content);
  263. }
  264. // Assert one of the entry's values
  265. $entry = $feed[1];
  266. $this->verifyProperty2($entry, "content", "text", "This will be fun.");
  267. }
  268. /**
  269. * Check for the existence of an <gCal:sendEventNotifications> and verify that it contains
  270. * the expected value.
  271. */
  272. public function testSendEventNotifications()
  273. {
  274. $feed = $this->eventFeed;
  275. // Assert that all entry's have a sendEventNotifications object
  276. foreach ($feed as $entry) {
  277. $this->assertTrue($entry->getSendEventNotifications() instanceof Zend_Gdata_Calendar_Extension_SendEventNotifications);
  278. }
  279. // Assert one of the entry's values
  280. $entry = $feed[1];
  281. $this->verifyProperty2($entry, "sendEventNotifications", "value", false);
  282. }
  283. /**
  284. * Check for the existence of an <gd:eventStatus> and verify that it contains
  285. * the expected value.
  286. */
  287. public function testEventStatus()
  288. {
  289. $feed = $this->eventFeed;
  290. // Assert that all entry's have a eventStatus object
  291. foreach ($feed as $entry) {
  292. $this->assertTrue($entry->getEventStatus() instanceof Zend_Gdata_Extension_EventStatus);
  293. }
  294. // Assert one of the entry's values
  295. $entry = $feed[1];
  296. $this->verifyProperty2($entry, "eventStatus", "value", "http://schemas.google.com/g/2005#event.confirmed");
  297. }
  298. /**
  299. * Check for the existence of an <gd:comments> and verify that it contains
  300. * the expected value.
  301. */
  302. public function testComments()
  303. {
  304. $feed = $this->eventFeed;
  305. // Assert one of the entry's commments links
  306. $entry = $feed[1];
  307. $this->assertTrue($entry->getComments() instanceof Zend_Gdata_Extension_Comments);
  308. $this->verifyProperty2($entry->getComments(), "feedLink", "href", "http://www.google.com/calendar/feeds/default/private/full/2qt3ao5hbaq7m9igr5ak9esjo0/comments");
  309. }
  310. /**
  311. * Check for the existence of an <gCal:visibility> and verify that it contains
  312. * the expected value.
  313. */
  314. public function testVisibility()
  315. {
  316. $feed = $this->eventFeed;
  317. // Assert that all entry's have a visibility object
  318. foreach ($feed as $entry) {
  319. $this->assertTrue($entry->getVisibility() instanceof Zend_Gdata_Extension_Visibility);
  320. }
  321. // Assert one of the entries values
  322. $entry = $feed[1];
  323. $this->verifyProperty2($entry, "visibility", "value", "http://schemas.google.com/g/2005#event.private");
  324. }
  325. /**
  326. * Check for the existence of an <gCal:transparency> and verify that it contains
  327. * the expected value.
  328. */
  329. public function testTransparency()
  330. {
  331. $feed = $this->eventFeed;
  332. // Assert that all entry's have a transparency object
  333. foreach ($feed as $entry) {
  334. $this->assertTrue($entry->getTransparency() instanceof Zend_Gdata_Extension_Transparency);
  335. }
  336. // Assert one of the entries values
  337. $entry = $feed[1];
  338. $this->verifyProperty2($entry, "transparency", "value", "http://schemas.google.com/g/2005#event.opaque");
  339. }
  340. /**
  341. * Check for the existence of an <gd:when> and verify that it contains
  342. * the expected value.
  343. */
  344. public function testWhen()
  345. {
  346. $feed = $this->eventFeed;
  347. // Assert one of the entry's values
  348. $entry = $feed[1];
  349. $when = $entry->getWhen();
  350. $this->assertEquals($entry->getWhen(), $entry->when);
  351. $this->assertEquals(1, count($when));
  352. $w = $when[0];
  353. $this->assertTrue($w instanceof Zend_Gdata_Extension_When);
  354. $this->verifyProperty($w, "startTime", "2007-03-24T12:00:00.000-07:00");
  355. $this->verifyProperty($w, "endTime", "2007-03-24T15:00:00.000-07:00");
  356. // Assert that the associated reminders are correct
  357. $reminders = $w->getReminders();
  358. $this->assertEquals(1, count($reminders));
  359. $this->verifyProperty($reminders[0], "minutes", "20");
  360. $this->verifyProperty($reminders[0], "method", "alert");
  361. }
  362. /**
  363. * Check for the existence of an <gd:where> and verify that it contains
  364. * the expected value.
  365. */
  366. public function testWhere()
  367. {
  368. $feed = $this->eventFeed;
  369. // Assert one of the entry's values
  370. $entry = $feed[1];
  371. $where = $entry->getWhere();
  372. $this->assertEquals(1, count($where));
  373. $this->assertTrue($where[0] instanceof Zend_Gdata_Extension_Where);
  374. $this->verifyProperty($where[0], "valueString", "Dolores Park with Kim");
  375. }
  376. /**
  377. * Check for the existence of an <gd:where> and verify that it contains
  378. * the expected value.
  379. */
  380. public function testWho()
  381. {
  382. $feed = $this->eventFeed;
  383. // For one of the entries, make sure that all who entries are of the
  384. // right kind
  385. $entry = $feed[1];
  386. $who = $entry->getWho();
  387. foreach ($who as $w) {
  388. $this->assertTrue($w instanceof Zend_Gdata_Extension_Who);
  389. }
  390. $this->assertEquals(2, count($who));
  391. // Check one of the who entries to make sure the values are valid
  392. $this->verifyProperty($who[0], "rel", "http://schemas.google.com/g/2005#event.organizer");
  393. $this->verifyProperty($who[0], "valueString", "GData Ops Demo");
  394. $this->verifyProperty($who[0], "email", "gdata.ops.demo@gmail.com");
  395. $this->verifyProperty2($who[0], "attendeeStatus", "value", "http://schemas.google.com/g/2005#event.accepted");
  396. }
  397. /**
  398. * Check for the existence of an <atom:generator> and verify that it contains
  399. * the expected value.
  400. */
  401. public function testGenerator()
  402. {
  403. $feed = $this->eventFeed;
  404. // Assert that the feed's generator is correct
  405. $this->assertTrue($feed->getGenerator() instanceof Zend_Gdata_App_Extension_Generator);
  406. $this->verifyProperty2($feed, "generator", "version", "1.0");
  407. $this->verifyProperty2($feed, "generator", "uri", "http://www.google.com/calendar");
  408. $this->verifyProperty2($feed, "generator", "text", "Google Calendar");
  409. }
  410. /**
  411. * Check for the existence of an <gd:quickadd> and verify that it contains
  412. * the expected value.
  413. */
  414. public function testQuickAdd()
  415. {
  416. $feed = $this->eventFeed;
  417. // Assert that one of the event's QuickAdd entries is correct
  418. $quickAdd = $feed->entry[1]->getQuickAdd();
  419. $this->assertTrue($quickAdd instanceof Zend_Gdata_Calendar_Extension_QuickAdd);
  420. $this->verifyProperty($quickAdd, "value", true);
  421. }
  422. }