You are here

protected function NodeViewCountTestBase::createUserWithRole in Node view count 8

Create user with given role name.

Parameters

string $user_role_name: User role name.

Return value

\Drupal\Core\Entity\EntityInterface Created user entity.

Throws

\Drupal\Core\Entity\EntityStorageException

4 calls to NodeViewCountTestBase::createUserWithRole()
NodeViewCountBaseFunctionalityTest::checkFullViewMode in src/Tests/NodeViewCountBaseFunctionalityTest.php
Check nodeviewcount settings on node view for full view mode.
NodeViewCountBaseFunctionalityTest::checkTeaserViewMode in src/Tests/NodeViewCountBaseFunctionalityTest.php
Check nodeviewcount settings on node view for teaser view mode.
NodeViewCountTestBase::setUp in src/Tests/NodeViewCountTestBase.php
NodeViewCountViewsTest::testLastViewsPerUserView in src/Tests/NodeViewCountViewsTest.php
Tests Last views per user view.

File

src/Tests/NodeViewCountTestBase.php, line 170

Class

NodeViewCountTestBase
Defines a base class for testing the nodeviewcount module.

Namespace

Drupal\nodeviewcount\Tests

Code

protected function createUserWithRole($user_role_name) {

  // Create a user assigned to that role.
  $edit['name'] = $this
    ->randomMachineName();
  $edit['mail'] = $edit['name'] . '@example.com';
  $edit['pass'] = user_password();
  $edit['status'] = 1;
  $edit['roles'] = [
    $user_role_name,
  ];
  $account = User::create($edit);
  $account
    ->save();
  $this
    ->assertTrue($account
    ->id(), new FormattableMarkup('User created with name %name and pass %pass', [
    '%name' => $edit['name'],
    '%pass' => $edit['pass'],
  ]));
  if (!$account
    ->id()) {
    return NULL;
  }

  // Add the raw password so that we can log in as this user.
  $account->pass_raw = $edit['pass'];
  return $account;
}