You are here

public function AdministerUsersByRoleTestCase::setUp in Administer Users by Role 7.2

Same name and namespace in other branches
  1. 6 administerusersbyrole.test \AdministerUsersByRoleTestCase::setUp()
  2. 7 administerusersbyrole.test \AdministerUsersByRoleTestCase::setUp()

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()

File

./administerusersbyrole.test, line 58
Test Administer Users by Role.

Class

AdministerUsersByRoleTestCase
@file Test Administer Users by Role.

Code

public function setUp() {
  parent::setUp('administerusersbyrole');

  // make sure our immediate dependencies are enabled, since parent::setUp() doesn't check this for us
  $this
    ->assertTrue(module_exists('administerusersbyrole'), "administerusersbyrole.module isn't installed");
  $this
    ->createUserWithRole('noroles', array());
  $this
    ->createRolesAndUsers('alpha', FALSE);
  $this
    ->createRolesAndUsers('beta', TRUE);
  $this
    ->createUserWithRole('alphabeta', array(
    'alpha',
    'beta',
  ));

  // alphabeta_ed
  $perms = array(
    'access content',
    _administerusersbyrole_build_perm_string($this->roles['alpha'], 'edit'),
    _administerusersbyrole_build_perm_string($this->roles['beta'], 'edit'),
  );
  $this
    ->checkPermissions(array(), TRUE);
  $this->roles['alphabeta_ed'] = $this
    ->drupalCreateRole($perms, 'alphabeta_ed');
  $this
    ->createUserWithRole('alphabeta_ed', array(
    'alphabeta_ed',
  ));

  // all_editor
  $perms = array(
    'access content',
    _administerusersbyrole_build_perm_string(DRUPAL_AUTHENTICATED_RID, 'edit'),
  );
  foreach ($this->roles as $roleName => $roleID) {
    $perms[] = _administerusersbyrole_build_perm_string($this->roles[$roleName], 'edit');
  }
  $this
    ->checkPermissions(array(), TRUE);
  $this->roles['all_editor'] = $this
    ->drupalCreateRole($perms, 'all_editor');
  $this
    ->createUserWithRole('all_editor', array(
    'all_editor',
  ));

  // all_deletor
  $perms = array(
    'access content',
    _administerusersbyrole_build_perm_string(DRUPAL_AUTHENTICATED_RID, 'cancel'),
  );
  foreach ($this->roles as $roleName => $roleID) {
    $perms[] = _administerusersbyrole_build_perm_string($roleID, 'cancel');
  }
  $this
    ->checkPermissions(array(), TRUE);
  $this->roles['all_deletor'] = $this
    ->drupalCreateRole($perms, 'all_deletor');
  $this
    ->createUserWithRole('all_deletor', array(
    'all_deletor',
  ));

  // creator
  $perms = array(
    'access content',
    'create users',
  );
  $this
    ->checkPermissions(array(), TRUE);
  $this->roles['creator'] = $this
    ->drupalCreateRole($perms, 'creator');
  $this
    ->createUserWithRole('creator', array(
    'creator',
  ));
}