You are here

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

Same name and namespace in other branches
  1. 6 administerusersbyrole.test \AdministerUsersByRoleTestCase::setUp()
  2. 7.2 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);

  // 'alpha and other' editor
  $perms = array(
    'access administration pages',
    'access content',
    'administer users',
    _administerusersbyrole_build_perm_string('alpha', 'edit', TRUE),
  );
  $this
    ->checkPermissions(array(), TRUE);
  $this->roles['alpha_o_ed'] = $this
    ->drupalCreateRole($perms, 'alpha_o_ed');
  $this
    ->createUserWithRole('alpha_o_ed', array(
    'alpha_o_ed',
  ));

  // 'alpha and other' deletor
  $perms = array(
    'access administration pages',
    'access content',
    'administer users',
    _administerusersbyrole_build_perm_string('alpha', 'cancel', TRUE),
  );
  $this
    ->checkPermissions(array(), TRUE);
  $this->roles['alpha_o_del'] = $this
    ->drupalCreateRole($perms, 'alpha_o_del');
  $this
    ->createUserWithRole('alpha_o_del', array(
    'alpha_o_del',
  ));
  $this
    ->createRolesAndUsers('beta', TRUE);

  // 'beta and other' editor
  $perms = array(
    'access administration pages',
    'access content',
    'administer users',
    _administerusersbyrole_build_perm_string('beta', 'edit', TRUE),
  );
  $this
    ->checkPermissions(array(), TRUE);
  $this->roles['beta_o_ed'] = $this
    ->drupalCreateRole($perms, 'beta_o_ed');
  $this
    ->createUserWithRole('beta_o_ed', array(
    'beta_o_ed',
  ));
  $this
    ->createUserWithRole('alphabeta', array(
    'alpha',
    'beta',
  ));

  // all_editor
  $perms = array(
    'access administration pages',
    'access content',
    'administer users',
    'edit users with no custom roles',
  );
  foreach ($this->roles as $roleName => $roleID) {
    $perms[] = _administerusersbyrole_build_perm_string($roleName, 'edit', FALSE);
  }
  $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 administration pages',
    'access content',
    'administer users',
    'cancel users with no custom roles',
  );
  foreach ($this->roles as $roleName => $roleID) {
    $perms[] = _administerusersbyrole_build_perm_string($roleName, 'cancel', FALSE);
  }
  $this
    ->checkPermissions(array(), TRUE);
  $this->roles['all_deletor'] = $this
    ->drupalCreateRole($perms, 'all_deletor');
  $this
    ->createUserWithRole('all_deletor', array(
    'all_deletor',
  ));

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