Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal-3443915
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
drupal-3443915
Commits
45da508e
Commit
45da508e
authored
14 years ago
by
Dries Buytaert
Browse files
Options
Downloads
Patches
Plain Diff
- Patch
#334671
by Steve Dondley, naxoc: add tests for user role administration.
parent
d6893186
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/user/user.test
+89
-0
89 additions, 0 deletions
modules/user/user.test
with
89 additions
and
0 deletions
modules/user/user.test
+
89
−
0
View file @
45da508e
...
...
@@ -1630,3 +1630,92 @@ class UserUserSearchTestCase extends DrupalWebTestCase {
}
/**
* Test role assignment.
*/
class
UserRolesAssignmentTestCase
extends
DrupalWebTestCase
{
protected
$admin_user
;
public
static
function
getInfo
()
{
return
array
(
'name'
=>
t
(
'Role assignment'
),
'description'
=>
t
(
'Tests that users can be assigned and unassigned roles.'
),
'group'
=>
t
(
'User'
)
);
}
function
setUp
()
{
parent
::
setUp
();
$this
->
admin_user
=
$this
->
drupalCreateUser
(
array
(
'administer permissions'
,
'administer users'
));
$this
->
drupalLogin
(
$this
->
admin_user
);
}
/**
* Tests that a user can be assigned a role and that the role can be removed
* again.
*/
function
testAssignAndRemoveRole
()
{
$rid
=
$this
->
drupalCreateRole
(
array
(
'administer content types'
));
$account
=
$this
->
drupalCreateUser
();
// Assign the role to the user.
$this
->
drupalPost
(
'user/'
.
$account
->
uid
.
'/edit'
,
array
(
"roles[
$rid
]"
=>
$rid
),
t
(
'Save'
));
$this
->
assertText
(
t
(
'The changes have been saved.'
));
$this
->
assertFieldChecked
(
'edit-roles-'
.
$rid
,
t
(
'Role is assigned.'
));
$this
->
userLoadAndCheckRoleAssigned
(
$account
,
$rid
);
// Remove the role from the user.
$this
->
drupalPost
(
'user/'
.
$account
->
uid
.
'/edit'
,
array
(
"roles[
$rid
]"
=>
FALSE
),
t
(
'Save'
));
$this
->
assertText
(
t
(
'The changes have been saved.'
));
$this
->
assertNoFieldChecked
(
'edit-roles-'
.
$rid
,
t
(
'Role is removed from user.'
));
$this
->
userLoadAndCheckRoleAssigned
(
$account
,
$rid
,
FALSE
);
}
/**
* Tests that when creating a user the role can be assigned. And that it can
* be removed again.
*/
function
testCreateUserWithRole
()
{
$rid
=
$this
->
drupalCreateRole
(
array
(
'administer content types'
));
// Create a new user and add the role at the same time.
$edit
=
array
(
'name'
=>
$this
->
randomName
(),
'mail'
=>
$this
->
randomName
()
.
'@example.com'
,
'pass[pass1]'
=>
$pass
=
$this
->
randomString
(),
'pass[pass2]'
=>
$pass
,
"roles[
$rid
]"
=>
$rid
,
);
$this
->
drupalPost
(
'admin/people/create'
,
$edit
,
t
(
'Create new account'
));
$this
->
assertText
(
t
(
'Created a new user account for !name.'
,
array
(
'!name'
=>
$edit
[
'name'
])));
// Get the newly added user.
$account
=
user_load_by_name
(
$edit
[
'name'
]);
$this
->
drupalGet
(
'user/'
.
$account
->
uid
.
'/edit'
);
$this
->
assertFieldChecked
(
'edit-roles-'
.
$rid
,
t
(
'Role is assigned.'
));
$this
->
userLoadAndCheckRoleAssigned
(
$account
,
$rid
);
// Remove the role again.
$this
->
drupalPost
(
'user/'
.
$account
->
uid
.
'/edit'
,
array
(
"roles[
$rid
]"
=>
FALSE
),
t
(
'Save'
));
$this
->
assertText
(
t
(
'The changes have been saved.'
));
$this
->
assertNoFieldChecked
(
'edit-roles-'
.
$rid
,
t
(
'Role is removed from user.'
));
$this
->
userLoadAndCheckRoleAssigned
(
$account
,
$rid
,
FALSE
);
}
/**
* Check role on user object.
*
* @param object $account User.
* @param integer $rid Role id.
* @param bool $is_assigned True if the role should present on the account.
*/
private
function
userLoadAndCheckRoleAssigned
(
$account
,
$rid
,
$is_assigned
=
TRUE
)
{
$account
=
user_load
(
$account
->
uid
,
TRUE
);
if
(
$is_assigned
)
{
$this
->
assertTrue
(
array_key_exists
(
$rid
,
$account
->
roles
),
t
(
'The role is present in the user object.'
));
}
else
{
$this
->
assertFalse
(
array_key_exists
(
$rid
,
$account
->
roles
),
t
(
'The role is not present in the user object.'
));
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment