PlaylistListFeedTest.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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/PlaylistListFeed.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_PlaylistListFeedTest extends PHPUnit_Framework_TestCase
  38. {
  39. public function setUp() {
  40. $this->feedText = file_get_contents(
  41. 'Zend/Gdata/YouTube/_files/PlaylistListFeedDataSample1.xml',
  42. true);
  43. $this->V2feedText = file_get_contents(
  44. 'Zend/Gdata/YouTube/_files/PlaylistListFeedDataSampleV2.xml',
  45. true);
  46. $this->feed = new Zend_Gdata_YouTube_PlaylistListFeed();
  47. }
  48. private function verifyAllSamplePropertiesAreCorrect ($playlistListFeed) {
  49. $this->assertEquals('http://gdata.youtube.com/feeds/users/testuser/playlists',
  50. $playlistListFeed->id->text);
  51. $this->assertEquals('2007-09-20T20:59:47.530Z', $playlistListFeed->updated->text);
  52. $this->assertEquals('http://schemas.google.com/g/2005#kind', $playlistListFeed->category[0]->scheme);
  53. $this->assertEquals('http://gdata.youtube.com/schemas/2007#playlistLink', $playlistListFeed->category[0]->term);
  54. $this->assertEquals('http://www.youtube.com/img/pic_youtubelogo_123x63.gif', $playlistListFeed->logo->text);
  55. $this->assertEquals('text', $playlistListFeed->title->type);
  56. $this->assertEquals('testuser\'s Playlists', $playlistListFeed->title->text);;
  57. $this->assertEquals('self', $playlistListFeed->getLink('self')->rel);
  58. $this->assertEquals('application/atom+xml', $playlistListFeed->getLink('self')->type);
  59. $this->assertEquals('http://gdata.youtube.com/feeds/users/testuser/playlists?start-index=1&max-results=25', $playlistListFeed->getLink('self')->href);
  60. $this->assertEquals('testuser', $playlistListFeed->author[0]->name->text);
  61. $this->assertEquals('http://gdata.youtube.com/feeds/users/testuser', $playlistListFeed->author[0]->uri->text);
  62. $this->assertEquals(2, $playlistListFeed->totalResults->text);
  63. }
  64. private function verifyAllSamplePropertiesAreCorrectV2 ($playlistListFeed) {
  65. $this->assertEquals('tag:youtube.com,2008:user:GoogleDevelopers:playlists',
  66. $playlistListFeed->id->text);
  67. $this->assertEquals('2008-12-10T09:56:03.000Z',
  68. $playlistListFeed->updated->text);
  69. $this->assertEquals('http://schemas.google.com/g/2005#kind',
  70. $playlistListFeed->category[0]->scheme);
  71. $this->assertEquals(
  72. 'http://gdata.youtube.com/schemas/2007#playlistLink',
  73. $playlistListFeed->category[0]->term);
  74. $this->assertEquals(
  75. 'http://www.youtube.com/img/pic_youtubelogo_123x63.gif',
  76. $playlistListFeed->logo->text);
  77. $this->assertEquals('Playlists of GoogleDevelopers',
  78. $playlistListFeed->title->text);;
  79. $this->assertEquals('self', $playlistListFeed->getLink('self')->rel);
  80. $this->assertEquals('application/atom+xml',
  81. $playlistListFeed->getLink('self')->type);
  82. $this->assertEquals(
  83. 'http://gdata.youtube.com/feeds/api/users/GoogleDevelopers/' .
  84. 'playlists?start-index=1&max-results=25&v=2',
  85. $playlistListFeed->getLink('self')->href);
  86. $this->assertEquals('GoogleDevelopers',
  87. $playlistListFeed->author[0]->name->text);
  88. $this->assertEquals('http://gdata.youtube.com/feeds/api/users/' .
  89. 'googledevelopers', $playlistListFeed->author[0]->uri->text);
  90. $this->assertEquals(70, $playlistListFeed->totalResults->text);
  91. }
  92. public function testEmptyEntryShouldHaveNoExtensionElements() {
  93. $this->assertTrue(is_array($this->feed->extensionElements));
  94. $this->assertEquals(0, count($this->feed->extensionElements));
  95. }
  96. public function testEmptyEntryShouldHaveNoExtensionAttributes() {
  97. $this->assertTrue(is_array($this->feed->extensionAttributes));
  98. $this->assertEquals(0, count($this->feed->extensionAttributes));
  99. }
  100. public function testSampleEntryShouldHaveNoExtensionElements() {
  101. $this->feed->transferFromXML($this->feedText);
  102. $this->assertTrue(is_array($this->feed->extensionElements));
  103. $this->assertEquals(0, count($this->feed->extensionElements));
  104. }
  105. public function testSampleEntryShouldHaveNoExtensionAttributes() {
  106. $this->feed->transferFromXML($this->feedText);
  107. $this->assertTrue(is_array($this->feed->extensionAttributes));
  108. $this->assertEquals(0, count($this->feed->extensionAttributes));
  109. }
  110. public function testSampleEntryShouldHaveNoExtensionElementsV2() {
  111. $this->feed->setMajorProtocolVersion(2);
  112. $this->feed->transferFromXML($this->V2feedText);
  113. $this->assertTrue(is_array($this->feed->extensionElements));
  114. $this->assertEquals(0, count($this->feed->extensionElements));
  115. }
  116. public function testSampleEntryShouldHaveNoExtensionAttributesV2() {
  117. $this->feed->setMajorProtocolVersion(2);
  118. $this->feed->transferFromXML($this->V2feedText);
  119. $this->assertTrue(is_array($this->feed->extensionAttributes));
  120. $this->assertEquals(0, count($this->feed->extensionAttributes));
  121. }
  122. public function testEmptyPlaylistListFeedToAndFromStringShouldMatch() {
  123. $feedXml = $this->feed->saveXML();
  124. $newPlaylistListFeed = new Zend_Gdata_YouTube_PlaylistListFeed();
  125. $newPlaylistListFeed->transferFromXML($feedXml);
  126. $newPlaylistListFeedXml = $newPlaylistListFeed->saveXML();
  127. $this->assertTrue($feedXml == $newPlaylistListFeedXml);
  128. }
  129. public function testEmptyPlaylistListFeedToAndFromStringShouldMatchV2() {
  130. $this->feed->setMajorProtocolVersion(2);
  131. $this->feed->transferFromXML($this->V2feedText);
  132. $feedXml = $this->feed->saveXML();
  133. $newPlaylistListFeed = new Zend_Gdata_YouTube_PlaylistListFeed();
  134. $newPlaylistListFeed->transferFromXML($feedXml);
  135. $newPlaylistListFeed->setMajorProtocolVersion(2);
  136. $newPlaylistListFeedXml = $newPlaylistListFeed->saveXML();
  137. $this->assertTrue($feedXml == $newPlaylistListFeedXml);
  138. }
  139. public function testSamplePropertiesAreCorrect () {
  140. $this->feed->transferFromXML($this->feedText);
  141. $this->verifyAllSamplePropertiesAreCorrect($this->feed);
  142. }
  143. public function testSamplePropertiesAreCorrectV2 () {
  144. $this->feed->setMajorProtocolVersion(2);
  145. $this->feed->transferFromXML($this->V2feedText);
  146. $this->verifyAllSamplePropertiesAreCorrectV2($this->feed);
  147. }
  148. public function testConvertPlaylistListFeedToAndFromString() {
  149. $this->feed->transferFromXML($this->feedText);
  150. $entryXml = $this->feed->saveXML();
  151. $newPlaylistListFeed = new Zend_Gdata_YouTube_PlaylistListFeed();
  152. $newPlaylistListFeed->transferFromXML($entryXml);
  153. $this->verifyAllSamplePropertiesAreCorrect($newPlaylistListFeed);
  154. $newPlaylistListFeedXml = $newPlaylistListFeed->saveXML();
  155. $this->assertEquals($entryXml, $newPlaylistListFeedXml);
  156. }
  157. }