InboxEntryTest.php 9.1 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_YouTube
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2009 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. /**
  23. * Test helper
  24. */
  25. require_once dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'TestHelper.php';
  26. require_once 'Zend/Gdata/YouTube/InboxEntry.php';
  27. require_once 'Zend/Gdata/YouTube.php';
  28. /**
  29. * @category Zend
  30. * @package Zend_Gdata_YouTube
  31. * @subpackage UnitTests
  32. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. * @group Zend_Gdata
  35. * @group Zend_Gdata_YouTube
  36. */
  37. class Zend_Gdata_YouTube_InboxEntryTest extends PHPUnit_Framework_TestCase
  38. {
  39. public function setUp() {
  40. $this->entryText = file_get_contents(
  41. 'Zend/Gdata/YouTube/_files/InboxEntryDataSample1.xml',
  42. true);
  43. $this->v2entryText = file_get_contents(
  44. 'Zend/Gdata/YouTube/_files/' .
  45. 'InboxEntryDataSampleV2.xml',
  46. true);
  47. $this->entry = new Zend_Gdata_YouTube_InboxEntry();
  48. }
  49. private function verifyAllSamplePropertiesAreCorrect ($InboxEntry) {
  50. $this->assertEquals(
  51. 'http://gdata.youtube.com/feeds/api/users/andyland74/' .
  52. 'inbox/ffb9a5f32cd5f55',
  53. $InboxEntry->id->text);
  54. $this->assertEquals('http://schemas.google.com/g/2005#kind',
  55. $InboxEntry->category[0]->scheme);
  56. $this->assertEquals(
  57. 'http://gdata.youtube.com/schemas/2007#videoMessage',
  58. $InboxEntry->category[0]->term);
  59. $this->assertEquals('andyland74sFriend sent you a video!',
  60. $InboxEntry->title->text);;
  61. $this->assertEquals('self',
  62. $InboxEntry->getLink('self')->rel);
  63. $this->assertEquals('application/atom+xml',
  64. $InboxEntry->getLink('self')->type);
  65. $this->assertEquals(
  66. 'http://gdata.youtube.com/feeds/api/users/andyland74/' .
  67. 'inbox/ffb9a5f32cd5f55',
  68. $InboxEntry->getLink('self')->href);
  69. $this->assertEquals('andyland74sFriend',
  70. $InboxEntry->author[0]->name->text);
  71. $this->assertEquals(
  72. 'http://gdata.youtube.com/feeds/api/users/andyland74sFriend',
  73. $InboxEntry->author[0]->uri->text);
  74. $this->assertEquals(
  75. 'Check out this video!',
  76. $InboxEntry->getDescription()->text);
  77. }
  78. public function verifyAllSamplePropertiesAreCorrectV2(
  79. $InboxEntry) {
  80. $this->assertEquals(
  81. 'tag:youtube,2008:user:andyland74:inbox:D_uaXzLRX1U',
  82. $InboxEntry->id->text);
  83. $this->assertEquals('2008-06-10T13:55:32.000-07:00',
  84. $InboxEntry->published->text);
  85. $this->assertEquals('2008-06-10T13:55:32.000-07:00',
  86. $InboxEntry->updated->text);
  87. $this->assertEquals(
  88. 'http://schemas.google.com/g/2005#kind',
  89. $InboxEntry->category[0]->scheme);
  90. $this->assertEquals(
  91. 'http://gdata.youtube.com/schemas/2007#videoMessage',
  92. $InboxEntry->category[0]->term);
  93. $this->assertEquals(
  94. 'http://gdata.youtube.com/schemas/2007/keywords.cat',
  95. $InboxEntry->category[1]->scheme);
  96. $this->assertEquals(
  97. 'surfing',
  98. $InboxEntry->category[1]->term);
  99. $this->assertEquals(
  100. 'http://gdata.youtube.com/schemas/2007/categories.cat',
  101. $InboxEntry->category[2]->scheme);
  102. $this->assertEquals(
  103. 'People',
  104. $InboxEntry->category[2]->term);
  105. $this->assertEquals('self',
  106. $InboxEntry->getLink('self')->rel);
  107. $this->assertEquals('application/atom+xml',
  108. $InboxEntry->getLink('self')->type);
  109. $this->assertEquals(
  110. 'http://gdata.youtube.com/feeds/api/users/andyland74/' .
  111. 'inbox/ffb9a5f32cd5f55?v=2',
  112. $InboxEntry->getLink('self')->href);
  113. $this->assertEquals('related',
  114. $InboxEntry->getLink('related')->rel);
  115. $this->assertEquals('application/atom+xml',
  116. $InboxEntry->getLink('related')->type);
  117. $this->assertEquals(
  118. 'http://gdata.youtube.com/feeds/api/videos/jXE6G9CYcJs?v=2',
  119. $InboxEntry->getLink('related')->href);
  120. $this->assertEquals('alternate',
  121. $InboxEntry->getLink('alternate')->rel);
  122. $this->assertEquals('text/html',
  123. $InboxEntry->getLink('alternate')->type);
  124. $this->assertEquals(
  125. 'http://www.youtube.com/watch?v=jXE6G9CYcJs',
  126. $InboxEntry->getLink('alternate')->href);
  127. $this->assertEquals('andyland74sFriend',
  128. $InboxEntry->author[0]->name->text);
  129. $this->assertEquals(
  130. 'http://gdata.youtube.com/feeds/api/users/andyland74sFriend',
  131. $InboxEntry->author[0]->uri->text);
  132. $this->assertEquals(877, $InboxEntry->getRating()->numRaters);
  133. $this->assertEquals(
  134. 'http://gdata.youtube.com/feeds/api/videos/jXE6G9CYcJs/comments',
  135. $InboxEntry->getComments()->getFeedLink()->getHref());
  136. $this->assertEquals(286355,
  137. $InboxEntry->getStatistics()->getViewCount());
  138. }
  139. public function testEmptyEntryShouldHaveNoExtensionElements() {
  140. $this->assertTrue(is_array($this->entry->extensionElements));
  141. $this->assertEquals(0, count($this->entry->extensionElements));
  142. }
  143. public function testEmptyEntryShouldHaveNoExtensionAttributes() {
  144. $this->assertTrue(is_array($this->entry->extensionAttributes));
  145. $this->assertEquals(0, count($this->entry->extensionAttributes));
  146. }
  147. public function testSampleEntryShouldHaveNoExtensionElements() {
  148. $this->entry->transferFromXML($this->entryText);
  149. $this->assertTrue(is_array($this->entry->extensionElements));
  150. $this->assertEquals(0, count($this->entry->extensionElements));
  151. }
  152. public function testSampleEntryShouldHaveNoExtensionAttributes() {
  153. $this->entry->transferFromXML($this->entryText);
  154. $this->assertTrue(is_array($this->entry->extensionAttributes));
  155. $this->assertEquals(0, count($this->entry->extensionAttributes));
  156. }
  157. public function testSampleEntryShouldHaveNoExtensionElementsV2() {
  158. $this->entry->setMajorProtocolVersion(2);
  159. $this->entry->transferFromXML($this->v2entryText);
  160. $this->assertTrue(is_array($this->entry->extensionElements));
  161. $this->assertEquals(0, count($this->entry->extensionElements));
  162. }
  163. public function testSampleEntryShouldHaveNoExtensionAttributesV2() {
  164. $this->entry->setMajorProtocolVersion(2);
  165. $this->entry->transferFromXML($this->v2entryText);
  166. $this->assertTrue(is_array($this->entry->extensionAttributes));
  167. $this->assertEquals(0, count($this->entry->extensionAttributes));
  168. }
  169. public function testEmptyInboxEntryToAndFromStringShouldMatch() {
  170. $entryXml = $this->entry->saveXML();
  171. $newInboxEntry = new Zend_Gdata_YouTube_InboxEntry();
  172. $newInboxEntry->transferFromXML($entryXml);
  173. $newInboxEntryXml = $newInboxEntry->saveXML();
  174. $this->assertTrue($entryXml == $newInboxEntryXml);
  175. }
  176. public function testEmptyInboxEntryToAndFromStringShouldMatchV2() {
  177. $this->entry->transferFromXML($this->v2entryText);
  178. $entryXml = $this->entry->saveXML();
  179. $newInboxEntry = new Zend_Gdata_YouTube_InboxEntry();
  180. $newInboxEntry->transferFromXML($entryXml);
  181. $newInboxEntry->setMajorProtocolVersion(2);
  182. $newInboxEntryXml = $newInboxEntry->saveXML();
  183. $this->assertTrue($entryXml == $newInboxEntryXml);
  184. }
  185. public function testSamplePropertiesAreCorrect () {
  186. $this->entry->transferFromXML($this->entryText);
  187. $this->verifyAllSamplePropertiesAreCorrect($this->entry);
  188. }
  189. public function testSamplePropertiesAreCorrectV2 () {
  190. $this->entry->setMajorProtocolVersion(2);
  191. $this->entry->transferFromXML($this->v2entryText);
  192. $this->verifyAllSamplePropertiesAreCorrectV2($this->entry);
  193. }
  194. public function testConvertInboxEntryToAndFromString() {
  195. $this->entry->transferFromXML($this->entryText);
  196. $entryXml = $this->entry->saveXML();
  197. $newInboxEntry = new Zend_Gdata_YouTube_InboxEntry();
  198. $newInboxEntry->transferFromXML($entryXml);
  199. $this->verifyAllSamplePropertiesAreCorrect($newInboxEntry);
  200. $newInboxEntryXml = $newInboxEntry->saveXML();
  201. $this->assertEquals($entryXml, $newInboxEntryXml);
  202. }
  203. }