protected function EntityUnitTestBase::createUser

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. The role_permission and users_roles tables must be installed before this can be used.

Return value

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

12 calls to EntityUnitTestBase::createUser()
EntityAccessTest::testEntityAccess in drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityAccessTest.php
Ensures entity access is properly working.
EntityAccessTest::testEntityAccessDefaultController in drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityAccessTest.php
Ensures that the default controller is used as a fallback.
EntityAccessTest::testEntityTranslationAccess in drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityAccessTest.php
Ensures entity access for entity translations is properly working.
EntityApiTest::testCRUD in drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityApiTest.php
Tests basic CRUD functionality of the Entity API.
EntityBCDecoratorTest::testBCDecorator in drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityBCDecoratorTest.php
Tests using the entity BC decorator with entity properties.

... See full list

File

drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUnitTestBase.php, line 45
Contains \Drupal\system\Tests\Entity\EntityUnitTestBase.

Class

EntityUnitTestBase
Defines an abstract test base for entity unit tests.

Namespace

Drupal\system\Tests\Entity

Code

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

    // Create a new role and apply permissions to it.
    $role = entity_create('user_role', array(
      'id' => strtolower($this
        ->randomName(8)),
      'label' => $this
        ->randomName(8),
    ));
    $role
      ->save();
    user_role_grant_permissions($role
      ->id(), $permissions);
    $values['roles'][] = $role
      ->id();
  }
  $account = entity_create('user', $values + array(
    'name' => $this
      ->randomName(),
    'status' => 1,
  ));
  $account
    ->enforceIsNew();
  $account
    ->save();
  return $account;
}