function CasAttributesTestCase::testSyncEveryLogin in CAS Attributes 7
File
- ./
cas_attributes.test, line 147 - Tests for CAS Attributes.
Class
- CasAttributesTestCase
- Test case for CAS attribute setting.
Code
function testSyncEveryLogin() {
// Create a new CAS user.
$cas_name = $this
->randomName();
$attributes = array(
'surname' => 'Smith',
'givenName' => 'John',
);
$cas_user = array(
'name' => $cas_name,
'attributes' => $attributes,
);
variable_set('cas_test_cas_user', $cas_user);
// Set up a relationship mapping, and leave sync_every_login turned off.
$this
->drupalLogin($this->admin_user);
$edit = array(
'cas_attributes_sync_every_login' => 0,
'cas_attributes_overwrite' => 1,
'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.
$this
->assertEqual($this->loggedInUser->test_user_name[LANGUAGE_NONE][0]['value'], 'John Smith');
// change the attributes
$attributes = array(
'surname' => 'Smith',
'givenName' => 'Dave',
);
$cas_user = array(
'name' => $cas_name,
'attributes' => $attributes,
);
variable_set('cas_test_cas_user', $cas_user);
// log out and log back in
$this
->drupalLogout();
$this
->casLogin($cas_name, $attributes);
$this->loggedInUser = user_load($this->loggedInUser->uid, TRUE);
// workaround since casLogin gets cached copy
// Sync every login is turned off so name should not have changed.
$this
->assertEqual($this->loggedInUser->test_user_name[LANGUAGE_NONE][0]['value'], 'John Smith');
// turn on sync every login
$this
->drupalLogout();
$this
->drupalLogin($this->admin_user);
$edit = array(
'cas_attributes_sync_every_login' => 1,
);
$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 CAS user back in
$this
->casLogin($cas_name, $attributes);
$this->loggedInUser = user_load($this->loggedInUser->uid, TRUE);
// workaround since casLogin gets cached copy
// Sync every login is on and overwrite is on so name should be updated.
$this
->assertEqual($this->loggedInUser->test_user_name[LANGUAGE_NONE][0]['value'], 'Dave Smith');
}