PhotosCommentEntryTest.php 8.0 KB

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