function CasAttributesTestCase::testNewUserLogin in CAS Attributes 7
Same name and namespace in other branches
- 6.3 cas_attributes.test \CasAttributesTestCase::testNewUserLogin()
Test the CAS attribute tokens.
File
- ./
cas_attributes.test, line 104 - Tests for CAS Attributes.
Class
- CasAttributesTestCase
- Test case for CAS attribute setting.
Code
function testNewUserLogin() {
// Create a new CAS user.
$cas_name = $this
->randomName();
$attributes = array(
'surname' => 'Smith',
'givenName' => 'John',
'memberOf' => array(
'CN=Staff,OU=Groups,DC=example,DC=edu',
'CN=Spanish Department,OU=Departments,OU=Groups,DC=example,DC=edu',
),
);
$cas_user = array(
'name' => $cas_name,
'attributes' => $attributes,
);
variable_set('cas_test_cas_user', $cas_user);
// Set up the relationship mappings.
$this
->drupalLogin($this->admin_user);
$edit = array(
'cas_attributes_sync_every_login' => 0,
'cas_attributes_overwrite' => 1,
'cas_attributes_relations[name]' => '[cas:attribute:NAME]',
'cas_attributes_relations[mail]' => '[cas:name]@example.com',
'cas_attributes_relations[test_user_memberof]' => '[cas:attribute:memberOf:first]',
'cas_attributes_relations[test_user_name]' => '[cas:attribute:givenName] [cas:attribute:surname]',
);
$this
->drupalPost('admin/config/people/cas/attributes', $edit, t('Save configuration'));
$this
->drupalGet('user/' . $this->admin_user->uid . '/edit');
$this
->drupalGet('admin/config/people/cas/attributes/cas');
$this
->drupalGet('user/' . $this->admin_user->uid . '/edit');
$this
->drupalLogout();
// Log in as the new CAS user.
$this
->casLogin($cas_name, $attributes);
// After login, the account is reloaded into $this->loggedInUser.
// The account name should not have been changed, since the token should
// evaluate to nothing.
$this
->assertEqual($this->loggedInUser->name, $cas_name);
$this
->assertEqual($this->loggedInUser->mail, "{$cas_name}@example.com");
$this
->assertEqual($this->loggedInUser->test_user_memberof[LANGUAGE_NONE][0]['value'], 'CN=Staff,OU=Groups,DC=example,DC=edu');
$this
->assertEqual($this->loggedInUser->test_user_name[LANGUAGE_NONE][0]['value'], 'John Smith');
}