You are here

public function FieldCollectionEntityTranslationTestCase::setUp in Field collection 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

./field_collection.test, line 787
Tests for field_collections.

Class

FieldCollectionEntityTranslationTestCase
Test using field collection with content that gets translated with Entity Translation.

Code

public function setUp() {
  parent::setUp(array(
    'field_collection',
    'entity_translation',
  ));
  $language_none = LANGUAGE_NONE;

  // Login with an admin user.
  $this
    ->login($this
    ->getAdminUser());

  // Add English and German languages.
  $this
    ->addLanguage('en');
  $this
    ->addLanguage('de');

  // Set "Article" content type to use multilingual support with translation.
  $edit = array();
  $edit['language_content_type'] = ENTITY_TRANSLATION_ENABLED;
  $this
    ->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
  $this
    ->assertRaw(t('The content type %type has been updated.', array(
    '%type' => 'Basic page',
  )), t('Basic page content type has been updated.'));

  // Create a field collection field to use for the tests.
  $this->field_name = 'field_test_collection';
  $this->field_base = "{$this->field_name}[{$language_none}]";
  $this->field = array(
    'field_name' => $this->field_name,
    'type' => 'field_collection',
    'cardinality' => -1,
    'translatable' => TRUE,
  );
  $this->field = field_create_field($this->field);
  $this->field_id = $this->field['id'];
  $this->instance = array(
    'field_name' => $this->field_name,
    'entity_type' => 'node',
    'bundle' => 'page',
    'label' => self::randomName() . '_label',
    'description' => self::randomName() . '_description',
    'weight' => random_int(0, 127),
    'settings' => array(),
    'widget' => array(
      'type' => 'field_collection_embed',
      'label' => 'Test',
      'settings' => array(),
    ),
  );
  $this->instance = field_create_instance($this->instance);

  // Enable entity translation of field collections.
  $this
    ->drupalGet('admin/config/regional/entity_translation');
  $this
    ->drupalPost('admin/config/regional/entity_translation', array(
    'entity_translation_entity_types[field_collection_item]' => TRUE,
  ), t('Save configuration'));
  $this
    ->assertRaw(t('The configuration options have been saved.'), t('Entity translation of field collections enabled.'));

  // Add an untraslatable field to the collection.
  $this->field_untrans_name = 'field_text_untrans';
  $this->field_untrans_base = "[{$this->field_untrans_name}][{$language_none}][0][value]";
  $field = array(
    'field_name' => $this->field_untrans_name,
    'type' => 'text',
    'cardinality' => 1,
    'translatable' => FALSE,
  );
  field_create_field($field);
  $instance = array(
    'entity_type' => 'field_collection_item',
    'field_name' => $this->field_untrans_name,
    'bundle' => $this->field_name,
    'label' => 'Test untranslatable text field',
    'widget' => array(
      'type' => 'text_textfield',
    ),
  );
  field_create_instance($instance);

  // Add a translatable field to the collection.
  $this->field_trans_name = 'field_text_trans';
  $this->field_trans_base = "[{$this->field_trans_name}][{$language_none}][0][value]";
  $this->field_trans_dest = "[{$this->field_trans_name}][de][0][value]";
  $field = array(
    'field_name' => $this->field_trans_name,
    'type' => 'text',
    'cardinality' => 1,
    'translatable' => TRUE,
  );
  field_create_field($field);
  $instance = array(
    'entity_type' => 'field_collection_item',
    'field_name' => $this->field_trans_name,
    'bundle' => $this->field_name,
    'label' => 'Test translatable text field',
    'widget' => array(
      'type' => 'text_textfield',
    ),
  );
  field_create_instance($instance);
  $this
    ->login($this
    ->getTranslatorUser());
}