public function SimpleLdapUserTestCase::verifySync in Simple LDAP 7
Same name and namespace in other branches
- 7.2 simple_ldap_user/simple_ldap_user.test \SimpleLdapUserTestCase::verifySync()
Verifies that Drupal, LDAP, and the test user values match.
5 calls to SimpleLdapUserTestCase::verifySync()
- SimpleLdapUserMassImportExportTestCase::testExport in simple_ldap_user/
simple_ldap_user.test - Test mass export.
- SimpleLdapUserMassImportExportTestCase::testImport in simple_ldap_user/
simple_ldap_user.test - Test mass import.
- SimpleLdapUserModifyProfileWebTestCase::testUserChangesProfile in simple_ldap_user/
simple_ldap_user.test - User edits profile information.
- SimpleLdapUserSyncTestCase::testSyncOnHookUserLoad in simple_ldap_user/
simple_ldap_user.test - Tests synchronization using hook_user_load().
- SimpleLdapUserSyncTestCase::testSyncOnHookUserLogin in simple_ldap_user/
simple_ldap_user.test - Tests data synchronization using hook_user_login().
File
- simple_ldap_user/
simple_ldap_user.test, line 264 - Tests for Simple LDAP User module.
Class
- SimpleLdapUserTestCase
- @file Tests for Simple LDAP User module.
Code
public function verifySync($suffix = '', $name = NULL, $multi = FALSE) {
// Load configuration variables.
$attribute_name = simple_ldap_user_variable_get('simple_ldap_user_attribute_name');
$attribute_mail = simple_ldap_user_variable_get('simple_ldap_user_attribute_mail');
$server = SimpleLdapServer::singleton();
// Load the LDAP user.
if ($name === NULL) {
$ldap_user = new SimpleLdapUser($this->ldapUser[0]->{$attribute_name}[0]);
$control = $this->ldapUser[0];
}
else {
$ldap_user = new SimpleLdapUser($name);
$control = $ldap_user;
}
// Load the Drupal user.
$drupal_user = user_load_multiple(array(), array(
'name' => $ldap_user->{$attribute_name}[0],
), TRUE);
$drupal_user = reset($drupal_user);
// Check the mapped fields.
$mapObject = SimpleLdapUserMap::singleton();
$attribute_map = $mapObject->map;
array_unshift($attribute_map, array(
'drupal' => array(
'mail',
),
'ldap' => $attribute_mail,
));
foreach ($attribute_map as $attribute) {
// Skip drupal-to-ldap, one-to-many maps, unless explicitely requested.
if (count($attribute['drupal']) == 1 || $multi) {
// Parse the drupal attribute name.
$drupal = '';
foreach ($attribute['drupal'] as $drupal_attribute) {
$type = substr($drupal_attribute, 0, 1);
switch ($type) {
case '#':
$drupal_attribute = substr($drupal_attribute, 1);
$items = field_get_items('user', $drupal_user, $drupal_attribute);
$drupal .= ' ' . $items[0]['value'];
break;
default:
$drupal .= ' ' . $drupal_user->{$drupal_attribute};
}
}
$drupal = trim($drupal);
// Make sure drupal and ldap match.
$this
->assertEqual($ldap_user->{$attribute['ldap']}[0], $drupal, t('The @ldap LDAP attribute :ldap and the @drupal Drupal field :drupal are synchronized.', array(
'@ldap' => $attribute['ldap'],
'@drupal' => $drupal_attribute,
':ldap' => $ldap_user->{$attribute['ldap']}[0],
':drupal' => $drupal,
)));
// Only single-valued fields will have a control to check.
if (count($attribute['drupal']) == 1) {
// Make sure simple entries match the control.
$attributetype = $server->schema
->get('attributetypes', $attribute['ldap']);
// A syntax type of 1.3.6.1.4.1.1466.115.121.1.27 is an integer.
if (isset($attributetype['syntax']) && $attributetype['syntax'] == '1.3.6.1.4.1.1466.115.121.1.27') {
if ($suffix) {
$value = hexdec(substr(sha1($suffix), 0, 2));
}
else {
$value = $control->{$attribute['ldap']}[0];
}
}
else {
$value = $control->{$attribute['ldap']}[0] . $suffix;
}
$this
->assertEqual($value, $drupal, t(':value matches the control value :control', array(
':value' => $drupal,
':control' => $value,
)));
}
}
}
}