PhotosAlbumFeedTest.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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/AlbumFeed.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_PhotosAlbumFeedTest extends PHPUnit_Framework_TestCase
  36. {
  37. protected $albumFeed = null;
  38. /**
  39. * Called before each test to setup any fixtures.
  40. */
  41. public function setUp()
  42. {
  43. $albumFeedText = file_get_contents(
  44. '_files/TestAlbumFeed.xml',
  45. true);
  46. $this->albumFeed = new Zend_Gdata_Photos_AlbumFeed($albumFeedText);
  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 testAlbumFeedToAndFromString()
  106. {
  107. $entryCount = 0;
  108. foreach ($this->albumFeed as $entry) {
  109. $entryCount++;
  110. $this->assertTrue($entry instanceof Zend_Gdata_Photos_PhotoEntry ||
  111. $entry instanceof Zend_Gdata_Photos_TagEntry);
  112. }
  113. $this->assertTrue($entryCount > 0);
  114. /* Grab XML from $this->albumFeed and convert back to objects */
  115. $newListFeed = new Zend_Gdata_Photos_UserFeed(
  116. $this->albumFeed->saveXML());
  117. $newEntryCount = 0;
  118. foreach ($newListFeed as $entry) {
  119. $newEntryCount++;
  120. $this->assertTrue($entry instanceof Zend_Gdata_Photos_PhotoEntry ||
  121. $entry instanceof Zend_Gdata_Photos_TagEntry);
  122. }
  123. $this->assertEquals($entryCount, $newEntryCount);
  124. }
  125. /**
  126. * Ensure that the number of entries equals the number
  127. * of entries defined in the sample file.
  128. */
  129. public function testEntryCount()
  130. {
  131. $entryCount = 0;
  132. foreach ($this->albumFeed as $entry) {
  133. $entryCount++;
  134. }
  135. $this->assertEquals(4, $entryCount);
  136. }
  137. /**
  138. * Check for the existence of an <atom:author> and verify that they
  139. * contain the expected values.
  140. */
  141. public function testAuthor()
  142. {
  143. $feed = $this->albumFeed;
  144. // Assert that the feed's author is correct
  145. $feedAuthor = $feed->getAuthor();
  146. $this->assertEquals($feedAuthor, $feed->author);
  147. $this->assertEquals(1, count($feedAuthor));
  148. $this->assertTrue($feedAuthor[0] instanceof Zend_Gdata_App_Extension_Author);
  149. $this->verifyProperty2($feedAuthor[0], "name", "text", "sample");
  150. $this->assertTrue($feedAuthor[0]->getUri() instanceof Zend_Gdata_App_Extension_Uri);
  151. $this->verifyProperty2($feedAuthor[0], "uri", "text", "http://picasaweb.google.com/sample.user");
  152. // Assert that each entry has valid author data
  153. foreach ($feed as $entry) {
  154. if ($entry instanceof Zend_Gdata_Photos_AlbumEntry) {
  155. $entryAuthor = $entry->getAuthor();
  156. $this->assertEquals(1, count($entryAuthor));
  157. $this->verifyProperty2($entryAuthor[0], "name", "text", "sample");
  158. $this->verifyProperty2($entryAuthor[0], "uri", "text", "http://picasaweb.google.com/sample.user");
  159. }
  160. }
  161. }
  162. /**
  163. * Check for the existence of an <atom:id> and verify that it contains
  164. * the expected value.
  165. */
  166. public function testId()
  167. {
  168. $feed = $this->albumFeed;
  169. // Assert that the feed's ID is correct
  170. $this->assertTrue($feed->getId() instanceof Zend_Gdata_App_Extension_Id);
  171. $this->verifyProperty2($feed, "id", "text",
  172. "http://picasaweb.google.com/data/feed/api/user/sample.user/albumid/1");
  173. // Assert that all entries have an Atom ID object
  174. foreach ($feed as $entry) {
  175. $this->assertTrue($entry->getId() instanceof Zend_Gdata_App_Extension_Id);
  176. }
  177. // Assert one of the entry's IDs
  178. $entry = $feed[0];
  179. $this->verifyProperty2($entry, "id", "text",
  180. "http://picasaweb.google.com/data/entry/api/user/sample.user/albumid/1/photoid/2");
  181. }
  182. /**
  183. * Check for the existence of an <atom:published> and verify that it contains
  184. * the expected value.
  185. */
  186. public function testPublished()
  187. {
  188. $feed = $this->albumFeed;
  189. // Assert that all photo entries have an Atom Published object
  190. foreach ($feed as $entry) {
  191. if ($entry instanceof Zend_Gdata_Photos_PhotoEntry) {
  192. $this->assertTrue($entry->getPublished() instanceof Zend_Gdata_App_Extension_Published);
  193. }
  194. }
  195. // Assert one of the entry's Published dates
  196. $entry = $feed[0];
  197. $this->verifyProperty2($entry, "published", "text", "2007-09-05T20:49:23.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->albumFeed;
  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-21T18:23:05.000Z");
  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-21T18:23:05.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->albumFeed;
  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", "Test");
  228. // Assert that all entries have an Atom ID object
  229. foreach ($feed as $entry) {
  230. $this->assertTrue($entry->getTitle() instanceof Zend_Gdata_App_Extension_Title);
  231. }
  232. // Assert one of the entry's Titles
  233. $entry = $feed[0];
  234. $this->verifyProperty2($entry, "title", "text", "Aqua Blue.jpg");
  235. }
  236. /**
  237. * Check for the existence of an <atom:subtitle> and verify that it contains
  238. * the expected value.
  239. */
  240. public function testSubtitle()
  241. {
  242. $feed = $this->albumFeed;
  243. // Assert that the feed's title is correct
  244. $this->assertTrue($feed->getSubtitle() instanceof Zend_Gdata_App_Extension_Subtitle);
  245. $this->verifyProperty2($feed, "subtitle", "text",
  246. "");
  247. }
  248. /**
  249. * Check for the existence of an <atom:generator> and verify that it contains
  250. * the expected value.
  251. */
  252. public function testGenerator()
  253. {
  254. $feed = $this->albumFeed;
  255. // Assert that the feed's generator is correct
  256. $this->assertTrue($feed->getGenerator() instanceof Zend_Gdata_App_Extension_Generator);
  257. $this->verifyProperty2($feed, "generator", "version", "1.00");
  258. $this->verifyProperty2($feed, "generator", "uri", "http://picasaweb.google.com/");
  259. $this->verifyProperty2($feed, "generator", "text", "Picasaweb");
  260. }
  261. /**
  262. * Check for the existence of an <atom:icon> and verify that it contains
  263. * the expected value.
  264. */
  265. public function testIcon()
  266. {
  267. $feed = $this->albumFeed;
  268. // Assert that the feed's title is correct
  269. $this->assertTrue($feed->getIcon() instanceof Zend_Gdata_App_Extension_Icon);
  270. $this->verifyProperty2($feed, "icon", "text",
  271. "http://lh6.google.com/sample.user/Rt8WNoDZEJE/AAAAAAAAABk/HQGlDhpIgWo/s160-c/Test.jpg");
  272. }
  273. /**
  274. * Check for the existence of an <gphoto:user> and verify that it contains
  275. * the expected value.
  276. */
  277. public function testGphotoUser()
  278. {
  279. $feed = $this->albumFeed;
  280. // Assert that the feed's title is correct
  281. $this->assertTrue($feed->getGphotoUser() instanceof Zend_Gdata_Photos_Extension_User);
  282. $this->verifyProperty2($feed, "gphotoUser", "text",
  283. "sample.user");
  284. $this->verifyProperty3($feed, "gphotoUser", "text",
  285. "sample.user");
  286. }
  287. /**
  288. * Check for the existence of an <gphoto:nickname> and verify that it contains
  289. * the expected value.
  290. */
  291. public function testGphotoNickname()
  292. {
  293. $feed = $this->albumFeed;
  294. // Assert that the feed's title is correct
  295. $this->assertTrue($feed->getGphotoNickname() instanceof Zend_Gdata_Photos_Extension_Nickname);
  296. $this->verifyProperty2($feed, "gphotoNickname", "text",
  297. "sample");
  298. $this->verifyProperty3($feed, "gphotoNickname", "text",
  299. "sample");
  300. }
  301. /**
  302. * Check for the existence of an <gphoto:name> and verify that it contains
  303. * the expected value.
  304. */
  305. public function testGphotoName()
  306. {
  307. $feed = $this->albumFeed;
  308. // Assert that the feed's title is correct
  309. $this->assertTrue($feed->getGphotoName() instanceof Zend_Gdata_Photos_Extension_Name);
  310. $this->verifyProperty2($feed, "gphotoName", "text",
  311. "Test");
  312. }
  313. /**
  314. * Check for the existence of an <gphoto:id> and verify that it contains
  315. * the expected value.
  316. */
  317. public function testGphotoId()
  318. {
  319. $feed = $this->albumFeed;
  320. // Assert that the feed's title is correct
  321. $this->assertTrue($feed->getGphotoId() instanceof Zend_Gdata_Photos_Extension_Id);
  322. $this->verifyProperty2($feed, "gphotoId", "text",
  323. "1");
  324. $this->verifyProperty3($feed, "gphotoId", "text",
  325. "1");
  326. }
  327. /**
  328. * Check for the existence of an <gphoto:location> and verify that it contains
  329. * the expected value.
  330. */
  331. public function testGphotoLocation()
  332. {
  333. $feed = $this->albumFeed;
  334. // Assert that the feed's title is correct
  335. $this->assertTrue($feed->getGphotoLocation() instanceof Zend_Gdata_Photos_Extension_Location);
  336. $this->verifyProperty2($feed, "gphotoLocation", "text",
  337. "");
  338. $this->verifyProperty3($feed, "gphotoLocation", "text",
  339. "");
  340. }
  341. /**
  342. * Check for the existence of an <gphoto:access> and verify that it contains
  343. * the expected value.
  344. */
  345. public function testGphotoAccess()
  346. {
  347. $feed = $this->albumFeed;
  348. // Assert that the feed's title is correct
  349. $this->assertTrue($feed->getGphotoAccess() instanceof Zend_Gdata_Photos_Extension_Access);
  350. $this->verifyProperty2($feed, "gphotoAccess", "text",
  351. "public");
  352. $this->verifyProperty3($feed, "gphotoAccess", "text",
  353. "public");
  354. }
  355. /**
  356. * Check for the existence of an <gphoto:timestamp> and verify that it contains
  357. * the expected value.
  358. */
  359. public function testGphotoTimestamp()
  360. {
  361. $feed = $this->albumFeed;
  362. // Assert that the feed's title is correct
  363. $this->assertTrue($feed->getGphotoTimestamp() instanceof Zend_Gdata_Photos_Extension_Timestamp);
  364. $this->verifyProperty2($feed, "gphotoTimestamp", "text",
  365. "1188975600000");
  366. $this->verifyProperty3($feed, "gphotoTimestamp", "text",
  367. "1188975600000");
  368. }
  369. /**
  370. * Check for the existence of an <gphoto:numphotos> and verify that it contains
  371. * the expected value.
  372. */
  373. public function testGphotoNumPhotos()
  374. {
  375. $feed = $this->albumFeed;
  376. // Assert that the feed's title is correct
  377. $this->assertTrue($feed->getGphotoNumPhotos() instanceof Zend_Gdata_Photos_Extension_NumPhotos);
  378. $this->verifyProperty2($feed, "gphotoNumPhotos", "text",
  379. "2");
  380. $this->verifyProperty3($feed, "gphotoNumPhotos", "text",
  381. "2");
  382. }
  383. /**
  384. * Check for the existence of an <gphoto:commentingEnabled> and verify that it contains
  385. * the expected value.
  386. */
  387. public function testGphotoCommentingEnabled()
  388. {
  389. $feed = $this->albumFeed;
  390. // Assert that the feed's title is correct
  391. $this->assertTrue($feed->getGphotoCommentingEnabled() instanceof Zend_Gdata_Photos_Extension_CommentingEnabled);
  392. $this->verifyProperty2($feed, "gphotoCommentingEnabled", "text",
  393. "true");
  394. $this->verifyProperty3($feed, "gphotoCommentingEnabled", "text",
  395. "true");
  396. }
  397. /**
  398. * Check for the existence of an <gphoto:commentCount> and verify that it contains
  399. * the expected value.
  400. */
  401. public function testGphotoCommentCount()
  402. {
  403. $feed = $this->albumFeed;
  404. // Assert that the feed's title is correct
  405. $this->assertTrue($feed->getGphotoCommentCount() instanceof Zend_Gdata_Photos_Extension_CommentCount);
  406. $this->verifyProperty2($feed, "gphotoCommentCount", "text",
  407. "0");
  408. $this->verifyProperty3($feed, "gphotoCommentCount", "text",
  409. "0");
  410. }
  411. }