You are here

public function WebformTestCase::setUp in Webform 7.4

Same name and namespace in other branches
  1. 6.3 tests/webform.test \WebformTestCase::setUp()
  2. 6.2 tests/webform.test \WebformTestCase::setUp()
  3. 7.3 tests/webform.test \WebformTestCase::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

tests/WebformTestCase.test, line 14

Class

WebformTestCase
Webform module tests.

Code

public function setUp($added_modules = array()) {

  // Enable Webform and Token modules.
  $modules = array(
    'webform',
    'token',
  );
  parent::setUp(array_merge($modules, $added_modules));

  // Create a profile field to test [user:?] tokens.
  $field = array(
    'field_name' => 'gender',
    'type' => 'text',
    'cardinality' => 1,
  );
  $instance = array(
    'field_name' => 'gender',
    'entity_type' => 'user',
    'bundle' => 'user',
    'label' => 'Gender',
    'widget' => array(
      'type' => 'text_textfield',
      'label' => 'Gender',
    ),
  );
  field_create_field($field);
  field_create_instance($instance);

  // Create a normal user that can view their own submissions.
  $permissions['userAccess'] = array(
    'access content',
    'access own webform submissions',
  );

  // Create a normal user than can edit their own submissions.
  $permissions['userEdit'] = array(
    'access content',
    'edit own webform submissions',
  );

  // Create a webform editor to test creating and editing own content.
  $permissions['editor'] = array(
    'access content',
    'create webform content',
    'edit own webform content',
    'access all webform results',
  );

  // Create a webform admin that will do all node creation.
  $permissions['admin'] = array(
    'access content',
    'administer nodes',
    'create webform content',
    'edit any webform content',
    'access all webform results',
    'edit all webform submissions',
    'delete all webform submissions',
  );
  foreach ($permissions as $user_key => $role_permissions) {
    $this->webform_users[$user_key] = $this
      ->drupalCreateUser($role_permissions);
    $this->webform_users[$user_key]->gender = array(
      LANGUAGE_NONE => array(
        array(
          'value' => 'Female',
        ),
      ),
    );
    user_save($this->webform_users[$user_key]);
  }
}