PhotosUserFeedTest.php 13 KB

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