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