You are here

public function FeedsCSVtoUsersTest::testRoleTargetNoRevokeRoles in Feeds 7.2

Tests if no roles are revoked if the option "Revoke roles" is disabled.

File

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

Class

FeedsCSVtoUsersTest
Test aggregating a feed as data records.

Code

public function testRoleTargetNoRevokeRoles() {

  // Create manager role.
  $manager_rid = $this
    ->drupalCreateRole(array(
    'access content',
  ), 'manager');

  // Create editor role.
  $editor_rid = $this
    ->drupalCreateRole(array(
    'access content',
  ), 'editor');

  // Set to update existing users.
  $this
    ->setSettings('user_import', 'FeedsUserProcessor', array(
    'update_existing' => FEEDS_UPDATE_EXISTING,
  ));

  // Add mapping to role. Set option to not revoke roles.
  $this
    ->addMappings('user_import', array(
    4 => array(
      'source' => 'roles',
      'target' => 'roles_list',
      'allowed_roles' => array(
        $manager_rid => FALSE,
        $editor_rid => $editor_rid,
      ),
      'revoke_roles' => FALSE,
    ),
  ));

  // Create account for Pugsley with roles "manager" and "editor". Pugsley has
  // no roles, but roles should not be revoked, so Pugsley should keep all
  // roles.
  user_save(drupal_anonymous_user(), array(
    'name' => 'Pugsley',
    'mail' => 'pugsley@example.com',
    'pass' => 'pugs',
    'status' => 1,
    'roles' => array(
      $manager_rid => $manager_rid,
      $editor_rid => $editor_rid,
    ),
  ));

  // Import CSV file.
  $this
    ->importFile('user_import', $this
    ->absolutePath() . '/tests/feeds/users_roles.csv');

  // Assert that Pugsley kept all roles.
  $account = user_load_by_name('Pugsley');
  $this
    ->assertTrue(isset($account->roles[$manager_rid]), 'Pugsley still has the manager role.');
  $this
    ->assertTrue(isset($account->roles[$editor_rid]), 'Pugsley still has the editor role.');
  $this
    ->assertEqual(3, count($account->roles), 'Pugsley has three roles.');
}