VideoFeedTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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-2009 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/VideoFeed.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-2009 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_VideoFeedTest extends PHPUnit_Framework_TestCase
  38. {
  39. public function setUp() {
  40. $this->feedText = file_get_contents(
  41. 'Zend/Gdata/YouTube/_files/VideoFeedDataSample1.xml',
  42. true);
  43. $this->feed = new Zend_Gdata_YouTube_VideoFeed();
  44. }
  45. private function verifyAllSamplePropertiesAreCorrect ($videoFeed) {
  46. $this->assertEquals('http://gdata.youtube.com/feeds/users/davidchoimusic/uploads',
  47. $videoFeed->id->text);
  48. $this->assertEquals('2007-09-21T02:27:22.638Z', $videoFeed->updated->text);
  49. $this->assertEquals('http://schemas.google.com/g/2005#kind', $videoFeed->category[0]->scheme);
  50. $this->assertEquals('http://gdata.youtube.com/schemas/2007#video', $videoFeed->category[0]->term);
  51. $this->assertEquals('http://www.youtube.com/img/pic_youtubelogo_123x63.gif', $videoFeed->logo->text);
  52. $this->assertEquals('text', $videoFeed->title->type);
  53. $this->assertEquals('Davidchoimusic\'s Videos', $videoFeed->title->text);;
  54. $this->assertEquals('self', $videoFeed->getLink('self')->rel);
  55. $this->assertEquals('application/atom+xml', $videoFeed->getLink('self')->type);
  56. $this->assertEquals('http://gdata.youtube.com/feeds/users/davidchoimusic/uploads?start-index=1&max-results=5', $videoFeed->getLink('self')->href);
  57. $this->assertEquals('davidchoimusic', $videoFeed->author[0]->name->text);
  58. $this->assertEquals('http://gdata.youtube.com/feeds/users/davidchoimusic', $videoFeed->author[0]->uri->text);
  59. $this->assertEquals(54, $videoFeed->totalResults->text);
  60. $this->assertEquals(1, $videoFeed->startIndex->text);
  61. $this->assertEquals(5, $videoFeed->itemsPerPage->text);
  62. }
  63. public function testEmptyEntryShouldHaveNoExtensionElements() {
  64. $this->assertTrue(is_array($this->feed->extensionElements));
  65. $this->assertTrue(count($this->feed->extensionElements) == 0);
  66. }
  67. public function testEmptyEntryShouldHaveNoExtensionAttributes() {
  68. $this->assertTrue(is_array($this->feed->extensionAttributes));
  69. $this->assertTrue(count($this->feed->extensionAttributes) == 0);
  70. }
  71. public function testSampleEntryShouldHaveNoExtensionElements() {
  72. $this->feed->transferFromXML($this->feedText);
  73. $this->assertTrue(is_array($this->feed->extensionElements));
  74. $this->assertTrue(count($this->feed->extensionElements) == 0);
  75. }
  76. public function testSampleEntryShouldHaveNoExtensionAttributes() {
  77. $this->feed->transferFromXML($this->feedText);
  78. $this->assertTrue(is_array($this->feed->extensionAttributes));
  79. $this->assertTrue(count($this->feed->extensionAttributes) == 0);
  80. }
  81. public function testEmptyVideoFeedToAndFromStringShouldMatch() {
  82. $entryXml = $this->feed->saveXML();
  83. $newVideoFeed = new Zend_Gdata_YouTube_VideoFeed();
  84. $newVideoFeed->transferFromXML($entryXml);
  85. $newVideoFeedXml = $newVideoFeed->saveXML();
  86. $this->assertTrue($entryXml == $newVideoFeedXml);
  87. }
  88. public function testSamplePropertiesAreCorrect () {
  89. $this->feed->transferFromXML($this->feedText);
  90. $this->verifyAllSamplePropertiesAreCorrect($this->feed);
  91. }
  92. public function testConvertVideoFeedToAndFromString() {
  93. $this->feed->transferFromXML($this->feedText);
  94. $entryXml = $this->feed->saveXML();
  95. $newVideoFeed = new Zend_Gdata_YouTube_VideoFeed();
  96. $newVideoFeed->transferFromXML($entryXml);
  97. $this->verifyAllSamplePropertiesAreCorrect($newVideoFeed);
  98. $newVideoFeedXml = $newVideoFeed->saveXML();
  99. $this->assertEquals($entryXml, $newVideoFeedXml);
  100. }
  101. }