diff --git a/src/Drupal/DrupalExtension/Context/DrupalContext.php b/src/Drupal/DrupalExtension/Context/DrupalContext.php index 6311231e..672da254 100644 --- a/src/Drupal/DrupalExtension/Context/DrupalContext.php +++ b/src/Drupal/DrupalExtension/Context/DrupalContext.php @@ -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);