PhotosUserFeedTest.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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/Photos.php';
  22. require_once 'Zend/Gdata/Photos/UserFeed.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_Photos_PhotosUserFeedTest extends PHPUnit_Framework_TestCase
  30. {
  31. protected $userFeed = null;
  32. /**
  33. * Called before each test to setup any fixtures.
  34. */
  35. public function setUp()
  36. {
  37. $userFeedText = file_get_contents(
  38. '_files/TestUserFeed.xml',
  39. true);
  40. $this->userFeed = new Zend_Gdata_Photos_UserFeed($userFeedText);
  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. * Verify that a given property is set to a specific value,
  76. * that it keeps that value when set using the setter,
  77. * and that the getter and magic variable return the same value.
  78. *
  79. * @param object $obj The object to be interrogated.
  80. * @param string $name The name of the property to be verified.
  81. * @param string $secondName 2nd level accessor function name
  82. * @param object $value The expected value of the property.
  83. */
  84. protected function verifyProperty3($obj, $name, $secondName, $value)
  85. {
  86. $propName = $name;
  87. $propGetter = "get" . ucfirst($name);
  88. $propSetter = "set" . ucfirst($name);
  89. $secondGetter = "get" . ucfirst($secondName);
  90. $secondSetter = "set" . ucfirst($secondName);
  91. $this->assertEquals($obj->$propGetter(), $obj->$propName);
  92. $obj->$propSetter($obj->$propName);
  93. $this->assertEquals($value, $obj->$propGetter()->$secondGetter());
  94. }
  95. /**
  96. * Convert sample feed to XML then back to objects. Ensure that
  97. * all objects are instances of appropriate entry type and object count matches.
  98. */
  99. public function testUserFeedToAndFromString()
  100. {
  101. $entryCount = 0;
  102. foreach ($this->userFeed as $entry) {
  103. $entryCount++;
  104. $this->assertTrue($entry instanceof Zend_Gdata_Photos_AlbumEntry ||
  105. $entry instanceof Zend_Gdata_Photos_PhotoEntry ||
  106. $entry instanceof Zend_Gdata_Photos_TagEntry);
  107. }
  108. $this->assertTrue($entryCount > 0);
  109. /* Grab XML from $this->userFeed and convert back to objects */
  110. $newListFeed = new Zend_Gdata_Photos_UserFeed(
  111. $this->userFeed->saveXML());
  112. $newEntryCount = 0;
  113. foreach ($newListFeed as $entry) {
  114. $newEntryCount++;
  115. $this->assertTrue($entry instanceof Zend_Gdata_Photos_AlbumEntry ||
  116. $entry instanceof Zend_Gdata_Photos_PhotoEntry ||
  117. $entry instanceof Zend_Gdata_Photos_TagEntry);
  118. }
  119. $this->assertEquals($entryCount, $newEntryCount);
  120. }
  121. /**
  122. * Ensure that the number of entries equals the number
  123. * of entries defined in the sample file.
  124. */
  125. public function testEntryCount()
  126. {
  127. $entryCount = 0;
  128. foreach ($this->userFeed as $entry) {
  129. $entryCount++;
  130. }
  131. $this->assertEquals(3, $entryCount);
  132. }
  133. /**
  134. * Check for the existence of an <atom:author> and verify that they
  135. * contain the expected values.
  136. */
  137. public function testAuthor()
  138. {
  139. $feed = $this->userFeed;
  140. // Assert that the feed's author is correct
  141. $feedAuthor = $feed->getAuthor();
  142. $this->assertEquals($feedAuthor, $feed->author);
  143. $this->assertEquals(1, count($feedAuthor));
  144. $this->assertTrue($feedAuthor[0] instanceof Zend_Gdata_App_Extension_Author);
  145. $this->verifyProperty2($feedAuthor[0], "name", "text", "sample");
  146. $this->assertTrue($feedAuthor[0]->getUri() instanceof Zend_Gdata_App_Extension_Uri);
  147. $this->verifyProperty2($feedAuthor[0], "uri", "text", "http://picasaweb.google.com/sample.user");
  148. // Assert that each entry has valid author data
  149. foreach ($feed as $entry) {
  150. if ($entry instanceof Zend_Gdata_Photos_AlbumEntry) {
  151. $entryAuthor = $entry->getAuthor();
  152. $this->assertEquals(1, count($entryAuthor));
  153. $this->verifyProperty2($entryAuthor[0], "name", "text", "sample");
  154. $this->verifyProperty2($entryAuthor[0], "uri", "text", "http://picasaweb.google.com/sample.user");
  155. }
  156. }
  157. }
  158. /**
  159. * Check for the existence of an <atom:id> and verify that it contains
  160. * the expected value.
  161. */
  162. public function testId()
  163. {
  164. $feed = $this->userFeed;
  165. // Assert that the feed's ID is correct
  166. $this->assertTrue($feed->getId() instanceof Zend_Gdata_App_Extension_Id);
  167. $this->verifyProperty2($feed, "id", "text",
  168. "http://picasaweb.google.com/data/feed/api/user/sample.user");
  169. // Assert that all entries have an Atom ID object
  170. foreach ($feed as $entry) {
  171. $this->assertTrue($entry->getId() instanceof Zend_Gdata_App_Extension_Id);
  172. }
  173. // Assert one of the entry's IDs
  174. $entry = $feed[0];
  175. $this->verifyProperty2($entry, "id", "text",
  176. "http://picasaweb.google.com/data/entry/api/user/sample.user/albumid/100");
  177. }
  178. /**
  179. * Check for the existence of an <atom:published> and verify that it contains
  180. * the expected value.
  181. */
  182. public function testPublished()
  183. {
  184. $feed = $this->userFeed;
  185. // Assert that all entries have an Atom Published object
  186. foreach ($feed as $entry) {
  187. $this->assertTrue($entry->getPublished() instanceof Zend_Gdata_App_Extension_Published);
  188. }
  189. // Assert one of the entry's Published dates
  190. $entry = $feed[0];
  191. $this->verifyProperty2($entry, "published", "text", "2007-09-05T07:00:00.000Z");
  192. }
  193. /**
  194. * Check for the existence of an <atom:updated> and verify that it contains
  195. * the expected value.
  196. */
  197. public function testUpdated()
  198. {
  199. $feed = $this->userFeed;
  200. // Assert that the feed's updated date is correct
  201. $this->assertTrue($feed->getUpdated() instanceof Zend_Gdata_App_Extension_Updated);
  202. $this->verifyProperty2($feed, "updated", "text",
  203. "2007-09-20T21:09:39.111Z");
  204. // Assert that all entries have an Atom Updated object
  205. foreach ($feed as $entry) {
  206. $this->assertTrue($entry->getUpdated() instanceof Zend_Gdata_App_Extension_Updated);
  207. }
  208. // Assert one of the entry's Updated dates
  209. $entry = $feed[0];
  210. $this->verifyProperty2($entry, "updated", "text", "2007-09-05T20:49:24.000Z");
  211. }
  212. /**
  213. * Check for the existence of an <atom:title> and verify that it contains
  214. * the expected value.
  215. */
  216. public function testTitle()
  217. {
  218. $feed = $this->userFeed;
  219. // Assert that the feed's title is correct
  220. $this->assertTrue($feed->getTitle() instanceof Zend_Gdata_App_Extension_Title);
  221. $this->verifyProperty2($feed, "title", "text",
  222. "sample.user");
  223. // Assert that all entries have an Atom ID object
  224. foreach ($feed as $entry) {
  225. $this->assertTrue($entry->getTitle() instanceof Zend_Gdata_App_Extension_Title);
  226. }
  227. // Assert one of the entry's Titles
  228. $entry = $feed[0];
  229. $this->verifyProperty2($entry, "title", "text", "Test");
  230. }
  231. /**
  232. * Check for the existence of an <atom:subtitle> and verify that it contains
  233. * the expected value.
  234. */
  235. public function testSubtitle()
  236. {
  237. $feed = $this->userFeed;
  238. // Assert that the feed's title is correct
  239. $this->assertTrue($feed->getSubtitle() instanceof Zend_Gdata_App_Extension_Subtitle);
  240. $this->verifyProperty2($feed, "subtitle", "text",
  241. "");
  242. }
  243. /**
  244. * Check for the existence of an <atom:generator> and verify that it contains
  245. * the expected value.
  246. */
  247. public function testGenerator()
  248. {
  249. $feed = $this->userFeed;
  250. // Assert that the feed's generator is correct
  251. $this->assertTrue($feed->getGenerator() instanceof Zend_Gdata_App_Extension_Generator);
  252. $this->verifyProperty2($feed, "generator", "version", "1.00");
  253. $this->verifyProperty2($feed, "generator", "uri", "http://picasaweb.google.com/");
  254. $this->verifyProperty2($feed, "generator", "text", "Picasaweb");
  255. }
  256. /**
  257. * Check for the existence of an <atom:icon> and verify that it contains
  258. * the expected value.
  259. */
  260. public function testIcon()
  261. {
  262. $feed = $this->userFeed;
  263. // Assert that the feed's title is correct
  264. $this->assertTrue($feed->getIcon() instanceof Zend_Gdata_App_Extension_Icon);
  265. $this->verifyProperty2($feed, "icon", "text",
  266. "http://lh5.google.com/sample.user/AAAAuZnob5E/AAAAAAAAAAA/EtCbNCdLGxM/s64-c/sample.user");
  267. }
  268. /**
  269. * Check for the existence of an <gphoto:user> and verify that it contains
  270. * the expected value.
  271. */
  272. public function testGphotoUser()
  273. {
  274. $feed = $this->userFeed;
  275. // Assert that the feed's title is correct
  276. $this->assertTrue($feed->getGphotoUser() instanceof Zend_Gdata_Photos_Extension_User);
  277. $this->verifyProperty2($feed, "gphotoUser", "text",
  278. "sample.user");
  279. $this->verifyProperty3($feed, "gphotoUser", "text",
  280. "sample.user");
  281. }
  282. /**
  283. * Check for the existence of an <gphoto:nickname> and verify that it contains
  284. * the expected value.
  285. */
  286. public function testGphotoNickname()
  287. {
  288. $feed = $this->userFeed;
  289. // Assert that the feed's title is correct
  290. $this->assertTrue($feed->getGphotoNickname() instanceof Zend_Gdata_Photos_Extension_Nickname);
  291. $this->verifyProperty2($feed, "gphotoNickname", "text",
  292. "sample");
  293. $this->verifyProperty3($feed, "gphotoNickname", "text",
  294. "sample");
  295. }
  296. /**
  297. * Check for the existence of an <gphoto:thumbnail> and verify that it contains
  298. * the expected value.
  299. */
  300. public function testGphotoThumbnail()
  301. {
  302. $feed = $this->userFeed;
  303. // Assert that the feed's title is correct
  304. $this->assertTrue($feed->getGphotoThumbnail() instanceof Zend_Gdata_Photos_Extension_Thumbnail);
  305. $this->verifyProperty2($feed, "gphotoThumbnail", "text",
  306. "http://lh5.google.com/sample.user/AAAAuZnob5E/AAAAAAAAAAA/EtCbNCdLGxM/s64-c/sample.user");
  307. $this->verifyProperty3($feed, "gphotoThumbnail", "text",
  308. "http://lh5.google.com/sample.user/AAAAuZnob5E/AAAAAAAAAAA/EtCbNCdLGxM/s64-c/sample.user");
  309. }
  310. }