public function FeedsCSVtoUsersTest::testRoleTargetWithRoleCreation in Feeds 7.2
Tests mapping to role with automatically creating new roles.
File
- tests/
feeds_processor_user.test, line 317 - Tests for plugins/FeedsUserProcessor.inc.
Class
- FeedsCSVtoUsersTest
- Test aggregating a feed as data records.
Code
public function testRoleTargetWithRoleCreation() {
// Add mapping to role.
$this
->addMappings('user_import', array(
4 => array(
'source' => 'roles',
'target' => 'roles_list',
'autocreate' => TRUE,
),
));
// Create manager role.
$manager_rid = $this
->drupalCreateRole(array(
'access content',
), 'manager');
// 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 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, the editor role and three roles in
// total.
$account = user_load_by_name('Gomez');
$this
->assertTrue(isset($account->roles[$manager_rid]), 'Gomez has the manager role.');
$this
->assertTrue(in_array('tester', $account->roles), 'Gomez has the tester role.');
$this
->assertEqual(3, count($account->roles), 'Gomez has three 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 five roles exist:
// - authenticated user
// - role from the admin user
// - manager
// - editor
// - tester
$roles = user_roles(TRUE);
$this
->assertEqual(5, count($roles), 'Five roles exist.');
}