You are here

class ContentAccessACLTestCase in Content Access 5

Same name and namespace in other branches
  1. 6 tests/content_access_acl.test \ContentAccessACLTestCase
  2. 7 tests/content_access_acl.test \ContentAccessACLTestCase

Hierarchy

Expanded class hierarchy of ContentAccessACLTestCase

File

tests/content_access_acl.test, line 10

View source
class ContentAccessACLTestCase extends ContentAccessTestCase {
  var $node;

  /**
   * Implementation of get_info() for information
   */
  function get_info() {
    return array(
      'name' => t('Content Access Module with ACL Module Tests'),
      'desc' => t('Various tests to check the combination of content access and ACL module.'),
      'group' => 'Content Access',
    );
  }

  /**
   * Setup configuration before each test
   */
  function setUp() {
    parent::setUp();

    // Create test nodes
    $this->node = $this
      ->createNode();
  }

  /**
   * Test Viewing accessibility with permissions for single users
   */
  function testViewAccess() {

    // Enable ACL module
    // Exit test if module could not be enabled
    if (!$this
      ->aclModuleEnable()) {
      $this
        ->pass('No ACL module present, skipping test');
      return;
    }

    // Restrict access to this content type (access is only allowed for the author)
    // Enable per node access control
    $access_permissions = array(
      'view[author]' => TRUE,
      'view[1]' => FALSE,
      'view[2]' => FALSE,
      'per_node' => TRUE,
    );
    $this
      ->changeAccessContentType($access_permissions);

    // Allow access for test user
    $edit = array(
      'acl[view][add]' => $this->test_user->name,
    );
    $this
      ->drupalPostRequest('node/' . $this->node->nid . '/access', $edit, 'Add User');
    $this
      ->postToCurrentPage(array(), 'Submit');

    // Logout admin, try to access the node anonymously
    $this
      ->drupalGet(url('logout'));
    $this
      ->drupalGet(url('node/' . $this->node->nid));
    $this
      ->assertText(t('Access denied'), 'node is not viewable');

    // Login test user, view access should be allowed now
    $this
      ->drupalLoginUser($this->test_user);
    $this
      ->drupalGet(url('node/' . $this->node->nid));
    $this
      ->assertNoText(t('Access denied'), 'node is viewable');

    // Login admin and disable per node access
    $this
      ->drupalGet(url('logout'));
    $this
      ->drupalLoginUser($this->admin_user);
    $this
      ->changeAccessPerNode(FALSE);

    // Logout admin, try to access the node anonymously
    $this
      ->drupalGet(url('logout'));
    $this
      ->drupalGet(url('node/' . $this->node->nid));
    $this
      ->assertText(t('Access denied'), 'node is not viewable');

    // Login test user, view access should be denied now
    $this
      ->drupalLoginUser($this->test_user);
    $this
      ->drupalGet(url('node/' . $this->node->nid));
    $this
      ->assertText(t('Access denied'), 'node is not viewable');
  }

  /**
   * Test Editing accessibility with permissions for single users
   */
  function testEditAccess() {

    // Enable ACL module
    // Exit test if module could not be enabled
    if (!$this
      ->aclModuleEnable()) {
      $this
        ->pass('No ACL module present, skipping test');
      return;
    }

    // Enable per node access control
    $this
      ->changeAccessPerNode();

    // Allow edit access for test user
    $edit = array(
      'acl[update][add]' => $this->test_user->name,
    );
    $this
      ->drupalPostRequest('node/' . $this->node->nid . '/access', $edit, 'acl[update][add_button]');
    $this
      ->postToCurrentPage(array(), 'Submit');

    // Logout admin, try to edit the node anonymously
    $this
      ->drupalGet(url('logout'));
    $this
      ->drupalGet(url('node/' . $this->node->nid . '/edit'));
    $this
      ->assertText(t('Access denied'), 'node is not editable');

    // Login test user, edit access should be allowed now
    $this
      ->drupalLoginUser($this->test_user);
    $this
      ->drupalGet(url('node/' . $this->node->nid . '/edit'));
    $this
      ->assertNoText(t('Access denied'), 'node is editable');

    // Login admin and disable per node access
    $this
      ->drupalGet(url('logout'));
    $this
      ->drupalLoginUser($this->admin_user);
    $this
      ->changeAccessPerNode(FALSE);

    // Logout admin, try to edit the node anonymously
    $this
      ->drupalGet(url('logout'));
    $this
      ->drupalGet(url('node/' . $this->node->nid . '/edit'));
    $this
      ->assertText(t('Access denied'), 'node is not editable');

    // Login test user, edit access should be denied now
    $this
      ->drupalLoginUser($this->test_user);
    $this
      ->drupalGet(url('node/' . $this->node->nid . '/edit'));
    $this
      ->assertText(t('Access denied'), 'node is not editable');
  }

