Skip to content

Commit

Permalink
Try to make phpcs happy.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea R Soper committed Dec 5, 2016
1 parent 3de8eea commit 86c2e6f
Showing 1 changed file with 43 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
<?php

/**
* @file
* Contains Palantirnet\PalantirBehatExtension\Context\DrupalUserContext
*
* @copyright Copyright (c) 2016 Palantir.net
* @copyright 2016 Palantir.net
*/

use Behat\Gherkin\Node\TableNode;
use Palantirnet\PalantirBehatExtension\Context\SharedDrupalContext;

class DrupalUserContext extends SharedDrupalContext {
/**
* Asserts a role has a list of permissions
*
* @Then the :role role should have the permission(s):
*
* @param String $role
* @param TableNode $perms
*/
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(!$roleStorage->isPermissionInRoles($perm, $rids)){
throw new Exception('Role '.$role.' does not have permission '.$perm);
}
}
}
}
/**
* 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

0 comments on commit 86c2e6f

Please sign in to comment.