public function FeedsCSVtoUsersTest::testRoleTargetWithAllowedRoles in Feeds 7.2
Tests mapping to role using only allowed roles.
File
- tests/
feeds_processor_user.test, line 420 - Tests for plugins/FeedsUserProcessor.inc.
Class
- FeedsCSVtoUsersTest
- Test aggregating a feed as data records.
Code
public function testRoleTargetWithAllowedRoles() {
// Create manager role.
$manager_rid = $this
->drupalCreateRole(array(
'access content',
), 'manager');
// Create editor role.
$editor_rid = $this
->drupalCreateRole(array(
'access content',
), 'editor');
// Add mapping to role.
// The manager role may not be assigned to the user by the feed.
$this
->addMappings('user_import', array(
4 => array(
'source' => 'roles',
'target' => 'roles_list',
'allowed_roles' => array(
$manager_rid => FALSE,
$editor_rid => $editor_rid,
),
'autocreate' => TRUE,
),
));
// Import CSV file.
$this
->importFile('user_import', $this
->absolutePath() . '/tests/feeds/users_roles.csv');
// Assert that Morticia got the editor role and two roles in total.
$account = user_load_by_name('Morticia');
$this
->assertTrue(in_array('editor', $account->roles), 'Morticia has the editor role.');
$this
->assertEqual(2, count($account->roles), 'Morticia has two roles.');
// Assert that Fester did not got the manager role, because that role was
// not an allowed value.
$account = user_load_by_name('Fester');
$this
->assertFalse(isset($account->roles[$manager_rid]), 'Fester does not have the manager role.');
$this
->assertEqual(1, count($account->roles), 'Fester has one role.');
// Assert that Gomez only got the tester role and not the manager role.
$account = user_load_by_name('Gomez');
$this
->assertFalse(isset($account->roles[$manager_rid]), 'Gomez does not have the manager role.');
$this
->assertTrue(in_array('tester', $account->roles), 'Gomez has the tester role.');
$this
->assertEqual(2, count($account->roles), 'Gomez has two roles.');
}