2
0

CalendarFeedCompositeTest.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  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_CalendarFeedCompositeTest 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/EventFeedCompositeSample1.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($obj->$propGetter(), $value);
  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($obj->$propGetter()->$secondGetter(), $value);
  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(7, $entryCount);
  108. $this->assertEquals($entryCount, $this->eventFeed->totalResults->text);
  109. }
  110. /**
  111. * Check for the existence of an <atom:author> and verify that they
  112. * contain the expected values.
  113. */
  114. public function testAuthor()
  115. {
  116. $feed = $this->eventFeed;
  117. // Assert that the feed's author is correct
  118. $feedAuthor = $feed->getAuthor();
  119. $this->assertEquals($feedAuthor, $feed->author);
  120. $this->assertEquals(1, count($feedAuthor));
  121. $this->assertTrue($feedAuthor[0] instanceof Zend_Gdata_App_Extension_Author);
  122. $this->verifyProperty2($feedAuthor[0], "name", "text", "GData Ops Demo");
  123. $this->verifyProperty2($feedAuthor[0], "email", "text", "gdata.ops.demo@gmail.com");
  124. // Assert that each entry has valid author data
  125. foreach ($feed as $entry) {
  126. $entryAuthor = $entry->getAuthor();
  127. $this->assertEquals(1, count($entryAuthor));
  128. $this->verifyProperty2($entryAuthor[0], "name", "text", "GData Ops Demo");
  129. $this->verifyProperty2($entryAuthor[0], "email", "text", "gdata.ops.demo@gmail.com");
  130. $this->verifyProperty($entryAuthor[0], "uri", null);
  131. }
  132. }
  133. /**
  134. * Check for the existence of an <atom:id> and verify that it contains
  135. * the expected value.
  136. */
  137. public function testId()
  138. {
  139. $feed = $this->eventFeed;
  140. // Assert that the feed's ID is correct
  141. $this->assertTrue($feed->getId() instanceof Zend_Gdata_App_Extension_Id);
  142. $this->verifyProperty2($feed, "id", "text",
  143. "http://www.google.com/calendar/feeds/default/private/composite");
  144. // Assert that all entry's have an Atom ID object
  145. foreach ($feed as $entry) {
  146. $this->assertTrue($entry->getId() instanceof Zend_Gdata_App_Extension_Id);
  147. }
  148. // Assert one of the entry's IDs
  149. $entry = $feed[2];
  150. $this->verifyProperty2($entry, "id", "text",
  151. "http://www.google.com/calendar/feeds/default/private/composite/lq2ai6imsbq209q3aeturho50g");
  152. }
  153. /**
  154. * Check for the existence of an <atom:published> and verify that it contains
  155. * the expected value.
  156. */
  157. public function testPublished()
  158. {
  159. $feed = $this->eventFeed;
  160. // Assert that all entry's have an Atom Published object
  161. foreach ($feed as $entry) {
  162. $this->assertTrue($entry->getPublished() instanceof Zend_Gdata_App_Extension_Published);
  163. }
  164. // Assert one of the entry's Published dates
  165. $entry = $feed[2];
  166. $this->verifyProperty2($entry, "published", "text", "2007-05-09T16:44:38.000Z");
  167. }
  168. /**
  169. * Check for the existence of an <atom:updated> and verify that it contains
  170. * the expected value.
  171. */
  172. public function testUpdated()
  173. {
  174. $feed = $this->eventFeed;
  175. // Assert that the feed's updated date is correct
  176. $this->assertTrue($feed->getUpdated() instanceof Zend_Gdata_App_Extension_Updated);
  177. $this->verifyProperty2($feed, "updated", "text",
  178. "2007-05-31T01:15:00.000Z");
  179. // Assert that all entry's have an Atom Published object
  180. foreach ($feed as $entry) {
  181. $this->assertTrue($entry->getUpdated() instanceof Zend_Gdata_App_Extension_Updated);
  182. }
  183. // Assert one of the entry's Published dates
  184. $entry = $feed[2];
  185. $this->verifyProperty2($entry, "updated", "text", "2007-05-17T10:33:49.000Z");
  186. }
  187. /**
  188. * Check for the existence of an <atom:title> and verify that it contains
  189. * the expected value.
  190. */
  191. public function testTitle()
  192. {
  193. $feed = $this->eventFeed;
  194. // Assert that the feed's title is correct
  195. $this->assertTrue($feed->getTitle() instanceof Zend_Gdata_App_Extension_Title);
  196. $this->verifyProperty2($feed, "title", "text",
  197. "GData Ops Demo's Composite View");
  198. // Assert that all entry's have an Atom ID object
  199. foreach ($feed as $entry) {
  200. $this->assertTrue($entry->getTitle() instanceof Zend_Gdata_App_Extension_Title);
  201. }
  202. // Assert one of the entry's Titles
  203. $entry = $feed[2];
  204. $this->verifyProperty2($entry, "title", "text", "all day event may 24");
  205. }
  206. /**
  207. * Check for the existence of an <atom:subtitle> and verify that it contains
  208. * the expected value.
  209. */
  210. public function testSubtitle()
  211. {
  212. $feed = $this->eventFeed;
  213. // Assert that the feed's title is correct
  214. $this->assertTrue($feed->getSubtitle() instanceof Zend_Gdata_App_Extension_Subtitle);
  215. $this->verifyProperty2($feed, "subtitle", "text",
  216. "GData Is Awesome");
  217. }
  218. /**
  219. * Check for the existence of an <gCal:timezone> and verify that it contains
  220. * the expected value.
  221. */
  222. public function testTimezone()
  223. {
  224. $feed = $this->eventFeed;
  225. // Assert that the feed's title is correct
  226. $this->assertTrue($feed->getTimezone() instanceof Zend_Gdata_Calendar_Extension_Timezone);
  227. $this->verifyProperty2($feed, "timezone", "value",
  228. "America/Chicago");
  229. }
  230. /**
  231. * Check for the existence of an <gCal:eventStatus> and verify that it contains
  232. * the expected value.
  233. */
  234. public function testEventStatus()
  235. {
  236. $feed = $this->eventFeed;
  237. // Assert that all entry's have an eventStatus object
  238. foreach ($feed as $entry) {
  239. $this->assertTrue($entry->getEventStatus() instanceof Zend_Gdata_Extension_EventStatus);
  240. }
  241. // Assert one of the entries values
  242. $entry = $feed[2];
  243. $this->verifyProperty2($entry, "eventStatus", "value", "http://schemas.google.com/g/2005#event.confirmed");
  244. }
  245. /**
  246. * Check for the existence of an <gCal:visibility> and verify that it contains
  247. * the expected value.
  248. */
  249. public function testVisibility()
  250. {
  251. $feed = $this->eventFeed;
  252. // Assert that all entry's have a visibility object
  253. foreach ($feed as $entry) {
  254. $this->assertTrue($entry->getVisibility() instanceof Zend_Gdata_Extension_Visibility);
  255. }
  256. // Assert one of the entries values
  257. $entry = $feed[2];
  258. $this->verifyProperty2($entry, "visibility", "value", "http://schemas.google.com/g/2005#event.default");
  259. }
  260. /**
  261. * Check for the existence of an <gCal:transparency> and verify that it contains
  262. * the expected value.
  263. */
  264. public function testTransparency()
  265. {
  266. $feed = $this->eventFeed;
  267. // Assert that all entry's have a transparency object
  268. foreach ($feed as $entry) {
  269. $this->assertTrue($entry->getTransparency() instanceof Zend_Gdata_Extension_Transparency);
  270. }
  271. // Assert one of the entries values
  272. $entry = $feed[2];
  273. $this->verifyProperty2($entry, "transparency", "value", "http://schemas.google.com/g/2005#event.transparent");
  274. }
  275. /**
  276. * Check for the existence of an <gCal:sendEventNotifications> and verify that it contains
  277. * the expected value.
  278. */
  279. public function testSendEventNotifications()
  280. {
  281. $feed = $this->eventFeed;
  282. // Assert that all entry's have a sendEventNotifications object
  283. foreach ($feed as $entry) {
  284. $this->assertTrue($entry->getSendEventNotifications() instanceof Zend_Gdata_Calendar_Extension_SendEventNotifications);
  285. }
  286. // Assert one of the entry's values
  287. $entry = $feed[2];
  288. $this->verifyProperty2($entry, "sendEventNotifications", "value", false);
  289. }
  290. /**
  291. * Check for the existence of an <gd:when> and verify that it contains
  292. * the expected value.
  293. */
  294. public function testWhen()
  295. {
  296. $feed = $this->eventFeed;
  297. // Assert one of the entry's values
  298. $entry = $feed[2];
  299. $when = $entry->getWhen();
  300. $this->assertEquals($entry->getWhen(), $entry->when);
  301. $this->assertEquals(1, count($when));
  302. $this->assertTrue($when[0] instanceof Zend_Gdata_Extension_When);
  303. $this->verifyProperty($when[0], "startTime", "2007-05-24");
  304. $this->verifyProperty($when[0], "endTime", "2007-05-25");
  305. // Verify that the reminders show up
  306. $reminders = $when[0]->getReminders();
  307. $this->assertEquals(2, count($reminders));
  308. $this->assertTrue($reminders[0] instanceof Zend_Gdata_Extension_Reminder);
  309. $this->assertTrue($reminders[1] instanceof Zend_Gdata_Extension_Reminder);
  310. $this->verifyProperty($reminders[0], "minutes", "10");
  311. $this->verifyProperty($reminders[0], "method", "alert");
  312. $this->verifyProperty($reminders[1], "minutes", "10");
  313. $this->verifyProperty($reminders[1], "method", "email");
  314. }
  315. /**
  316. * Check for the existence of an <gd:where> and verify that it contains
  317. * the expected value.
  318. */
  319. public function testWhere()
  320. {
  321. $feed = $this->eventFeed;
  322. // Assert one of the entry's values
  323. $entry = $feed[2];
  324. $where = $entry->getWhere();
  325. $this->assertEquals(1, count($where));
  326. $this->assertTrue($where[0] instanceof Zend_Gdata_Extension_Where);
  327. $this->verifyProperty($where[0], "valueString", "Mountain View, California");
  328. }
  329. /**
  330. * Check for the existence of an <gd:comments> and verify that it contains
  331. * the expected value.
  332. */
  333. public function testComments()
  334. {
  335. $feed = $this->eventFeed;
  336. // Assert one of the entries has the correct values
  337. // Make sure the comment element looks right
  338. $entry = $feed[2];
  339. $c = $entry->getComments();
  340. $this->assertEquals($c, $entry->comments);
  341. $this->assertTrue($c instanceof Zend_Gdata_Extension_Comments);
  342. // Make sure that the feedLink looks right
  343. $fl = $c->getFeedLink();
  344. $this->assertTrue($fl instanceof Zend_Gdata_Extension_FeedLink);
  345. $this->assertEquals($fl, $c->feedLink);
  346. $this->verifyProperty($fl, "href", "http://www.google.com/calendar/feeds/default/private/full/lq2ai6imsbq209q3aeturho50g/comments");
  347. // Make sure the embedded feed looks right
  348. $cFeed = $fl->getFeed();
  349. $this->assertTrue($cFeed instanceof Zend_Gdata_App_Feed);
  350. $this->assertEquals($cFeed, $fl->feed);
  351. // Verify the remainder of the comment feed metadata
  352. $this->assertTrue($cFeed->getUpdated() instanceof Zend_Gdata_App_Extension_Updated);
  353. $this->verifyProperty2($cFeed, "updated", "text", "2007-05-31T01:15:13.249Z");
  354. $this->assertTrue($cFeed->getTitle() instanceof Zend_Gdata_App_Extension_Title);
  355. $this->verifyProperty2($cFeed, "title", "text", "Comments for: all day event may 24");
  356. // Verify that the comments appear to be good
  357. $commentCount = 0;
  358. foreach ($cFeed as $entry)
  359. {
  360. $this->assertTrue($entry instanceof Zend_Gdata_Entry);
  361. $commentCount++;
  362. }
  363. $this->assertEquals(2, $commentCount);
  364. // Closely examine one of the comments
  365. $comment = $cFeed[1];
  366. $this->assertTrue($comment->getId() instanceof Zend_Gdata_App_Extension_Id);
  367. $this->verifyProperty2($comment, "id", "text", "i9q87onko1uphfs7i21elnnb4g");
  368. $this->assertTrue($comment->getPublished() instanceof Zend_Gdata_App_Extension_Published);
  369. $this->verifyProperty2($comment, "published", "text", "2007-06-01T21:21:47.000Z");
  370. $this->assertTrue($comment->getUpdated() instanceof Zend_Gdata_App_Extension_Updated);
  371. $this->verifyProperty2($comment, "updated", "text", "2007-06-01T21:21:47.000Z");
  372. $this->assertEquals(1, count($comment->author));
  373. $this->assertTrue($comment->author[0] instanceof Zend_Gdata_App_Extension_Author);
  374. $this->assertTrue($comment->author[0]->getName() instanceof Zend_Gdata_App_Extension_Name);
  375. $this->assertTrue($comment->author[0]->getEmail() instanceof Zend_Gdata_App_Extension_Email);
  376. $this->verifyProperty2($comment->author[0], "name", "text", "User 2");
  377. $this->verifyProperty2($comment->author[0], "email", "text", "user2@nowhere.invalid");
  378. $this->assertTrue($comment->getContent() instanceof Zend_Gdata_App_Extension_Content);
  379. $this->verifyProperty($comment->getContent(), "type", "html");
  380. $this->assertEquals('<p>This is a user supplied comment.</p>', $comment->getContent()->text);
  381. }
  382. /**
  383. * Check for the existence of an <gd:where> and verify that it contains
  384. * the expected value.
  385. */
  386. public function testRecurrence()
  387. {
  388. $feed = $this->eventFeed;
  389. // Assert one of the entry's values
  390. $entry = $feed[1];
  391. $this->assertTrue($entry->getRecurrence() instanceof Zend_Gdata_Extension_Recurrence);
  392. $this->verifyProperty2($entry, "recurrence", "text",
  393. "DTSTART;VALUE=DATE:20070501 DTEND;VALUE=DATE:20070502 RRULE:FREQ=WEEKLY;BYDAY=Tu;UNTIL=20070904");
  394. }
  395. /**
  396. * Check for the existence of an <openSearch:startIndex> and verify that it contains
  397. * the expected value.
  398. */
  399. public function testStartIndex()
  400. {
  401. $feed = $this->eventFeed;
  402. // Assert that the feed's startIndex is correct
  403. $this->assertTrue($feed->getStartIndex() instanceof Zend_Gdata_Extension_OpenSearchStartIndex);
  404. $this->verifyProperty2($feed, "startIndex", "text", "1");
  405. }
  406. /**
  407. * Check for the existence of an <openSearch:itemsPerPage> and verify that it contains
  408. * the expected value.
  409. */
  410. public function testItemsPerPage()
  411. {
  412. $feed = $this->eventFeed;
  413. // Assert that the feed's itemsPerPage is correct
  414. $this->assertTrue($feed->getItemsPerPage() instanceof Zend_Gdata_Extension_OpenSearchItemsPerPage);
  415. $this->verifyProperty2($feed, "itemsPerPage", "text", "25");
  416. }
  417. /**
  418. * Check for the existence of an <atom:generator> and verify that it contains
  419. * the expected value.
  420. */
  421. public function testGenerator()
  422. {
  423. $feed = $this->eventFeed;
  424. // Assert that the feed's generator is correct
  425. $this->assertTrue($feed->getGenerator() instanceof Zend_Gdata_App_Extension_Generator);
  426. $this->verifyProperty2($feed, "generator", "version", "1.0");
  427. $this->verifyProperty2($feed, "generator", "uri", "http://www.google.com/calendar");
  428. }
  429. }