You are here

entity_print.test in Entity Print 7

Entity print tests.

File

tests/entity_print.test
View source
<?php

/**
 * @file
 * Entity print tests.
 */
class EntityPrintTest extends DrupalWebTestCase {

  /**
   * The node object to test against.
   *
   * @var \stdClass
   */
  protected $node;

  /**
   * {@inheritdoc}
   */
  public static function getInfo() {
    return array(
      'name' => t('Entity Print Tests'),
      'description' => t('Entity print css and permission tests.'),
      'group' => 'Entity Print',
    );
  }

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp(array(
      'entity_print_test',
    ));

    // We revoke the access content permission because we use that to test our
    // permissions around entity view.
    user_role_revoke_permissions(DRUPAL_ANONYMOUS_RID, array(
      'access content',
    ));
    user_role_revoke_permissions(DRUPAL_AUTHENTICATED_RID, array(
      'access content',
    ));
    $this->node = $this
      ->drupalCreateNode();
    theme_enable(array(
      'entity_print_test_theme',
    ));
    variable_set('theme_default', 'entity_print_test_theme');
  }

  /**
   * Test that CSS is parsed from our test theme correctly.
   */
  public function testEntityPrintThemeCss() {
    $account = $this
      ->drupalCreateUser(array(
      'bypass entity print access',
      'access content',
    ));
    $this
      ->drupalLogin($account);
    $this
      ->drupalGet('entityprint/node/' . $this->node->nid . '/debug');

    // Test the global CSS is there.
    $this
      ->assertRaw('entity-print.css');

    // Disable the global CSS and test it is not there.
    variable_set('entity_print_default_css', FALSE);
    $this
      ->drupalGet($this
      ->getUrl());
    $this
      ->assertNoRaw('entity-print.css');

    // Assert that the css files have been parsed out of our test theme.
    $this
      ->assertRaw('entityprint-all.css');
    $this
      ->assertRaw('entityprint-page.css');
    $this
      ->assertRaw('entityprint-node.css');

    // Test that CSS was added from hook_entity_print_css(). See the
    // entity_print_test module for the implementation.
    $this
      ->assertRaw('entityprint-module.css');
  }

  /**
   * Test the access works for viewing the PDF's.
   */
  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.');
  }

}

Classes

Namesort descending Description
EntityPrintTest @file Entity print tests.