You are here

public function EntityPrintTest::testEntityPrintAccess in Entity Print 7

Test the access works for viewing the PDF's.

File

tests/entity_print.test, line 72
Entity print tests.

Class

EntityPrintTest
@file Entity print tests.

Code

public function testEntityPrintAccess() {

  // User with bypass entity print access but not content access.
  $account = $this
    ->drupalCreateUser(array(
    'bypass entity print access',
  ));
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet('entityprint/node/' . $this->node->nid . '/debug');
  $this
    ->assertResponse(403, 'User with only the bypass entity print access permission cannot view PDF.');

  // User with access content but not bypass entity print access.
  $account = $this
    ->drupalCreateUser(array(
    'access content',
  ));
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet('entityprint/node/' . $this->node->nid . '/debug');
  $this
    ->assertResponse(403, 'User with access content but not bypass entity print permission cannot view PDF.');

  // User with both bypass entity print access and entity view.
  $account = $this
    ->drupalCreateUser(array(
    'bypass entity print access',
    'access content',
  ));
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet('entityprint/node/' . $this->node->nid . '/debug');
  $this
    ->assertResponse(200, 'User with both permissions can view the PDF.');

  // User with entity type access permission and entity view.
  $account = $this
    ->drupalCreateUser(array(
    'entity print access type node',
    'access content',
  ));
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet('entityprint/node/' . $this->node->nid . '/debug');
  $this
    ->assertResponse(200, 'User with entity print type and access content permission is allowed to see the content.');

  // User with different entity type access permission and entity view.
  $account = $this
    ->drupalCreateUser(array(
    'entity print access type user',
    'access content',
  ));
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet('entityprint/node/' . $this->node->nid . '/debug');
  $this
    ->assertResponse(403, 'User with different entity print type and access content permission is not allowed to see the content.');

  // User with entity bundle access permission and entity view.
  $account = $this
    ->drupalCreateUser(array(
    'entity print access bundle page',
    'access content',
  ));
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet('entityprint/node/' . $this->node->nid . '/debug');
  $this
    ->assertResponse(200, 'User with entity print bundle and access content permission is allowed to see the content.');

  // User with different bundle permission and entity view.
  $account = $this
    ->drupalCreateUser(array(
    'entity print access bundle user',
    'access content',
  ));
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet('entityprint/node/' . $this->node->nid . '/debug');
  $this
    ->assertResponse(403, 'User with different entity print bundle and access content permission is not allowed to see the content.');

  // User with neither permissions.
  $account = $this
    ->drupalCreateUser(array());
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet('entityprint/node/' . $this->node->nid . '/debug');
  $this
    ->assertResponse(403, 'User with neither permission cannot view the PDF.');
}