common_syndication_parser.test

  1. nittany7 modules/contrib/feeds/tests/common_syndication_parser.test
  2. cis7 modules/contrib/feeds/tests/common_syndication_parser.test
  3. mooc7 modules/contrib/feeds/tests/common_syndication_parser.test

Tests for the common syndication parser.

Classes

Namesort descending Description
CommonSyndicationParserTestCase Test cases for common syndication parser library.

File

modules/contrib/feeds/tests/common_syndication_parser.test
View source
  1. <?php
  2. /**
  3. * @file
  4. * Tests for the common syndication parser.
  5. */
  6. /**
  7. * Test cases for common syndication parser library.
  8. *
  9. * @todo Break out into Drupal independent test framework.
  10. * @todo Could I use DrupalUnitTestCase here?
  11. */
  12. class CommonSyndicationParserTestCase extends DrupalWebTestCase {
  13. public static function getInfo() {
  14. return array(
  15. 'name' => 'Common Syndication Parser',
  16. 'description' => 'Unit tests for Common Syndication Parser.',
  17. 'group' => 'Feeds',
  18. );
  19. }
  20. public function setUp() {
  21. parent::setUp(array('feeds', 'feeds_ui', 'ctools', 'job_scheduler'));
  22. feeds_include_library('common_syndication_parser.inc', 'common_syndication_parser');
  23. }
  24. /**
  25. * Dispatch tests, only use one entry point method testX to save time.
  26. */
  27. public function test() {
  28. $this->_testRSS10();
  29. $this->_testRSS2();
  30. $this->_testAtomGeoRSS();
  31. }
  32. /**
  33. * Test RSS 1.0.
  34. */
  35. protected function _testRSS10() {
  36. $string = $this->readFeed('magento.rss1');
  37. $feed = common_syndication_parser_parse($string);
  38. $this->assertEqual($feed['title'], 'Magento Sites Network - A directory listing of Magento Commerce stores');
  39. $this->assertEqual($feed['items'][0]['title'], 'Gezondheidswebwinkel');
  40. $this->assertEqual($feed['items'][0]['url'], 'http://www.magentosites.net/store/2010/04/28/gezondheidswebwinkel/index.html');
  41. $this->assertEqual($feed['items'][1]['url'], 'http://www.magentosites.net/store/2010/04/26/mybobinocom/index.html');
  42. $this->assertEqual($feed['items'][1]['guid'], 'http://www.magentosites.net/node/3472');
  43. $this->assertEqual($feed['items'][2]['guid'], 'http://www.magentosites.net/node/3471');
  44. $this->assertEqual($feed['items'][2]['timestamp'], 1272285294);
  45. }
  46. /**
  47. * Test RSS 2.
  48. */
  49. protected function _testRSS2() {
  50. $string = $this->readFeed('developmentseed.rss2');
  51. $feed = common_syndication_parser_parse($string);
  52. $this->assertEqual($feed['title'], 'Development Seed - Technological Solutions for Progressive Organizations');
  53. $this->assertEqual($feed['items'][0]['title'], 'Open Atrium Translation Workflow: Two Way Translation Updates');
  54. $this->assertEqual($feed['items'][1]['url'], 'http://developmentseed.org/blog/2009/oct/05/week-dc-tech-october-5th-edition');
  55. $this->assertEqual($feed['items'][1]['guid'], '973 at http://developmentseed.org');
  56. $this->assertEqual($feed['items'][2]['guid'], '972 at http://developmentseed.org');
  57. $this->assertEqual($feed['items'][2]['timestamp'], 1254493864);
  58. }
  59. /**
  60. * Test Geo RSS in Atom feed.
  61. */
  62. protected function _testAtomGeoRSS() {
  63. $string = $this->readFeed('earthquake-georss.atom');
  64. $feed = common_syndication_parser_parse($string);
  65. $this->assertEqual($feed['title'], 'USGS M2.5+ Earthquakes');
  66. $this->assertEqual($feed['items'][0]['title'], 'M 2.6, Central Alaska');
  67. $this->assertEqual($feed['items'][1]['url'], 'http://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/us2010axbz.php');
  68. $this->assertEqual($feed['items'][1]['guid'], 'urn:earthquake-usgs-gov:us:2010axbz');
  69. $this->assertEqual($feed['items'][2]['guid'], 'urn:earthquake-usgs-gov:us:2010axbr');
  70. $this->assertEqual($feed['items'][2]['geolocations'][0]['name'], '-53.1979 -118.0676');
  71. $this->assertEqual($feed['items'][2]['geolocations'][0]['lat'], '-53.1979');
  72. $this->assertEqual($feed['items'][2]['geolocations'][0]['lon'], '-118.0676');
  73. $this->assertEqual($feed['items'][3]['geolocations'][0]['name'], '-43.4371 172.5902');
  74. $this->assertEqual($feed['items'][3]['geolocations'][0]['lat'], '-43.4371');
  75. $this->assertEqual($feed['items'][3]['geolocations'][0]['lon'], '172.5902');
  76. }
  77. /**
  78. * Helper to read a feed.
  79. */
  80. protected function readFeed($filename) {
  81. $feed = dirname(__FILE__) . '/feeds/' . $filename;
  82. $handle = fopen($feed, 'r');
  83. $string = fread($handle, filesize($feed));
  84. fclose($handle);
  85. return $string;
  86. }
  87. }