You are here

protected function ApigeeEdgeFunctionalTestTrait::createAccount in Apigee Edge 8

Creates a Drupal account.

Parameters

array $permissions: Permissions to add.

bool $status: Status of the Drupal account.

string $prefix: Prefix of the Drupal account's email.

Return value

\Drupal\user\UserInterface Drupal user.

23 calls to ApigeeEdgeFunctionalTestTrait::createAccount()
AccessTest::setUp in modules/apigee_edge_teams/tests/src/Functional/AccessTest.php
ApiProductAccessTest::setUp in tests/src/FunctionalJavascript/ApiProductAccessTest.php
ApiProductRoleBasedAccessTestBase::setUp in modules/apigee_edge_apiproduct_rbac/tests/src/FunctionalJavascript/ApiProductRoleBasedAccessTestBase.php
CacheTest::setUp in tests/src/FunctionalJavascript/CacheTest.php
ConfigurationPermissionTest::testAccess in tests/src/Functional/ConfigurationPermissionTest.php
Tests access to the admin pages with admin/authenticated/anonymous roles.

... See full list

File

tests/src/Traits/ApigeeEdgeFunctionalTestTrait.php, line 92

Class

ApigeeEdgeFunctionalTestTrait
Provides common functionality for the Apigee Edge test classes.

Namespace

Drupal\Tests\apigee_edge\Traits

Code

protected function createAccount(array $permissions = [], bool $status = TRUE, string $prefix = '') : ?UserInterface {
  $rid = NULL;
  if ($permissions) {
    $rid = $this
      ->createRole($permissions);
    static::assertNotFalse($rid, 'Role created');
  }
  $edit = [
    'first_name' => $this
      ->randomMachineName(),
    'last_name' => $this
      ->randomMachineName(),
    'name' => $this
      ->randomMachineName(),
    'pass' => user_password(),
    'status' => $status,
  ];
  if ($rid) {
    $edit['roles'][] = $rid;
  }
  if ($prefix) {
    $edit['mail'] = "{$prefix}.{$edit['name']}@example.com";
  }
  else {
    $edit['mail'] = "{$edit['name']}@example.com";
  }
  $account = User::create($edit);
  $account
    ->save();
  static::assertNotFalse($account
    ->id(), 'User created.');
  if (!$account
    ->id()) {
    return NULL;
  }

  // This is here to make drupalLogin() work.
  $account->passRaw = $edit['pass'];
  return $account;
}