function LdapAuthorizationDerivationsTests::testDeriveFromEntry in Lightweight Directory Access Protocol (LDAP) 7
File
- ldap_authorization/tests/DeriveFromEntry/DeriveFromEntry.test, line 21
Class
- LdapAuthorizationDerivationsTests
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();
$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');
$this
->assertTrue(count($new_authorizations[$this->consumerType]) == 0, 'user account unkool tested for granting no drupal roles ', $this->ldapTestId . '.nomatch');
$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');
$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');
$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');
$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);
}
}