You are here

public function FeedsMapperMultilingualFieldsTestCase::testClearOutValuesWithDisabledLanguage in Feeds 7.2

Tests if values are cleared out when an empty value is provided for a language that got disabled.

File

tests/feeds_mapper_multilingual_fields.test, line 684
Contains FeedsMapperMultilingualFieldsTestCase.

Class

FeedsMapperMultilingualFieldsTestCase
Tests field mapping with multiple languages.

Code

public function testClearOutValuesWithDisabledLanguage() {

  // Set to update existing nodes.
  $this
    ->setSettings('node', 'FeedsNodeProcessor', array(
    'update_existing' => FEEDS_UPDATE_EXISTING,
  ));

  // Configure importer to import in French language.
  $this
    ->setSettings('node', 'FeedsNodeProcessor', array(
    'language' => 'fr',
  ));
  $this
    ->addMappings('node', $this
    ->getMappingsInLanguage('fr'));

  // Now disable the French language.
  $path = 'admin/config/regional/language';
  $edit = array(
    'enabled[fr]' => FALSE,
  );
  $this
    ->drupalPost($path, $edit, t('Save configuration'));

  // Ensure no error messages are shown on the mappings page.
  $this
    ->drupalGet('admin/structure/feeds/node/mapping');

  // Import content. Since the French language was disabled, the content
  // should be imported as LANGUAGE_NONE.
  // @see ::testDisabledLanguage()
  $this
    ->importFile('node', $this
    ->absolutePath() . '/tests/feeds/multilingual_fr.csv');
  $this
    ->assertText(t('Created 1 node'));

  // Now import a file with empty values.
  $this
    ->importFile('node', $this
    ->absolutePath() . '/tests/feeds/multilingual_empty.csv');
  $this
    ->assertText(t('Updated 1 node'));

  // Load node.
  $node = node_load(1, NULL, TRUE);

  // Check that the values in LANGUAGE_NONE are gone.
  $fields = array(
    'body',
    'field_date',
    'field_datestamp',
    'field_datetime',
    'field_image',
    'field_link',
    'field_list_boolean',
    'field_number_decimal',
    'field_number_float',
    'field_number_integer',
    'field_category',
    'field_text',
  );
  foreach ($fields as $field_name) {
    $this
      ->assertTrue(empty($node->{$field_name}[LANGUAGE_NONE]), format_string('The field %field is empty.', array(
      '%field' => $field_name,
    )));
  }
}