function LdapAuthorizationDerivationsTests::testDeriveFromEntry in Lightweight Directory Access Protocol (LDAP) 7
File
- ldap_authorization/
tests/ DeriveFromEntry/ DeriveFromEntry.test, line 21
Class
Code
function testDeriveFromEntry() {
$this->ldapTestId = 'DeriveFromEntry.not_nested';
$this->serversData = 'DeriveFromEntry/ldap_servers.inc';
$this->authorizationData = 'DeriveFromEntry/ldap_authorization.inc';
$this->authenticationData = 'DeriveFromEntry/ldap_authentication.inc';
$this->consumerType = 'drupal_role';
$this
->prepTestData();
/**
* test: DeriveFromEntry.nomatch no matches on dn attribute.
*
* should not match any mappings
*/
$user = $this
->drupalCreateUser(array());
$unkool = $this->testFunctions
->drupalLdapUpdateUser(array(
'name' => 'unkool',
'mail' => 'unkool@nowhere.myuniversity.edu',
), TRUE, $user);
list($new_authorizations, $notifications) = ldap_authorizations_user_authorizations($unkool, 'query');
// just see if the correct ones are derived.
$this
->assertTrue(count($new_authorizations[$this->consumerType]) == 0, 'user account unkool tested for granting no drupal roles ', $this->ldapTestId . '.nomatch');
/**
* test: DeriveFromEntry.not_nested.one_match where group has childgroups
*
*/
$user = $this
->drupalCreateUser(array());
$joeprojectmanager = $this->testFunctions
->drupalLdapUpdateUser(array(
'name' => 'joeprojectmanager',
'mail' => 'joeprojectmanager@myuniversity.edu',
), TRUE, $user);
list($new_authorizations, $notifications) = ldap_authorizations_user_authorizations($joeprojectmanager, 'query');
// just see if the correct ones are derived.
$correct_roles = (bool) (isset($new_authorizations[$this->consumerType]) && in_array('it', $new_authorizations[$this->consumerType]));
$this
->assertTrue($correct_roles, 'user account joeprojectmanager tested for granting drupal_role "it"', $this->ldapTestId . '.onematch');
/**
* test: DeriveFromEntry.not_nested.one_match2 where group has no child groups
*/
$user = $this
->drupalCreateUser(array());
$jdoe = $this->testFunctions
->drupalLdapUpdateUser(array(
'name' => 'jdoe',
'mail' => 'jdoe@myuniversity.edu',
), TRUE, $user);
list($new_authorizations, $notifications) = ldap_authorizations_user_authorizations($jdoe, 'query');
// just see if the correct ones are derived.
$correct_roles = (bool) (isset($new_authorizations[$this->consumerType]) && in_array('students', $new_authorizations[$this->consumerType]));
$this
->assertTrue($correct_roles, 'user account jdoe tested for granting "students" drupal roles ', $this->ldapTestId . '.one_match2');
if (!$correct_roles) {
debug('new_authorizations');
debug($new_authorizations);
}
}