PhotosPhotoFeedTest.php 15 KB

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