CalendarFeedTest.php 13 KB

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