You are here

public function MultifieldEntityTranslationTestCase::setUp in Multifield 7.2

Same name and namespace in other branches
  1. 7 tests/MultifieldEntityTranslationTestCase.test \MultifieldEntityTranslationTestCase::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/MultifieldEntityTranslationTestCase.test, line 15

Class

MultifieldEntityTranslationTestCase

Code

public function setUp() {
  parent::setUp(array(
    'field_ui',
    'multifield',
    'locale',
    'entity_translation',
  ));
  $account = $this
    ->drupalCreateUser(array(
    'administer multifield',
    'bypass node access',
    'toggle field translatability',
    'translate any entity',
  ));
  $this
    ->drupalLogin($account);

  // Add the test node type.
  $this->nodeType = $this
    ->drupalCreateContentType();

  // Add a second language.
  locale_add_language('es');

  // Enable entity translation for the node type.
  variable_set('language_content_type_' . $this->nodeType->type, ENTITY_TRANSLATION_ENABLED);

  // Create the multifield.
  $multifield_field = array(
    'field_name' => 'field_multifield',
    'type' => 'multifield',
    'cardinality' => FIELD_CARDINALITY_UNLIMITED,
    // Set the multifield to be translated.
    'translatable' => TRUE,
  );
  field_create_field($multifield_field);

  // Create fields on the multifield.
  $field_name1 = 'field_text1';
  $field1 = array(
    'field_name' => $field_name1,
    'type' => 'text',
    'cardinality' => 1,
  );
  field_create_field($field1);
  $instance1 = array(
    'field_name' => $field_name1,
    'entity_type' => 'multifield',
    'bundle' => 'field_multifield',
  );
  field_create_instance($instance1);
  $field_name2 = 'field_text2';
  $field2 = array(
    'field_name' => $field_name2,
    'type' => 'text',
    'cardinality' => 1,
    // Set this field as translatable to ensure that even in a multifield, it
    // isn't actually translated.
    'translatable' => TRUE,
  );
  field_create_field($field2);
  $instance2 = array(
    'field_name' => $field_name2,
    'entity_type' => 'multifield',
    'bundle' => 'field_multifield',
  );
  field_create_instance($instance2);
  $multifield_instance = array(
    'field_name' => 'field_multifield',
    'entity_type' => 'node',
    'bundle' => $this->nodeType->type,
  );
  field_create_instance($multifield_instance);
}