PhotosUserEntryTest.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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/UserEntry.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_PhotosUserEntryTest extends PHPUnit_Framework_TestCase
  30. {
  31. protected $userEntry = null;
  32. /**
  33. * Called before each test to setup any fixtures.
  34. */
  35. public function setUp()
  36. {
  37. $userEntryText = file_get_contents(
  38. '_files/TestUserEntry.xml',
  39. true);
  40. $this->userEntry = new Zend_Gdata_Photos_UserEntry($userEntryText);
  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->userEntry;
  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->userEntry;
  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");
  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->userEntry;
  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-24T23:45:49.059Z");
  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->userEntry;
  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-24T23:45:49.059Z");
  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->userEntry;
  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", "sample.user");
  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->userEntry;
  164. // Assert that the entry's user is correct
  165. $this->assertTrue($entry->getGphotoUser() instanceof Zend_Gdata_Photos_Extension_User);
  166. $this->verifyProperty2($entry, "gphotoUser", "text", "sample.user");
  167. $this->verifyProperty3($entry, "gphotoUser", "text", "sample.user");
  168. }
  169. /**
  170. * Check for the existence of an <gphoto:nickname> and verify that it contains
  171. * the expected value.
  172. */
  173. public function testGphotoNickname()
  174. {
  175. $entry = $this->userEntry;
  176. // Assert that the entry's nickname is correct
  177. $this->assertTrue($entry->getGphotoNickname() instanceof Zend_Gdata_Photos_Extension_Nickname);
  178. $this->verifyProperty2($entry, "gphotoNickname", "text", "sample");
  179. $this->verifyProperty3($entry, "gphotoNickname", "text", "sample");
  180. }
  181. /**
  182. * Check for the existence of an <gphoto:thumbnail> and verify that it contains
  183. * the expected value.
  184. */
  185. public function testGphotoThumbnail()
  186. {
  187. $entry = $this->userEntry;
  188. // Assert that the entry's thumbnail is correct
  189. $this->assertTrue($entry->getGphotoThumbnail() instanceof Zend_Gdata_Photos_Extension_Thumbnail);
  190. $this->verifyProperty2($entry, "gphotoThumbnail", "text",
  191. "http://lh5.google.com/sample.user/AAAAuZnob5E/AAAAAAAAAAA/EtCbNCdLGxM/s64-c/sample.user");
  192. $this->verifyProperty3($entry, "gphotoThumbnail", "text",
  193. "http://lh5.google.com/sample.user/AAAAuZnob5E/AAAAAAAAAAA/EtCbNCdLGxM/s64-c/sample.user");
  194. }
  195. }