PhotosCommentEntryTest.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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/CommentEntry.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_PhotosCommentEntryTest extends PHPUnit_Framework_TestCase
  30. {
  31. protected $commentEntry = null;
  32. /**
  33. * Called before each test to setup any fixtures.
  34. */
  35. public function setUp()
  36. {
  37. $commentEntryText = file_get_contents(
  38. '_files/TestCommentEntry.xml',
  39. true);
  40. $this->commentEntry = new Zend_Gdata_Photos_CommentEntry($commentEntryText);
  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->commentEntry;
  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/commentid/5");
  106. }
  107. /**
  108. * Check for the existence of an <atom:author> and verify that they
  109. * contain the expected values.
  110. */
  111. public function testAuthor()
  112. {
  113. $entry = $this->commentEntry;
  114. // Assert that the entry's author is correct
  115. $entryAuthor = $entry->getAuthor();
  116. $this->assertEquals($entryAuthor, $entry->author);
  117. $this->assertEquals(1, count($entryAuthor));
  118. $this->assertTrue($entryAuthor[0] instanceof Zend_Gdata_App_Extension_Author);
  119. $this->verifyProperty2($entryAuthor[0], "name", "text", "sample");
  120. $this->assertTrue($entryAuthor[0]->getUri() instanceof Zend_Gdata_App_Extension_Uri);
  121. $this->verifyProperty2($entryAuthor[0], "uri", "text", "http://picasaweb.google.com/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->commentEntry;
  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-21T18:22:53.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->commentEntry;
  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-21T18:22:53.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->commentEntry;
  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");
  156. }
  157. /**
  158. * Check for the existence of an <atom:content> and verify that it contains
  159. * the expected value.
  160. */
  161. public function testContent()
  162. {
  163. $entry = $this->commentEntry;
  164. // Assert that the entry's title is correct
  165. $this->assertTrue($entry->getContent() instanceof Zend_Gdata_App_Extension_Content);
  166. $this->verifyProperty2($entry, "content", "text", "test comment");
  167. }
  168. /**
  169. * Check for the existence of an <gphoto:id> and verify that it contains
  170. * the expected value.
  171. */
  172. public function testGphotoId()
  173. {
  174. $entry = $this->commentEntry;
  175. // Assert that the entry's title is correct
  176. $this->assertTrue($entry->getGphotoId() instanceof Zend_Gdata_Photos_Extension_Id);
  177. $this->verifyProperty2($entry, "gphotoId", "text",
  178. "5");
  179. $this->verifyProperty3($entry, "gphotoId", "text",
  180. "5");
  181. }
  182. /**
  183. * Check for the existence of an <gphoto:photoid> and verify that it contains
  184. * the expected value.
  185. */
  186. public function testGphotoPhotoId()
  187. {
  188. $entry = $this->commentEntry;
  189. // Assert that the entry's title is correct
  190. $this->assertTrue($entry->getGphotoPhotoId() instanceof Zend_Gdata_Photos_Extension_PhotoId);
  191. $this->verifyProperty2($entry, "gphotoPhotoId", "text",
  192. "100");
  193. $this->verifyProperty3($entry, "gphotoPhotoId", "text",
  194. "100");
  195. }
  196. }