PhotosUserEntryTest.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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/UserEntry.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_PhotosUserEntryTest extends PHPUnit_Framework_TestCase
  36. {
  37. protected $userEntry = null;
  38. /**
  39. * Called before each test to setup any fixtures.
  40. */
  41. public function setUp()
  42. {
  43. $userEntryText = file_get_contents(
  44. '_files/TestUserEntry.xml',
  45. true);
  46. $this->userEntry = new Zend_Gdata_Photos_UserEntry($userEntryText);
  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:author> and verify that they
  103. * contain the expected values.
  104. */
  105. public function testAuthor()
  106. {
  107. $entry = $this->userEntry;
  108. // Assert that the entry's author is correct
  109. $entryAuthor = $entry->getAuthor();
  110. $this->assertEquals($entryAuthor, $entry->author);
  111. $this->assertEquals(1, count($entryAuthor));
  112. $this->assertTrue($entryAuthor[0] instanceof Zend_Gdata_App_Extension_Author);
  113. $this->verifyProperty2($entryAuthor[0], "name", "text", "sample");
  114. $this->assertTrue($entryAuthor[0]->getUri() instanceof Zend_Gdata_App_Extension_Uri);
  115. $this->verifyProperty2($entryAuthor[0], "uri", "text", "http://picasaweb.google.com/sample.user");
  116. }
  117. /**
  118. * Check for the existence of an <atom:id> and verify that it contains
  119. * the expected value.
  120. */
  121. public function testId()
  122. {
  123. $entry = $this->userEntry;
  124. // Assert that the entry's ID is correct
  125. $this->assertTrue($entry->getId() instanceof Zend_Gdata_App_Extension_Id);
  126. $this->verifyProperty2($entry, "id", "text",
  127. "http://picasaweb.google.com/data/entry/api/user/sample.user");
  128. }
  129. /**
  130. * Check for the existence of an <atom:published> and verify that it contains
  131. * the expected value.
  132. */
  133. public function testPublished()
  134. {
  135. $entry = $this->userEntry;
  136. // Assert that the photo entry has an Atom Published object
  137. $this->assertTrue($entry->getPublished() instanceof Zend_Gdata_App_Extension_Published);
  138. $this->verifyProperty2($entry, "published", "text", "2007-09-24T23:45:49.059Z");
  139. }
  140. /**
  141. * Check for the existence of an <atom:updated> and verify that it contains
  142. * the expected value.
  143. */
  144. public function testUpdated()
  145. {
  146. $entry = $this->userEntry;
  147. // Assert that the entry's updated date is correct
  148. $this->assertTrue($entry->getUpdated() instanceof Zend_Gdata_App_Extension_Updated);
  149. $this->verifyProperty2($entry, "updated", "text",
  150. "2007-09-24T23:45:49.059Z");
  151. }
  152. /**
  153. * Check for the existence of an <atom:title> and verify that it contains
  154. * the expected value.
  155. */
  156. public function testTitle()
  157. {
  158. $entry = $this->userEntry;
  159. // Assert that the entry's title is correct
  160. $this->assertTrue($entry->getTitle() instanceof Zend_Gdata_App_Extension_Title);
  161. $this->verifyProperty2($entry, "title", "text", "sample.user");
  162. }
  163. /**
  164. * Check for the existence of an <gphoto:user> and verify that it contains
  165. * the expected value.
  166. */
  167. public function testGphotoUser()
  168. {
  169. $entry = $this->userEntry;
  170. // Assert that the entry's user is correct
  171. $this->assertTrue($entry->getGphotoUser() instanceof Zend_Gdata_Photos_Extension_User);
  172. $this->verifyProperty2($entry, "gphotoUser", "text", "sample.user");
  173. $this->verifyProperty3($entry, "gphotoUser", "text", "sample.user");
  174. }
  175. /**
  176. * Check for the existence of an <gphoto:nickname> and verify that it contains
  177. * the expected value.
  178. */
  179. public function testGphotoNickname()
  180. {
  181. $entry = $this->userEntry;
  182. // Assert that the entry's nickname is correct
  183. $this->assertTrue($entry->getGphotoNickname() instanceof Zend_Gdata_Photos_Extension_Nickname);
  184. $this->verifyProperty2($entry, "gphotoNickname", "text", "sample");
  185. $this->verifyProperty3($entry, "gphotoNickname", "text", "sample");
  186. }
  187. /**
  188. * Check for the existence of an <gphoto:thumbnail> and verify that it contains
  189. * the expected value.
  190. */
  191. public function testGphotoThumbnail()
  192. {
  193. $entry = $this->userEntry;
  194. // Assert that the entry's thumbnail is correct
  195. $this->assertTrue($entry->getGphotoThumbnail() instanceof Zend_Gdata_Photos_Extension_Thumbnail);
  196. $this->verifyProperty2($entry, "gphotoThumbnail", "text",
  197. "http://lh5.google.com/sample.user/AAAAuZnob5E/AAAAAAAAAAA/EtCbNCdLGxM/s64-c/sample.user");
  198. $this->verifyProperty3($entry, "gphotoThumbnail", "text",
  199. "http://lh5.google.com/sample.user/AAAAuZnob5E/AAAAAAAAAAA/EtCbNCdLGxM/s64-c/sample.user");
  200. }
  201. }