You are here

public function OgMigrate7000TestCase::testogMigrateUpgradeUsers in Organic groups 7

File

og_migrate/og_migrate.test, line 92

Class

OgMigrate7000TestCase
Upgrade 7000 test.

Code

public function testogMigrateUpgradeUsers() {

  // Run the required migration.
  $edit = array(
    'migrate[upgrade_group]' => TRUE,
    'migrate[upgrade_user]' => TRUE,
  );
  $this
    ->drupalPost('admin/config/group/group-migrate', $edit, t('Migrate'));

  // Check user membership.
  $group = og_get_group('node', 10);

  // Assert users.
  $values = array(
    // Uid 3 is the group manager, so in OG6 it was marked as admin.
    3 => array(
      'admin' => TRUE,
    ),
    4 => array(
      'active' => FALSE,
    ),
    5 => array(),
    6 => array(
      'active' => FALSE,
      'admin' => TRUE,
    ),
    7 => array(
      'admin' => TRUE,
    ),
  );
  foreach ($values as $uid => $value) {

    // Set default values.
    $value += array(
      'active' => TRUE,
      'admin' => FALSE,
    );
    $roles = array();
    if ($value['active']) {
      $op = t('active');
      $states = array(
        OG_STATE_ACTIVE,
      );
      $roles[2] = 2;
    }
    else {
      $op = t('pending');
      $states = array(
        OG_STATE_PENDING,
      );

      // If the member is pending then they have the anonymous role.
      $roles[1] = 1;
    }
    $account = user_load($uid);
    if ($value['admin']) {

      // OG_ADMINISTRATOR_ROLE
      $roles[3] = 3;
    }
    $this
      ->assertTrue(og_is_member($group->gid, 'user', $account, $states), t('User @uid is @op member in group.', array(
      '@uid' => $uid,
      '@op' => $op,
    )));

    // Pass also pending state, so we make sure that even if the user isn't
    // active they are considered members, to check they get the correct role.
    $this
      ->assertEqual(og_get_user_roles($group->gid, $uid), $roles, t('User @uid has the correct roles in group.', array(
      '@uid' => $uid,
    )));
  }
}