You are here

function DraftyTitleTestCase::setUp in Drafty 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()

File

tests/DraftyTitleTestCase.test, line 23

Class

DraftyTitleTestCase
Tests for legacy field replacement.

Code

function setUp(array $modules = array()) {
  $modules[] = 'locale';
  $modules[] = 'entity_translation';
  $modules[] = 'title';
  $modules[] = 'drafty';
  $modules[] = 'drafty_enforce';
  $modules[] = 'drafty_1992010';
  parent::setUp($modules);

  // Create a power user.
  $admin_user = $this
    ->drupalCreateUser(array(
    'administer modules',
    'view the administration theme',
    'administer languages',
    'administer entity translation',
    'translate any entity',
  ));
  $this
    ->drupalLogin($admin_user);

  // Enable a translation language.
  $edit = array(
    'langcode' => 'it',
  );
  $this
    ->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
  $this
    ->assertTrue(drupal_multilingual(), t('Italian language installed.'));

  // Enable URL language negotiation.
  $name = 'language_content[enabled][locale-url]';
  $edit = array(
    $name => 1,
  );
  $this
    ->drupalPost('admin/config/regional/language/configure', $edit, t('Save settings'));
  $this
    ->assertFieldByName($name, 1, t('URL language negotiation enabled.'));

  // Enable node translation.
  $name = 'entity_translation_entity_types[node]';
  $edit = array(
    $name => 1,
  );
  $this
    ->drupalPost('admin/config/regional/entity_translation', $edit, t('Save configuration'));
  $this
    ->assertFieldByName($name, 'node', t('Node translation enabled.'));

  // Replace the title field.
  $entity_type = 'node';
  foreach (title_field_replacement_info($entity_type) as $legacy_field => $info) {
    title_field_replacement_toggle($entity_type, 'page', $legacy_field);
    $t_args = array(
      '%legacy_field' => $legacy_field,
    );
    $this
      ->assertTrue(field_info_instance($entity_type, $info['field']['field_name'], 'page'), t('The %legacy_field field has been correctly replaced.', $t_args));
  }

  // Ensure static caches do not interfere with API calls.
  drupal_static_reset();
}