You are here

protected function EntityUnitTestBase::createUser in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Entity/EntityUnitTestBase.php \Drupal\system\Tests\Entity\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.

Return value

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

34 calls to EntityUnitTestBase::createUser()
CommentDefaultFormatterCacheTagsTest::setUp in core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php
Performs setup tasks before each individual test method is run.
CommentDefaultFormatterCacheTagsTest::testCacheTags in core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php
Tests the bubbling of cache tags.
CommentFieldAccessTest::testAccessToAdministrativeFields in core/modules/comment/src/Tests/CommentFieldAccessTest.php
Test permissions on comment fields.
ContentEntityChangedTest::testChanged in core/modules/system/src/Tests/Entity/ContentEntityChangedTest.php
Tests basic EntityChangedInterface functionality.
ContentEntityChangedTest::testRevisionChanged in core/modules/system/src/Tests/Entity/ContentEntityChangedTest.php
Tests revisionable EntityChangedInterface functionality.

... See full list

File

core/modules/system/src/Tests/Entity/EntityUnitTestBase.php, line 99
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
        ->randomMachineName(8)),
      'label' => $this
        ->randomMachineName(8),
    ));
    $role
      ->save();
    user_role_grant_permissions($role
      ->id(), $permissions);
    $values['roles'][] = $role
      ->id();
  }
  $account = entity_create('user', $values + array(
    'name' => $this
      ->randomMachineName(),
    'status' => 1,
  ));
  $account
    ->enforceIsNew();
  $account
    ->save();
  return $account;
}