You are here

public function SocialDrupalContext::assertLoggedInWithPermissionsByName in Open Social 8.8

Same name and namespace in other branches
  1. 8.9 tests/behat/features/bootstrap/SocialDrupalContext.php \Drupal\social\Behat\SocialDrupalContext::assertLoggedInWithPermissionsByName()
  2. 8.7 tests/behat/features/bootstrap/SocialDrupalContext.php \Drupal\social\Behat\SocialDrupalContext::assertLoggedInWithPermissionsByName()
  3. 10.3.x tests/behat/features/bootstrap/SocialDrupalContext.php \Drupal\social\Behat\SocialDrupalContext::assertLoggedInWithPermissionsByName()
  4. 10.0.x tests/behat/features/bootstrap/SocialDrupalContext.php \Drupal\social\Behat\SocialDrupalContext::assertLoggedInWithPermissionsByName()
  5. 10.1.x tests/behat/features/bootstrap/SocialDrupalContext.php \Drupal\social\Behat\SocialDrupalContext::assertLoggedInWithPermissionsByName()
  6. 10.2.x tests/behat/features/bootstrap/SocialDrupalContext.php \Drupal\social\Behat\SocialDrupalContext::assertLoggedInWithPermissionsByName()

@Given I am logged in as :name with the :permissions permission(s)

File

tests/behat/features/bootstrap/SocialDrupalContext.php, line 319

Class

SocialDrupalContext
Provides pre-built step definitions for interacting with Open Social.

Namespace

Drupal\social\Behat

Code

public function assertLoggedInWithPermissionsByName($name, $permissions) {

  // Create a temporary role with given permissions.
  $permissions = array_map('trim', explode(',', $permissions));
  $role = $this
    ->getDriver()
    ->roleCreate($permissions);
  $manager = $this
    ->getUserManager();

  // Change internal current user.
  $manager
    ->setCurrentUser($manager
    ->getUser($name));
  $user = $manager
    ->getUser($name);

  // Assign the temporary role with given permissions.
  $this
    ->getDriver()
    ->userAddRole($user, $role);
  $this->roles[] = $role;

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