PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/ZendFramework/tests/Zend/Gdata/YouTube/PlaylistListEntryTest.php

https://bitbucket.org/Dal-Papa/is-340-publish-base
PHP | 239 lines | 180 code | 26 blank | 33 comment | 1 complexity | ac502cd7a00d649c05efbad2bbed64cc MD5 | raw file
  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-2012 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/PlaylistListEntry.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-2012 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_PlaylistListEntryTest extends PHPUnit_Framework_TestCase
  34. {
  35. public function setUp() {
  36. $this->entryText = file_get_contents(
  37. 'Zend/Gdata/YouTube/_files/PlaylistListEntryDataSample1.xml',
  38. true);
  39. $this->v2entryText = file_get_contents(
  40. 'Zend/Gdata/YouTube/_files/PlaylistListEntryDataSampleV2.xml',
  41. true);
  42. $this->entry = new Zend_Gdata_YouTube_PlaylistListEntry();
  43. }
  44. private function verifyAllSamplePropertiesAreCorrect ($playlistListEntry) {
  45. $this->assertEquals('http://gdata.youtube.com/feeds/users/testuser/playlists/46A2F8C9B36B6FE7',
  46. $playlistListEntry->id->text);
  47. $this->assertEquals('2007-09-20T13:42:19.000-07:00', $playlistListEntry->updated->text);
  48. $this->assertEquals('http://gdata.youtube.com/schemas/2007/tags.cat', $playlistListEntry->category[0]->scheme);
  49. $this->assertEquals('music', $playlistListEntry->category[0]->term);
  50. $this->assertEquals('http://schemas.google.com/g/2005#kind', $playlistListEntry->category[1]->scheme);
  51. $this->assertEquals('http://gdata.youtube.com/schemas/2007#playlistLink', $playlistListEntry->category[1]->term);
  52. $this->assertEquals('text', $playlistListEntry->title->type);
  53. $this->assertEquals('YouTube Musicians', $playlistListEntry->title->text);;
  54. $this->assertEquals('text', $playlistListEntry->content->type);
  55. $this->assertEquals('Music from talented people on YouTube.', $playlistListEntry->content->text);;
  56. $this->assertEquals('self', $playlistListEntry->getLink('self')->rel);
  57. $this->assertEquals('application/atom+xml', $playlistListEntry->getLink('self')->type);
  58. $this->assertEquals('http://gdata.youtube.com/feeds/users/testuser/playlists/46A2F8C9B36B6FE7', $playlistListEntry->getLink('self')->href);
  59. $this->assertEquals('testuser', $playlistListEntry->author[0]->name->text);
  60. $this->assertEquals('http://gdata.youtube.com/feeds/users/testuser', $playlistListEntry->author[0]->uri->text);
  61. $this->assertEquals('Music from talented people on YouTube.', $playlistListEntry->description->text);
  62. $this->assertEquals('http://gdata.youtube.com/feeds/playlists/46A2F8C9B36B6FE7', $playlistListEntry->getPlaylistVideoFeedUrl());
  63. $this->assertEquals('http://gdata.youtube.com/feeds/playlists/46A2F8C9B36B6FE7', $playlistListEntry->feedLink[0]->href);
  64. $this->assertEquals('http://gdata.youtube.com/schemas/2007#playlist', $playlistListEntry->feedLink[0]->rel);
  65. }
  66. private function verifyAllSamplePropertiesAreCorrectV2 ($playlistListEntry) {
  67. $this->assertEquals('tag:youtube.com,2008:user:googledevelopers:playlist:8E2186857EE27746',
  68. $playlistListEntry->id->text);
  69. $this->assertEquals('2008-12-10T09:56:03.000Z', $playlistListEntry->updated->text);
  70. $this->assertEquals('2007-08-23T21:48:43.000Z', $playlistListEntry->published->text);
  71. $this->assertEquals('http://schemas.google.com/g/2005#kind', $playlistListEntry->category[0]->scheme);
  72. $this->assertEquals('http://gdata.youtube.com/schemas/2007#playlistLink', $playlistListEntry->category[0]->term);
  73. $this->assertEquals('http://schemas.google.com/g/2005#kind', $playlistListEntry->category[0]->scheme);
  74. $this->assertEquals('Non-google Interviews', $playlistListEntry->title->text);
  75. $this->assertEquals('This playlist contains interviews with people outside of Google.', $playlistListEntry->summary->text);
  76. $this->assertEquals('self', $playlistListEntry->getLink('self')->rel);
  77. $this->assertEquals('http://gdata.youtube.com/feeds/api/users/googledevelopers/playlists/8E2186857EE27746?v=2', $playlistListEntry->getLink('self')->href);
  78. $this->assertEquals('application/atom+xml', $playlistListEntry->getLink('self')->type);
  79. $this->assertEquals('alternate', $playlistListEntry->getLink('alternate')->rel);
  80. $this->assertEquals('http://www.youtube.com/view_play_list?p=8E2186857EE27746', $playlistListEntry->getLink('alternate')->href);
  81. $this->assertEquals('text/html', $playlistListEntry->getLink('alternate')->type);
  82. $this->assertEquals('related', $playlistListEntry->getLink('related')->rel);
  83. $this->assertEquals('http://gdata.youtube.com/feeds/api/users/googledevelopers?v=2', $playlistListEntry->getLink('related')->href);
  84. $this->assertEquals('application/atom+xml', $playlistListEntry->getLink('related')->type);
  85. $this->assertEquals('googledevelopers', $playlistListEntry->author[0]->name->text);
  86. $this->assertEquals('http://gdata.youtube.com/feeds/api/users/googledevelopers', $playlistListEntry->author[0]->uri->text);
  87. $this->assertEquals('8E2186857EE27746', $playlistListEntry->getPlaylistId()->text);
  88. $this->assertEquals('1', $playlistListEntry->getCountHint()->text);
  89. $this->assertEquals('application/atom+xml;type=feed', $playlistListEntry->getContent()->getType());
  90. $this->assertEquals('http://gdata.youtube.com/feeds/api/playlists/8E2186857EE27746?v=2', $playlistListEntry->getContent()->getSrc());
  91. }
  92. public function testEmptyEntryShouldHaveNoExtensionElements() {
  93. $this->assertTrue(is_array($this->entry->extensionElements));
  94. $this->assertEquals(0, count($this->entry->extensionElements));
  95. }
  96. public function testEmptyEntryShouldHaveNoExtensionAttributes() {
  97. $this->assertTrue(is_array($this->entry->extensionAttributes));
  98. $this->assertEquals(0, count($this->entry->extensionAttributes));
  99. }
  100. public function testSampleEntryShouldHaveNoExtensionElements() {
  101. $this->entry->transferFromXML($this->entryText);
  102. $this->assertTrue(is_array($this->entry->extensionElements));
  103. $this->assertEquals(0, count($this->entry->extensionElements));
  104. }
  105. public function testSampleEntryShouldHaveNoExtensionAttributes() {
  106. $this->entry->transferFromXML($this->entryText);
  107. $this->assertTrue(is_array($this->entry->extensionAttributes));
  108. $this->assertEquals(0, count($this->entry->extensionAttributes));
  109. }
  110. public function testEmptyPlaylistListEntryToAndFromStringShouldMatch() {
  111. $entryXml = $this->entry->saveXML();
  112. $newPlaylistListEntry = new Zend_Gdata_YouTube_PlaylistListEntry();
  113. $newPlaylistListEntry->transferFromXML($entryXml);
  114. $newPlaylistListEntryXml = $newPlaylistListEntry->saveXML();
  115. $this->assertTrue($entryXml == $newPlaylistListEntryXml);
  116. }
  117. public function testSampleEntryShouldHaveNoExtensionElementsV2() {
  118. $this->entry->transferFromXML($this->entryText);
  119. $this->entry->setMajorProtocolVersion(2);
  120. $this->assertTrue(is_array($this->entry->extensionElements));
  121. $this->assertEquals(0, count($this->entry->extensionElements));
  122. }
  123. public function testSampleEntryShouldHaveNoExtensionAttributesV2() {
  124. $this->entry->transferFromXML($this->entryText);
  125. $this->entry->setMajorProtocolVersion(2);
  126. $this->assertTrue(is_array($this->entry->extensionAttributes));
  127. $this->assertEquals(0, count($this->entry->extensionAttributes));
  128. }
  129. public function testGetFeedLinkReturnsAllStoredEntriesWhenUsedWithNoParameters() {
  130. // Prepare test data
  131. $entry1 = new Zend_Gdata_Extension_FeedLink();
  132. $entry1->rel = "first";
  133. $entry1->href= "foo";
  134. $entry2 = new Zend_Gdata_Extension_FeedLink();
  135. $entry2->rel = "second";
  136. $entry2->href= "bar";
  137. $data = array($entry1, $entry2);
  138. // Load test data and run test
  139. $this->entry->feedLink = $data;
  140. $this->assertEquals(2, count($this->entry->feedLink));
  141. }
  142. public function testGetFeedLinkCanReturnEntriesByRelValue() {
  143. // Prepare test data
  144. $entry1 = new Zend_Gdata_Extension_FeedLink();
  145. $entry1->rel = "first";
  146. $entry1->href= "foo";
  147. $entry2 = new Zend_Gdata_Extension_FeedLink();
  148. $entry2->rel = "second";
  149. $entry2->href= "bar";
  150. $data = array($entry1, $entry2);
  151. // Load test data and run test
  152. $this->entry->feedLink = $data;
  153. $this->assertEquals($entry1, $this->entry->getFeedLink('first'));
  154. $this->assertEquals($entry2, $this->entry->getFeedLink('second'));
  155. }
  156. public function testSamplePropertiesAreCorrect () {
  157. $this->entry->transferFromXML($this->entryText);
  158. $this->verifyAllSamplePropertiesAreCorrect($this->entry);
  159. }
  160. public function testSamplePropertiesAreCorrectV2 () {
  161. $this->entry->transferFromXML($this->v2entryText);
  162. $this->entry->setMajorProtocolVersion(2);
  163. $this->verifyAllSamplePropertiesAreCorrectV2($this->entry);
  164. }
  165. public function testConvertPlaylistListEntryToAndFromStringV2() {
  166. $this->entry->transferFromXML($this->v2entryText);
  167. $entryXml = $this->entry->saveXML();
  168. $newPlaylistListEntry = new Zend_Gdata_YouTube_PlaylistListEntry();
  169. $newPlaylistListEntry->transferFromXML($entryXml);
  170. $newPlaylistListEntry->setMajorProtocolVersion(2);
  171. $this->verifyAllSamplePropertiesAreCorrectV2($newPlaylistListEntry);
  172. $newPlaylistListEntryXml = $newPlaylistListEntry->saveXML();
  173. $this->assertEquals($entryXml, $newPlaylistListEntryXml);
  174. }
  175. public function testConvertPlaylistListEntryToAndFromString() {
  176. $this->entry->transferFromXML($this->entryText);
  177. $entryXml = $this->entry->saveXML();
  178. $newPlaylistListEntry = new Zend_Gdata_YouTube_PlaylistListEntry();
  179. $newPlaylistListEntry->transferFromXML($entryXml);
  180. $this->verifyAllSamplePropertiesAreCorrect($newPlaylistListEntry);
  181. $newPlaylistListEntryXml = $newPlaylistListEntry->saveXML();
  182. $this->assertEquals($entryXml, $newPlaylistListEntryXml);
  183. }
  184. public function testGettingCountHintOnV1EntryShouldThrowException() {
  185. $exceptionCaught = false;
  186. $this->entry->transferFromXML($this->entryText);
  187. try {
  188. $this->entry->getCountHint();
  189. } catch (Zend_Gdata_App_VersionException $e) {
  190. $exceptionCaught = true;
  191. }
  192. $this->assertTrue($exceptionCaught, 'Calling getCountHint on a v1 ' .
  193. 'playlistListEntry should throw an exception');
  194. }
  195. public function testGettingPlaylistIdOnV1EntryShouldThrowException() {
  196. $exceptionCaught = false;
  197. $this->entry->transferFromXML($this->entryText);
  198. try {
  199. $this->entry->getPlaylistId();
  200. } catch (Zend_Gdata_App_VersionException $e) {
  201. $exceptionCaught = true;
  202. }
  203. $this->assertTrue($exceptionCaught, 'Calling getPlaylistId on a v1 ' .
  204. 'playlistListEntry should throw an exception');
  205. }
  206. public function testGetPlaylistVideoFeedUrlWorksInV2() {
  207. $this->entry->transferFromXML($this->v2entryText);
  208. $this->entry->setMajorProtocolVersion(2);
  209. $this->assertEquals(
  210. 'http://gdata.youtube.com/feeds/api/playlists/8E2186857EE27746?v=2',
  211. $this->entry->getPlaylistVideoFeedUrl());
  212. }
  213. }