You are here

public function FeedsCSVtoUsersTest::testRoleTargetWithoutRoleCreation in Feeds 7.2

Tests mapping to role without automatically creating new roles.

File

tests/feeds_processor_user.test, line 269
Tests for plugins/FeedsUserProcessor.inc.

Class

FeedsCSVtoUsersTest
Test aggregating a feed as data records.

Code

public function testRoleTargetWithoutRoleCreation() {

  // Add mapping to role.
  $this
    ->addMappings('user_import', array(
    4 => array(
      'source' => 'roles',
      'target' => 'roles_list',
    ),
  ));

  // 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 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 role but not the tester role, since
  // that role doesn't exist on the system.
  $account = user_load_by_name('Gomez');
  $this
    ->assertTrue(isset($account->roles[$manager_rid]), 'Gomez has the manager role.');
  $this
    ->assertFalse(in_array('tester', $account->roles), 'Gomez does not have the tester role.');
  $this
    ->assertEqual(2, 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 only three roles exist:
  // - authenticated user
  // - role from the admin user
  // - manager
  $roles = user_roles(TRUE);
  $this
    ->assertEqual(3, count($roles), 'Only three roles exist.');
}