You are here

public function WebformAccountAccessTest::testWebformAccountAccess in Webform 6.x

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

Tests the check webform account access.

@covers ::checkAdminAccess @covers ::checkSubmissionAccess @covers ::checkOverviewAccess

File

tests/src/Unit/Access/WebformAccountAccessTest.php, line 22

Class

WebformAccountAccessTest
@coversDefaultClass \Drupal\webform\Access\WebformAccountAccess

Namespace

Drupal\Tests\webform\Unit\Access

Code

public function testWebformAccountAccess() {

  // Mock anonymous account.
  $anonymous_account = $this
    ->mockAccount();

  // Mock admin account.
  $admin_account = $this
    ->mockAccount([
    'administer webform' => TRUE,
    'administer webform submission' => TRUE,
  ]);

  // Mock submission account.
  $submission_account = $this
    ->mockAccount([
    'access webform overview' => TRUE,
    'view any webform submission' => TRUE,
  ]);

  /**************************************************************************/

  // Check admin access.
  $this
    ->assertEquals(AccessResult::neutral()
    ->cachePerPermissions(), WebformAccountAccess::checkAdminAccess($anonymous_account)
    ->setReason(''));
  $this
    ->assertEquals(AccessResult::allowed()
    ->cachePerPermissions(), WebformAccountAccess::checkAdminAccess($admin_account));

  // Check submission access.
  $this
    ->assertEquals(AccessResult::neutral()
    ->cachePerPermissions(), WebformAccountAccess::checkSubmissionAccess($anonymous_account)
    ->setReason(''));
  $this
    ->assertEquals(AccessResult::allowed()
    ->cachePerPermissions(), WebformAccountAccess::checkSubmissionAccess($submission_account));

  // Check overview access.
  $this
    ->assertEquals(AccessResult::neutral()
    ->cachePerPermissions(), WebformAccountAccess::checkOverviewAccess($anonymous_account)
    ->setReason(''));
  $this
    ->assertEquals(AccessResult::allowed()
    ->cachePerPermissions(), WebformAccountAccess::checkOverviewAccess($submission_account));
}