diff --git a/CHANGELOG.txt b/CHANGELOG.txt index e89090da467f8c930114ac3643b3bcc68e14ecfb..098f789bea21073e365101d513240ea061259c52 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -3,6 +3,7 @@ Feeds 6.x 1.X XXXX ------------------ +- #854628 DanielJohnston, alex_b: Fix user importer assigns all roles. - #838018 infojunkie: Mapper for Formatted Number CCK field. - #856408 c.ex: Pass all $targets for hook_feeds_node_processor_targets_alter() by reference. diff --git a/plugins/FeedsUserProcessor.inc b/plugins/FeedsUserProcessor.inc index e526ca8cd07bb0d897ce66dc3f09d00f2d5b1b22..c0b0605daee0a8a353c177ae13429387c6600e36 100644 --- a/plugins/FeedsUserProcessor.inc +++ b/plugins/FeedsUserProcessor.inc @@ -100,7 +100,7 @@ class FeedsUserProcessor extends FeedsProcessor { // Prepare term object. $target_account = new stdClass(); $target_account->uid = 0; - $target_account->roles = $this->config['roles']; + $target_account->roles = array_filter($this->config['roles']); $target_account->status = $this->config['status']; // Have parent class do the iterating. diff --git a/tests/feeds.test b/tests/feeds.test index ca567243ee3609b751dfe2289b4062ecb78e7a3b..608307b4b962febde8d5a11113edc666d417a9a0 100644 --- a/tests/feeds.test +++ b/tests/feeds.test @@ -618,18 +618,32 @@ class FeedsCSVtoUsersTest extends FeedsWebTestCase { ); $this->drupalPost('admin/build/feeds/edit/user_import/settings', $edit, 'Save'); + // Create roles and assign one of them to the users to be imported. + $manager_rid = $this->drupalCreateRole(array('access content'), 'manager'); + $admin_rid = $this->drupalCreateRole(array('access content'), 'administrator'); + $edit = array( + "roles[$manager_rid]" => TRUE, + "roles[$admin_rid]" => FALSE, + ); + $this->setSettings('user_import', 'FeedsUserProcessor', $edit); + // Import CSV file. $this->importFile('user_import', $this->absolutePath() .'/tests/feeds/users.csv'); // Assert result. $this->assertText('Created 4 users.'); - // 1 user has an invalid email address. + // 1 user has an invalid email address, all users should be assigned + // the manager role. $this->assertText('There was 1 user that could not be imported because either their name or their email was empty or not valid. Check import data and mapping settings on User processor.'); $this->drupalGet('admin/user/user'); $this->assertText('Morticia'); $this->assertText('Fester'); $this->assertText('Gomez'); $this->assertText('Pugsley'); + $count = db_result(db_query("SELECT count(*) FROM {users_roles} WHERE rid = %d", $manager_rid)); + $this->assertEqual($count, 4, t('All imported users were assigned the manager role.')); + $count = db_result(db_query("SELECT count(*) FROM {users_roles} WHERE rid = %d", $admin_rid)); + $this->assertEqual($count, 0, t('No imported user was assigned the administrator role.')); // @todo Test status setting, update existing and role settings. }