source: sipes/modules_contrib/feeds/tests/common_syndication_parser.test @ 92213c1

stableversion-3.0
Last change on this file since 92213c1 was 177a560, checked in by José Gregorio Puentes <jpuentes@…>, 8 años ago

se agrego el directorio de modulos contribuidos de drupal

  • Propiedad mode establecida a 100755
File size: 3.8 KB
Línea 
1<?php
2
3/**
4 * Test cases for common syndication parser library.
5 *
6 * @todo Break out into Drupal independent test framework.
7 * @todo Could I use DrupalUnitTestCase here?
8 */
9class CommonSyndicationParserTestCase extends DrupalWebTestCase {
10  public static function getInfo() {
11    return array(
12      'name' => 'Common Syndication Parser',
13      'description' => 'Unit tests for Common Syndication Parser.',
14      'group' => 'Feeds',
15    );
16  }
17
18  public function setUp() {
19    parent::setUp(array('feeds', 'feeds_ui', 'ctools', 'job_scheduler'));
20    feeds_include_library('common_syndication_parser.inc', 'common_syndication_parser');
21  }
22
23  /**
24   * Dispatch tests, only use one entry point method testX to save time.
25   */
26  public function test() {
27    $this->_testRSS10();
28    $this->_testRSS2();
29    $this->_testAtomGeoRSS();
30  }
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  /**
48   * Test RSS 2.
49   */
50  protected function _testRSS2() {
51    $string = $this->readFeed('developmentseed.rss2');
52    $feed = common_syndication_parser_parse($string);
53    $this->assertEqual($feed['title'], 'Development Seed - Technological Solutions for Progressive Organizations');
54    $this->assertEqual($feed['items'][0]['title'], 'Open Atrium Translation Workflow: Two Way Translation Updates');
55    $this->assertEqual($feed['items'][1]['url'], 'http://developmentseed.org/blog/2009/oct/05/week-dc-tech-october-5th-edition');
56    $this->assertEqual($feed['items'][1]['guid'], '973 at http://developmentseed.org');
57    $this->assertEqual($feed['items'][2]['guid'], '972 at http://developmentseed.org');
58    $this->assertEqual($feed['items'][2]['timestamp'], 1254493864);
59  }
60
61  /**
62   * Test Geo RSS in Atom feed.
63   */
64  protected function _testAtomGeoRSS() {
65    $string = $this->readFeed('earthquake-georss.atom');
66    $feed = common_syndication_parser_parse($string);
67    $this->assertEqual($feed['title'], 'USGS M2.5+ Earthquakes');
68    $this->assertEqual($feed['items'][0]['title'], 'M 2.6, Central Alaska');
69    $this->assertEqual($feed['items'][1]['url'], 'http://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/us2010axbz.php');
70    $this->assertEqual($feed['items'][1]['guid'], 'urn:earthquake-usgs-gov:us:2010axbz');
71    $this->assertEqual($feed['items'][2]['guid'], 'urn:earthquake-usgs-gov:us:2010axbr');
72    $this->assertEqual($feed['items'][2]['geolocations'][0]['name'], '-53.1979 -118.0676');
73    $this->assertEqual($feed['items'][2]['geolocations'][0]['lat'], '-53.1979');
74    $this->assertEqual($feed['items'][2]['geolocations'][0]['lon'], '-118.0676');
75    $this->assertEqual($feed['items'][3]['geolocations'][0]['name'], '-43.4371 172.5902');
76    $this->assertEqual($feed['items'][3]['geolocations'][0]['lat'], '-43.4371');
77    $this->assertEqual($feed['items'][3]['geolocations'][0]['lon'], '172.5902');
78  }
79
80  /**
81   * Helper to read a feed.
82   */
83  protected function readFeed($filename) {
84    $feed = dirname(__FILE__) . '/feeds/' . $filename;
85    $handle = fopen($feed, 'r');
86    $string = fread($handle, filesize($feed));
87    fclose($handle);
88    return $string;
89  }
90}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.