public function FeedsCSVtoUsersTest::testAdditionalRolesSettingWithRoleTarget in Feeds 7.2
Tests if additional roles are assigned when also the role mapper is used.
File
- tests/
feeds_processor_user.test, line 658 - Tests for plugins/FeedsUserProcessor.inc.
Class
- FeedsCSVtoUsersTest
- Test aggregating a feed as data records.
Code
public function testAdditionalRolesSettingWithRoleTarget() {
// Create manager role.
$manager_rid = $this
->drupalCreateRole(array(
'access content',
), 'manager');
// Create editor role.
$editor_rid = $this
->drupalCreateRole(array(
'access content',
), 'editor');
// Create tester role.
$tester_rid = $this
->drupalCreateRole(array(
'access content',
), 'tester');
// Set that the "manager" role should be assigned to every user that is
// imported.
$this
->setSettings('user_import', 'FeedsUserProcessor', array(
"roles[{$manager_rid}]" => TRUE,
'update_existing' => FEEDS_UPDATE_EXISTING,
));
// Add mapping to role.
$this
->addMappings('user_import', array(
4 => array(
'source' => 'roles',
'target' => 'roles_list',
),
));
// Create account for Morticia with roles "manager" and "tester". In the
// source, Morticia does not have the "manager" role, but because on the
// user processor settings that is an additional role to add, that role
// should not be revoked. The "tester" role, on the other hand, should be
// revoked.
user_save(drupal_anonymous_user(), array(
'name' => 'Morticia',
'mail' => 'morticia@example.com',
'pass' => 'mort',
'status' => 1,
'roles' => array(
$manager_rid => $manager_rid,
$tester_rid => $tester_rid,
),
));
// Import CSV file.
$this
->importFile('user_import', $this
->absolutePath() . '/tests/feeds/users_roles.csv');
// Assert that Morticia kept the "manager" role, lost the "tester" role and
// gained the "editor" role.
$account = user_load_by_name('Morticia');
$this
->assertTrue(isset($account->roles[$manager_rid]), 'Morticia still has the manager role.');
$this
->assertTrue(isset($account->roles[$editor_rid]), 'Morticia has the editor role.');
$this
->assertFalse(isset($account->roles[$tester_rid]), 'Morticia no longer has the tester role.');
$this
->assertEqual(3, count($account->roles), 'Morticia has three roles.');
// Assert that all other imported users got the "manager" role as well.
$user_names = array(
'Fester',
'Gomez',
'Pugsley',
);
foreach ($user_names as $user_name) {
$vars = array(
'@user' => $user_name,
);
// Assert that this user has the "manager" role.
$account = user_load_by_name($user_name);
$this
->assertTrue(isset($account->roles[$manager_rid]), format_string('@user has the manager role.', $vars));
}
}