You are here

public function ViewsAccessTest::testEntityPrintAccess in Entity Print 8.2

Test the access works for viewing the PDF's.

File

modules/entity_print_views/tests/src/Kernel/ViewsAccessTest.php, line 49

Class

ViewsAccessTest
Views access test.

Namespace

Drupal\Tests\entity_print_views\Kernel

Code

public function testEntityPrintAccess() {

  // By default we don't have the Entity Print permissions and cannot see the
  // printable version of the view.
  $this
    ->assertFalse($this
    ->checkAccess(new AnonymousUserSession(), 'my_test_view', 'page_1'), 'Access not allowed because we do not have permission');

  // Only entity print access.
  $account = $this
    ->createUser([
    'entity print views access',
  ]);
  $this
    ->assertFalse($this
    ->checkAccess($account, 'my_test_view', 'page_1'), 'Access not allowed because user does not have permission set on view');

  // Only views access.
  $account = $this
    ->createUser([
    'administer nodes',
  ]);
  $this
    ->assertFalse($this
    ->checkAccess($account, 'my_test_view', 'page_1'), 'Access not allowed because user does not have entity print permission.');

  // Both entity print access and views access.
  $account = $this
    ->createUser([
    'entity print views access',
    'administer nodes',
  ]);
  $this
    ->assertTrue($this
    ->checkAccess($account, 'my_test_view', 'page_1'), 'Access allowed for user with "entity print views access" and "administer nodes"');
}