function CategorizeFeedItemTestCase::testCategorizeFeedItem
7.x aggregator.test | CategorizeFeedItemTestCase::testCategorizeFeedItem() |
Checks that children of a feed inherit a defined category.
If a feed has a category, make sure that the children inherit that categorization.
File
- drupal-7.x/
modules/ aggregator/ aggregator.test, line 645 - Tests for aggregator.module.
Class
- CategorizeFeedItemTestCase
- Tests categorization functionality in the Aggregator module.
Code
function testCategorizeFeedItem() {
$this->createSampleNodes();
// Simulate form submission on "admin/config/services/aggregator/add/category".
$edit = array('title' => $this->randomName(10), 'description' => '');
$this->drupalPost('admin/config/services/aggregator/add/category', $edit, t('Save'));
$this->assertRaw(t('The category %title has been added.', array('%title' => $edit['title'])), format_string('The category %title has been added.', array('%title' => $edit['title'])));
$category = db_query("SELECT * FROM {aggregator_category} WHERE title = :title", array(':title' => $edit['title']))->fetch();
$this->assertTrue(!empty($category), 'The category found in database.');
$link_path = 'aggregator/categories/' . $category->cid;
$menu_link = db_query("SELECT * FROM {menu_links} WHERE link_path = :link_path", array(':link_path' => $link_path))->fetch();
$this->assertTrue(!empty($menu_link), 'The menu link associated with the category found in database.');
$feed = $this->createFeed();
db_insert('aggregator_category_feed')
->fields(array(
'cid' => $category->cid,
'fid' => $feed->fid,
))
->execute();
$this->updateFeedItems($feed, $this->getDefaultFeedItemCount());
$this->getFeedCategories($feed);
$this->assertTrue(!empty($feed->categories), 'The category found in the feed.');
// For each category of a feed, ensure feed items have that category, too.
if (!empty($feed->categories) && !empty($feed->items)) {
foreach ($feed->categories as $category) {
$categorized_count = db_select('aggregator_category_item')
->condition('iid', $feed->items, 'IN')
->countQuery()
->execute()
->fetchField();
$this->assertEqual($feed->item_count, $categorized_count, 'Total items in feed equal to the total categorized feed items in database');
}
}
// Delete feed.
$this->deleteFeed($feed);
}