public function FeedsCSVtoUsersTest::testRoleTargetRids in Feeds 7.2
Tests mapping to role using role ID's.
File
- tests/
feeds_processor_user.test, line 367 - Tests for plugins/FeedsUserProcessor.inc.
Class
- FeedsCSVtoUsersTest
- Test aggregating a feed as data records.
Code
public function testRoleTargetRids() {
// Add mapping to role.
$this
->addMappings('user_import', array(
4 => array(
'source' => 'rids',
'target' => 'roles_list',
'role_search' => FeedsUserProcessor::ROLE_SEARCH_RID,
),
));
// Create manager and tester roles.
$manager_rid = $this
->drupalCreateRole(array(
'access content',
), 'manager');
$tester_rid = $this
->drupalCreateRole(array(
'access content',
), 'tester');
// Ensure expected ID's of these roles.
$this
->assertEqual(4, $manager_rid);
$this
->assertEqual(5, $tester_rid);
// Import CSV file.
$this
->importFile('user_import', $this
->absolutePath() . '/tests/feeds/users_roles.csv');
// Assert that Morticia did not get the editor role and has one role in
// total.
$account = user_load_by_name('Morticia');
$this
->assertFalse(in_array('editor', $account->roles), 'Morticia does not have the editor role.');
$this
->assertEqual(1, count($account->roles), 'Morticia has one role.');
// Assert that Fester got the manager role and two roles in total.
$account = user_load_by_name('Fester');
$this
->assertTrue(isset($account->roles[$manager_rid]), 'Fester has the manager role.');
$this
->assertEqual(2, count($account->roles), 'Fester has two roles.');
// Assert that Gomez got the manager and tester roles.
$account = user_load_by_name('Gomez');
$this
->assertTrue(isset($account->roles[$manager_rid]), 'Gomez has the manager role.');
$this
->assertTrue(isset($account->roles[$manager_rid]), 'Gomez has the tester role.');
$this
->assertEqual(3, count($account->roles), 'Gomez has two roles.');
// Assert that Pugsley only has one role.
$account = user_load_by_name('Pugsley');
$this
->assertEqual(1, count($account->roles), 'Pugsley has one role.');
// Assert that four roles exist:
// - authenticated user
// - role from the admin user
// - manager
// - tester
$roles = user_roles(TRUE);
$this
->assertEqual(4, count($roles), 'Four roles exist.');
}