public function FeedsMapperMultilingualFieldsTestCase::testChangedLanguageImportForExistingNode in Feeds 7.2
Tests if values of fields in other languages are kept when not importing in that language for nodes that were not created by Feeds.
File
- tests/
feeds_mapper_multilingual_fields.test, line 305 - Contains FeedsMapperMultilingualFieldsTestCase.
Class
- FeedsMapperMultilingualFieldsTestCase
- Tests field mapping with multiple languages.
Code
public function testChangedLanguageImportForExistingNode() {
// Add Dutch language.
$this
->addLanguage('nl', 'Dutch');
// Date settings.
foreach (array(
'datestamp',
'datetime',
) as $field) {
$field = 'field_' . $field;
$edit = array(
'field[settings][granularity][second]' => 1,
);
$this
->drupalPost('admin/structure/types/manage/' . $this->contentType . '/fields/' . $field . '/field-settings', $edit, 'Save field settings');
}
// Hack to get date fields to not round to every 15 seconds.
foreach (array(
'date',
'datestamp',
'datetime',
) as $field) {
$field = 'field_' . $field;
$edit = array(
'widget_type' => 'date_select',
);
$this
->drupalPost('admin/structure/types/manage/' . $this->contentType . '/fields/' . $field . '/widget-type', $edit, 'Continue');
$edit = array(
'instance[widget][settings][increment]' => 1,
'field[settings][enddate_get]' => 1,
);
$this
->drupalPost('admin/structure/types/manage/' . $this->contentType . '/fields/' . $field, $edit, 'Save settings');
$edit = array(
'widget_type' => 'date_text',
);
$this
->drupalPost('admin/structure/types/manage/' . $this->contentType . '/fields/' . $field . '/widget-type', $edit, 'Continue');
}
// Create a node with Dutch values (except for the title, which is used as
// unique target).
$edit = array(
'title' => 'Teste Feeds Multilingue 1',
'language' => 'nl',
);
$this
->drupalPost('node/add/' . $this->contentType, $edit, t('Save'));
// Add values for Dutch fields.
$edit = array(
'body[nl][0][value]' => 'Dit is de berichttekst',
'field_date[nl][0][value][date]' => '07/29/1985',
'field_datestamp[nl][0][value][date]' => '07/29/1985 - 04:48:12',
'field_datetime[nl][0][value][date]' => '07/29/1985 - 04:48:12',
'field_link[nl][0][url]' => 'http://google.nl',
'field_list_boolean[nl]' => '1',
'field_number_decimal[nl][0][value]' => '30.3',
'field_number_float[nl][0][value]' => '30.2795',
'field_number_integer[nl][0][value]' => '30',
'field_text[nl][0][value]' => 'Wortelen',
'files[field_image_nl_0]' => drupal_realpath('public://images/attersee.jpeg'),
'field_category[nl]' => 'Nieuws',
);
$this
->drupalPost('node/1/edit/nl', $edit, t('Save'));
// Add alt/title to the image.
$edit = array(
'field_image[nl][0][alt]' => 'Bij het zien',
'field_image[nl][0][title]' => 'Bij het zien van de groene vloeistof',
);
$this
->drupalPost('node/1/edit/nl', $edit, t('Save'));
$this
->drupalGet('node/1/edit/nl');
// Assert that the Dutch values were put in as expected.
$node = node_load(1, NULL, TRUE);
$dutch = $this
->getDutchValues($node) + array(
'field_category' => array(
'expected' => 1,
'actual' => $node->field_category['nl'][0]['tid'],
),
);
foreach ($dutch as $field_name => $value) {
$this
->assertEqual($value['expected'], $value['actual'], format_string('The Dutch field %field has the expected value (actual: @actual).', array(
'%field' => $field_name,
'@actual' => $value['actual'],
)));
}
// Change unique target from guid (0) to title (1).
$path = 'admin/structure/feeds/node/mapping';
$this
->drupalPostAJAX($path, array(), 'mapping_settings_edit_0');
$edit = array(
"config[0][settings][unique]" => FALSE,
);
$this
->drupalPostAJAX(NULL, $edit, 'mapping_settings_update_0');
$this
->drupalPost(NULL, array(), t('Save'));
$this
->drupalPostAJAX($path, array(), 'mapping_settings_edit_1');
$edit = array(
"config[1][settings][unique]" => 1,
);
$this
->drupalPostAJAX(NULL, $edit, 'mapping_settings_update_1');
$this
->drupalPost(NULL, array(), t('Save'));
// Update this item with Feeds.
$this
->setSettings('node', 'FeedsNodeProcessor', array(
'update_existing' => FEEDS_UPDATE_EXISTING,
));
$this
->addMappings('node', $this
->getMappingsInLanguage('fr'));
$this
->importFile('node', $this
->absolutePath() . '/tests/feeds/multilingual_fr.csv');
$this
->assertText(t('Updated 1 node'));
// Assert that French values were created.
$node = node_load(1, NULL, TRUE);
$french = $this
->getFrenchValues($node) + array(
'field_category' => array(
'expected' => 2,
'actual' => $node->field_category['fr'][0]['tid'],
),
);
foreach ($french as $field_name => $value) {
$this
->assertEqual($value['expected'], $value['actual'], format_string('The French field %field has the expected value (actual: @actual).', array(
'%field' => $field_name,
'@actual' => $value['actual'],
)));
}
// Assert that Dutch values still exist.
$dutch = $this
->getDutchValues($node) + array(
'field_category' => array(
'expected' => 1,
'actual' => $node->field_category['nl'][0]['tid'],
),
);
foreach ($dutch as $field_name => $value) {
$this
->assertEqual($value['expected'], $value['actual'], format_string('The Dutch field %field has the expected value (actual: @actual).', array(
'%field' => $field_name,
'@actual' => $value['actual'],
)));
}
}