PhotosAlbumEntryTest.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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/AlbumEntry.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_PhotosAlbumEntryTest extends PHPUnit_Framework_TestCase
  30. {
  31. protected $albumEntry = null;
  32. /**
  33. * Called before each test to setup any fixtures.
  34. */
  35. public function setUp()
  36. {
  37. $albumEntryText = file_get_contents(
  38. '_files/TestAlbumEntry.xml',
  39. true);
  40. $this->albumEntry = new Zend_Gdata_Photos_AlbumEntry($albumEntryText);
  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:author> and verify that they
  97. * contain the expected values.
  98. */
  99. public function testAuthor()
  100. {
  101. $entry = $this->albumEntry;
  102. // Assert that the entry's author is correct
  103. $entryAuthor = $entry->getAuthor();
  104. $this->assertEquals($entryAuthor, $entry->author);
  105. $this->assertEquals(1, count($entryAuthor));
  106. $this->assertTrue($entryAuthor[0] instanceof Zend_Gdata_App_Extension_Author);
  107. $this->verifyProperty2($entryAuthor[0], "name", "text", "sample");
  108. $this->assertTrue($entryAuthor[0]->getUri() instanceof Zend_Gdata_App_Extension_Uri);
  109. $this->verifyProperty2($entryAuthor[0], "uri", "text", "http://picasaweb.google.com/sample.user");
  110. }
  111. /**
  112. * Check for the existence of an <atom:id> and verify that it contains
  113. * the expected value.
  114. */
  115. public function testId()
  116. {
  117. $entry = $this->albumEntry;
  118. // Assert that the entry's ID is correct
  119. $this->assertTrue($entry->getId() instanceof Zend_Gdata_App_Extension_Id);
  120. $this->verifyProperty2($entry, "id", "text",
  121. "http://picasaweb.google.com/data/entry/api/user/sample.user/albumid/1");
  122. }
  123. /**
  124. * Check for the existence of an <atom:published> and verify that it contains
  125. * the expected value.
  126. */
  127. public function testPublished()
  128. {
  129. $entry = $this->albumEntry;
  130. // Assert that the photo entry has an Atom Published object
  131. $this->assertTrue($entry->getPublished() instanceof Zend_Gdata_App_Extension_Published);
  132. $this->verifyProperty2($entry, "published", "text", "2007-09-05T07:00:00.000Z");
  133. }
  134. /**
  135. * Check for the existence of an <atom:updated> and verify that it contains
  136. * the expected value.
  137. */
  138. public function testUpdated()
  139. {
  140. $entry = $this->albumEntry;
  141. // Assert that the entry's updated date is correct
  142. $this->assertTrue($entry->getUpdated() instanceof Zend_Gdata_App_Extension_Updated);
  143. $this->verifyProperty2($entry, "updated", "text",
  144. "2007-09-05T20:49:24.000Z");
  145. }
  146. /**
  147. * Check for the existence of an <atom:title> and verify that it contains
  148. * the expected value.
  149. */
  150. public function testTitle()
  151. {
  152. $entry = $this->albumEntry;
  153. // Assert that the entry's title is correct
  154. $this->assertTrue($entry->getTitle() instanceof Zend_Gdata_App_Extension_Title);
  155. $this->verifyProperty2($entry, "title", "text", "Test");
  156. }
  157. /**
  158. * Check for the existence of an <gphoto:user> and verify that it contains
  159. * the expected value.
  160. */
  161. public function testGphotoUser()
  162. {
  163. $entry = $this->albumEntry;
  164. // Assert that the entry's title is correct
  165. $this->assertTrue($entry->getGphotoUser() instanceof Zend_Gdata_Photos_Extension_User);
  166. $this->verifyProperty2($entry, "gphotoUser", "text",
  167. "sample.user");
  168. $this->verifyProperty3($entry, "gphotoUser", "text",
  169. "sample.user");
  170. }
  171. /**
  172. * Check for the existence of an <gphoto:nickname> and verify that it contains
  173. * the expected value.
  174. */
  175. public function testGphotoNickname()
  176. {
  177. $entry = $this->albumEntry;
  178. // Assert that the entry's title is correct
  179. $this->assertTrue($entry->getGphotoNickname() instanceof Zend_Gdata_Photos_Extension_Nickname);
  180. $this->verifyProperty2($entry, "gphotoNickname", "text",
  181. "sample");
  182. $this->verifyProperty3($entry, "gphotoNickname", "text",
  183. "sample");
  184. }
  185. /**
  186. * Check for the existence of an <gphoto:name> and verify that it contains
  187. * the expected value.
  188. */
  189. public function testGphotoName()
  190. {
  191. $entry = $this->albumEntry;
  192. // Assert that the entry's title is correct
  193. $this->assertTrue($entry->getGphotoName() instanceof Zend_Gdata_Photos_Extension_Name);
  194. $this->verifyProperty2($entry, "gphotoName", "text",
  195. "Test");
  196. $this->verifyProperty3($entry, "gphotoName", "text",
  197. "Test");
  198. }
  199. /**
  200. * Check for the existence of an <gphoto:id> and verify that it contains
  201. * the expected value.
  202. */
  203. public function testGphotoId()
  204. {
  205. $entry = $this->albumEntry;
  206. // Assert that the entry's title is correct
  207. $this->assertTrue($entry->getGphotoId() instanceof Zend_Gdata_Photos_Extension_Id);
  208. $this->verifyProperty2($entry, "gphotoId", "text",
  209. "1");
  210. $this->verifyProperty3($entry, "gphotoId", "text",
  211. "1");
  212. }
  213. /**
  214. * Check for the existence of an <gphoto:location> and verify that it contains
  215. * the expected value.
  216. */
  217. public function testGphotoLocation()
  218. {
  219. $entry = $this->albumEntry;
  220. // Assert that the entry's title is correct
  221. $this->assertTrue($entry->getGphotoLocation() instanceof Zend_Gdata_Photos_Extension_Location);
  222. $this->verifyProperty2($entry, "gphotoLocation", "text",
  223. "");
  224. }
  225. /**
  226. * Check for the existence of an <gphoto:access> and verify that it contains
  227. * the expected value.
  228. */
  229. public function testGphotoAccess()
  230. {
  231. $entry = $this->albumEntry;
  232. // Assert that the entry's title is correct
  233. $this->assertTrue($entry->getGphotoAccess() instanceof Zend_Gdata_Photos_Extension_Access);
  234. $this->verifyProperty2($entry, "gphotoAccess", "text",
  235. "public");
  236. $this->verifyProperty3($entry, "gphotoAccess", "text",
  237. "public");
  238. }
  239. /**
  240. * Check for the existence of an <gphoto:timestamp> and verify that it contains
  241. * the expected value.
  242. */
  243. public function testGphotoTimestamp()
  244. {
  245. $entry = $this->albumEntry;
  246. // Assert that the entry's title is correct
  247. $this->assertTrue($entry->getGphotoTimestamp() instanceof Zend_Gdata_Photos_Extension_Timestamp);
  248. $this->verifyProperty2($entry, "gphotoTimestamp", "text",
  249. "1188975600000");
  250. $this->verifyProperty3($entry, "gphotoTimestamp", "text",
  251. "1188975600000");
  252. }
  253. /**
  254. * Check for the existence of an <gphoto:numphotos> and verify that it contains
  255. * the expected value.
  256. */
  257. public function testGphotoNumPhotos()
  258. {
  259. $entry = $this->albumEntry;
  260. // Assert that the entry's title is correct
  261. $this->assertTrue($entry->getGphotoNumPhotos() instanceof Zend_Gdata_Photos_Extension_NumPhotos);
  262. $this->verifyProperty2($entry, "gphotoNumPhotos", "text",
  263. "2");
  264. $this->verifyProperty3($entry, "gphotoNumPhotos", "text",
  265. "2");
  266. }
  267. /**
  268. * Check for the existence of an <gphoto:commentingEnabled> and verify that it contains
  269. * the expected value.
  270. */
  271. public function testGphotoCommentingEnabled()
  272. {
  273. $entry = $this->albumEntry;
  274. // Assert that the entry's title is correct
  275. $this->assertTrue($entry->getGphotoCommentingEnabled() instanceof Zend_Gdata_Photos_Extension_CommentingEnabled);
  276. $this->verifyProperty2($entry, "gphotoCommentingEnabled", "text",
  277. "true");
  278. $this->verifyProperty3($entry, "gphotoCommentingEnabled", "text",
  279. "true");
  280. }
  281. /**
  282. * Check for the existence of an <gphoto:commentCount> and verify that it contains
  283. * the expected value.
  284. */
  285. public function testGphotoCommentCount()
  286. {
  287. $entry = $this->albumEntry;
  288. // Assert that the entry's title is correct
  289. $this->assertTrue($entry->getGphotoCommentCount() instanceof Zend_Gdata_Photos_Extension_CommentCount);
  290. $this->verifyProperty2($entry, "gphotoCommentCount", "text",
  291. "0");
  292. $this->verifyProperty3($entry, "gphotoCommentCount", "text",
  293. "0");
  294. }
  295. /**
  296. * Check for the existence of a <media:group>
  297. */
  298. public function testMediaGroup()
  299. {
  300. $entry = $this->albumEntry;
  301. // Assert that the entry's media group exists
  302. $this->assertTrue($entry->getMediaGroup() instanceof Zend_Gdata_Media_Extension_MediaGroup);
  303. }
  304. /**
  305. * Check for the geo data and verify that it contains the expected values
  306. */
  307. public function testGeoData()
  308. {
  309. $geoRssWhere = $this->albumEntry->geoRssWhere;
  310. $point = $geoRssWhere->point;
  311. $pos = $point->pos;
  312. $this->assertEquals("42.87194 13.56738", $pos->text);
  313. }
  314. }