diff --git a/modules/aggregator/aggregator.parser.inc b/modules/aggregator/aggregator.parser.inc
index 5eb84db42f9..4b1ff205327 100644
--- a/modules/aggregator/aggregator.parser.inc
+++ b/modules/aggregator/aggregator.parser.inc
@@ -177,7 +177,6 @@ function aggregator_element_start($parser, $name, $attributes) {
switch ($name) {
case 'image':
case 'textinput':
- case 'content':
case 'summary':
case 'tagline':
case 'subtitle':
@@ -186,16 +185,20 @@ function aggregator_element_start($parser, $name, $attributes) {
$element = $name;
break;
case 'id':
+ case 'content':
if ($element != 'item') {
$element = $name;
}
case 'link':
- if (!empty($attributes['rel']) && $attributes['rel'] == 'alternate') {
+ // According to RFC 4287, link elements in Atom feeds without a 'rel'
+ // attribute should be interpreted as though the relation type is
+ // "alternate".
+ if (!empty($attributes['HREF']) && (empty($attributes['REL']) || $attributes['REL'] == 'alternate')) {
if ($element == 'item') {
- $items[$item]['link'] = $attributes['href'];
+ $items[$item]['link'] = $attributes['HREF'];
}
else {
- $channel['link'] = $attributes['href'];
+ $channel['link'] = $attributes['HREF'];
}
}
break;
@@ -223,12 +226,12 @@ function aggregator_element_end($parser, $name) {
case 'textinput':
case 'item':
case 'entry':
- case 'content':
case 'info':
$element = '';
break;
case 'id':
- if ($element == 'id') {
+ case 'content':
+ if ($element == $name) {
$element = '';
}
}
diff --git a/modules/aggregator/aggregator.test b/modules/aggregator/aggregator.test
index 93e77f98907..b37c0f93356 100644
--- a/modules/aggregator/aggregator.test
+++ b/modules/aggregator/aggregator.test
@@ -248,6 +248,12 @@ EOF;
return $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'aggregator') . '/tests/aggregator_test_rss091.xml';
}
+ function getAtomSample() {
+ // The content of this sample ATOM feed is based directly off of the
+ // example provided in RFC 4287.
+ return $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'aggregator') . '/tests/aggregator_test_atom.xml';
+ }
+
function createSampleNodes() {
$langcode = LANGUAGE_NONE;
// Post 5 articles.
@@ -686,3 +692,51 @@ class AggregatorCronTestCase extends AggregatorTestCase {
$this->assertEqual(5, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->fid))->fetchField(), 'Expected number of items in database.');
}
}
+
+/**
+ * Tests for feed parsing.
+ */
+class FeedParserTestCase extends AggregatorTestCase {
+ function getInfo() {
+ return array(
+ 'name' => 'Feed parser functionality',
+ 'description' => 'Test the built-in feed parser with valid feed samples.',
+ 'group' => 'Aggregator',
+ );
+ }
+
+ function setUp() {
+ parent::setUp();
+ // Do not remove old aggregator items during these tests, since our sample
+ // feeds have hardcoded dates in them (which may be expired when this test
+ // is run).
+ variable_set('aggregator_clear', AGGREGATOR_CLEAR_NEVER);
+ }
+
+ /**
+ * Test a feed that uses the RSS 0.91 format.
+ */
+ function testRSS091Sample() {
+ $feed = $this->createFeed($this->getRSS091Sample());
+ aggregator_refresh($feed);
+ $this->drupalGet('aggregator/sources/' . $feed->fid);
+ $this->assertResponse(200, t('Feed %name exists.', array('%name' => $feed->title)));
+ $this->assertText('First example feed item title');
+ $this->assertLinkByHref('http://example.com/example-turns-one');
+ $this->assertText('First example feed item description.');
+ }
+
+ /**
+ * Test a feed that uses the Atom format.
+ */
+ function testAtomSample() {
+ $feed = $this->createFeed($this->getAtomSample());
+ aggregator_refresh($feed);
+ $this->drupalGet('aggregator/sources/' . $feed->fid);
+ $this->assertResponse(200, t('Feed %name exists.', array('%name' => $feed->title)));
+ $this->assertText('Atom-Powered Robots Run Amok');
+ $this->assertLinkByHref('http://example.org/2003/12/13/atom03');
+ $this->assertText('Some text.');
+ }
+}
+
diff --git a/modules/aggregator/tests/aggregator_test_atom.xml b/modules/aggregator/tests/aggregator_test_atom.xml
new file mode 100644
index 00000000000..357b2e5a156
--- /dev/null
+++ b/modules/aggregator/tests/aggregator_test_atom.xml
@@ -0,0 +1,20 @@
+
+
+
+ Example Feed
+
+ 2003-12-13T18:30:02Z
+
+ John Doe
+
+ urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6
+
+
+ Atom-Powered Robots Run Amok
+
+ urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a
+ 2003-12-13T18:30:02Z
+ Some text.
+
+
+
diff --git a/modules/aggregator/tests/aggregator_test_rss091.xml b/modules/aggregator/tests/aggregator_test_rss091.xml
index 9576f7c164f..1fd5320d3e9 100644
--- a/modules/aggregator/tests/aggregator_test_rss091.xml
+++ b/modules/aggregator/tests/aggregator_test_rss091.xml
@@ -17,14 +17,14 @@
Example updates
- Example turns one
+ First example feed item title
http://example.com/example-turns-one
- Example turns one.
+ First example feed item description.
- Example turns two
+ Second example feed item title
http://example.com/example-turns-two
- Example turns two.
+ Second example feed item description.
-
\ No newline at end of file
+