You are here

protected function WebformAccessTestBase::mockAccount in Webform 6.x

Same name and namespace in other branches
  1. 8.5 tests/src/Unit/Access/WebformAccessTestBase.php \Drupal\Tests\webform\Unit\Access\WebformAccessTestBase::mockAccount()

Create a mock account with permissions.

Parameters

array $permissions: An associative array of permissions and results.

Return value

\Drupal\Core\Session\AccountInterface A mock account with ::hasPermission method.

3 calls to WebformAccessTestBase::mockAccount()
WebformAccountAccessTest::testWebformAccountAccess in tests/src/Unit/Access/WebformAccountAccessTest.php
Tests the check webform account access.
WebformSourceEntityAccessTest::testWebformSourceEntityAccess in tests/src/Unit/Access/WebformSourceEntityAccessTest.php
Tests the check webform source entity access.
WebformSubmissionAccessTest::testWebformSubmissionAccess in tests/src/Unit/Access/WebformSubmissionAccessTest.php
Tests the check webform submission access.

File

tests/src/Unit/Access/WebformAccessTestBase.php, line 48

Class

WebformAccessTestBase
Base class for test access checks.

Namespace

Drupal\Tests\webform\Unit\Access

Code

protected function mockAccount(array $permissions = []) {

  // Convert permission to value map.
  $value_map = [];
  foreach ($permissions as $permission => $result) {
    $value_map[] = [
      $permission,
      $result,
    ];
  }
  $account = $this
    ->createMock('Drupal\\Core\\Session\\AccountInterface');
  $account
    ->expects($this
    ->any())
    ->method('hasPermission')
    ->will($this
    ->returnValueMap($value_map));

  /** @var \Drupal\Core\Session\AccountInterface $account */
  return $account;
}