ActivityFeedTest.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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/ActivityFeed.php';
  26. require_once 'Zend/Gdata/YouTube.php';
  27. /**
  28. * @package Zend_Gdata_YouTube
  29. * @subpackage UnitTests
  30. */
  31. class Zend_Gdata_YouTube_ActivityFeedTest extends PHPUnit_Framework_TestCase
  32. {
  33. public function setUp() {
  34. $this->feedText = file_get_contents(
  35. 'Zend/Gdata/YouTube/_files/ActivityFeedDataSample1.xml',
  36. true);
  37. $this->feed = new Zend_Gdata_YouTube_ActivityFeed();
  38. $this->feed->setMajorProtocolVersion(2);
  39. }
  40. private function verifyAllSamplePropertiesAreCorrect ($activityFeed) {
  41. $this->assertEquals('2009-01-28T09:13:49.000-08:00',
  42. $activityFeed->updated->text);
  43. $this->assertEquals(
  44. 'http://schemas.google.com/g/2005#kind',
  45. $activityFeed->category[0]->scheme);
  46. $this->assertEquals('http://gdata.youtube.com/schemas/2007#userEvent',
  47. $activityFeed->category[0]->term);
  48. $this->assertEquals('Activity of tayzonzay',
  49. $activityFeed->title->text);;
  50. $this->assertEquals('self', $activityFeed->getLink('self')->rel);
  51. $this->assertEquals('application/atom+xml',
  52. $activityFeed->getLink('self')->type);
  53. $this->assertEquals(
  54. 'http://gdata.youtube.com/feeds/api/events?author=gdpython' .
  55. '&start-index=1&max-results=25&v=2',
  56. $activityFeed->getLink('self')->href);
  57. $this->assertEquals('http://schemas.google.com/g/2005#feed',
  58. $activityFeed->getLink(
  59. 'http://schemas.google.com/g/2005#feed')->rel);
  60. $this->assertEquals('application/atom+xml',
  61. $activityFeed->getLink(
  62. 'http://schemas.google.com/g/2005#feed')->type);
  63. $this->assertEquals('http://gdata.youtube.com/feeds/api/events?v=2',
  64. $activityFeed->getLink(
  65. 'http://schemas.google.com/g/2005#feed')->href);
  66. $this->assertEquals('http://schemas.google.com/g/2005#batch',
  67. $activityFeed->getLink(
  68. 'http://schemas.google.com/g/2005#batch')->rel);
  69. $this->assertEquals('application/atom+xml',
  70. $activityFeed->getLink(
  71. 'http://schemas.google.com/g/2005#batch')->type);
  72. $this->assertEquals(
  73. 'application/atom+xml',
  74. $activityFeed->getLink(
  75. 'http://schemas.google.com/g/2005#batch')->type);
  76. $this->assertEquals('service',
  77. $activityFeed->getLink('service')->rel);
  78. $this->assertEquals('application/atomsvc+xml',
  79. $activityFeed->getLink('service')->type);
  80. $this->assertEquals(
  81. 'http://gdata.youtube.com/feeds/api/events?alt=atom-service&v=2',
  82. $activityFeed->getLink('service')->href);
  83. $this->assertEquals('YouTube', $activityFeed->author[0]->name->text);
  84. $this->assertEquals('http://www.youtube.com/',
  85. $activityFeed->author[0]->uri->text);
  86. $this->assertEquals(12, $activityFeed->totalResults->text);
  87. $this->assertEquals(1, $activityFeed->startIndex->text);
  88. $this->assertEquals(25, $activityFeed->itemsPerPage->text);
  89. }
  90. public function testEmptyEntryShouldHaveNoExtensionElements() {
  91. $this->assertTrue(is_array($this->feed->extensionElements));
  92. $this->assertEquals(0, count($this->feed->extensionElements));
  93. }
  94. public function testEmptyEntryShouldHaveNoExtensionAttributes() {
  95. $this->assertTrue(is_array($this->feed->extensionAttributes));
  96. $this->assertEquals(0, count($this->feed->extensionAttributes));
  97. }
  98. public function testSampleEntryShouldHaveNoExtensionElements() {
  99. $this->feed->transferFromXML($this->feedText);
  100. $this->assertTrue(is_array($this->feed->extensionElements));
  101. $this->assertEquals(0, count($this->feed->extensionElements));
  102. }
  103. public function testSampleEntryShouldHaveNoExtensionAttributes() {
  104. $this->feed->transferFromXML($this->feedText);
  105. $this->assertTrue(is_array($this->feed->extensionAttributes));
  106. $this->assertEquals(0, count($this->feed->extensionAttributes));
  107. }
  108. public function testEmptyActivityFeedToAndFromStringShouldMatch() {
  109. $entryXml = $this->feed->saveXML();
  110. $newActivityFeed = new Zend_Gdata_YouTube_ActivityFeed();
  111. $newActivityFeed->transferFromXML($entryXml);
  112. $newActivityFeedXml = $newActivityFeed->saveXML();
  113. $this->assertTrue($entryXml == $newActivityFeedXml);
  114. }
  115. public function testSamplePropertiesAreCorrect () {
  116. $this->feed->transferFromXML($this->feedText);
  117. $this->verifyAllSamplePropertiesAreCorrect($this->feed);
  118. }
  119. public function testConvertActivityFeedToAndFromString() {
  120. $this->feed->transferFromXML($this->feedText);
  121. $entryXml = $this->feed->saveXML();
  122. $newActivityFeed = new Zend_Gdata_YouTube_ActivityFeed();
  123. $newActivityFeed->transferFromXML($entryXml);
  124. $this->verifyAllSamplePropertiesAreCorrect($newActivityFeed);
  125. $newActivityFeedXml = $newActivityFeed->saveXML();
  126. $this->assertEquals($entryXml, $newActivityFeedXml);
  127. }
  128. public function testEntryCanBeRetrieved() {
  129. $this->feed->transferFromXML($this->feedText);
  130. $this->assertTrue(count($this->feed->entries) > 0);
  131. }
  132. }