InboxFeedTest.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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/InboxFeed.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_InboxFeedTest extends PHPUnit_Framework_TestCase
  34. {
  35. public function setUp() {
  36. $this->feedText = file_get_contents(
  37. 'Zend/Gdata/YouTube/_files/InboxFeedDataSample1.xml',
  38. true);
  39. $this->V2feedText = file_get_contents(
  40. 'Zend/Gdata/YouTube/_files/InboxFeedDataSampleV2.xml',
  41. true);
  42. $this->feed = new Zend_Gdata_YouTube_InboxFeed();
  43. }
  44. private function verifyAllSamplePropertiesAreCorrect ($inboxFeed) {
  45. $this->assertEquals('http://gdata.youtube.com/feeds/api/users/' .
  46. 'default/inbox',
  47. $inboxFeed->id->text);
  48. $this->assertEquals('2008-06-10T20:55:40.271Z',
  49. $inboxFeed->updated->text);
  50. $this->assertEquals('http://schemas.google.com/g/2005#kind',
  51. $inboxFeed->category[0]->scheme);
  52. $this->assertEquals(
  53. 'http://gdata.youtube.com/schemas/2007#videoMessage',
  54. $inboxFeed->category[0]->term);
  55. $this->assertEquals(
  56. 'http://www.youtube.com/img/pic_youtubelogo_123x63.gif',
  57. $inboxFeed->logo->text);
  58. $this->assertEquals('text', $inboxFeed->title->type);
  59. $this->assertEquals('Inbox of andyland74',
  60. $inboxFeed->title->text);;
  61. $this->assertEquals('self', $inboxFeed->getLink('self')->rel);
  62. $this->assertEquals('application/atom+xml',
  63. $inboxFeed->getLink('self')->type);
  64. $this->assertEquals(
  65. 'http://gdata.youtube.com/feeds/api/users/andyland74/inbox?...',
  66. $inboxFeed->getLink('self')->href);
  67. $this->assertEquals('andyland74', $inboxFeed->author[0]->name->text);
  68. $this->assertEquals(
  69. 'http://gdata.youtube.com/feeds/api/users/andyland74',
  70. $inboxFeed->author[0]->uri->text);
  71. $this->assertEquals(1, $inboxFeed->totalResults->text);
  72. }
  73. private function verifyAllSamplePropertiesAreCorrectV2 ($inboxFeed) {
  74. $this->assertEquals('tag:youtube,2008:user:andyland74:inbox',
  75. $inboxFeed->id->text);
  76. $this->assertEquals('2008-07-21T17:54:30.236Z',
  77. $inboxFeed->updated->text);
  78. $this->assertEquals('http://schemas.google.com/g/2005#kind',
  79. $inboxFeed->category[0]->scheme);
  80. $this->assertEquals(
  81. 'http://gdata.youtube.com/schemas/2007#videoMessage',
  82. $inboxFeed->category[0]->term);
  83. $this->assertEquals(
  84. 'http://www.youtube.com/img/pic_youtubelogo_123x63.gif',
  85. $inboxFeed->logo->text);
  86. $this->assertEquals('Inbox of andyland74',
  87. $inboxFeed->title->text);;
  88. $this->assertEquals('andyland74',
  89. $inboxFeed->author[0]->name->text);
  90. $this->assertEquals(
  91. 'http://gdata.youtube.com/feeds/api/users/andyland74',
  92. $inboxFeed->author[0]->uri->text);
  93. $this->assertEquals('self', $inboxFeed->getLink('self')->rel);
  94. $this->assertEquals('application/atom+xml',
  95. $inboxFeed->getLink('self')->type);
  96. $this->assertEquals(
  97. 'http://gdata.youtube.com/feeds/api/users/andyland74/inbox?...',
  98. $inboxFeed->getLink('self')->href);
  99. $this->assertEquals('alternate', $inboxFeed->getLink('alternate')->rel);
  100. $this->assertEquals('text/html',
  101. $inboxFeed->getLink('alternate')->type);
  102. $this->assertEquals(
  103. 'http://www.youtube.com/my_messages?folder=inbox&filter=videos',
  104. $inboxFeed->getLink('alternate')->href);
  105. $this->assertEquals('service', $inboxFeed->getLink('service')->rel);
  106. $this->assertEquals('application/atomsvc+xml',
  107. $inboxFeed->getLink('service')->type);
  108. $this->assertEquals(
  109. 'http://gdata.youtube.com/feeds/api/users/andyland74/inbox?' .
  110. 'alt=...',
  111. $inboxFeed->getLink('service')->href);
  112. }
  113. public function testEmptyEntryShouldHaveNoExtensionElements() {
  114. $this->assertTrue(is_array($this->feed->extensionElements));
  115. $this->assertEquals(0, count($this->feed->extensionElements));
  116. }
  117. public function testEmptyEntryShouldHaveNoExtensionAttributes() {
  118. $this->assertTrue(is_array($this->feed->extensionAttributes));
  119. $this->assertEquals(0, count($this->feed->extensionAttributes));
  120. }
  121. public function testSampleEntryShouldHaveNoExtensionElements() {
  122. $this->feed->transferFromXML($this->feedText);
  123. $this->assertTrue(is_array($this->feed->extensionElements));
  124. $this->assertEquals(0, count($this->feed->extensionElements));
  125. }
  126. public function testSampleEntryShouldHaveNoExtensionAttributes() {
  127. $this->feed->transferFromXML($this->feedText);
  128. $this->assertTrue(is_array($this->feed->extensionAttributes));
  129. $this->assertEquals(0, count($this->feed->extensionAttributes));
  130. }
  131. public function testEmptyInboxFeedToAndFromStringShouldMatch() {
  132. $feedXml = $this->feed->saveXML();
  133. $newInboxFeed = new Zend_Gdata_YouTube_InboxFeed();
  134. $newInboxFeed->transferFromXML($feedXml);
  135. $newInboxFeedXml = $newInboxFeed->saveXML();
  136. $this->assertTrue($feedXml == $newInboxFeedXml);
  137. }
  138. public function testSamplePropertiesAreCorrect () {
  139. $this->feed->transferFromXML($this->feedText);
  140. $this->verifyAllSamplePropertiesAreCorrect($this->feed);
  141. }
  142. public function testSamplePropertiesAreCorrectV2 () {
  143. $this->feed->transferFromXML($this->V2feedText);
  144. $this->verifyAllSamplePropertiesAreCorrectV2($this->feed);
  145. }
  146. public function testConvertInboxFeedToAndFromString() {
  147. $this->feed->transferFromXML($this->feedText);
  148. $feedXml = $this->feed->saveXML();
  149. $newInboxFeed = new Zend_Gdata_YouTube_InboxFeed();
  150. $newInboxFeed->transferFromXML($feedXml);
  151. $this->verifyAllSamplePropertiesAreCorrect($newInboxFeed);
  152. $newInboxFeedXml = $newInboxFeed->saveXML();
  153. $this->assertEquals($feedXml, $newInboxFeedXml);
  154. }
  155. public function testConvertInboxFeedToAndFromStringV2() {
  156. $this->feed->setMajorProtocolVersion(2);
  157. $this->feed->transferFromXML($this->V2feedText);
  158. $feedXml = $this->feed->saveXML();
  159. $newInboxFeed = new Zend_Gdata_YouTube_InboxFeed();
  160. $newInboxFeed->transferFromXML($feedXml);
  161. $newInboxFeed->setMajorProtocolVersion(2);
  162. $this->verifyAllSamplePropertiesAreCorrectV2($newInboxFeed);
  163. $newInboxFeedXml = $newInboxFeed->saveXML();
  164. $this->assertEquals($feedXml, $newInboxFeedXml);
  165. }
  166. }