protected function UserProtectProtectionWebTest::testRolesProtection in User protect 7
Tests if the user's roles field has the expected protection.
File
- tests/
UserProtectProtectionWebTest.test, line 138 - Contains UserProtectProtectionWebTest.
Class
- UserProtectProtectionWebTest
- Tests creating, editing and deleting protection rules through the UI.
Code
protected function testRolesProtection() {
$protected_account = $this
->createProtectedUser(array(
'up_roles' => 1,
));
// Add a role to the protected account.
$rid1 = $this
->drupalCreateRole(array());
$protected_account->roles[$rid1] = $rid1;
user_save($protected_account);
// Add another role. We try to add this role to the user form later.
$rid2 = $this
->drupalCreateRole(array());
// Re-load the user and check its roles.
$protected_account = user_load($protected_account->uid, TRUE);
// Assert the protected account's roles.
$this
->assertTrue(isset($protected_account->roles[$rid1]));
$this
->assertFalse(isset($protected_account->roles[$rid2]));
// Try to add the second role to this user.
$edit = array(
'roles[' . $rid2 . ']' => $rid2,
);
$this
->userprotectPostForm('user/' . $protected_account->uid . '/edit', $edit, t('Save'));
// Re-load the user and assert the roles it has are still the same.
$protected_account = user_load($protected_account->uid, TRUE);
$this
->assertTrue(isset($protected_account->roles[$rid1]));
$this
->assertFalse(isset($protected_account->roles[$rid2]));
}