CalendarFeedCompositeTest.php 19 KB

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