CalendarFeedTest.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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_CalendarFeedTest extends PHPUnit_Framework_TestCase
  36. {
  37. protected $listFeed = null;
  38. /**
  39. * Called before each test to setup any fixtures.
  40. */
  41. public function setUp()
  42. {
  43. $listFeedText = file_get_contents(
  44. 'Zend/Gdata/Calendar/_files/ListFeedSample1.xml',
  45. true);
  46. $this->listFeed = new Zend_Gdata_Calendar_ListFeed($listFeedText);
  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->listFeed as $entry) {
  88. $entryCount++;
  89. $this->assertTrue($entry instanceof Zend_Gdata_Calendar_ListEntry);
  90. }
  91. $this->assertTrue($entryCount > 0);
  92. /* Grab XML from $this->listFeed and convert back to objects */
  93. $newListFeed = new Zend_Gdata_Calendar_ListFeed(
  94. $this->listFeed->saveXML());
  95. $newEntryCount = 0;
  96. foreach ($newListFeed as $entry) {
  97. $newEntryCount++;
  98. $this->assertTrue($entry instanceof Zend_Gdata_Calendar_ListEntry);
  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->listFeed as $entry) {
  111. $entryCount++;
  112. }
  113. $this->assertEquals(9, $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->listFeed;
  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->listFeed;
  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");
  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/ri3u1buho56d1k2papoec4c16s%40group.calendar.google.com");
  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->listFeed;
  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-05-30T00:23:27.005Z");
  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->listFeed;
  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-05-30T00:23:26.998Z");
  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-05-30T00:20:38.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->listFeed;
  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's Calendar List");
  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", "My Other Awesome Calendar");
  212. }
  213. /**
  214. * Check for the existence of an <gCal:color> and verify that it contains
  215. * the expected value.
  216. */
  217. public function testColor()
  218. {
  219. $feed = $this->listFeed;
  220. // Assert that all entry's have an color object
  221. foreach ($feed as $entry) {
  222. $this->assertTrue($entry->getColor() instanceof Zend_Gdata_Calendar_Extension_Color);
  223. }
  224. // Assert one of the entry's Titles
  225. $entry = $feed[1];
  226. $this->verifyProperty2($entry, "color", "value", "#A32929");
  227. }
  228. /**
  229. * Check for the existence of an <gCal:accessLevel> and verify that it contains
  230. * the expected value.
  231. */
  232. public function testAccessLevel()
  233. {
  234. $feed = $this->listFeed;
  235. // Assert that all entry's have an accessLevel object
  236. foreach ($feed as $entry) {
  237. $this->assertTrue($entry->getAccessLevel() instanceof Zend_Gdata_Calendar_Extension_AccessLevel);
  238. }
  239. // Assert one of the entry's Titles
  240. $entry = $feed[1];
  241. $this->verifyProperty2($entry, "accessLevel", "value", "owner");
  242. }
  243. /**
  244. * Check for the existence of an <gCal:timezone> and verify that it contains
  245. * the expected value.
  246. */
  247. public function testTimezone()
  248. {
  249. $feed = $this->listFeed;
  250. // Assert that all entry's have an accessLevel object
  251. foreach ($feed as $entry) {
  252. $this->assertTrue($entry->getTimezone() instanceof Zend_Gdata_Calendar_Extension_Timezone);
  253. }
  254. // Assert one of the entry's Titles
  255. $entry = $feed[1];
  256. $this->verifyProperty2($entry, "timezone", "value", "America/Chicago");
  257. }
  258. /**
  259. * Check for the existence of an <gCal:hidden> and verify that it contains
  260. * the expected value.
  261. */
  262. public function testHidden()
  263. {
  264. $feed = $this->listFeed;
  265. // Assert that all entry's have an accessLevel object
  266. foreach ($feed as $entry) {
  267. $this->assertTrue($entry->getHidden() instanceof Zend_Gdata_Calendar_Extension_Hidden);
  268. }
  269. // Assert one of the entry's Titles
  270. $entry = $feed[1];
  271. $this->verifyProperty2($entry, "hidden", "value", false);
  272. }
  273. /**
  274. * Check for the existence of an <gCal:selected> and verify that it contains
  275. * the expected value.
  276. */
  277. public function testSelected()
  278. {
  279. $feed = $this->listFeed;
  280. // Assert that all entry's have a selected object
  281. foreach ($feed as $entry) {
  282. $this->assertTrue($entry->getSelected() instanceof Zend_Gdata_Calendar_Extension_Selected);
  283. }
  284. // Assert one of the entry's Titles
  285. $entry = $feed[1];
  286. $this->verifyProperty2($entry, "selected", "value", true);
  287. }
  288. /**
  289. * Check for the existence of an <openSearch:startIndex> and verify that it contains
  290. * the expected value.
  291. */
  292. public function testStartIndex()
  293. {
  294. $feed = $this->listFeed;
  295. // Assert that the feed's startIndex is correct
  296. $this->assertTrue($feed->getStartIndex() instanceof Zend_Gdata_Extension_OpenSearchStartIndex);
  297. $this->verifyProperty2($feed, "startIndex", "text", "1");
  298. }
  299. /**
  300. * Check for the existence of an <gd:where> and verify that it contains
  301. * the expected value.
  302. */
  303. public function testWhere()
  304. {
  305. $feed = $this->listFeed;
  306. // Assert one of the entry's where values
  307. $entry = $feed[1];
  308. $this->assertEquals($entry->getWhere(), $entry->where);
  309. $this->assertTrue($entry->where[0] instanceof Zend_Gdata_Extension_Where);
  310. $this->assertEquals("Palo Alto, California", $entry->where[0]->getValueString());
  311. }
  312. /**
  313. * Check for the existence of an <atom:summary> and verify that it contains
  314. * the expected value.
  315. */
  316. public function testSummary()
  317. {
  318. $feed = $this->listFeed;
  319. // Assert one of the entry's summaries
  320. $entry = $feed[1];
  321. $this->assertTrue($entry->getSummary() instanceof Zend_Gdata_App_Extension_Summary);
  322. $this->verifyProperty2($entry, "summary", "text", "This is my other calendar.");
  323. }
  324. /**
  325. * Check for the existence of an <atom:generator> and verify that it contains
  326. * the expected value.
  327. */
  328. public function testGenerator()
  329. {
  330. $feed = $this->listFeed;
  331. // Assert that the feed's generator is correct
  332. $this->assertTrue($feed->getGenerator() instanceof Zend_Gdata_App_Extension_Generator);
  333. $this->verifyProperty2($feed, "generator", "version", "1.0");
  334. $this->verifyProperty2($feed, "generator", "uri", "http://www.google.com/calendar");
  335. }
  336. }