public function SimpleLdapUserModifyProfileWebTestCase::postProfileForm in Simple LDAP 7
Same name and namespace in other branches
- 7.2 simple_ldap_user/simple_ldap_user.test \SimpleLdapUserModifyProfileWebTestCase::postProfileForm()
Submits the user profile edit form.
Values are taken from the configured test user, and appended by $suffix.
1 call to SimpleLdapUserModifyProfileWebTestCase::postProfileForm()
- SimpleLdapUserModifyProfileWebTestCase::testUserChangesProfile in simple_ldap_user/
simple_ldap_user.test - User edits profile information.
File
- simple_ldap_user/
simple_ldap_user.test, line 525 - Tests for Simple LDAP User module.
Class
Code
public function postProfileForm($suffix = '') {
// 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();
// Get the drupal user.
$drupal_user = user_load_by_name($this->ldapUser[0]->{$attribute_name}[0]);
// Create the form variable array.
$edit = array();
$edit['current_pass'] = $this->userPassword[0];
$edit['mail'] = $this->ldapUser[0]->{$attribute_mail}[0] . $suffix;
$mapObject = SimpleLdapUserMap::singleton();
foreach ($mapObject->map as $attribute) {
// Skip drupal-to-ldap many-to-one mappings.
if (count($attribute['drupal']) > 1) {
continue;
}
// Get the field name and type.
$drupal_attribute = reset($attribute['drupal']);
$type = substr($drupal_attribute, 0, 1);
$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 = $this->ldapUser[0]->{$attribute['ldap']}[0];
}
}
else {
$value = $this->ldapUser[0]->{$attribute['ldap']}[0] . $suffix;
}
switch ($type) {
case '#':
$drupal_attribute = substr($drupal_attribute, 1);
$edit[$drupal_attribute . '[und][0][value]'] = $value;
break;
default:
$edit[$drupal_attribute] = $value;
}
}
// Submit user edit form.
$this
->drupalPost('user/' . $drupal_user->uid . '/edit', $edit, t('Save'));
}