function CategorizeFeedTestCase::testCategorizeFeed
7.x aggregator.test | CategorizeFeedTestCase::testCategorizeFeed() |
Creates a feed and makes sure you can add more than one category to it.
File
- drupal-7.x/
modules/ aggregator/ aggregator.test, line 419 - Tests for aggregator.module.
Class
- CategorizeFeedTestCase
- Tests the categorize feed functionality in the Aggregator module.
Code
function testCategorizeFeed() {
// Create 2 categories.
$category_1 = array('title' => $this->randomName(10), 'description' => '');
$this->drupalPost('admin/config/services/aggregator/add/category', $category_1, t('Save'));
$this->assertRaw(t('The category %title has been added.', array('%title' => $category_1['title'])), format_string('The category %title has been added.', array('%title' => $category_1['title'])));
$category_2 = array('title' => $this->randomName(10), 'description' => '');
$this->drupalPost('admin/config/services/aggregator/add/category', $category_2, t('Save'));
$this->assertRaw(t('The category %title has been added.', array('%title' => $category_2['title'])), format_string('The category %title has been added.', array('%title' => $category_2['title'])));
// Get categories from database.
$categories = $this->getCategories();
// Create a feed and assign 2 categories to it.
$feed = $this->getFeedEditArray();
$feed['block'] = 5;
foreach ($categories as $cid => $category) {
$feed['category'][$cid] = $cid;
}
// Use aggregator_save_feed() function to save the feed.
aggregator_save_feed($feed);
$db_feed = db_query("SELECT * FROM {aggregator_feed} WHERE title = :title AND url = :url", array(':title' => $feed['title'], ':url' => $feed['url']))->fetch();
// Assert the feed has two categories.
$this->getFeedCategories($db_feed);
$this->assertEqual(count($db_feed->categories), 2, 'Feed has 2 categories');
}