function CasAttributesTestCase::testRoleMappingFromMultipleVariables in CAS Attributes 7
File
- ./
cas_attributes.test, line 386 - Tests for CAS Attributes.
Class
- CasAttributesTestCase
- Test case for CAS attribute setting.
Code
function testRoleMappingFromMultipleVariables() {
// Create a new CAS user.
$cas_name = $this
->randomName();
$attributes = array(
'a_role' => array(
'architect',
),
'some_other_roles' => array(
'teacher',
'scholar',
),
'yet_another_role' => array(
'doctor',
),
);
$cas_user = array(
'name' => $cas_name,
'attributes' => $attributes,
);
variable_set('cas_test_cas_user', $cas_user);
// create several roles
$role_ids = array();
$teacher_role_id = $this
->drupalCreateRole(array(), 'teacher');
$role_ids[$teacher_role_id] = $teacher_role_id;
$scholar_role_id = $this
->drupalCreateRole(array(), 'scholar');
$role_ids[$scholar_role_id] = $scholar_role_id;
$philosopher_role_id = $this
->drupalCreateRole(array(), 'philosopher');
$role_ids[$philosopher_role_id] = $philosopher_role_id;
$architect_role_id = $this
->drupalCreateRole(array(), 'architect');
$role_ids[$architect_role_id] = $architect_role_id;
$doctor_role_id = $this
->drupalCreateRole(array(), 'doctor');
$role_ids[$doctor_role_id] = $doctor_role_id;
// Manage all five new roles via CAS
$this->admin_user = $this
->drupalCreateUser(array(
'administer users',
'administer cas',
'administer permissions',
));
$this
->drupalLogin($this->admin_user);
$edit = array(
'cas_attributes_sync_every_login' => 1,
'cas_attributes_overwrite' => 0,
'cas_attributes_roles_mapping' => "a_role\nsome_other_roles \nyet_another_role\n\n",
);
foreach ($role_ids as $rid) {
$edit['cas_attributes_roles_manage[' . $rid . ']'] = $rid;
}
$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, user should have roles teacher, scholar, architect, and doctor, but not philosopher
$user_roles = $this->loggedInUser->roles;
$this
->assertTrue(array_key_exists($teacher_role_id, $user_roles), "Test user has role teacher.");
$this
->assertTrue(array_key_exists($scholar_role_id, $user_roles), "Test user has role scholar.");
$this
->assertFalse(array_key_exists($philosopher_role_id, $user_roles), "Test user does not have role philosopher.");
$this
->assertTrue(array_key_exists($architect_role_id, $user_roles), "Test user has role architect.");
$this
->assertTrue(array_key_exists($doctor_role_id, $user_roles), "Test user has role doctor.");
}