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