ActivityEntryTest.php 6.4 KB

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