PhotosPhotoFeedTest.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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/PhotoFeed.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_PhotosPhotoFeedTest extends PHPUnit_Framework_TestCase
  36. {
  37. protected $photoFeed = null;
  38. /**
  39. * Called before each test to setup any fixtures.
  40. */
  41. public function setUp()
  42. {
  43. $photoFeedText = file_get_contents(
  44. '_files/TestPhotoFeed.xml',
  45. true);
  46. $this->photoFeed = new Zend_Gdata_Photos_PhotoFeed($photoFeedText);
  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 testPhotoFeedToAndFromString()
  106. {
  107. $entryCount = 0;
  108. foreach ($this->photoFeed as $entry) {
  109. $entryCount++;
  110. $this->assertTrue($entry instanceof Zend_Gdata_Photos_CommentEntry ||
  111. $entry instanceof Zend_Gdata_Photos_TagEntry);
  112. }
  113. $this->assertTrue($entryCount > 0);
  114. /* Grab XML from $this->photoFeed and convert back to objects */
  115. $newListFeed = new Zend_Gdata_Photos_PhotoFeed(
  116. $this->photoFeed->saveXML());
  117. $newEntryCount = 0;
  118. foreach ($newListFeed as $entry) {
  119. $newEntryCount++;
  120. $this->assertTrue($entry instanceof Zend_Gdata_Photos_CommentEntry ||
  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->photoFeed as $entry) {
  133. $entryCount++;
  134. }
  135. $this->assertEquals(3, $entryCount);
  136. }
  137. /**
  138. * Check for the existence of an <atom:id> and verify that it contains
  139. * the expected value.
  140. */
  141. public function testId()
  142. {
  143. $feed = $this->photoFeed;
  144. // Assert that the feed's ID is correct
  145. $this->assertTrue($feed->getId() instanceof Zend_Gdata_App_Extension_Id);
  146. $this->verifyProperty2($feed, "id", "text",
  147. "http://picasaweb.google.com/data/feed/api/user/sample.user/albumid/1/photoid/100");
  148. // Assert that all entries have an Atom ID object
  149. foreach ($feed as $entry) {
  150. $this->assertTrue($entry->getId() instanceof Zend_Gdata_App_Extension_Id);
  151. }
  152. // Assert one of the entry's IDs
  153. $entry = $feed[0];
  154. $this->verifyProperty2($entry, "id", "text",
  155. "http://picasaweb.google.com/data/entry/api/user/sample.user/albumid/1/photoid/100/tag/tag");
  156. }
  157. /**
  158. * Check for the existence of an <atom:updated> and verify that it contains
  159. * the expected value.
  160. */
  161. public function testUpdated()
  162. {
  163. $feed = $this->photoFeed;
  164. // Assert that the feed's updated date is correct
  165. $this->assertTrue($feed->getUpdated() instanceof Zend_Gdata_App_Extension_Updated);
  166. $this->verifyProperty2($feed, "updated", "text",
  167. "2007-09-21T18:23:05.000Z");
  168. // Assert that all entries have an Atom Updated object
  169. foreach ($feed as $entry) {
  170. $this->assertTrue($entry->getUpdated() instanceof Zend_Gdata_App_Extension_Updated);
  171. }
  172. // Assert one of the entry's Updated dates
  173. $entry = $feed[0];
  174. $this->verifyProperty2($entry, "updated", "text", "2007-09-21T18:23:05.000Z");
  175. }
  176. /**
  177. * Check for the existence of an <atom:title> and verify that it contains
  178. * the expected value.
  179. */
  180. public function testTitle()
  181. {
  182. $feed = $this->photoFeed;
  183. // Assert that the feed's title is correct
  184. $this->assertTrue($feed->getTitle() instanceof Zend_Gdata_App_Extension_Title);
  185. $this->verifyProperty2($feed, "title", "text", "Aqua Blue.jpg");
  186. // Assert that all entries have an Atom ID object
  187. foreach ($feed as $entry) {
  188. $this->assertTrue($entry->getTitle() instanceof Zend_Gdata_App_Extension_Title);
  189. }
  190. }
  191. /**
  192. * Check for the existence of an <atom:subtitle> and verify that it contains
  193. * the expected value.
  194. */
  195. public function testSubtitle()
  196. {
  197. $feed = $this->photoFeed;
  198. // Assert that the feed's title is correct
  199. $this->assertTrue($feed->getSubtitle() instanceof Zend_Gdata_App_Extension_Subtitle);
  200. $this->verifyProperty2($feed, "subtitle", "text",
  201. "Blue");
  202. }
  203. /**
  204. * Check for the existence of an <atom:generator> and verify that it contains
  205. * the expected value.
  206. */
  207. public function testGenerator()
  208. {
  209. $feed = $this->photoFeed;
  210. // Assert that the feed's generator is correct
  211. $this->assertTrue($feed->getGenerator() instanceof Zend_Gdata_App_Extension_Generator);
  212. $this->verifyProperty2($feed, "generator", "version", "1.00");
  213. $this->verifyProperty2($feed, "generator", "uri", "http://picasaweb.google.com/");
  214. $this->verifyProperty2($feed, "generator", "text", "Picasaweb");
  215. }
  216. /**
  217. * Check for the existence of an <atom:icon> and verify that it contains
  218. * the expected value.
  219. */
  220. public function testIcon()
  221. {
  222. $feed = $this->photoFeed;
  223. // Assert that the feed's title is correct
  224. $this->assertTrue($feed->getIcon() instanceof Zend_Gdata_App_Extension_Icon);
  225. $this->verifyProperty2($feed, "icon", "text",
  226. "http://lh4.google.com/sample.user/Rt8WU4DZEKI/AAAAAAAAABY/IVgLqmnzJII/s288/Aqua%20Blue.jpg");
  227. }
  228. /**
  229. * Check for the existence of an <gphoto:id> and verify that it contains
  230. * the expected value.
  231. */
  232. public function testGphotoId()
  233. {
  234. $feed = $this->photoFeed;
  235. // Assert that the feed's title is correct
  236. $this->assertTrue($feed->getGphotoId() instanceof Zend_Gdata_Photos_Extension_Id);
  237. $this->verifyProperty2($feed, "gphotoId", "text",
  238. "100");
  239. $this->verifyProperty3($feed, "gphotoId", "text",
  240. "100");
  241. }
  242. /**
  243. * Check for the existence of an <gphoto:version> and verify that it contains
  244. * the expected value.
  245. */
  246. public function testGphotoVersion()
  247. {
  248. $feed = $this->photoFeed;
  249. // Assert that the feed's version is correct
  250. $this->assertTrue($feed->getGphotoVersion() instanceof Zend_Gdata_Photos_Extension_Version);
  251. $this->verifyProperty2($feed, "gphotoVersion", "text",
  252. "1190398985145172");
  253. $this->verifyProperty3($feed, "gphotoVersion", "text",
  254. "1190398985145172");
  255. }
  256. /**
  257. * Check for the existence of an <gphoto:albumid> and verify that it contains
  258. * the expected value.
  259. */
  260. public function testGphotoAlbumId()
  261. {
  262. $feed = $this->photoFeed;
  263. // Assert that the feed's albumid is correct
  264. $this->assertTrue($feed->getGphotoAlbumId() instanceof Zend_Gdata_Photos_Extension_AlbumId);
  265. $this->verifyProperty2($feed, "gphotoAlbumId", "text",
  266. "1");
  267. $this->verifyProperty3($feed, "gphotoAlbumId", "text",
  268. "1");
  269. }
  270. /**
  271. * Check for the existence of an <gphoto:timestamp> and verify that it contains
  272. * the expected value.
  273. */
  274. public function testGphotoTimestamp()
  275. {
  276. $feed = $this->photoFeed;
  277. // Assert that the feed's timestamp is correct
  278. $this->assertTrue($feed->getGphotoTimestamp() instanceof Zend_Gdata_Photos_Extension_Timestamp);
  279. $this->verifyProperty2($feed, "gphotoTimestamp", "text",
  280. "1189025362000");
  281. $this->verifyProperty3($feed, "gphotoTimestamp", "text",
  282. "1189025362000");
  283. }
  284. /**
  285. * Check for the existence of an <gphoto:width> and verify that it contains
  286. * the expected value.
  287. */
  288. public function testGphotoWidth()
  289. {
  290. $feed = $this->photoFeed;
  291. // Assert that the feed's width is correct
  292. $this->assertTrue($feed->getGphotoWidth() instanceof Zend_Gdata_Photos_Extension_Width);
  293. $this->verifyProperty2($feed, "gphotoWidth", "text",
  294. "2560");
  295. $this->verifyProperty3($feed, "gphotoWidth", "text",
  296. "2560");
  297. }
  298. /**
  299. * Check for the existence of an <gphoto:height> and verify that it contains
  300. * the expected value.
  301. */
  302. public function testGphotoHeight()
  303. {
  304. $feed = $this->photoFeed;
  305. // Assert that the feed's height is correct
  306. $this->assertTrue($feed->getGphotoHeight() instanceof Zend_Gdata_Photos_Extension_Height);
  307. $this->verifyProperty2($feed, "gphotoHeight", "text",
  308. "1600");
  309. $this->verifyProperty3($feed, "gphotoHeight", "text",
  310. "1600");
  311. }
  312. /**
  313. * Check for the existence of an <gphoto:size> and verify that it contains
  314. * the expected value.
  315. */
  316. public function testGphotoSize()
  317. {
  318. $feed = $this->photoFeed;
  319. // Assert that the feed's size is correct
  320. $this->assertTrue($feed->getGphotoSize() instanceof Zend_Gdata_Photos_Extension_Size);
  321. $this->verifyProperty2($feed, "gphotoSize", "text",
  322. "883405");
  323. $this->verifyProperty3($feed, "gphotoSize", "text",
  324. "883405");
  325. }
  326. /**
  327. * Check for the existence of an <gphoto:client> and verify that it contains
  328. * the expected value.
  329. */
  330. public function testGphotoClient()
  331. {
  332. $feed = $this->photoFeed;
  333. // Assert that the feed's client is correct
  334. $this->assertTrue($feed->getGphotoClient() instanceof Zend_Gdata_Photos_Extension_Client);
  335. $this->verifyProperty2($feed, "gphotoClient", "text",
  336. "");
  337. $this->verifyProperty3($feed, "gphotoClient", "text",
  338. "");
  339. }
  340. /**
  341. * Check for the existence of an <gphoto:checksum> and verify that it contains
  342. * the expected value.
  343. */
  344. public function testGphotoChecksum()
  345. {
  346. $feed = $this->photoFeed;
  347. // Assert that the feed's checksum is correct
  348. $this->assertTrue($feed->getGphotoChecksum() instanceof Zend_Gdata_Photos_Extension_Checksum);
  349. $this->verifyProperty2($feed, "gphotoChecksum", "text",
  350. "");
  351. $this->verifyProperty3($feed, "gphotoChecksum", "text",
  352. "");
  353. }
  354. /**
  355. * Check for the existence of an <gphoto:commentingEnabled> and verify that it contains
  356. * the expected value.
  357. */
  358. public function testGphotoCommentingEnabled()
  359. {
  360. $feed = $this->photoFeed;
  361. // Assert that the feed's title is correct
  362. $this->assertTrue($feed->getGphotoCommentingEnabled() instanceof Zend_Gdata_Photos_Extension_CommentingEnabled);
  363. $this->verifyProperty2($feed, "gphotoCommentingEnabled", "text",
  364. "true");
  365. $this->verifyProperty3($feed, "gphotoCommentingEnabled", "text",
  366. "true");
  367. }
  368. /**
  369. * Check for the existence of an <gphoto:commentCount> and verify that it contains
  370. * the expected value.
  371. */
  372. public function testGphotoCommentCount()
  373. {
  374. $feed = $this->photoFeed;
  375. // Assert that the feed's title is correct
  376. $this->assertTrue($feed->getGphotoCommentCount() instanceof Zend_Gdata_Photos_Extension_CommentCount);
  377. $this->verifyProperty2($feed, "gphotoCommentCount", "text",
  378. "1");
  379. $this->verifyProperty3($feed, "gphotoCommentCount", "text",
  380. "1");
  381. }
  382. }