PhotosPhotoEntryTest.php 14 KB

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