You are here

protected function LinkitKernelTestBase::createUser in Linkit 8.5

Creates a user.

Parameters

array $values: (optional) The values used to create the entity.

array $permissions: (optional) Array of permission names to assign to user.

Return value

\Drupal\user\Entity\User The created user entity.

9 calls to LinkitKernelTestBase::createUser()
ContactFormMatcherTest::setUp in tests/src/Kernel/Matchers/ContactFormMatcherTest.php
FileMatcherTest::setUp in tests/src/Kernel/Matchers/FileMatcherTest.php
LinkitAutocompleteTest::setUp in tests/src/Kernel/LinkitAutocompleteTest.php
MediaMatcherTest::setUp in tests/src/Kernel/Matchers/MediaMatcherTest.php
NodeMatcherTest::setUp in tests/src/Kernel/Matchers/NodeMatcherTest.php

... See full list

File

tests/src/Kernel/LinkitKernelTestBase.php, line 52

Class

LinkitKernelTestBase
Defines an abstract test base for entity kernel tests.

Namespace

Drupal\Tests\linkit\Kernel

Code

protected function createUser(array $values = [], array $permissions = []) {
  if ($permissions) {

    // Create a new role and apply permissions to it.
    $role = Role::create([
      'id' => mb_strtolower($this
        ->randomMachineName(8)),
      'label' => $this
        ->randomMachineName(8),
    ]);
    $role
      ->save();
    user_role_grant_permissions($role
      ->id(), $permissions);
    $values['roles'][] = $role
      ->id();
  }
  $account = User::create($values + [
    'name' => $this
      ->randomMachineName(),
    'status' => 1,
  ]);
  $account
    ->enforceIsNew();
  $account
    ->save();
  return $account;
}