You are here

public function TaxonomyAccessTestCase::setUp in Taxonomy Access Control 7

Sets up a Drupal site for running functional and integration tests.

Generates a random database prefix and installs Drupal with the specified installation profile in DrupalWebTestCase::$profile into the prefixed database. Afterwards, installs any additional modules specified by the test.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

Parameters

...: List of modules to enable for the duration of the test. This can be either a single array or a variable number of string arguments.

Overrides DrupalWebTestCase::setUp

See also

DrupalWebTestCase::prepareDatabasePrefix()

DrupalWebTestCase::changeDatabasePrefix()

DrupalWebTestCase::prepareEnvironment()

4 calls to TaxonomyAccessTestCase::setUp()
TaxonomyAccessConfigTest::setUp in ./taxonomy_access.test
Sets up a Drupal site for running functional and integration tests.
TaxonomyAccessExternalChanges::setUp in ./taxonomy_access.test
Sets up a Drupal site for running functional and integration tests.
TaxonomyAccessNodeGrantTest::setUp in ./taxonomy_access.test
Sets up a Drupal site for running functional and integration tests.
TaxonomyAccessTermGrantTest::setUp in ./taxonomy_access.test
Sets up a Drupal site for running functional and integration tests.
4 methods override TaxonomyAccessTestCase::setUp()
TaxonomyAccessConfigTest::setUp in ./taxonomy_access.test
Sets up a Drupal site for running functional and integration tests.
TaxonomyAccessExternalChanges::setUp in ./taxonomy_access.test
Sets up a Drupal site for running functional and integration tests.
TaxonomyAccessNodeGrantTest::setUp in ./taxonomy_access.test
Sets up a Drupal site for running functional and integration tests.
TaxonomyAccessTermGrantTest::setUp in ./taxonomy_access.test
Sets up a Drupal site for running functional and integration tests.

File

./taxonomy_access.test, line 42
Automated tests for the Taxonomy Access Control module.

Class

TaxonomyAccessTestCase
Provides a base test class and helper methods for automated tests.

Code

public function setUp() {

  // Enable module and dependencies.
  parent::setUp('taxonomy_access');

  // Rebuild node access on installation.
  node_access_rebuild();

  // Configure users with base permission patterns.
  foreach ($this->user_config as $user => $permissions) {
    $this->users[$user] = $this
      ->drupalCreateUser($permissions);

    // Save the role ID separately so it's easy to retrieve.
    foreach ($this->users[$user]->roles as $rid => $role) {
      if ($rid != DRUPAL_AUTHENTICATED_RID) {
        $this->user_roles[$user] = user_role_load($rid);
      }
    }
  }

  // Give the anonymous and authenticated roles ignore grants.
  $rows = array();
  foreach (array(
    DRUPAL_ANONYMOUS_RID,
    DRUPAL_AUTHENTICATED_RID,
  ) as $rid) {
    $ignore = array(
      'view' => TAXONOMY_ACCESS_NODE_IGNORE,
      'update' => TAXONOMY_ACCESS_NODE_IGNORE,
      'delete' => TAXONOMY_ACCESS_NODE_IGNORE,
    );
    $rows[] = _taxonomy_access_format_grant_record(TAXONOMY_ACCESS_GLOBAL_DEFAULT, $rid, $ignore, TRUE);
  }
  taxonomy_access_set_default_grants($rows);
  foreach (array(
    DRUPAL_ANONYMOUS_RID,
    DRUPAL_AUTHENTICATED_RID,
  ) as $rid) {
    $r = db_query('SELECT grant_view FROM {taxonomy_access_default}
           WHERE vid = :vid AND rid = :rid', array(
      ':vid' => TAXONOMY_ACCESS_GLOBAL_DEFAULT,
      ':rid' => $rid,
    ))
      ->fetchField();
    $this
      ->assertTrue(is_numeric($r) && $r == 0, t("Set global default for role %rid to <em>Ignore</em>", array(
      '%rid' => $rid,
    )));
  }
}