public function FeedsMapperFieldTestCase::addMappings in Entity reference 7
Adds mappings to a given configuration.
Parameters
string $id: ID of the importer.
array $mappings: An array of mapping arrays. Each mapping array must have a source and an target key and can have a unique key.
bool $test_mappings: (optional) TRUE to automatically test mapping configs. Defaults to TRUE.
1 call to FeedsMapperFieldTestCase::addMappings()
- FeedsMapperFieldTestCase::test in tests/
entityreference.feeds.test - Basic test loading a double entry CSV file.
File
- tests/
entityreference.feeds.test, line 87 - Test case for simple CCK field mapper mappers/content.inc.
Class
- FeedsMapperFieldTestCase
- Class for testing Feeds field mapper.
Code
public function addMappings($id, $mappings, $test_mappings = TRUE) {
$path = "admin/structure/feeds/{$id}/mapping";
// Iterate through all mappings and add the mapping via the form.
foreach ($mappings as $i => $mapping) {
if ($test_mappings) {
$current_mapping_key = $this
->mappingExists($id, $i, $mapping['source'], $mapping['target']);
$this
->assertEqual($current_mapping_key, -1, 'Mapping does not exist before addition.');
}
// Get unique flag and unset it. Otherwise, drupalPost will complain that
// Split up config and mapping.
$config = $mapping;
unset($config['source'], $config['target']);
$mapping = array(
'source' => $mapping['source'],
'target' => $mapping['target'],
);
// Add mapping.
$this
->drupalPost($path, $mapping, t('Add'));
// If there are other configuration options, set them.
if ($config) {
$this
->drupalPostAJAX(NULL, array(), 'mapping_settings_edit_' . $i);
// Set some settings.
$edit = array();
foreach ($config as $key => $value) {
$edit["config[{$i}][settings][{$key}]"] = $value;
}
$this
->drupalPostAJAX(NULL, $edit, 'mapping_settings_update_' . $i);
$this
->drupalPost(NULL, array(), t('Save'));
}
if ($test_mappings) {
$current_mapping_key = $this
->mappingExists($id, $i, $mapping['source'], $mapping['target']);
$this
->assertTrue($current_mapping_key >= 0, 'Mapping exists after addition.');
}
}
}