You are here

public function SimpleLdapUserMassImportExportTestCase::testImport in Simple LDAP 7.2

Same name and namespace in other branches
  1. 7 simple_ldap_user/simple_ldap_user.test \SimpleLdapUserMassImportExportTestCase::testImport()

Test mass import.

File

simple_ldap_user/simple_ldap_user.test, line 1226
Tests for Simple LDAP User module.

Class

SimpleLdapUserMassImportExportTestCase

Code

public function testImport() {

  // Get configuration.
  $server = SimpleLdapServer::singleton();
  $basedn = simple_ldap_user_variable_get('simple_ldap_user_basedn');
  $scope = simple_ldap_user_variable_get('simple_ldap_user_scope');
  $attribute_name = simple_ldap_user_variable_get('simple_ldap_user_attribute_name');

  // Log in as user 1.
  $this
    ->drupalUser1Login();

  // Clear cache, otherwise the import menu item doesn't work.
  $this
    ->drupalPost('admin/config/development/performance', array(), t('Clear all caches'));

  // Verify that the LDAP users do not exist in Drupal.
  foreach ($this->ldapUser as $ldap_user) {
    $drupal_user = user_load_by_name($ldap_user->{$attribute_name}[0]);
    $this
      ->assertIdentical($drupal_user, FALSE, t('The user :name does not exist in Drupal.', array(
      ':name' => $ldap_user->{$attribute_name}[0],
    )));
  }

  // Submit the import user form.
  $edit = array();

  // Perform the same search that is done to generate the form, so all of the
  // extra entries can be set to false. We just want to import the users
  // created specifically for this test.
  $filter = '(&(' . $attribute_name . '=*)' . SimpleLdapUser::filter() . ')';
  $ldap_users = SimpleLdap::clean($server
    ->search($basedn, $filter, $scope, array(
    'dn',
    $attribute_name,
  )));
  foreach ($ldap_users as $ldap_user) {
    $edit['users[' . $ldap_user[$attribute_name][0] . ']'] = FALSE;
  }

  // Select the users that were created for this test.
  foreach ($this->ldapUser as $ldap_user) {
    $edit['users[' . $ldap_user->{$attribute_name}[0] . ']'] = TRUE;
  }
  $this
    ->drupalPost('admin/people/simple_ldap_user_import', $edit, t('Import'));

  // Verify that the users were imported into Drupal.
  foreach ($this->ldapUser as $ldap_user) {
    $drupal_user = user_load_by_name($ldap_user->{$attribute_name}[0]);
    $this
      ->assertNotIdentical($drupal_user, FALSE, t('The test user :name was created in Drupal.', array(
      ':name' => $ldap_user->{$attribute_name}[0],
    )));
    $this
      ->verifySync('', $ldap_user->{$attribute_name}[0]);
  }
}