You are here

protected function GroupLevelAccessTest::createOgRole in Organic groups 8

Creates an OG role with the given permissions and admin flag.

Parameters

string[] $permissions: The permissions to set on the role.

bool $is_admin: Whether or not this is an admin role.

Return value

\Drupal\og\OgRoleInterface The newly created role.

3 calls to GroupLevelAccessTest::createOgRole()
GroupLevelAccessTest::setUp in tests/src/Kernel/Access/GroupLevelAccessTest.php
GroupLevelAccessTest::setupGroupEntityOperationPermissions in tests/src/Kernel/Access/GroupLevelAccessTest.php
Returns test users with permissions to perform group entity operations.
GroupLevelAccessTest::setupUserAccessArbitraryPermissions in tests/src/Kernel/Access/GroupLevelAccessTest.php
Sets up a matrix of users and roles with arbitrary permissions.

File

tests/src/Kernel/Access/GroupLevelAccessTest.php, line 379

Class

GroupLevelAccessTest
Tests user access to group level entity operations and permissions.

Namespace

Drupal\Tests\og\Kernel\Access

Code

protected function createOgRole(array $permissions = [], bool $is_admin = FALSE) : OgRoleInterface {

  /** @var \Drupal\og\OgRoleInterface $role */
  $role = OgRole::create();
  $role
    ->setName($this
    ->randomMachineName())
    ->setLabel($this
    ->randomString())
    ->setGroupType($this->group
    ->getEntityTypeId())
    ->setGroupBundle($this->groupBundle)
    ->setIsAdmin($is_admin);
  foreach ($permissions as $permission) {
    $role
      ->grantPermission($permission);
  }
  $role
    ->save();
  return $role;
}