PhotosAlbumFeedTest.php 16 KB

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