PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/Zend/GData/Photos/PhotosUserEntryTest.php

https://github.com/sidealice/zf2
PHP | 227 lines | 99 code | 27 blank | 101 comment | 0 complexity | 01fa5313207b12f02231a3a92cf94ae9 MD5 | raw file
  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-2011 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * @namespace
  23. */
  24. namespace ZendTest\GData\Photos;
  25. /**
  26. * @category Zend
  27. * @package Zend_GData_Photos
  28. * @subpackage UnitTests
  29. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. * @group Zend_GData
  32. * @group Zend_GData_Photos
  33. */
  34. class PhotosUserEntryTest extends \PHPUnit_Framework_TestCase
  35. {
  36. protected $userEntry = null;
  37. /**
  38. * Called before each test to setup any fixtures.
  39. */
  40. public function setUp()
  41. {
  42. $userEntryText = file_get_contents(
  43. '_files/TestUserEntry.xml',
  44. true);
  45. $this->userEntry = new \Zend\GData\Photos\UserEntry($userEntryText);
  46. }
  47. /**
  48. * Verify that a given property is set to a specific value
  49. * and that the getter and magic variable return the same value.
  50. *
  51. * @param object $obj The object to be interrogated.
  52. * @param string $name The name of the property to be verified.
  53. * @param object $value The expected value of the property.
  54. */
  55. protected function verifyProperty($obj, $name, $value)
  56. {
  57. $propName = $name;
  58. $propGetter = "get" . ucfirst($name);
  59. $this->assertEquals($obj->$propGetter(), $obj->$propName);
  60. $this->assertEquals($value, $obj->$propGetter());
  61. }
  62. /**
  63. * Verify that a given property is set to a specific value
  64. * and that the getter and magic variable return the same value.
  65. *
  66. * @param object $obj The object to be interrogated.
  67. * @param string $name The name of the property to be verified.
  68. * @param string $secondName 2nd level accessor function name
  69. * @param object $value The expected value of the property.
  70. */
  71. protected function verifyProperty2($obj, $name, $secondName, $value)
  72. {
  73. $propName = $name;
  74. $propGetter = "get" . ucfirst($name);
  75. $secondGetter = "get" . ucfirst($secondName);
  76. $this->assertEquals($obj->$propGetter(), $obj->$propName);
  77. $this->assertEquals($value, $obj->$propGetter()->$secondGetter());
  78. }
  79. /**
  80. * Verify that a given property is set to a specific value,
  81. * that it keeps that value when set using the setter,
  82. * and that the getter and magic variable return the same value.
  83. *
  84. * @param object $obj The object to be interrogated.
  85. * @param string $name The name of the property to be verified.
  86. * @param string $secondName 2nd level accessor function name
  87. * @param object $value The expected value of the property.
  88. */
  89. protected function verifyProperty3($obj, $name, $secondName, $value)
  90. {
  91. $propName = $name;
  92. $propGetter = "get" . ucfirst($name);
  93. $propSetter = "set" . ucfirst($name);
  94. $secondGetter = "get" . ucfirst($secondName);
  95. $secondSetter = "set" . ucfirst($secondName);
  96. $this->assertEquals($obj->$propGetter(), $obj->$propName);
  97. $obj->$propSetter($obj->$propName);
  98. $this->assertEquals($value, $obj->$propGetter()->$secondGetter());
  99. }
  100. /**
  101. * Check for the existence of an <atom:author> and verify that they
  102. * contain the expected values.
  103. */
  104. public function testAuthor()
  105. {
  106. $entry = $this->userEntry;
  107. // Assert that the entry's author is correct
  108. $entryAuthor = $entry->getAuthor();
  109. $this->assertEquals($entryAuthor, $entry->author);
  110. $this->assertEquals(1, count($entryAuthor));
  111. $this->assertTrue($entryAuthor[0] instanceof \Zend\GData\App\Extension\Author);
  112. $this->verifyProperty2($entryAuthor[0], "name", "text", "sample");
  113. $this->assertTrue($entryAuthor[0]->getUri() instanceof \Zend\GData\App\Extension\Uri);
  114. $this->verifyProperty2($entryAuthor[0], "uri", "text", "http://picasaweb.google.com/sample.user");
  115. }
  116. /**
  117. * Check for the existence of an <atom:id> and verify that it contains
  118. * the expected value.
  119. */
  120. public function testId()
  121. {
  122. $entry = $this->userEntry;
  123. // Assert that the entry's ID is correct
  124. $this->assertTrue($entry->getId() instanceof \Zend\GData\App\Extension\Id);
  125. $this->verifyProperty2($entry, "id", "text",
  126. "http://picasaweb.google.com/data/entry/api/user/sample.user");
  127. }
  128. /**
  129. * Check for the existence of an <atom:published> and verify that it contains
  130. * the expected value.
  131. */
  132. public function testPublished()
  133. {
  134. $entry = $this->userEntry;
  135. // Assert that the photo entry has an Atom Published object
  136. $this->assertTrue($entry->getPublished() instanceof \Zend\GData\App\Extension\Published);
  137. $this->verifyProperty2($entry, "published", "text", "2007-09-24T23:45:49.059Z");
  138. }
  139. /**
  140. * Check for the existence of an <atom:updated> and verify that it contains
  141. * the expected value.
  142. */
  143. public function testUpdated()
  144. {
  145. $entry = $this->userEntry;
  146. // Assert that the entry's updated date is correct
  147. $this->assertTrue($entry->getUpdated() instanceof \Zend\GData\App\Extension\Updated);
  148. $this->verifyProperty2($entry, "updated", "text",
  149. "2007-09-24T23:45:49.059Z");
  150. }
  151. /**
  152. * Check for the existence of an <atom:title> and verify that it contains
  153. * the expected value.
  154. */
  155. public function testTitle()
  156. {
  157. $entry = $this->userEntry;
  158. // Assert that the entry's title is correct
  159. $this->assertTrue($entry->getTitle() instanceof \Zend\GData\App\Extension\Title);
  160. $this->verifyProperty2($entry, "title", "text", "sample.user");
  161. }
  162. /**
  163. * Check for the existence of an <gphoto:user> and verify that it contains
  164. * the expected value.
  165. */
  166. public function testGphotoUser()
  167. {
  168. $entry = $this->userEntry;
  169. // Assert that the entry's user is correct
  170. $this->assertTrue($entry->getGphotoUser() instanceof \Zend\GData\Photos\Extension\User);
  171. $this->verifyProperty2($entry, "gphotoUser", "text", "sample.user");
  172. $this->verifyProperty3($entry, "gphotoUser", "text", "sample.user");
  173. }
  174. /**
  175. * Check for the existence of an <gphoto:nickname> and verify that it contains
  176. * the expected value.
  177. */
  178. public function testGphotoNickname()
  179. {
  180. $entry = $this->userEntry;
  181. // Assert that the entry's nickname is correct
  182. $this->assertTrue($entry->getGphotoNickname() instanceof \Zend\GData\Photos\Extension\Nickname);
  183. $this->verifyProperty2($entry, "gphotoNickname", "text", "sample");
  184. $this->verifyProperty3($entry, "gphotoNickname", "text", "sample");
  185. }
  186. /**
  187. * Check for the existence of an <gphoto:thumbnail> and verify that it contains
  188. * the expected value.
  189. */
  190. public function testGphotoThumbnail()
  191. {
  192. $entry = $this->userEntry;
  193. // Assert that the entry's thumbnail is correct
  194. $this->assertTrue($entry->getGphotoThumbnail() instanceof \Zend\GData\Photos\Extension\Thumbnail);
  195. $this->verifyProperty2($entry, "gphotoThumbnail", "text",
  196. "http://lh5.google.com/sample.user/AAAAuZnob5E/AAAAAAAAAAA/EtCbNCdLGxM/s64-c/sample.user");
  197. $this->verifyProperty3($entry, "gphotoThumbnail", "text",
  198. "http://lh5.google.com/sample.user/AAAAuZnob5E/AAAAAAAAAAA/EtCbNCdLGxM/s64-c/sample.user");
  199. }
  200. }