1 user.test | UserPermissionsTestCase::testEditorRole() |
Test assigning of permissions for the editor role.
File
- core/
modules/ user/ tests/ user.test, line 1476 - Tests for user.module.
Class
Code
function testEditorRole() {
$this->backdropLogin($this->admin_user);
$this->backdropGet('admin/config/people/roles');
// Before setting an admin role, check that no permissions are automatically
// assigned on new content types.
$this->backdropGet('admin/structure/types/add');
$this->assertRaw(t('No permissions assigned for this content type. Content of this type may not be able to be created, updated or deleted until permissions have been configured appropriately.'));
$this->assertNoFieldByXPath("//table[@id='permissions']//input[@checked]");
// Set both an admin role and editor role.
$edit = array();
$edit['user_admin_role'] = $this->admin_role_name;
$edit['user_editor_role'] = $this->editor_role_name;
$this->backdropPost('admin/config/people/roles', $edit, t('Save configuration'));
// Create a new content type and confirm the permissions are added.
$this->backdropGet('admin/structure/types/add');
$this->assertRaw(t('The %admin and %editor roles have been assigned permissions to create, edit, and delete content of this type.', array(
'%admin' => $this->admin_role_name,
'%editor' => $this->editor_role_name
)));
// Opposite of the above assertNoFieldByXPath(), confirm that there are at
// least some permission checkboxes checked.
$this->assertFieldByXPath("//table[@id='permissions']//input[@checked]");
$content_type_permissions = array(
'create content',
'edit own content',
'edit any content',
'delete own content',
'delete any content',
);
// In this case, both admin and editor checkboxes are checked.
$role_names = array(
$this->admin_role_name,
$this->editor_role_name,
);
foreach ($content_type_permissions as $type_permission) {
foreach ($role_names as $role_name) {
if (!($type_permission == 'delete any content' && $role_name == $this->editor_role_name)) {
$checkbox_id = backdrop_strtolower(str_replace(' ', '-', "edit $role_name $type_permission"));
$this->assertFieldChecked($checkbox_id);
}
}
}
// Save the form with no other changes.
$content_type_name = backdrop_strtolower($this->randomName());
$edit = array(
'name' => $content_type_name,
'type' => $content_type_name,
);
$this->backdropPost(NULL, $edit, t('Save content type'));
// Now check permissions were correctly assigned.
$user_accounts = array(
$this->admin_user,
$this->editor_user,
);
backdrop_static_reset('user_roles');
backdrop_static_reset('user_access');
foreach ($content_type_permissions as $type_permission) {
$permission_name = backdrop_strtolower(str_replace('content', "$content_type_name content", $type_permission));
foreach ($user_accounts as $user_account) {
if (!($type_permission == 'delete any content' && $user_account == $this->editor_user)) {
$this->assertTrue(user_access($permission_name, $user_account));
}
}
}
}