ActivityEntryTest.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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) 2009 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/ActivityEntry.php';
  26. require_once 'Zend/Gdata/YouTube.php';
  27. /**
  28. * @package Zend_Gdata_YouTube
  29. * @subpackage UnitTests
  30. */
  31. class Zend_Gdata_YouTube_ActivityEntryTest extends PHPUnit_Framework_TestCase
  32. {
  33. public function setUp() {
  34. $this->entryText = file_get_contents(
  35. 'Zend/Gdata/YouTube/_files/ActivityEntryDataSample1.xml',
  36. true);
  37. $this->entry = new Zend_Gdata_YouTube_ActivityEntry();
  38. $this->entry->setMajorProtocolVersion(2);
  39. }
  40. private function verifyAllSamplePropertiesAreCorrect ($activityEntry) {
  41. $this->assertEquals(
  42. 'tag:youtube.com,2008:event:Z2RweXRob24xMTIzNDMwMDAyMzI5NTQ2N' .
  43. 'zg2MA%3D%3D',
  44. $activityEntry->id->text);
  45. $this->assertEquals('2009-01-16T09:13:49.000-08:00',
  46. $activityEntry->updated->text);
  47. $this->assertEquals(
  48. 'http://gdata.youtube.com/schemas/2007/userevents.cat',
  49. $activityEntry->category[0]->scheme);
  50. $this->assertEquals('video_favorited',
  51. $activityEntry->category[0]->term);
  52. $this->assertEquals('http://schemas.google.com/g/2005#kind',
  53. $activityEntry->category[1]->scheme);
  54. $this->assertEquals('http://gdata.youtube.com/schemas/2007#userEvent',
  55. $activityEntry->category[1]->term);
  56. $this->assertEquals('tayzonzay has favorited a video',
  57. $activityEntry->title->text);;
  58. $this->assertEquals('self', $activityEntry->getLink('self')->rel);
  59. $this->assertEquals('application/atom+xml',
  60. $activityEntry->getLink('self')->type);
  61. $this->assertEquals(
  62. 'http://gdata.youtube.com/feeds/api/events/VGF5Wm9uZGF5MzEyaIl2' .
  63. 'MTMxOTcxMDk3NzQ5MzM%3D?v=2',
  64. $activityEntry->getLink('self')->href);
  65. $this->assertEquals('alternate',
  66. $activityEntry->getLink('alternate')->rel);
  67. $this->assertEquals('text/html',
  68. $activityEntry->getLink('alternate')->type);
  69. $this->assertEquals('http://www.youtube.com',
  70. $activityEntry->getLink('alternate')->href);
  71. $this->assertEquals('http://gdata.youtube.com/schemas/2007#video',
  72. $activityEntry->getLink(
  73. 'http://gdata.youtube.com/schemas/2007#video')->rel);
  74. $this->assertEquals('application/atom+xml', $activityEntry->getLink(
  75. 'http://gdata.youtube.com/schemas/2007#video')->type);
  76. $this->assertEquals(
  77. 'http://gdata.youtube.com/feeds/api/videos/z3U0kuLH974?v=2',
  78. $activityEntry->getLink(
  79. 'http://gdata.youtube.com/schemas/2007#video')->href);
  80. $this->assertEquals('tayzonzay', $activityEntry->author[0]->name->text);
  81. $this->assertEquals(
  82. 'http://gdata.youtube.com/feeds/api/users/tayzonzay',
  83. $activityEntry->author[0]->uri->text);
  84. }
  85. public function testEmptyEntryShouldHaveNoExtensionElements() {
  86. $this->assertTrue(is_array($this->entry->extensionElements));
  87. $this->assertTrue(count($this->entry->extensionElements) == 0);
  88. }
  89. public function testEmptyEntryShouldHaveNoExtensionAttributes() {
  90. $this->assertTrue(is_array($this->entry->extensionAttributes));
  91. $this->assertTrue(count($this->entry->extensionAttributes) == 0);
  92. }
  93. public function testSampleEntryShouldHaveNoExtensionElements() {
  94. $this->entry->transferFromXML($this->entryText);
  95. $this->assertTrue(is_array($this->entry->extensionElements));
  96. $this->assertTrue(count($this->entry->extensionElements) == 0);
  97. }
  98. public function testSampleEntryShouldHaveNoExtensionAttributes() {
  99. $this->entry->transferFromXML($this->entryText);
  100. $this->assertTrue(is_array($this->entry->extensionAttributes));
  101. $this->assertTrue(count($this->entry->extensionAttributes) == 0);
  102. }
  103. public function testEmptyActivityEntryToAndFromStringShouldMatch() {
  104. $entryXml = $this->entry->saveXML();
  105. $newActivityEntry = new Zend_Gdata_YouTube_ActivityEntry();
  106. $newActivityEntry->transferFromXML($entryXml);
  107. $newActivityEntryXml = $newActivityEntry->saveXML();
  108. $this->assertTrue($entryXml == $newActivityEntryXml);
  109. }
  110. public function testSamplePropertiesAreCorrect () {
  111. $this->entry->transferFromXML($this->entryText);
  112. $this->verifyAllSamplePropertiesAreCorrect($this->entry);
  113. }
  114. public function testHelperMethods() {
  115. $this->entry->transferFromXML($this->entryText);
  116. $this->assertEquals('z3U0kuLH974',
  117. $this->entry->getVideoId()->getText());
  118. $this->assertEquals('foo',
  119. $this->entry->getUsername()->getText());
  120. $this->assertEquals('2',
  121. $this->entry->getRatingValue());
  122. $this->assertEquals('video_favorited',
  123. $this->entry->getActivityType());
  124. }
  125. public function testConvertActivityEntryToAndFromString() {
  126. $this->entry->transferFromXML($this->entryText);
  127. $entryXml = $this->entry->saveXML();
  128. $newActivityEntry = new Zend_Gdata_YouTube_ActivityEntry();
  129. $newActivityEntry->transferFromXML($entryXml);
  130. $this->verifyAllSamplePropertiesAreCorrect($newActivityEntry);
  131. $newActivityEntryXml = $newActivityEntry->saveXML();
  132. $this->assertEquals($entryXml, $newActivityEntryXml);
  133. }
  134. }