Skip to content

Commit

Permalink
Merge pull request #434 from jhedstrom/nlisgo-hotfix/assert_logged_in…
Browse files Browse the repository at this point in the history
…_with_pemissions

reroll: Undesirable PHP Notice displayed when Exception thrown

Signed-off-by: Jonathan Hedstrom <[email protected]>
jhedstrom committed Dec 4, 2017
1 parent 1ee6082 commit d9b6060
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/Drupal/DrupalExtension/Context/DrupalContext.php
Original file line number Diff line number Diff line change
@@ -123,19 +123,22 @@ public function assertLoggedInByName($name) {
* @Given I am logged in as a user with the :permissions permission(s)
*/
public function assertLoggedInWithPermissions($permissions) {
// Create a temporary role with given permissions.
$permissions = array_map('trim', explode(',', $permissions));
$role = $this->getDriver()->roleCreate($permissions);

// Create user.
$user = (object) array(
'name' => $this->getRandom()->name(8),
'pass' => $this->getRandom()->name(16),
'role' => $role,
);
$user->mail = "{$user->name}@example.com";
$this->userCreate($user);

// Create and assign a temporary role with given permissions.
$permissions = array_map('trim', explode(',', $permissions));
$rid = $this->getDriver()->roleCreate($permissions);
$this->getDriver()->userAddRole($user, $rid);
$this->roles[] = $rid;
// Assign the temporary role with given permissions.
$this->getDriver()->userAddRole($user, $role);
$this->roles[] = $role;

// Login.
$this->login($user);

0 comments on commit d9b6060

Please sign in to comment.