$this->assertRaw(t('The feed %name has been added.',array('%name'=>$edit['title'])),t('The feed !name has been added.',array('!name'=>$edit['title'])));
...
...
@@ -38,11 +43,16 @@ class AggregatorTestCase extends DrupalWebTestCase {
/**
* Return a randomly generated feed edit array.
*
* @return array Feed array.
* @param $feed_url
* If given, feed will be created with this URL, otherwise /rss.xml will be used.
@@ -51,20 +61,30 @@ class AggregatorTestCase extends DrupalWebTestCase {
return$edit;
}
/**
* Return the count of the randomly created feed array.
*
* @return
* Number of feed items on default feed created by createFeed().
*/
functiongetDefaultFeedItemCount(){
// Our tests are based off of rss.xml, so let's find out how many elements should be related.
$feed_count=db_query_range('SELECT COUNT(*) FROM {node} n WHERE n.promote = 1 AND n.status = 1',0,variable_get('feed_default_items',10))->fetchField();
return$feed_count>10?10:$feed_count;
}
/**
* Update feed items (simulate click to admin/content/aggregator/update/$fid).
*
* @param object $feed Feed object representing the feed.
* @param $feed
* Feed object representing the feed.
* @param $expected_count
* Expected number of feed items.
*/
functionupdateFeedItems(&$feed){
functionupdateFeedItems(&$feed,$expected_count){
// First, let's ensure we can get to the rss xml.
$this->drupalGet('rss.xml');
$this->assertResponse(200,t('rss.xml is reachable.'));
// Our tests are based off of rss.xml, so let's find out how many elements should be related.
// @todo: remove db_rewrite_sql() when possible
$feed_count=db_query_range(db_rewrite_sql('SELECT COUNT(*) FROM {node} n WHERE n.promote = 1 AND n.status = 1'),0,variable_get('feed_default_items',10))->fetchField();
$feed_count=$feed_count>10?10:$feed_count;
$this->drupalGet($feed->url);
$this->assertResponse(200,t('!url is reachable.',array('!url'=>$feed->url)));
@@ -77,7 +97,7 @@ class AggregatorTestCase extends DrupalWebTestCase {
$feed->items[]=$item->iid;
}
$feed->item_count=count($feed->items);
$this->assertEqual($feed_count,$feed->item_count,t('Total items in feed equal to the total items in database (!val1 != !val2)',array('!val1'=>$feed_count,'!val2'=>$feed->item_count)));
$this->assertEqual($expected_count,$feed->item_count,t('Total items in feed equal to the total items in database (!val1 != !val2)',array('!val1'=>$expected_count,'!val2'=>$feed->item_count)));
}
/**
...
...
@@ -90,6 +110,22 @@ class AggregatorTestCase extends DrupalWebTestCase {
$this->assertRaw(t('The news items from %title have been removed.',array('%title'=>$feed->title)),t('Feed items removed.'));
}
/**
* Add and remove feed items and ensure that the count is zero.
*
* @param $feed
* Feed object representing the feed.
* @param $expected_count
* Expected number of feed items.
*/
functionupdateAndRemove($feed,$expected_count){
$this->updateFeedItems($feed,$expected_count);
$this->assertText('There is new syndicated content from');
$this->removeFeedItems($feed);
$count=db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid',array(':fid'=>$feed->fid))->fetchField();
$this->assertTrue($count==0);
}
/**
* Pull feed categories from aggregator_category_feed table.
*
...
...
@@ -192,36 +228,7 @@ EOF;
}
functiongetRSS091Sample(){
$feed=<<<EOT
<?xml version="1.0" encoding="UTF-8"?>
<rss version="0.91">
<channel>
<title>Example</title>
<link>http://example.com</link>
<description>Example updates</description>
<language>en-us</language>
<copyright>Copyright 2000, Example team.</copyright>