CalendarEventTest.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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_CalendarEventTest 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/TestDataEventFeedSample1.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($value, $obj->$propGetter());
  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($value, $obj->$propGetter()->$secondGetter());
  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(10, $entryCount);
  114. }
  115. /**
  116. * Check for the existence of an <atom:author> and verify that they
  117. * contain the expected values.
  118. */
  119. public function testAuthor()
  120. {
  121. $feed = $this->eventFeed;
  122. // Assert that the feed's author is correct
  123. $feedAuthor = $feed->getAuthor();
  124. $this->assertEquals($feedAuthor, $feed->author);
  125. $this->assertEquals(1, count($feedAuthor));
  126. $this->assertTrue($feedAuthor[0] instanceof Zend_Gdata_App_Extension_Author);
  127. $this->verifyProperty2($feedAuthor[0], "name", "text", "GData Ops Demo");
  128. $this->verifyProperty2($feedAuthor[0], "email", "text", "gdata.ops.demo@gmail.com");
  129. $this->assertTrue($feedAuthor[0]->getUri() instanceof Zend_Gdata_App_Extension_Uri);
  130. $this->verifyProperty2($feedAuthor[0], "uri", "text", "http://test.address.invalid/");
  131. // Assert that each entry has valid author data
  132. foreach ($feed as $entry) {
  133. $entryAuthor = $entry->getAuthor();
  134. $this->assertEquals(1, count($entryAuthor));
  135. $this->verifyProperty2($entryAuthor[0], "name", "text", "GData Ops Demo");
  136. $this->verifyProperty2($entryAuthor[0], "email", "text", "gdata.ops.demo@gmail.com");
  137. $this->verifyProperty($entryAuthor[0], "uri", null);
  138. }
  139. }
  140. /**
  141. * Check for the existence of an <atom:id> and verify that it contains
  142. * the expected value.
  143. */
  144. public function testId()
  145. {
  146. $feed = $this->eventFeed;
  147. // Assert that the feed's ID is correct
  148. $this->assertTrue($feed->getId() instanceof Zend_Gdata_App_Extension_Id);
  149. $this->verifyProperty2($feed, "id", "text",
  150. "http://www.google.com/calendar/feeds/default/private/full");
  151. // Assert that all entry's have an Atom ID object
  152. foreach ($feed as $entry) {
  153. $this->assertTrue($entry->getId() instanceof Zend_Gdata_App_Extension_Id);
  154. }
  155. // Assert one of the entry's IDs
  156. $entry = $feed[1];
  157. $this->verifyProperty2($entry, "id", "text",
  158. "http://www.google.com/calendar/feeds/default/private/full/2qt3ao5hbaq7m9igr5ak9esjo0");
  159. }
  160. /**
  161. * Check for the existence of an <atom:published> and verify that it contains
  162. * the expected value.
  163. */
  164. public function testPublished()
  165. {
  166. $feed = $this->eventFeed;
  167. // Assert that all entry's have an Atom Published object
  168. foreach ($feed as $entry) {
  169. $this->assertTrue($entry->getPublished() instanceof Zend_Gdata_App_Extension_Published);
  170. }
  171. // Assert one of the entry's Published dates
  172. $entry = $feed[1];
  173. $this->verifyProperty2($entry, "published", "text", "2007-03-20T21:26:04.000Z");
  174. }
  175. /**
  176. * Check for the existence of an <atom:published> and verify that it contains
  177. * the expected value.
  178. */
  179. public function testUpdated()
  180. {
  181. $feed = $this->eventFeed;
  182. // Assert that the feed's updated date is correct
  183. $this->assertTrue($feed->getUpdated() instanceof Zend_Gdata_App_Extension_Updated);
  184. $this->verifyProperty2($feed, "updated", "text",
  185. "2007-03-20T21:29:57.000Z");
  186. // Assert that all entry's have an Atom Published object
  187. foreach ($feed as $entry) {
  188. $this->assertTrue($entry->getUpdated() instanceof Zend_Gdata_App_Extension_Updated);
  189. }
  190. // Assert one of the entry's Published dates
  191. $entry = $feed[1];
  192. $this->verifyProperty2($entry, "updated", "text", "2007-03-20T21:28:46.000Z");
  193. }
  194. /**
  195. * Check for the existence of an <atom:title> and verify that it contains
  196. * the expected value.
  197. */
  198. public function testTitle()
  199. {
  200. $feed = $this->eventFeed;
  201. // Assert that the feed's title is correct
  202. $this->assertTrue($feed->getTitle() instanceof Zend_Gdata_App_Extension_Title);
  203. $this->verifyProperty2($feed, "title", "text",
  204. "GData Ops Demo");
  205. // Assert that all entry's have an Atom ID object
  206. foreach ($feed as $entry) {
  207. $this->assertTrue($entry->getTitle() instanceof Zend_Gdata_App_Extension_Title);
  208. }
  209. // Assert one of the entry's Titles
  210. $entry = $feed[1];
  211. $this->verifyProperty2($entry, "title", "text", "Afternoon at Dolores Park with Kim");
  212. }
  213. /**
  214. * Check for the existence of an <atom:subtitle> and verify that it contains
  215. * the expected value.
  216. */
  217. public function testSubtitle()
  218. {
  219. $feed = $this->eventFeed;
  220. // Assert that the feed's title is correct
  221. $this->assertTrue($feed->getSubtitle() instanceof Zend_Gdata_App_Extension_Subtitle);
  222. $this->verifyProperty2($feed, "subtitle", "text",
  223. "Demo Feed");
  224. }
  225. /**
  226. * Check for the existence of an <gCal:timezone> and verify that it contains
  227. * the expected value.
  228. */
  229. public function testTimezone()
  230. {
  231. $feed = $this->eventFeed;
  232. // Assert that the feed's timezone is correct
  233. $this->assertTrue($feed->getTimezone() instanceof Zend_Gdata_Calendar_Extension_Timezone);
  234. $this->verifyProperty2($feed, "timezone", "value",
  235. "America/Los_Angeles");
  236. }
  237. /**
  238. * Check for the existence of an <openSearch:startIndex> and verify that it contains
  239. * the expected value.
  240. */
  241. public function testStartIndex()
  242. {
  243. $feed = $this->eventFeed;
  244. // Assert that the feed's startIndex is correct
  245. $this->assertTrue($feed->getStartIndex() instanceof Zend_Gdata_Extension_OpenSearchStartIndex);
  246. $this->verifyProperty2($feed, "startIndex", "text", "1");
  247. }
  248. /**
  249. * Check for the existence of an <openSearch:itemsPerPage> and verify that it contains
  250. * the expected value.
  251. */
  252. public function testItemsPerPage()
  253. {
  254. $feed = $this->eventFeed;
  255. // Assert that the feed's itemsPerPage is correct
  256. $this->assertTrue($feed->getItemsPerPage() instanceof Zend_Gdata_Extension_OpenSearchItemsPerPage);
  257. $this->verifyProperty2($feed, "itemsPerPage", "text", "25");
  258. }
  259. /**
  260. * Check for the existence of an <atom:content> and verify that it contains
  261. * the expected value.
  262. */
  263. public function testContent()
  264. {
  265. $feed = $this->eventFeed;
  266. // Assert that all entry's have a content object
  267. foreach ($feed as $entry) {
  268. $this->assertTrue($entry->getContent() instanceof Zend_Gdata_App_Extension_Content);
  269. }
  270. // Assert one of the entry's values
  271. $entry = $feed[1];
  272. $this->verifyProperty2($entry, "content", "text", "This will be fun.");
  273. }
  274. /**
  275. * Check for the existence of an <gCal:sendEventNotifications> and verify that it contains
  276. * the expected value.
  277. */
  278. public function testSendEventNotifications()
  279. {
  280. $feed = $this->eventFeed;
  281. // Assert that all entry's have a sendEventNotifications object
  282. foreach ($feed as $entry) {
  283. $this->assertTrue($entry->getSendEventNotifications() instanceof Zend_Gdata_Calendar_Extension_SendEventNotifications);
  284. }
  285. // Assert one of the entry's values
  286. $entry = $feed[1];
  287. $this->verifyProperty2($entry, "sendEventNotifications", "value", false);
  288. }
  289. /**
  290. * Check for the existence of an <gd:eventStatus> and verify that it contains
  291. * the expected value.
  292. */
  293. public function testEventStatus()
  294. {
  295. $feed = $this->eventFeed;
  296. // Assert that all entry's have a eventStatus object
  297. foreach ($feed as $entry) {
  298. $this->assertTrue($entry->getEventStatus() instanceof Zend_Gdata_Extension_EventStatus);
  299. }
  300. // Assert one of the entry's values
  301. $entry = $feed[1];
  302. $this->verifyProperty2($entry, "eventStatus", "value", "http://schemas.google.com/g/2005#event.confirmed");
  303. }
  304. /**
  305. * Check for the existence of an <gd:comments> and verify that it contains
  306. * the expected value.
  307. */
  308. public function testComments()
  309. {
  310. $feed = $this->eventFeed;
  311. // Assert one of the entry's commments links
  312. $entry = $feed[1];
  313. $this->assertTrue($entry->getComments() instanceof Zend_Gdata_Extension_Comments);
  314. $this->verifyProperty2($entry->getComments(), "feedLink", "href", "http://www.google.com/calendar/feeds/default/private/full/2qt3ao5hbaq7m9igr5ak9esjo0/comments");
  315. }
  316. /**
  317. * Check for the existence of an <gCal:visibility> and verify that it contains
  318. * the expected value.
  319. */
  320. public function testVisibility()
  321. {
  322. $feed = $this->eventFeed;
  323. // Assert that all entry's have a visibility object
  324. foreach ($feed as $entry) {
  325. $this->assertTrue($entry->getVisibility() instanceof Zend_Gdata_Extension_Visibility);
  326. }
  327. // Assert one of the entries values
  328. $entry = $feed[1];
  329. $this->verifyProperty2($entry, "visibility", "value", "http://schemas.google.com/g/2005#event.private");
  330. }
  331. /**
  332. * Check for the existence of an <gCal:transparency> and verify that it contains
  333. * the expected value.
  334. */
  335. public function testTransparency()
  336. {
  337. $feed = $this->eventFeed;
  338. // Assert that all entry's have a transparency object
  339. foreach ($feed as $entry) {
  340. $this->assertTrue($entry->getTransparency() instanceof Zend_Gdata_Extension_Transparency);
  341. }
  342. // Assert one of the entries values
  343. $entry = $feed[1];
  344. $this->verifyProperty2($entry, "transparency", "value", "http://schemas.google.com/g/2005#event.opaque");
  345. }
  346. /**
  347. * Check for the existence of an <gd:when> and verify that it contains
  348. * the expected value.
  349. */
  350. public function testWhen()
  351. {
  352. $feed = $this->eventFeed;
  353. // Assert one of the entry's values
  354. $entry = $feed[1];
  355. $when = $entry->getWhen();
  356. $this->assertEquals($entry->getWhen(), $entry->when);
  357. $this->assertEquals(1, count($when));
  358. $w = $when[0];
  359. $this->assertTrue($w instanceof Zend_Gdata_Extension_When);
  360. $this->verifyProperty($w, "startTime", "2007-03-24T12:00:00.000-07:00");
  361. $this->verifyProperty($w, "endTime", "2007-03-24T15:00:00.000-07:00");
  362. // Assert that the associated reminders are correct
  363. $reminders = $w->getReminders();
  364. $this->assertEquals(1, count($reminders));
  365. $this->verifyProperty($reminders[0], "minutes", "20");
  366. $this->verifyProperty($reminders[0], "method", "alert");
  367. }
  368. /**
  369. * Check for the existence of an <gd:where> and verify that it contains
  370. * the expected value.
  371. */
  372. public function testWhere()
  373. {
  374. $feed = $this->eventFeed;
  375. // Assert one of the entry's values
  376. $entry = $feed[1];
  377. $where = $entry->getWhere();
  378. $this->assertEquals(1, count($where));
  379. $this->assertTrue($where[0] instanceof Zend_Gdata_Extension_Where);
  380. $this->verifyProperty($where[0], "valueString", "Dolores Park with Kim");
  381. }
  382. /**
  383. * Check for the existence of an <gd:where> and verify that it contains
  384. * the expected value.
  385. */
  386. public function testWho()
  387. {
  388. $feed = $this->eventFeed;
  389. // For one of the entries, make sure that all who entries are of the
  390. // right kind
  391. $entry = $feed[1];
  392. $who = $entry->getWho();
  393. foreach ($who as $w) {
  394. $this->assertTrue($w instanceof Zend_Gdata_Extension_Who);
  395. }
  396. $this->assertEquals(2, count($who));
  397. // Check one of the who entries to make sure the values are valid
  398. $this->verifyProperty($who[0], "rel", "http://schemas.google.com/g/2005#event.organizer");
  399. $this->verifyProperty($who[0], "valueString", "GData Ops Demo");
  400. $this->verifyProperty($who[0], "email", "gdata.ops.demo@gmail.com");
  401. $this->verifyProperty2($who[0], "attendeeStatus", "value", "http://schemas.google.com/g/2005#event.accepted");
  402. }
  403. /**
  404. * Check for the existence of an <atom:generator> and verify that it contains
  405. * the expected value.
  406. */
  407. public function testGenerator()
  408. {
  409. $feed = $this->eventFeed;
  410. // Assert that the feed's generator is correct
  411. $this->assertTrue($feed->getGenerator() instanceof Zend_Gdata_App_Extension_Generator);
  412. $this->verifyProperty2($feed, "generator", "version", "1.0");
  413. $this->verifyProperty2($feed, "generator", "uri", "http://www.google.com/calendar");
  414. $this->verifyProperty2($feed, "generator", "text", "Google Calendar");
  415. }
  416. /**
  417. * Check for the existence of an <gd:quickadd> and verify that it contains
  418. * the expected value.
  419. */
  420. public function testQuickAdd()
  421. {
  422. $feed = $this->eventFeed;
  423. // Assert that one of the event's QuickAdd entries is correct
  424. $quickAdd = $feed->entry[1]->getQuickAdd();
  425. $this->assertTrue($quickAdd instanceof Zend_Gdata_Calendar_Extension_QuickAdd);
  426. $this->verifyProperty($quickAdd, "value", true);
  427. }
  428. }