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