protected function UserProtectCreationTrait::createProtectedRole in User protect 8
Creates a protected role.
Parameters
array $protections: (optional) The active protections. Defaults to an empty array.
Return value
string The ID of the created role.
2 calls to UserProtectCreationTrait::createProtectedRole()
- ProtectionRuleBypassTest::doRoleProtectionBypassTest in tests/
src/ Kernel/ ProtectionRuleBypassTest.php - Tests if bypassing a certain role protection is respected.
- UserProtectCreationTrait::createUserWithProtectedRole in tests/
src/ Traits/ UserProtectCreationTrait.php - Creates an user with a protected role.
File
- tests/
src/ Traits/ UserProtectCreationTrait.php, line 25
Class
- UserProtectCreationTrait
- Provides methods to create protection rules.
Namespace
Drupal\Tests\userprotect\TraitsCode
protected function createProtectedRole(array $protections = []) {
// Create a role.
$rid = $this
->drupalCreateRole([]);
// Protect this role.
$protection_rule = $this
->createProtectionRule($rid, $protections);
$protection_rule
->save();
// Reset available permissions.
drupal_static_reset('checkPermissions');
return $rid;
}