CommentFeedTest.php 4.7 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) 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/CommentFeed.php';
  26. require_once 'Zend/Gdata/YouTube.php';
  27. /**
  28. * @package Zend_Gdata_App
  29. * @subpackage UnitTests
  30. */
  31. class Zend_Gdata_YouTube_CommentFeedTest extends PHPUnit_Framework_TestCase
  32. {
  33. public function setUp() {
  34. $this->feedText = file_get_contents(
  35. 'Zend/Gdata/YouTube/_files/CommentFeedDataSample1.xml',
  36. true);
  37. $this->feed = new Zend_Gdata_YouTube_CommentFeed();
  38. }
  39. private function verifyAllSamplePropertiesAreCorrect ($commentFeed) {
  40. $this->assertEquals('http://gdata.youtube.com/feeds/videos/Lnio-pqLPgg/comments',
  41. $commentFeed->id->text);
  42. $this->assertEquals('2007-09-21T02:32:55.032Z', $commentFeed->updated->text);
  43. $this->assertEquals('http://schemas.google.com/g/2005#kind', $commentFeed->category[0]->scheme);
  44. $this->assertEquals('http://gdata.youtube.com/schemas/2007#comment', $commentFeed->category[0]->term);
  45. $this->assertEquals('http://www.youtube.com/img/pic_youtubelogo_123x63.gif', $commentFeed->logo->text);
  46. $this->assertEquals('text', $commentFeed->title->type);
  47. $this->assertEquals('Comments on \'"That Girl" - Original Song - Acoustic Version\'', $commentFeed->title->text);;
  48. $this->assertEquals('self', $commentFeed->getLink('self')->rel);
  49. $this->assertEquals('application/atom+xml', $commentFeed->getLink('self')->type);
  50. $this->assertEquals('http://gdata.youtube.com/feeds/videos/Lnio-pqLPgg/comments?start-index=1&max-results=4', $commentFeed->getLink('self')->href);
  51. $this->assertEquals('YouTube', $commentFeed->author[0]->name->text);
  52. $this->assertEquals('http://www.youtube.com/', $commentFeed->author[0]->uri->text);
  53. $this->assertEquals(100, $commentFeed->totalResults->text);
  54. $this->assertEquals(1, $commentFeed->startIndex->text);
  55. $this->assertEquals(4, $commentFeed->itemsPerPage->text);
  56. }
  57. public function testEmptyEntryShouldHaveNoExtensionElements() {
  58. $this->assertTrue(is_array($this->feed->extensionElements));
  59. $this->assertTrue(count($this->feed->extensionElements) == 0);
  60. }
  61. public function testEmptyEntryShouldHaveNoExtensionAttributes() {
  62. $this->assertTrue(is_array($this->feed->extensionAttributes));
  63. $this->assertTrue(count($this->feed->extensionAttributes) == 0);
  64. }
  65. public function testSampleEntryShouldHaveNoExtensionElements() {
  66. $this->feed->transferFromXML($this->feedText);
  67. $this->assertTrue(is_array($this->feed->extensionElements));
  68. $this->assertTrue(count($this->feed->extensionElements) == 0);
  69. }
  70. public function testSampleEntryShouldHaveNoExtensionAttributes() {
  71. $this->feed->transferFromXML($this->feedText);
  72. $this->assertTrue(is_array($this->feed->extensionAttributes));
  73. $this->assertTrue(count($this->feed->extensionAttributes) == 0);
  74. }
  75. public function testEmptyCommentFeedToAndFromStringShouldMatch() {
  76. $entryXml = $this->feed->saveXML();
  77. $newCommentFeed = new Zend_Gdata_YouTube_CommentFeed();
  78. $newCommentFeed->transferFromXML($entryXml);
  79. $newCommentFeedXml = $newCommentFeed->saveXML();
  80. $this->assertTrue($entryXml == $newCommentFeedXml);
  81. }
  82. public function testSamplePropertiesAreCorrect () {
  83. $this->feed->transferFromXML($this->feedText);
  84. $this->verifyAllSamplePropertiesAreCorrect($this->feed);
  85. }
  86. public function testConvertCommentFeedToAndFromString() {
  87. $this->feed->transferFromXML($this->feedText);
  88. $entryXml = $this->feed->saveXML();
  89. $newCommentFeed = new Zend_Gdata_YouTube_CommentFeed();
  90. $newCommentFeed->transferFromXML($entryXml);
  91. $this->verifyAllSamplePropertiesAreCorrect($newCommentFeed);
  92. $newCommentFeedXml = $newCommentFeed->saveXML();
  93. $this->assertEquals($entryXml, $newCommentFeedXml);
  94. }
  95. }