Index: modules/aggregator/aggregator.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/aggregator/aggregator.test,v
retrieving revision 1.5
diff -u -r1.5 aggregator.test
--- modules/aggregator/aggregator.test	3 Aug 2008 18:16:51 -0000	1.5
+++ modules/aggregator/aggregator.test	17 Aug 2008 17:26:06 -0000
@@ -522,3 +522,121 @@
     $this->submitImportForm();
   }
 }
+
+class FeedParserTestCase extends AggregatorTestCase {
+  /**
+   * Implementation of getInfo().
+   */
+  function getInfo() {
+    return array(
+      'name' => t('Feed parser tests'),
+      'description' => t("Test Aggregator's built-in feed parser with valid feed samples."),
+      'group' => t('Aggregator'),
+    );
+  }
+
+  function testFeedParser() {
+    $this->_testAtomEntryLinkSample();
+  }
+
+  function addUpdateFeed($edit) {
+    $this->drupalGet($edit['url']);
+    $this->assertResponse(array(200), t('URL !url is accessible', array('!url' => $edit['url'])));
+
+    $this->drupalPost('admin/content/aggregator/add/feed', $edit, t('Save'));
+    $this->assertRaw(t('The feed %name has been added.', array('%name' => $edit['title'])), t('The feed !name has been added.', array('!name' => $edit['title'])));
+
+    $feed = db_fetch_object(db_query("SELECT * FROM {aggregator_feed} WHERE url = '%s'", $edit['url']));
+    $this->drupalGet('admin/content/aggregator/update/' . $feed->fid);
+
+    $this->drupalPost('admin/content/aggregator/remove/' . $feed->fid, array(), t('Remove items'));
+    $this->assertRaw(t('The news items from %title have been removed.', array('%title' => $feed->title)), t('Feed items removed.'));
+
+    $this->drupalGet('admin/content/aggregator/update/' . $feed->fid);
+
+    // Get updated feed information from database.
+    $feed = db_fetch_object(db_query("SELECT * FROM {aggregator_feed} WHERE fid = %d", $feed->fid));
+    return $feed;
+  }
+
+  function _testAtomEntryLinkSample() {
+    $edit = array(
+      'title' => "Example blog",
+      'url' => file_create_url($this->getAtomEntryLinkSample()),
+    );
+    $feed = $this->addUpdateFeed($edit);
+
+    $result = db_query('SELECT * FROM {aggregator_item} WHERE fid = %d', $feed->fid);
+    $items = array();
+    while ($item = db_fetch_object($result)) {
+      $items[] = $item;
+    }
+    $this->assertEqual($items[0]->link, 'http://www.example.com/post-1', t('Link !link', array('!link' => $items[0]->link)));
+    $this->assertEqual($items[1]->link, 'http://www.example.com/post-2', t('Link !link', array('!link' => $items[1]->link)));
+    $this->assertEqual($items[2]->link, 'http://www.example.com/post-3', t('Link !link', array('!link' => $items[2]->link)));
+  }
+
+  /**
+   * Sample Atom formatted feed.
+   *
+   * @see http://drupal.org/node/130344
+   */
+  function getAtomEntryLinkSample() {
+    $feed = <<<EOF
+<?xml version='1.0' encoding='UTF-8'?>
+<feed xmlns='http://www.w3.org/2005/Atom'>
+  <id>tag:example.com,1999:blog</id>
+  <updated>2008-08-15T13:18:44.515-04:00</updated>
+  <title type='text'>Example blog</title>
+  <link rel='alternate' type='text/html' href='http://www.example.com/'/>
+  <link rel='self' type='application/atom+xml' href='http://www.example.com/rss.xml'/>
+  <entry>
+    <id>tag:example.com,1999:blog.post-1</id>
+    <published>2008-08-13T04:55:00.003-04:00</published>
+    <updated>2008-08-13T05:13:11.626-04:00</updated>
+    <title type='text'>Post one</title>
+    <content type='html'>Example blog post one</content>
+    <link rel='alternate' type='text/html' href='http://www.example.com/post-1' title='Post one'/>
+    <link rel='self' type='application/atom+xml' href='http://www.example.com/post-1/edit'/>
+    <author>
+      <name>Tim</name>
+      <uri>http://www.example.com/profile</uri>
+      <email>noreply@example.com</email>
+    </author>
+  </entry>
+  <entry>
+    <id>tag:example.com,1999:blog.post-2</id>
+    <published>2008-08-12T12:51:00.003-04:00</published>
+    <updated>2008-08-13T06:04:43.803-04:00</updated>
+    <title type='text'>Post two</title>
+    <content type='html'>Example blog post two</content>
+    <link rel='alternate' type='text/html' href='http://www.example.com/post-2' title='Post two'/>
+    <link rel='self' type='application/atom+xml' href='http://www.example.com/post-2/edit'/>
+    <author>
+      <name>Tim</name>
+      <uri>http://www.example.com/profile</uri>
+      <email>noreply@example.com</email>
+    </author>
+  </entry>
+  <entry>
+    <id>tag:example.com,1999:blog.post-3</id>
+    <published>2008-08-12T10:49:00.002-04:00</published>
+    <updated>2008-08-12T11:22:09.742-04:00</updated>
+    <title type='text'>Post three</title>
+    <content type='html'>Example blog post three</content>
+    <link rel='alternate' type='text/html' href='http://www.example.com/post-3' title='Post three'/>
+    <link rel='self' type='application/atom+xml' href='http://www.example.com/post-3/edit'/>
+    <author>
+      <name>Tim</name>
+      <uri>http://www.example.com/profile</uri>
+      <email>noreply@example.com</email>
+    </author>
+  </entry>
+</feed>
+EOF;
+
+    $path = file_directory_path() . '/atom-entry-link.xml';
+    file_save_data($feed, $path);
+    return $path;
+  }
+}
