2
0

CommentEntryTest.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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/CommentEntry.php';
  26. require_once 'Zend/Gdata/YouTube.php';
  27. /**
  28. * @package Zend_Gdata_App
  29. * @subpackage UnitTests
  30. */
  31. class Zend_Gdata_YouTube_CommentEntryTest extends PHPUnit_Framework_TestCase
  32. {
  33. public function setUp() {
  34. $this->entryText = file_get_contents(
  35. 'Zend/Gdata/YouTube/_files/CommentEntryDataSample1.xml',
  36. true);
  37. $this->entry = new Zend_Gdata_YouTube_CommentEntry();
  38. }
  39. private function verifyAllSamplePropertiesAreCorrect ($commentEntry) {
  40. $this->assertEquals('http://gdata.youtube.com/feeds/videos/Lnio-pqLPgg/comments/CE0314DEBFFC9052',
  41. $commentEntry->id->text);
  42. $this->assertEquals('2007-09-02T18:00:04.000-07:00', $commentEntry->updated->text);
  43. $this->assertEquals('http://schemas.google.com/g/2005#kind', $commentEntry->category[0]->scheme);
  44. $this->assertEquals('http://gdata.youtube.com/schemas/2007#comment', $commentEntry->category[0]->term);
  45. $this->assertEquals('text', $commentEntry->title->type);
  46. $this->assertEquals('how to turn ...', $commentEntry->title->text);;
  47. $this->assertEquals('text', $commentEntry->content->type);
  48. $this->assertEquals('how to turn rejection and heartbreak into something positive is the big mystery of life but you\'re managed to turn it to your advantage with a beautiful song. Who was she?', $commentEntry->content->text);;
  49. $this->assertEquals('self', $commentEntry->getLink('self')->rel);
  50. $this->assertEquals('application/atom+xml', $commentEntry->getLink('self')->type);
  51. $this->assertEquals('http://gdata.youtube.com/feeds/videos/Lnio-pqLPgg/comments/CE0314DEBFFC9052', $commentEntry->getLink('self')->href);
  52. $this->assertEquals('reneemathome', $commentEntry->author[0]->name->text);
  53. $this->assertEquals('http://gdata.youtube.com/feeds/users/reneemathome', $commentEntry->author[0]->uri->text);
  54. }
  55. public function testEmptyEntryShouldHaveNoExtensionElements() {
  56. $this->assertTrue(is_array($this->entry->extensionElements));
  57. $this->assertTrue(count($this->entry->extensionElements) == 0);
  58. }
  59. public function testEmptyEntryShouldHaveNoExtensionAttributes() {
  60. $this->assertTrue(is_array($this->entry->extensionAttributes));
  61. $this->assertTrue(count($this->entry->extensionAttributes) == 0);
  62. }
  63. public function testSampleEntryShouldHaveNoExtensionElements() {
  64. $this->entry->transferFromXML($this->entryText);
  65. $this->assertTrue(is_array($this->entry->extensionElements));
  66. $this->assertTrue(count($this->entry->extensionElements) == 0);
  67. }
  68. public function testSampleEntryShouldHaveNoExtensionAttributes() {
  69. $this->entry->transferFromXML($this->entryText);
  70. $this->assertTrue(is_array($this->entry->extensionAttributes));
  71. $this->assertTrue(count($this->entry->extensionAttributes) == 0);
  72. }
  73. public function testEmptyCommentEntryToAndFromStringShouldMatch() {
  74. $entryXml = $this->entry->saveXML();
  75. $newCommentEntry = new Zend_Gdata_YouTube_CommentEntry();
  76. $newCommentEntry->transferFromXML($entryXml);
  77. $newCommentEntryXml = $newCommentEntry->saveXML();
  78. $this->assertTrue($entryXml == $newCommentEntryXml);
  79. }
  80. public function testSamplePropertiesAreCorrect () {
  81. $this->entry->transferFromXML($this->entryText);
  82. $this->verifyAllSamplePropertiesAreCorrect($this->entry);
  83. }
  84. public function testConvertCommentEntryToAndFromString() {
  85. $this->entry->transferFromXML($this->entryText);
  86. $entryXml = $this->entry->saveXML();
  87. $newCommentEntry = new Zend_Gdata_YouTube_CommentEntry();
  88. $newCommentEntry->transferFromXML($entryXml);
  89. $this->verifyAllSamplePropertiesAreCorrect($newCommentEntry);
  90. $newCommentEntryXml = $newCommentEntry->saveXML();
  91. $this->assertEquals($entryXml, $newCommentEntryXml);
  92. }
  93. }