You are here

public function FeedsMapperMultilingualFieldsTestCase::setUp in Feeds 7.2

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 FeedsWebTestCase::setUp

See also

DrupalWebTestCase::prepareDatabasePrefix()

DrupalWebTestCase::changeDatabasePrefix()

DrupalWebTestCase::prepareEnvironment()

File

tests/feeds_mapper_multilingual_fields.test, line 40
Contains FeedsMapperMultilingualFieldsTestCase.

Class

FeedsMapperMultilingualFieldsTestCase
Tests field mapping with multiple languages.

Code

public function setUp() {
  $modules = array(
    'locale',
    'entity_translation',
    'date',
    'link',
    'list',
    'number',
  );
  $permissions = array(
    'administer entity translation',
    'translate any entity',
    'administer languages',
  );
  parent::setUp($modules, $permissions);

  // Include FeedsProcessor.inc so processor related constants are available.
  module_load_include('inc', 'feeds', 'plugins/FeedsProcessor');

  // Add French language.
  $this
    ->addLanguage('fr', 'French');

  // Add Categories vocabulary.
  $edit = array(
    'name' => 'Categories',
    'machine_name' => 'categories',
  );
  $this
    ->drupalPost('admin/structure/taxonomy/add', $edit, 'Save');

  // Create content type.
  $this->fields = array(
    'date' => array(
      'type' => 'date',
      'settings' => array(
        'field[settings][granularity][hour]' => FALSE,
        'field[settings][granularity][minute]' => FALSE,
        'field[settings][tz_handling]' => 'none',
      ),
    ),
    'datestamp' => array(
      'type' => 'datestamp',
      'settings' => array(
        'field[settings][granularity][second]' => TRUE,
        'field[settings][tz_handling]' => 'utc',
      ),
    ),
    'datetime' => array(
      'type' => 'datetime',
      'settings' => array(
        'field[settings][granularity][second]' => TRUE,
        'field[settings][tz_handling]' => 'utc',
      ),
    ),
    'image' => array(
      'type' => 'image',
      'instance_settings' => array(
        'instance[settings][alt_field]' => 1,
        'instance[settings][title_field]' => 1,
      ),
    ),
    'link' => 'link_field',
    'list_boolean' => 'list_boolean',
    'number_integer' => 'number_integer',
    'number_decimal' => 'number_decimal',
    'number_float' => 'number_float',
    'text' => 'text',
  );
  $this->contentType = $this
    ->createContentType(array(), $this->fields);

  // Create term reference field.
  $field = array(
    'field_name' => 'field_category',
    'type' => 'taxonomy_term_reference',
    'cardinality' => FIELD_CARDINALITY_UNLIMITED,
    'settings' => array(
      'allowed_values' => array(
        array(
          'vocabulary' => 'categories',
          'parent' => 0,
        ),
      ),
    ),
  );
  field_create_field($field);

  // Add term reference field to article bundle.
  $this->instance = array(
    'field_name' => 'field_category',
    'bundle' => $this->contentType,
    'entity_type' => 'node',
    'widget' => array(
      'type' => 'taxonomy_autocomplete',
    ),
    'display' => array(
      'default' => array(
        'type' => 'taxonomy_term_reference_link',
      ),
    ),
  );
  field_create_instance($this->instance);

  // Make content type and fields multilingual.
  $field_names = array(
    'body',
    'field_category',
  );
  foreach ($this->fields as $field_name => $field_type) {
    $field_names[] = 'field_' . $field_name;
  }
  $this
    ->setupMultilingual($this->contentType, $field_names);

  // Copy directory of source files, CSV file expects them in public://images.
  $this
    ->copyDir($this
    ->absolutePath() . '/tests/feeds/assets', 'public://images');

  // Create an importer configuration with basic mapping.
  $this
    ->createImporterConfiguration('Test multilingual fields import from CSV', 'node');
  $this
    ->setPlugin('node', 'FeedsCSVParser');
  $this
    ->setPlugin('node', 'FeedsFileFetcher');
  $this
    ->setSettings('node', 'FeedsNodeProcessor', array(
    'bundle' => $this->contentType,
    'language' => 'en',
  ));

  // Add language neutral mappings.
  $this
    ->addMappings('node', array(
    0 => array(
      'source' => 'guid',
      'target' => 'guid',
      'unique' => 1,
    ),
    1 => array(
      'source' => 'title',
      'target' => 'title',
    ),
  ));
}