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