You are here

public function TitleTranslationTestCase::setUp in Title 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/TitleTranslationTestCase.test, line 28

Class

TitleTranslationTestCase
Tests for legacy field replacement.

Code

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

  // Core.
  $modules[] = 'field_test';
  $modules[] = 'locale';
  $modules[] = 'taxonomy';

  // Other dependencies.
  $modules[] = 'entity_translation';

  // This module.
  $modules[] = 'title';
  $modules[] = 'title_test';
  parent::setUp($modules);

  // Create a power user.
  $permissions = array(
    'administer modules',
    'view the administration theme',
    'administer languages',
    'administer taxonomy',
    'administer entity translation',
    'translate any entity',
  );
  $admin_user = $this
    ->drupalCreateUser($permissions);
  $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 taxonomy translation.
  $name = 'entity_translation_entity_types[taxonomy_term]';
  $edit = array(
    $name => 1,
  );
  $this
    ->drupalPost('admin/config/regional/entity_translation', $edit, t('Save configuration'));
  $this
    ->assertFieldByName($name, 'taxonomy_term', t('Taxonomy translation enabled.'));

  // Create a new vocabulary.
  $name = drupal_strtolower($this
    ->randomName());
  $edit = array(
    'name' => $this
      ->randomString(),
    'machine_name' => $name,
    'entity_translation_taxonomy' => 1,
  );
  $this
    ->drupalPost('admin/structure/taxonomy/add', $edit, t('Save'));
  $this->vocabulary = taxonomy_vocabulary_machine_name_load($name);
  $this
    ->assertTrue($this->vocabulary, t('Vocabulary created.'));

  // Replace both taxonomy term legacy fields.
  $entity_type = 'taxonomy_term';
  foreach (title_field_replacement_info($entity_type) as $legacy_field => $info) {
    title_field_replacement_toggle($entity_type, $name, $legacy_field);
    $t_args = array(
      '%legacy_field' => $legacy_field,
    );
    $this
      ->assertTrue(field_info_instance($entity_type, $info['field']['field_name'], $name), t('The %legacy_field field has been correctly replaced.', $t_args));
  }

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