1
|
<?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
|
$this->_testAtomGeoRSSWithoutAuthor();
|
36
|
}
|
37
|
|
38
|
/**
|
39
|
* Test RSS 1.0.
|
40
|
*/
|
41
|
protected function _testRSS10() {
|
42
|
$string = $this->readFeed('magento.rss1');
|
43
|
$feed = common_syndication_parser_parse($string);
|
44
|
$this->assertEqual($feed['title'], 'Magento Sites Network - A directory listing of Magento Commerce stores');
|
45
|
$this->assertEqual($feed['items'][0]['title'], 'Gezondheidswebwinkel');
|
46
|
$this->assertEqual($feed['items'][0]['url'], 'http://www.magentosites.net/store/2010/04/28/gezondheidswebwinkel/index.html');
|
47
|
$this->assertEqual($feed['items'][1]['url'], 'http://www.magentosites.net/store/2010/04/26/mybobinocom/index.html');
|
48
|
$this->assertEqual($feed['items'][1]['guid'], 'http://www.magentosites.net/node/3472');
|
49
|
$this->assertEqual($feed['items'][2]['guid'], 'http://www.magentosites.net/node/3471');
|
50
|
$this->assertEqual($feed['items'][2]['timestamp'], 1272285294);
|
51
|
}
|
52
|
|
53
|
/**
|
54
|
* Test RSS 2.
|
55
|
*/
|
56
|
protected function _testRSS2() {
|
57
|
$string = $this->readFeed('developmentseed.rss2');
|
58
|
$feed = common_syndication_parser_parse($string);
|
59
|
$this->assertEqual($feed['title'], 'Development Seed - Technological Solutions for Progressive Organizations');
|
60
|
$this->assertEqual($feed['items'][0]['title'], 'Open Atrium Translation Workflow: Two Way Translation Updates');
|
61
|
$this->assertEqual($feed['items'][1]['url'], 'http://developmentseed.org/blog/2009/oct/05/week-dc-tech-october-5th-edition');
|
62
|
$this->assertEqual($feed['items'][1]['guid'], '973 at http://developmentseed.org');
|
63
|
$this->assertEqual($feed['items'][2]['guid'], '972 at http://developmentseed.org');
|
64
|
$this->assertEqual($feed['items'][2]['timestamp'], 1254493864);
|
65
|
}
|
66
|
|
67
|
/**
|
68
|
* Test Geo RSS in Atom feed.
|
69
|
*/
|
70
|
protected function _testAtomGeoRSS() {
|
71
|
$string = $this->readFeed('earthquake-georss.atom');
|
72
|
$feed = common_syndication_parser_parse($string);
|
73
|
$this->assertEqual($feed['title'], 'USGS M2.5+ Earthquakes');
|
74
|
$this->assertEqual($feed['items'][0]['title'], 'M 2.6, Central Alaska');
|
75
|
$this->assertEqual($feed['items'][1]['url'], 'http://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/us2010axbz.php');
|
76
|
$this->assertEqual($feed['items'][1]['guid'], 'urn:earthquake-usgs-gov:us:2010axbz');
|
77
|
$this->assertEqual($feed['items'][2]['guid'], 'urn:earthquake-usgs-gov:us:2010axbr');
|
78
|
$this->assertEqual($feed['items'][2]['geolocations'][0]['name'], '-53.1979 -118.0676');
|
79
|
$this->assertEqual($feed['items'][2]['geolocations'][0]['lat'], '-53.1979');
|
80
|
$this->assertEqual($feed['items'][2]['geolocations'][0]['lon'], '-118.0676');
|
81
|
$this->assertEqual($feed['items'][3]['geolocations'][0]['name'], '-43.4371 172.5902');
|
82
|
$this->assertEqual($feed['items'][3]['geolocations'][0]['lat'], '-43.4371');
|
83
|
$this->assertEqual($feed['items'][3]['geolocations'][0]['lon'], '172.5902');
|
84
|
}
|
85
|
|
86
|
/**
|
87
|
* Tests parsing an Atom feed without an author.
|
88
|
*/
|
89
|
protected function _testAtomGeoRSSWithoutAuthor() {
|
90
|
$string = $this->readFeed('earthquake-georss-noauthor.atom');
|
91
|
$feed = common_syndication_parser_parse($string);
|
92
|
}
|
93
|
|
94
|
/**
|
95
|
* Helper to read a feed.
|
96
|
*/
|
97
|
protected function readFeed($filename) {
|
98
|
$feed = dirname(__FILE__) . '/feeds/' . $filename;
|
99
|
$handle = fopen($feed, 'r');
|
100
|
$string = fread($handle, filesize($feed));
|
101
|
fclose($handle);
|
102
|
return $string;
|
103
|
}
|
104
|
}
|