public function LdapAuthenticationTestCase::testUI in Lightweight Directory Access Protocol (LDAP) 7.2
Same name and namespace in other branches
- 8.2 ldap_authentication/tests/ldap_authentication.test \LdapAuthenticationTestCase::testUI()
Make sure user admin interface works.
File
- ldap_authentication/
tests/ ldap_authentication.test, line 672
Class
- LdapAuthenticationTestCase
- LdapAuthenticationTestCase.
Code
public function testUI() {
// Just to give warning if setup doesn't succeed. may want to take these out at some point.
$setup_success = module_exists('ldap_user') && module_exists('ldap_servers') && module_exists('ldap_authentication') && variable_get('ldap_simpletest', 2) > 0;
$this
->assertTrue($setup_success, ' ldap_authentication UI setup successful', $this
->testId('user interface tests'));
$sid = 'activedirectory1';
$sids = [
'activedirectory1',
];
$this
->prepTestData(LDAP_TEST_LDAP_NAME, $sids, 'provisionToDrupal', 'default');
$this->privileged_user = $this
->drupalCreateUser([
'administer site configuration',
]);
$this
->drupalLogin($this->privileged_user);
$ldap_authentication_conf_pre = ldap_authentication_get_valid_conf();
$this
->drupalGet('admin/config/people/ldap/authentication');
$form_tests = [
'authenticationMode' => [
'property' => 'authenticationMode',
'values' => [
LDAP_AUTHENTICATION_MIXED,
LDAP_AUTHENTICATION_EXCLUSIVE,
],
'required' => TRUE,
],
'authenticationServers[' . $sid . ']' => [
'property' => 'enabledAuthenticationServers',
'values' => [
TRUE,
TRUE,
],
'desired_result' => [
[
$sid,
],
[
$sid,
],
],
],
'loginUIUsernameTxt' => [
'property' => 'loginUIUsernameTxt',
'values' => [
'',
'Hogwarts UserID',
],
],
'loginUIPasswordTxt' => [
'property' => 'loginUIPasswordTxt',
'values' => [
'',
'Hogwarts UserID Password',
],
],
'ldapUserHelpLinkUrl' => [
'property' => 'ldapUserHelpLinkUrl',
'values' => [
'',
'http://passwords.hogwarts.edu',
],
],
'ldapUserHelpLinkText' => [
'property' => 'ldapUserHelpLinkText',
'values' => [
'Hogwarts Password Management Page',
'Hogwarts Password Management Page',
],
],
'allowOnlyIfTextInDn' => [
'property' => 'allowOnlyIfTextInDn',
'values' => [
'witch\\nwarlord\\nwisecracker',
"witch\nwarlord\nwisecracker",
],
'desired_result' => [
[
'witch',
'warlord',
'wisecracker',
],
[
'witch',
'warlord',
'wisecracker',
],
],
],
'excludeIfTextInDn' => [
'property' => 'excludeIfTextInDn',
'values' => [
"muggle\nmuddle\nmummy",
"muggle\nmuddle\nmummy",
],
'desired_result' => [
[
'muggle',
'muddle',
'mummy',
],
[
'muggle',
'muddle',
'mummy',
],
],
],
'excludeIfNoAuthorizations' => [
'property' => 'excludeIfNoAuthorizations',
'values' => [
1,
1,
],
],
'emailOption' => [
'property' => 'emailOption',
'values' => [
LDAP_AUTHENTICATION_EMAIL_FIELD_REMOVE,
LDAP_AUTHENTICATION_EMAIL_FIELD_DISABLE,
],
'required' => TRUE,
],
'emailUpdate' => [
'property' => 'emailUpdate',
'values' => [
LDAP_AUTHENTICATION_EMAIL_UPDATE_ON_LDAP_CHANGE_ENABLE,
LDAP_AUTHENTICATION_EMAIL_UPDATE_ON_LDAP_CHANGE_DISABLE,
],
'required' => TRUE,
],
'allowTestPhp' => [
'property' => 'allowTestPhp',
'values' => [
'pretend php',
'pretend php',
],
],
];
module_enable([
'php',
]);
foreach ([
0,
1,
] as $i) {
$edit = [];
foreach ($form_tests as $field_name => $conf) {
$value = $conf['values'][$i];
$property = isset($conf['property']) ? $conf['property'] : $field_name;
$edit[$field_name] = $value;
}
$this
->drupalPost('admin/config/people/ldap/authentication', $edit, t('Save'));
$ldap_authentication_conf_post = ldap_authentication_get_valid_conf(TRUE);
foreach ($form_tests as $field_name => $conf) {
$property = isset($conf['property']) ? $conf['property'] : $field_name;
$desired = isset($conf['desired_result']) ? isset($conf['desired_result'][$i]) : $conf['values'][$i];
if (is_array($desired) && is_array($ldap_authentication_conf_post->{$property})) {
$success = count($desired) == count($ldap_authentication_conf_post->{$property});
}
else {
$success = $ldap_authentication_conf_post->{$property} == $desired;
}
$this
->assertTrue($success, $property . ' ' . t('field set correctly'), $this
->testId('ldap authentication user interface tests'));
if (!$success) {
debug("fail {$i} {$property}");
debug("desired:");
debug($desired);
debug("actual:");
debug($ldap_authentication_conf_post->{$property});
}
}
}
}