You are here

function ContentAccessTestCase::setUp in Content Access 7

Same name and namespace in other branches
  1. 5 tests/content_access_test_help.php \ContentAccessTestCase::setUp()
  2. 6 tests/content_access_test_help.php \ContentAccessTestCase::setUp()

Preparation work that is done before each test. Test users, content types, nodes etc. are created.

Overrides DrupalWebTestCase::setUp

2 calls to ContentAccessTestCase::setUp()
ContentAccessACLTestCase::setUp in tests/content_access_acl.test
Setup configuration before each test
ContentAccessModuleTestCase::setUp in tests/content_access.test
Preparation work that is done before each test. Test users, content types, nodes etc. are created.
2 methods override ContentAccessTestCase::setUp()
ContentAccessACLTestCase::setUp in tests/content_access_acl.test
Setup configuration before each test
ContentAccessModuleTestCase::setUp in tests/content_access.test
Preparation work that is done before each test. Test users, content types, nodes etc. are created.

File

tests/content_access_test_help.php, line 22
Helper class with auxiliary functions for content access module tests

Class

ContentAccessTestCase
@file Helper class with auxiliary functions for content access module tests

Code

function setUp($module = '') {
  if (empty($module)) {

    // Enable content access module
    parent::setUp('content_access');
  }
  else {

    // Enable content access module plus another module
    parent::setUp('content_access', $module);

    // Stop setup when module could not be enabled
    if (!module_exists($module)) {
      $this
        ->pass('No ' . $module . ' module present, skipping test');
      return;
    }
  }

  // Create test user with separate role.
  $this->test_user = $this
    ->drupalCreateUser(array(
    'access content',
  ));

  // Get the value of the new role.
  // Needed in D7 because drupalCreateUser() creates two roles for new users:
  // one role is Authenticated and the second has the given permissions.
  // @see drupalCreateUser()
  $roles = $this->test_user->roles;
  unset($roles[DRUPAL_AUTHENTICATED_RID]);
  $this->rid = key($roles);

  // Create admin user
  $this->admin_user = $this
    ->drupalCreateUser(array(
    'access content',
    'administer content types',
    'grant content access',
    'grant own content access',
    'bypass node access',
    'administer nodes',
    'access administration pages',
  ));
  $this
    ->drupalLogin($this->admin_user);

  // Rebuild content access permissions
  node_access_rebuild();

  // Create test content type
  $this->content_type = $this
    ->drupalCreateContentType();
}