  /**
   * Test Deleting accessibility with permissions for single users
   */
  function testDeleteAccess() {

    // Enable ACL module
    // Exit test if module could not be enabled
    if (!$this
      ->aclModuleEnable()) {
      $this
        ->pass('No ACL module present, skipping test');
      return;
    }

    // Enable per node access control
    $this
      ->changeAccessPerNode();

    // Allow delete access for test user
    $edit = array(
      'acl[delete][add]' => $this->test_user->name,
    );
    $this
      ->drupalPostRequest('node/' . $this->node->nid . '/access', $edit, 'acl[delete][add_button]');
    $this
      ->postToCurrentPage(array(), 'Submit');

    // Logout admin, try to delete the node anonymously
    $this
      ->drupalGet(url('logout'));
    $this
      ->drupalGet(url('node/' . $this->node->nid . '/delete'));
    $this
      ->assertText(t('Access denied'), 'node is not deletable');

    // Login test user, delete access should be allowed now
    $this
      ->drupalLoginUser($this->test_user);
    $this
      ->drupalGet(url('node/' . $this->node->nid . '/delete'));
    $this
      ->assertNoText(t('Access denied'), 'node is deletable');

    // Login admin and disable per node access
    $this
      ->drupalGet(url('logout'));
    $this
      ->drupalLoginUser($this->admin_user);
    $this
      ->changeAccessPerNode(FALSE);

    // Logout admin, try to delete the node anonymously
    $this
      ->drupalGet(url('logout'));
    $this
      ->drupalGet(url('node/' . $this->node->nid . '/delete'));
    $this
      ->assertText(t('Access denied'), 'node is not deletable');

    // Login test user, delete access should be denied now
    $this
      ->drupalLoginUser($this->test_user);
    $this
      ->drupalGet(url('node/' . $this->node->nid . '/delete'));
    $this
      ->assertText(t('Access denied'), 'node is not deletable');
  }

