public function FeedsMapperMultilingualFieldsTestCase::testMultilingualFieldMappings in Feeds 7.2
Tests multilingual mappings to translatable fields (entity translation).
File
- tests/
feeds_mapper_multilingual_fields.test, line 182 - Contains FeedsMapperMultilingualFieldsTestCase.
Class
- FeedsMapperMultilingualFieldsTestCase
- Tests field mapping with multiple languages.
Code
public function testMultilingualFieldMappings() {
// Add English mappers.
$index = 2;
$mappings = $this
->getMappingsInLanguage('en', $index);
// Append "_en" to each source name.
foreach ($mappings as &$mapping) {
$mapping['source'] .= '_en';
}
$this
->addMappings('node', $mappings);
$index += count($mappings);
// Add French mappers.
$mappings = $this
->getMappingsInLanguage('fr', $index);
// Append "_fr" to each source name.
foreach ($mappings as &$mapping) {
$mapping['source'] .= '_fr';
}
$this
->addMappings('node', $mappings);
// Import file that has items with both English and French field values.
$this
->importFile('node', $this
->absolutePath() . '/tests/feeds/multilingual_en_fr.csv');
$this
->assertText(t('Created 1 node'));
// Load node.
$node = node_load(1, NULL, TRUE);
// Inspect availability of English values.
$english = $this
->getEnglishValues($node) + array(
'field_category' => array(
'expected' => 1,
'actual' => $node->field_category['en'][0]['tid'],
),
);
foreach ($english as $field_name => $value) {
$this
->assertEqual($value['expected'], $value['actual'], format_string('The English field %field has the expected value (actual: @actual).', array(
'%field' => $field_name,
'@actual' => $value['actual'],
)));
}
// Inspect availability of French values.
$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'],
)));
}
}