Commit d30b2bad authored by Dries's avatar Dries
Browse files

- Patch #865970 by swentel: can't assign more than one category to a source.

parent 27555328
......@@ -547,9 +547,9 @@ function aggregator_save_feed($edit) {
if (!empty($edit['category'])) {
foreach ($edit['category'] as $cid => $value) {
if ($value) {
db_merge('aggregator_category_feed')
->key(array('fid' => $edit['fid']))
db_insert('aggregator_category_feed')
->fields(array(
'fid' => $edit['fid'],
'cid' => $cid,
))
->execute();
......
......@@ -149,6 +149,19 @@ class AggregatorTestCase extends DrupalWebTestCase {
}
}
/**
* Pull categories from aggregator_category table.
*/
function getCategories() {
$categories = array();
$result = db_query('SELECT * FROM {aggregator_category}');
foreach ($result as $category) {
$categories[$category->cid] = $category;
}
return $categories;
}
/**
* Check if the feed name and url is unique.
*
......@@ -297,6 +310,49 @@ class AddFeedTestCase extends AggregatorTestCase {
}
}
class CategorizeFeedTestCase extends AggregatorTestCase {
public static function getInfo() {
return array(
'name' => 'Categorize feed functionality',
'description' => 'Categorize feed test.',
'group' => 'Aggregator'
);
}
/**
* Create a feed and make sure you can add more than one category to it.
*/
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'])), t('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'])), t('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, t('Feed has 2 categories'));
}
}
class UpdateFeedTestCase extends AggregatorTestCase {
public static function getInfo() {
return array(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment