diff --git a/src/Palantirnet/PalantirBehatExtension/Context/DrupalUserContext.php b/src/Palantirnet/PalantirBehatExtension/Context/DrupalUserContext.php index e8c740c..a91a106 100644 --- a/src/Palantirnet/PalantirBehatExtension/Context/DrupalUserContext.php +++ b/src/Palantirnet/PalantirBehatExtension/Context/DrupalUserContext.php @@ -1,38 +1,52 @@ getStorage('user_role'); - - // convert the single role given to an array for the isPermissionInRoles() function - $rids = array($role); - - foreach($perms->getHash() as $row){ - // grab the value out of the row. it will always be the first value - $perm = reset($row); - - // check the permission against the role - if(!$roleStorage->isPermissionInRoles($perm, $rids)){ - throw new Exception('Role '.$role.' does not have permission '.$perm); - } - } - } -} \ No newline at end of file +/** + * Class DrupalUserContext + */ +class DrupalUserContext extends SharedDrupalContext +{ + + + /** + * Asserts a role has a list of permissions + * + * @Then the :role role should have the permission(s): + * + * @param String $role The role to check for the list of permissions. + * @param TableNode $perms The permissions this role should have. + * + * @return void + * + * @throws \Exception + */ + public function assertRoleHasPermission($role, TableNode $perms) + { + // Get the role storage object so we can query it for permissions. + $roleStorage = \Drupal::entityManager()->getStorage('user_role'); + + // Convert the single role given to an array for the isPermissionInRoles() function. + $rids = array($role); + + foreach ($perms->getHash() as $row) { + // Grab the value out of the row. It will always be the first value. + $perm = reset($row); + + // Check the permission against the role. + if (false === $roleStorage->isPermissionInRoles($perm, $rids)) { + throw new Exception('Role '.$role.' does not have permission '.$perm); + } + } + + }//end assertRoleHasPermission() + + +}//end class