public function FeedsMapperMultilingualFieldsTestCase::testChangedLanguageImport in Feeds 7.2
Tests if values of fields in other languages are kept when not importing in that language.
File
- tests/
feeds_mapper_multilingual_fields.test, line 235 - Contains FeedsMapperMultilingualFieldsTestCase.
Class
- FeedsMapperMultilingualFieldsTestCase
- Tests field mapping with multiple languages.
Code
public function testChangedLanguageImport() {
// Add Dutch language.
$this
->addLanguage('nl', 'Dutch');
// Import an item first in the Dutch language.
$this
->setSettings('node', 'FeedsNodeProcessor', array(
'language' => 'nl',
));
$mappings = $this
->getMappingsInLanguage('nl', 2);
$this
->addMappings('node', $mappings);
$this
->importFile('node', $this
->absolutePath() . '/tests/feeds/multilingual_nl.csv');
$this
->assertText(t('Created 1 node'));
// Assert that Dutch values were created.
$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'],
)));
}
// Set import to update existing nodes.
$this
->setSettings('node', 'FeedsNodeProcessor', array(
'update_existing' => FEEDS_UPDATE_EXISTING,
));
// Change mappers language to French.
$path = 'admin/structure/feeds/node/mapping';
foreach ($mappings as $i => $mapping) {
$this
->drupalPostAJAX($path, array(), 'mapping_settings_edit_' . $i);
$edit = array(
"config[{$i}][settings][field_language]" => 'fr',
);
$this
->drupalPostAJAX(NULL, $edit, 'mapping_settings_update_' . $i);
$this
->drupalPost(NULL, array(), t('Save'));
}
// Import French item.
$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'],
)));
}
}