  /**
   * Enables the ACL module and returns TRUE on success
   */
  function aclModuleEnable() {
    if (module_exists('acl')) {
      return TRUE;
    }
    module_enable(array(
      'acl',
    ));
    if (module_exists('acl')) {
      module_disable(array(
        'acl',
      ));

      // Make sure we use drupalModuleEnable(), so the module is disabled again afterwards.
      $this
        ->drupalModuleEnable('acl');
      return TRUE;
    }
    return FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContentAccessACLTestCase::$node property
ContentAccessACLTestCase::aclModuleEnable function Enables the ACL module and returns TRUE on success
ContentAccessACLTestCase::get_info function Implementation of get_info() for information
ContentAccessACLTestCase::setUp function Setup configuration before each test Overrides ContentAccessTestCase::setUp
ContentAccessACLTestCase::testDeleteAccess function Test Deleting accessibility with permissions for single users
ContentAccessACLTestCase::testEditAccess function Test Editing accessibility with permissions for single users
ContentAccessACLTestCase::testViewAccess function Test Viewing accessibility with permissions for single users
ContentAccessTestCase::$admin_user property
ContentAccessTestCase::$content_type_name property
ContentAccessTestCase::$node1 property 1
ContentAccessTestCase::$node2 property 1
ContentAccessTestCase::$test_user property
ContentAccessTestCase::$url_content_type_name property
ContentAccessTestCase::changeAccessContentType function Change access permissions for a content type
ContentAccessTestCase::changeAccessContentTypeKeyword function Change access permissions for a content type by a given keyword (view, update or delete) for the role of the user
ContentAccessTestCase::changeAccessNode function Change access permission for a node
ContentAccessTestCase::changeAccessNodeKeyword function Change access permissions for a node by a given keyword (view, update or delete)
ContentAccessTestCase::changeAccessPerNode function Change the per node access setting for a content type
ContentAccessTestCase::createNode function Creates a node for testing purposes
ContentAccessTestCase::debugCurrentPage function Stores the current page in the files directory, so it can be viewed by the developer. Useful for debugging code.
ContentAccessTestCase::postToCurrentPage function Replacement for drupalPostRequest() if we don't want to reload a path
ContentAccessTestCase::tearDown function Clear up work that is done after each test. Users get deleted automatically, so we just have to delete the content type. (nodes get deleted automatically, too) Overrides DrupalTestCase::tearDown
DrupalTestCase::$_cleanupModules property
DrupalTestCase::$_cleanupRoles property
DrupalTestCase::$_cleanupUsers property
DrupalTestCase::$_cleanupVariables property
DrupalTestCase::$_content property
DrupalTestCase::assertCopy function Will trigger a pass if both parameters refer to different objects. Fail otherwise.
DrupalTestCase::assertEqual function Will trigger a pass if the two parameters have the same value only. Otherwise a fail.
DrupalTestCase::assertError function Confirms that an error has occurred and optionally that the error text matches exactly.
DrupalTestCase::assertErrorPattern function Confirms that an error has occurred and that the error text matches a Perl regular expression.
DrupalTestCase::assertIdentical function Will trigger a pass if the two parameters have the same value and same type. Otherwise a fail.
DrupalTestCase::assertIsA function Type and class test. Will pass if class matches the type name or is a subclass or if not an object, but the type is correct.
DrupalTestCase::assertNoErrors function Confirms that no errors have occurred so far in the test method.
DrupalTestCase::assertNotA function Type and class mismatch test. Will pass if class name or underling type does not match the one specified.
DrupalTestCase::assertNotEqual function Will trigger a pass if the two parameters have a different value. Otherwise a fail.
DrupalTestCase::assertNotIdentical function Will trigger a pass if the two parameters have the different value or different type.
DrupalTestCase::assertNotNull function Will be true if the value is set.
DrupalTestCase::assertNoUnwantedPattern function Will trigger a pass if the Perl regex pattern is not present in subject. Fail if found.
DrupalTestCase::assertNoUnwantedRaw function Will trigger a pass if the raw text is NOT found on the loaded page Fail otherwise.
DrupalTestCase::assertNull function Will be true if the value is null.
DrupalTestCase::assertReference function Will trigger a pass if both parameters refer to the same object. Fail otherwise.
DrupalTestCase::assertWantedPattern function Will trigger a pass if the Perl regex pattern is found in the subject. Fail otherwise.
DrupalTestCase::assertWantedRaw function Will trigger a pass if the raw text is found on the loaded page Fail otherwise.
DrupalTestCase::clickLink function Follows a link by name. Will click the first link found with this link text by default, or a later one if an index is given. Match is case insensitive with normalised space. Does make assertations if the click was sucessful or not and it does…
DrupalTestCase::drupalCheckAuth function @abstract Checks to see if we need to send a http-auth header to authenticate when browsing a site.
DrupalTestCase::drupalCreateRolePerm function Create a role / perm combination specified by permissions
DrupalTestCase::drupalCreateUserRolePerm function Creates a user / role / permissions combination specified by permissions
DrupalTestCase::drupalGet function @abstract Brokder for the get function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com>
DrupalTestCase::drupalGetContent function @TODO: needs documentation
DrupalTestCase::drupalLoginUser function Logs in a user with the internal browser
DrupalTestCase::drupalModuleDisable function Disables a drupal module
DrupalTestCase::drupalModuleEnable function Enables a drupal module
DrupalTestCase::drupalPostRequest function Do a post request on a drupal page. It will be done as usual post request with SimpleBrowser
DrupalTestCase::drupalRawPost function @abstract Broker for the post function adds the authentication headers if necessary @author Earnest Berry III <earnest.berry@gmail.com>
DrupalTestCase::DrupalTestCase function
DrupalTestCase::drupalVariableSet function Set a druapl variable and keep track of the changes for tearDown()
DrupalTestCase::randomName function Generates a random string, to be used as name or whatever
DrupalTestCase::run function Just some info for the reporter