PlaylistVideoFeedTest.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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/PlaylistVideoFeed.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_PlaylistVideoFeedTest extends PHPUnit_Framework_TestCase
  38. {
  39. public function setUp() {
  40. $this->feedText = file_get_contents(
  41. 'Zend/Gdata/YouTube/_files/PlaylistVideoFeedDataSample1.xml',
  42. true);
  43. $this->feed = new Zend_Gdata_YouTube_PlaylistVideoFeed();
  44. }
  45. private function verifyAllSamplePropertiesAreCorrect ($playlistVideoFeed) {
  46. $this->assertEquals('http://gdata.youtube.com/feeds/playlists/46A2F8C9B36B6FE7',
  47. $playlistVideoFeed->id->text);
  48. $this->assertEquals('2007-09-20T13:42:19.000-07:00', $playlistVideoFeed->updated->text);
  49. $this->assertEquals('http://schemas.google.com/g/2005#kind', $playlistVideoFeed->category[0]->scheme);
  50. $this->assertEquals('http://gdata.youtube.com/schemas/2007#playlist', $playlistVideoFeed->category[0]->term);
  51. $this->assertEquals('http://gdata.youtube.com/schemas/2007/tags.cat', $playlistVideoFeed->category[1]->scheme);
  52. $this->assertEquals('music', $playlistVideoFeed->category[1]->term);
  53. $this->assertEquals('http://www.youtube.com/img/pic_youtubelogo_123x63.gif', $playlistVideoFeed->logo->text);
  54. $this->assertEquals('text', $playlistVideoFeed->title->type);
  55. $this->assertEquals('YouTube Musicians', $playlistVideoFeed->title->text);;
  56. $this->assertEquals('self', $playlistVideoFeed->getLink('self')->rel);
  57. $this->assertEquals('application/atom+xml', $playlistVideoFeed->getLink('self')->type);
  58. $this->assertEquals('http://gdata.youtube.com/feeds/playlists/46A2F8C9B36B6FE7?start-index=1&max-results=25', $playlistVideoFeed->getLink('self')->href);
  59. $this->assertEquals('testuser', $playlistVideoFeed->author[0]->name->text);
  60. $this->assertEquals('http://gdata.youtube.com/feeds/users/testuser', $playlistVideoFeed->author[0]->uri->text);
  61. $this->assertEquals(13, $playlistVideoFeed->totalResults->text);
  62. $this->assertEquals(13, count($playlistVideoFeed->entry));
  63. $entries = $playlistVideoFeed->entry;
  64. $this->assertEquals(1, $entries[0]->getPosition()->getText());
  65. }
  66. public function testEmptyEntryShouldHaveNoExtensionElements() {
  67. $this->assertTrue(is_array($this->feed->extensionElements));
  68. $this->assertTrue(count($this->feed->extensionElements) == 0);
  69. }
  70. public function testEmptyEntryShouldHaveNoExtensionAttributes() {
  71. $this->assertTrue(is_array($this->feed->extensionAttributes));
  72. $this->assertTrue(count($this->feed->extensionAttributes) == 0);
  73. }
  74. public function testSampleEntryShouldHaveNoExtensionElements() {
  75. $this->feed->transferFromXML($this->feedText);
  76. $this->assertTrue(is_array($this->feed->extensionElements));
  77. $this->assertTrue(count($this->feed->extensionElements) == 0);
  78. }
  79. public function testSampleEntryShouldHaveNoExtensionAttributes() {
  80. $this->feed->transferFromXML($this->feedText);
  81. $this->assertTrue(is_array($this->feed->extensionAttributes));
  82. $this->assertTrue(count($this->feed->extensionAttributes) == 0);
  83. }
  84. public function testEmptyPlaylistVideoFeedToAndFromStringShouldMatch() {
  85. $entryXml = $this->feed->saveXML();
  86. $newPlaylistVideoFeed = new Zend_Gdata_YouTube_PlaylistVideoFeed();
  87. $newPlaylistVideoFeed->transferFromXML($entryXml);
  88. $newPlaylistVideoFeedXml = $newPlaylistVideoFeed->saveXML();
  89. $this->assertTrue($entryXml == $newPlaylistVideoFeedXml);
  90. }
  91. public function testSamplePropertiesAreCorrect () {
  92. $this->feed->transferFromXML($this->feedText);
  93. $this->verifyAllSamplePropertiesAreCorrect($this->feed);
  94. }
  95. public function testConvertPlaylistVideoFeedToAndFromString() {
  96. $this->feed->transferFromXML($this->feedText);
  97. $feedXml = $this->feed->saveXML();
  98. $newPlaylistVideoFeed = new Zend_Gdata_YouTube_PlaylistVideoFeed();
  99. $newPlaylistVideoFeed->transferFromXML($feedXml);
  100. $this->verifyAllSamplePropertiesAreCorrect($newPlaylistVideoFeed);
  101. $newPlaylistVideoFeedXml = $newPlaylistVideoFeed->saveXML();
  102. $this->assertEquals($feedXml, $newPlaylistVideoFeedXml);
  103. }
  104. }