PhotosPhotoEntryTest.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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/PhotoEntry.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_PhotosPhotoEntryTest extends PHPUnit_Framework_TestCase
  30. {
  31. protected $photoEntry = null;
  32. /**
  33. * Called before each test to setup any fixtures.
  34. */
  35. public function setUp()
  36. {
  37. $photoEntryText = file_get_contents(
  38. '_files/TestPhotoEntry.xml',
  39. true);
  40. $this->photoEntry = new Zend_Gdata_Photos_PhotoEntry($photoEntryText);
  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. * Check for the existence of an <atom:id> and verify that it contains
  97. * the expected value.
  98. */
  99. public function testId()
  100. {
  101. $entry = $this->photoEntry;
  102. // Assert that the entry's ID is correct
  103. $this->assertTrue($entry->getId() instanceof Zend_Gdata_App_Extension_Id);
  104. $this->verifyProperty2($entry, "id", "text",
  105. "http://picasaweb.google.com/data/entry/api/user/sample.user/albumid/1/photoid/100");
  106. }
  107. /**
  108. * Check for the existence of an <atom:published> and verify that it contains
  109. * the expected value.
  110. */
  111. public function testPublished()
  112. {
  113. $entry = $this->photoEntry;
  114. // Assert that the photo entry has an Atom Published object
  115. $this->assertTrue($entry->getPublished() instanceof Zend_Gdata_App_Extension_Published);
  116. $this->verifyProperty2($entry, "published", "text", "2007-09-05T20:49:24.000Z");
  117. }
  118. /**
  119. * Check for the existence of an <atom:updated> and verify that it contains
  120. * the expected value.
  121. */
  122. public function testUpdated()
  123. {
  124. $entry = $this->photoEntry;
  125. // Assert that the entry's updated date is correct
  126. $this->assertTrue($entry->getUpdated() instanceof Zend_Gdata_App_Extension_Updated);
  127. $this->verifyProperty2($entry, "updated", "text",
  128. "2007-09-21T18:19:38.000Z");
  129. }
  130. /**
  131. * Check for the existence of an <atom:title> and verify that it contains
  132. * the expected value.
  133. */
  134. public function testTitle()
  135. {
  136. $entry = $this->photoEntry;
  137. // Assert that the entry's title is correct
  138. $this->assertTrue($entry->getTitle() instanceof Zend_Gdata_App_Extension_Title);
  139. $this->verifyProperty2($entry, "title", "text", "Aqua Graphite.jpg");
  140. }
  141. /**
  142. * Check for the existence of an <gphoto:id> and verify that it contains
  143. * the expected value.
  144. */
  145. public function testGphotoId()
  146. {
  147. $entry = $this->photoEntry;
  148. // Assert that the entry's title is correct
  149. $this->assertTrue($entry->getGphotoId() instanceof Zend_Gdata_Photos_Extension_Id);
  150. $this->verifyProperty2($entry, "gphotoId", "text",
  151. "100");
  152. $this->verifyProperty3($entry, "gphotoId", "text",
  153. "100");
  154. }
  155. /**
  156. * Check for the existance of exif namespaced data and verify that it contains
  157. * the expected value.
  158. */
  159. public function testExifData()
  160. {
  161. $exifTags = $this->photoEntry->exifTags;
  162. $this->assertTrue($exifTags != null);
  163. $this->assertTrue($exifTags->flash != null);
  164. $this->assertTrue($exifTags->fstop != null);
  165. $this->assertTrue($exifTags->exposure != null);
  166. $this->assertTrue($exifTags->focallength != null);
  167. $this->assertTrue($exifTags->iso != null);
  168. $this->assertTrue($exifTags->time != null);
  169. $this->assertTrue($exifTags->distance != null);
  170. $this->assertTrue($exifTags->make != null);
  171. $this->assertTrue($exifTags->model != null);
  172. $this->assertTrue($exifTags->imageUniqueID != null);
  173. $this->assertEquals("true", $exifTags->flash->text);
  174. $this->assertEquals("11.0", $exifTags->fstop->text);
  175. $this->assertEquals("0.0040", $exifTags->exposure->text);
  176. $this->assertEquals("22.0", $exifTags->focallength->text);
  177. $this->assertEquals("200", $exifTags->iso->text);
  178. $this->assertEquals("1180950900000", $exifTags->time->text);
  179. $this->assertEquals("0.0",$exifTags->distance->text);
  180. $this->assertEquals("Fictitious Camera Company",$exifTags->make->text);
  181. $this->assertEquals("AMAZING-100D",$exifTags->model->text);
  182. $this->assertEquals("a5ce2e36b9df7d3cb081511c72e73926", $exifTags->imageUniqueID->text);
  183. }
  184. /**
  185. * Check for the geo data and verify that it contains the expected values
  186. */
  187. public function testGeoData()
  188. {
  189. $geoRssWhere = $this->photoEntry->geoRssWhere;
  190. $point = $geoRssWhere->point;
  191. $pos = $point->pos;
  192. $this->assertEquals("41.87194 12.56738", $pos->text);
  193. }
  194. /**
  195. * Check for the existence of an <gphoto:version> and verify that it contains
  196. * the expected value.
  197. */
  198. public function testGphotoVersion()
  199. {
  200. $entry = $this->photoEntry;
  201. // Assert that the entry's version is correct
  202. $this->assertTrue($entry->getGphotoVersion() instanceof Zend_Gdata_Photos_Extension_Version);
  203. $this->verifyProperty2($entry, "gphotoVersion", "text",
  204. "1190398778006402");
  205. $this->verifyProperty3($entry, "gphotoVersion", "text",
  206. "1190398778006402");
  207. }
  208. /**
  209. * Check for the existence of an <gphoto:albumid> and verify that it contains
  210. * the expected value.
  211. */
  212. public function testGphotoAlbumId()
  213. {
  214. $entry = $this->photoEntry;
  215. // Assert that the entry's albumid is correct
  216. $this->assertTrue($entry->getGphotoAlbumId() instanceof Zend_Gdata_Photos_Extension_AlbumId);
  217. $this->verifyProperty2($entry, "gphotoAlbumId", "text",
  218. "1");
  219. $this->verifyProperty3($entry, "gphotoAlbumId", "text",
  220. "1");
  221. }
  222. /**
  223. * Check for the existence of an <gphoto:width> and verify that it contains
  224. * the expected value.
  225. */
  226. public function testGphotoWidth()
  227. {
  228. $entry = $this->photoEntry;
  229. // Assert that the entry's width is correct
  230. $this->assertTrue($entry->getGphotoWidth() instanceof Zend_Gdata_Photos_Extension_Width);
  231. $this->verifyProperty2($entry, "gphotoWidth", "text",
  232. "2560");
  233. $this->verifyProperty3($entry, "gphotoWidth", "text",
  234. "2560");
  235. }
  236. /**
  237. * Check for the existence of an <gphoto:height> and verify that it contains
  238. * the expected value.
  239. */
  240. public function testGphotoHeight()
  241. {
  242. $entry = $this->photoEntry;
  243. // Assert that the entry's height is correct
  244. $this->assertTrue($entry->getGphotoHeight() instanceof Zend_Gdata_Photos_Extension_Height);
  245. $this->verifyProperty2($entry, "gphotoHeight", "text",
  246. "1600");
  247. $this->verifyProperty3($entry, "gphotoHeight", "text",
  248. "1600");
  249. }
  250. /**
  251. * Check for the existence of an <gphoto:size> and verify that it contains
  252. * the expected value.
  253. */
  254. public function testGphotoSize()
  255. {
  256. $entry = $this->photoEntry;
  257. // Assert that the entry's size is correct
  258. $this->assertTrue($entry->getGphotoSize() instanceof Zend_Gdata_Photos_Extension_Size);
  259. $this->verifyProperty2($entry, "gphotoSize", "text",
  260. "798334");
  261. $this->verifyProperty3($entry, "gphotoSize", "text",
  262. "798334");
  263. }
  264. /**
  265. * Check for the existence of an <gphoto:client> and verify that it contains
  266. * the expected value.
  267. */
  268. public function testGphotoClient()
  269. {
  270. $entry = $this->photoEntry;
  271. // Assert that the entry's client is correct
  272. $this->assertTrue($entry->getGphotoClient() instanceof Zend_Gdata_Photos_Extension_Client);
  273. $this->verifyProperty2($entry, "gphotoClient", "text",
  274. "");
  275. $this->verifyProperty3($entry, "gphotoClient", "text",
  276. "");
  277. }
  278. /**
  279. * Check for the existence of an <gphoto:checksum> and verify that it contains
  280. * the expected value.
  281. */
  282. public function testGphotoChecksum()
  283. {
  284. $entry = $this->photoEntry;
  285. // Assert that the entry's checksum is correct
  286. $this->assertTrue($entry->getGphotoChecksum() instanceof Zend_Gdata_Photos_Extension_Checksum);
  287. $this->verifyProperty2($entry, "gphotoChecksum", "text",
  288. "");
  289. $this->verifyProperty3($entry, "gphotoChecksum", "text",
  290. "");
  291. }
  292. /**
  293. * Check for the existence of an <gphoto:timestamp> and verify that it contains
  294. * the expected value.
  295. */
  296. public function testGphotoTimestamp()
  297. {
  298. $entry = $this->photoEntry;
  299. // Assert that the entry's title is correct
  300. $this->assertTrue($entry->getGphotoTimestamp() instanceof Zend_Gdata_Photos_Extension_Timestamp);
  301. $this->verifyProperty2($entry, "gphotoTimestamp", "text",
  302. "1189025363000");
  303. $this->verifyProperty3($entry, "gphotoTimestamp", "text",
  304. "1189025363000");
  305. }
  306. /**
  307. * Check for the existence of an <gphoto:commentingEnabled> and verify that it contains
  308. * the expected value.
  309. */
  310. public function testGphotoCommentingEnabled()
  311. {
  312. $entry = $this->photoEntry;
  313. // Assert that the entry's title is correct
  314. $this->assertTrue($entry->getGphotoCommentingEnabled() instanceof Zend_Gdata_Photos_Extension_CommentingEnabled);
  315. $this->verifyProperty2($entry, "gphotoCommentingEnabled", "text",
  316. "true");
  317. $this->verifyProperty3($entry, "gphotoCommentingEnabled", "text",
  318. "true");
  319. }
  320. /**
  321. * Check for the existence of an <gphoto:commentCount> and verify that it contains
  322. * the expected value.
  323. */
  324. public function testGphotoCommentCount()
  325. {
  326. $entry = $this->photoEntry;
  327. // Assert that the entry's title is correct
  328. $this->assertTrue($entry->getGphotoCommentCount() instanceof Zend_Gdata_Photos_Extension_CommentCount);
  329. $this->verifyProperty2($entry, "gphotoCommentCount", "text",
  330. "0");
  331. $this->verifyProperty3($entry, "gphotoCommentCount", "text",
  332. "0");
  333. }
  334. /**
  335. * Check for the existence of a <media:group>
  336. */
  337. public function testMediaGroup()
  338. {
  339. $entry = $this->photoEntry;
  340. // Assert that the entry's media group exists
  341. $this->assertTrue($entry->getMediaGroup() instanceof Zend_Gdata_Media_Extension_MediaGroup);
  342. }
  343. }