VideoFeedTest.php 4.8 KB

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