InboxFeedTest.php 7.7 KB

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