PlaylistListFeedTest.php 7.9 KB

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