public function SalesforceMappingMapTestCase::testMappingValidation in Salesforce Suite 7.3
Test validation of the mapping form.
File
- modules/
salesforce_mapping/ tests/ salesforce_mapping.map.test, line 316
Class
- SalesforceMappingMapTestCase
- Tests the user interface for mapping Drupal entities to Salesforce objects.
Code
public function testMappingValidation() {
$this
->salesforceConnect();
$this
->createSalesforceMapping('foo', 'foobar');
// Cannot map the same entity, bundle and salesforce object combo.
$edit = array();
$this
->drupalGet($this->addMapPath);
$edit['drupal_entity_type'] = 'user';
$this
->drupalPostAjax(NULL, $edit, 'drupal_entity_type');
$edit['drupal_bundle'] = 'user';
$this
->drupalPostAjax(NULL, $edit, 'drupal_bundle');
$edit['salesforce_object_type'] = 'Contact';
$this
->drupalPostAjax(NULL, $edit, 'salesforce_object_type');
$this
->drupalPost(NULL, $edit, 'Save mapping');
$this
->assertText('This Drupal bundle has already been mapped to a Salesforce object', 'Validation failed when a new map was created to map the same entity, bundle an salesforce object that matched a previous mapping.');
// Label cannot exceed SALESFORCE_MAPPING_NAME_LENGTH.
$this
->drupalGet($this->manageMapPrefix . 'foobar');
$length = SALESFORCE_MAPPING_NAME_LENGTH + 1;
$edit = array(
'label' => $this
->randomName($length),
);
$this
->drupalPost(NULL, $edit, 'Save mapping');
$this
->assertText('Label cannot be longer than 128 characters but is currently 129 characters long.', 'Validation rejected label length that was too long.');
// When sync trigger Salesforce Create selected, at least one row must have
// direction 'sync' or 'sf_drupal'.
$edit = array(
'salesforce_field_mappings[0][direction]' => 'drupal_sf',
'salesforce_field_mappings[1][direction]' => 'drupal_sf',
'salesforce_field_mappings[2][direction]' => 'drupal_sf',
'sync_triggers[8]' => TRUE,
);
$this
->drupalPost(NULL, $edit, 'Save mapping');
$this
->assertText('One mapping must be set to "Sync" or "SF to Drupal" when "Salesforce object create" is selected', 'Validation rejected when salesforce create sync trigger is selected and no row had either "sync" or "sf to drupal" direction selected.');
// Key must be set on a field that is configured to be externalId.
$edit = array(
'key' => '0',
);
$this
->drupalPost(NULL, $edit, 'Save mapping');
$this
->assertText('is not configured as an external id', 'Validation rejected when row selected as "key" was not a salesforce field with a valid external id field.');
$edit = array(
'key' => '2',
);
$this
->drupalPost(NULL, $edit, 'Save mapping');
$this
->assertText('s not configured as an external id', 'Validation rejected when row selected as "key" was not a salesforce field with a valid external id field.');
// Verify salesforce_mapping_property_validation().
$property_tests = array(
'sync' => array(
'datetime' => array(
'sf_value' => 'CreatedDate',
'drupal_value' => array(
'integer' => 'uid',
'text' => 'name',
'uri' => 'url',
),
),
'email' => array(
'sf_value' => 'Email',
'drupal_value' => array(
'date' => 'created',
'integer' => 'uid',
'uri' => 'url',
),
),
'id' => array(
'sf_value' => 'Id',
'drupal_value' => array(
'date' => 'created',
'uri' => 'url',
),
),
'string' => array(
'sf_value' => 'LastName',
'drupal_value' => array(
'date' => 'created',
'integer' => 'uid',
),
),
),
'drupal_sf' => array(
'datetime' => array(
'sf_value' => 'CreatedDate',
'drupal_value' => array(
'integer' => 'uid',
'text' => 'name',
'uri' => 'url',
),
),
'email' => array(
'sf_value' => 'Email',
'drupal_value' => array(
'date' => 'created',
'integer' => 'uid',
'uri' => 'url',
),
),
'id' => array(
'sf_value' => 'Id',
'drupal_value' => array(
'date' => 'created',
'uri' => 'url',
),
),
'string' => array(
'sf_value' => 'LastName',
'drupal_value' => array(),
),
),
'sf_drupal' => array(
'datetime' => array(
'sf_value' => 'CreatedDate',
'drupal_value' => array(
'integer' => 'uid',
'text' => 'name',
'uri' => 'url',
),
),
'email' => array(
'sf_value' => 'Email',
'drupal_value' => array(
'date' => 'created',
'integer' => 'uid',
'uri' => 'url',
),
),
'id' => array(
'sf_value' => 'Id',
'drupal_value' => array(
'date' => 'created',
'uri' => 'url',
),
),
'string' => array(
'sf_value' => 'LastName',
'drupal_value' => array(
'date' => 'created',
'uri' => 'url',
),
),
),
);
foreach ($property_tests as $direction => $sf_field_types) {
foreach ($sf_field_types as $sf_field_type => $data) {
$sf_field = $data['sf_value'];
foreach ($data['drupal_value'] as $drupal_field_type => $drupal_field) {
$edit = array(
'salesforce_field_mappings[0][direction]' => $direction,
'salesforce_field_mappings[0][salesforce_field]' => $sf_field,
'salesforce_field_mappings[0][drupal_field][fieldmap_value]' => $drupal_field,
);
$this
->drupalPost(NULL, $edit, 'Save mapping');
$this
->assertText('and cannot be mapped in the ' . $direction . ' direction', 'Validation failed when direction is "' . $direction . '", salesforce field type is "' . $sf_field_type . '" and drupal field type is "' . $drupal_field_type . '".');
}
}
}
}