InboxEntryTest.php 8.9 KB

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