You are here

public function SalesforceMappingMapTestCase::testMappingCreate in Salesforce Suite 7.3

Tests the creation of a map.

File

modules/salesforce_mapping/tests/salesforce_mapping.map.test, line 205

Class

SalesforceMappingMapTestCase
Tests the user interface for mapping Drupal entities to Salesforce objects.

Code

public function testMappingCreate() {
  $this
    ->salesforceConnect();
  $this
    ->createSalesforceMapping('foo', 'foobar');

  // Open the form and verify it reloaded correctly.
  $this
    ->drupalGet($this->manageMapPrefix . 'foobar');
  $this
    ->assertFieldById('edit-label', 'foo', 'Label has correct value.');
  $this
    ->assertFieldById('edit-name', 'foobar', 'Machine name has correct value.');
  $this
    ->assertOptionSelected('edit-drupal-entity-type', 'user', 'Drupal entity type has correct value.');
  $this
    ->assertOptionSelected('edit-drupal-bundle', 'user', 'Drupal bundle has correct value.');
  $this
    ->assertOptionSelected('edit-salesforce-object-type', 'Contact', 'Salesforce object has correct value.');
  $this
    ->assertFieldByName('salesforce_record_type', 'default', 'Salesforce record type has correct value.');
  $this
    ->assertOptionSelected('edit-fieldmap-type-0', 'property', 'Row 0 fieldmap type has correct value.');
  $this
    ->assertOptionSelected('edit-fieldmap-type-1', 'property', 'Row 1 fieldmap type has correct value.');
  $this
    ->assertOptionSelected('edit-fieldmap-type-2', 'property', 'Row 2 fieldmap type has correct value.');
  $this
    ->assertOptionSelected('edit-fieldmap-value-0', 'name', 'Row 0 fieldmap value has correct value.');
  $this
    ->assertOptionSelected('edit-fieldmap-value-1', 'mail', 'Row 1 fieldmap value has correct value.');
  $this
    ->assertOptionSelected('edit-fieldmap-value-2', 'created', 'Row 2 fieldmap value has correct value.');
  $this
    ->assertOptionSelected('edit-salesforce-field-0', 'Name', 'Row 0 Salesforce field has correct value.');
  $this
    ->assertOptionSelected('edit-salesforce-field-1', 'Email', 'Row 1 Salesforce field has correct value.');
  $this
    ->assertOptionSelected('edit-salesforce-field-2', 'CreatedDate', 'Row 2 Salesforce field has correct value.');
  $this
    ->assertRadioOptionSelected('salesforce_field_mappings[0][direction]', 'drupal_sf', 'Row 0 direction has correct value.');
  $this
    ->assertRadioOptionSelected('salesforce_field_mappings[1][direction]', 'sync', 'Row 1 direction has correct value.');
  $this
    ->assertRadioOptionSelected('salesforce_field_mappings[2][direction]', 'sf_drupal', 'Row 2 direction has correct value.');
  $this
    ->assertRadioOptionSelected('key', 1, 'Key has correct value.');
  $this
    ->assertFieldChecked('edit-sync-triggers-1', 'Trigger on Drupal entity create field has correct value.');
  $this
    ->assertFieldChecked('edit-sync-triggers-2', 'Trigger on Drupal entity update field has correct value.');
  $this
    ->assertFieldChecked('edit-sync-triggers-4', 'Trigger on Drupal entity delete field has correct value.');
  $this
    ->assertFieldChecked('edit-sync-triggers-8', 'Trigger on Salesforce object create field has correct value.');
  $this
    ->assertFieldChecked('edit-sync-triggers-16', 'Trigger on Salesforce object update field has correct value.');
  $this
    ->assertFieldChecked('edit-sync-triggers-32', 'Trigger on Salesforce object delete field has correct value.');
  $this
    ->assertFieldChecked('edit-push-async', 'Push async field has correct value.');
  $this
    ->assertNoFieldChecked('edit-push-batch', 'Push batch field has correct value.');

  // Delete row.
  $edit = array(
    'delete_field_mapping-2' => TRUE,
  );
  $this
    ->drupalPostAjax(NULL, $edit, 'delete_field_mapping-2');
  $this
    ->assertFieldById('edit-fieldmap-type-0', '', 'First row still exists.');
  $this
    ->assertOptionSelected('edit-fieldmap-value-0', 'name', 'Row 0 fieldmap value still has correct value.');
  $this
    ->assertFieldById('edit-fieldmap-type-1', '', 'Second row still exists.');
  $this
    ->assertOptionSelected('edit-fieldmap-value-1', 'mail', 'Row 1 fieldmap value still has correct value.');
  $this
    ->assertNoFieldById('edit-fieldmap-type-2', '', 'Third row successfully deleted.');
  $edit = array();

  // Add row.Initial_Registration_Date__c
  $this
    ->drupalPostAjax(NULL, $edit, array(
    'salesforce_add_field' => 'Add another field mapping',
  ));
  $this
    ->assertFieldById('edit-fieldmap-type-2', '', 'New row now exists.');
  $edit['salesforce_field_mappings[2][drupal_field][fieldmap_type]'] = 'property';
  $this
    ->drupalPostAjax(NULL, $edit, 'salesforce_field_mappings[2][drupal_field][fieldmap_type]');
  $edit['salesforce_field_mappings[2][drupal_field][fieldmap_value]'] = 'created';
  $edit['salesforce_field_mappings[2][salesforce_field]'] = 'Initial_Registration_Date__c';
  $edit['salesforce_field_mappings[2][direction]'] = 'drupal_sf';

  // Modify row.
  $edit['salesforce_field_mappings[0][salesforce_field]'] = 'LastName';

  // Save, verify field alterations remained.
  $this
    ->drupalPost(NULL, $edit, 'Save mapping');
  $this
    ->drupalGet($this->manageMapPrefix . 'foobar');
  $this
    ->assertFieldById('edit-label', 'foo', 'Label has correct value.');
  $this
    ->assertFieldById('edit-name', 'foobar', 'Machine name has correct value.');
  $this
    ->assertOptionSelected('edit-drupal-entity-type', 'user', 'Drupal entity type has correct value.');
  $this
    ->assertOptionSelected('edit-drupal-bundle', 'user', 'Drupal bundle has correct value.');
  $this
    ->assertOptionSelected('edit-salesforce-object-type', 'Contact', 'Salesforce object has correct value.');
  $this
    ->assertFieldByName('salesforce_record_type', 'default', 'Salesforce record type has correct value.');
  $this
    ->assertOptionSelected('edit-fieldmap-type-0', 'property', 'Row 0 fieldmap type has correct value.');
  $this
    ->assertOptionSelected('edit-fieldmap-type-1', 'property', 'Row 1 fieldmap type has correct value.');
  $this
    ->assertOptionSelected('edit-fieldmap-type-2', 'property', 'Row 2 fieldmap type has correct value.');
  $this
    ->assertOptionSelected('edit-fieldmap-value-0', 'name', 'Row 0 fieldmap value has correct value.');
  $this
    ->assertOptionSelected('edit-fieldmap-value-1', 'mail', 'Row 1 fieldmap value has correct value.');
  $this
    ->assertOptionSelected('edit-fieldmap-value-2', 'created', 'Row 2 fieldmap value has correct value.');
  $this
    ->assertOptionSelected('edit-salesforce-field-0', 'LastName', 'Row 0 Salesforce field has correct value.');
  $this
    ->assertOptionSelected('edit-salesforce-field-1', 'Email', 'Row 1 Salesforce field has correct value.');
  $this
    ->assertOptionSelected('edit-salesforce-field-2', 'Initial_Registration_Date__c', 'Row 2 Salesforce field has correct value.');
  $this
    ->assertRadioOptionSelected('salesforce_field_mappings[0][direction]', 'drupal_sf', 'Row 0 direction has correct value.');
  $this
    ->assertRadioOptionSelected('salesforce_field_mappings[1][direction]', 'sync', 'Row 1 direction has correct value.');
  $this
    ->assertRadioOptionSelected('salesforce_field_mappings[2][direction]', 'drupal_sf', 'Row 2 direction has correct value.');
  $this
    ->assertRadioOptionSelected('key', 1, 'Key has correct value.');
  $this
    ->assertFieldChecked('edit-sync-triggers-1', 'Trigger on Drupal entity create field has correct value.');
  $this
    ->assertFieldChecked('edit-sync-triggers-2', 'Trigger on Drupal entity update field has correct value.');
  $this
    ->assertFieldChecked('edit-sync-triggers-4', 'Trigger on Drupal entity delete field has correct value.');
  $this
    ->assertFieldChecked('edit-sync-triggers-8', 'Trigger on Salesforce object create field has correct value.');
  $this
    ->assertFieldChecked('edit-sync-triggers-16', 'Trigger on Salesforce object update field has correct value.');
  $this
    ->assertFieldChecked('edit-sync-triggers-32', 'Trigger on Salesforce object delete field has correct value.');
  $this
    ->assertFieldChecked('edit-push-async', 'Push async field has correct value.');
  $this
    ->assertNoFieldChecked('edit-push-batch', 'Push batch field has correct value.');

  // Change the Salesforce object type.
  $edit = array(
    'salesforce_object_type' => 'Account',
  );
  $this
    ->drupalPostAjax(NULL, $edit, 'salesforce_object_type');
  $this
    ->assertOptionSelected('edit-fieldmap-type-0', 'property', 'Row 0 fieldmap type has correct value.');
  $this
    ->assertOptionSelected('edit-fieldmap-type-1', 'property', 'Row 1 fieldmap type has correct value.');
  $this
    ->assertOptionSelected('edit-fieldmap-type-2', 'property', 'Row 2 fieldmap type has correct value.');
  $this
    ->assertOptionSelected('edit-fieldmap-value-0', 'name', 'Row 0 fieldmap value has correct value.');
  $this
    ->assertOptionSelected('edit-fieldmap-value-1', 'mail', 'Row 1 fieldmap value has correct value.');
  $this
    ->assertOptionSelected('edit-fieldmap-value-2', 'created', 'Row 2 fieldmap value has correct value.');
  $this
    ->assertRadioOptionSelected('salesforce_field_mappings[0][direction]', 'drupal_sf', 'Row 0 direction has correct value.');
  $this
    ->assertRadioOptionSelected('salesforce_field_mappings[1][direction]', 'sync', 'FieldByName Row 1 direction has correct value.');
  $this
    ->assertRadioOptionSelected('salesforce_field_mappings[2][direction]', 'drupal_sf', 'Row 2 direction has correct value.');
  $this
    ->assertRadioOptionSelected('key', 1, 'Key has correct value.');

  // Change the Drupal entity type.
  $edit['drupal_entity_type'] = 'node';
  $this
    ->drupalPostAjax(NULL, $edit, 'drupal_entity_type');
  $this
    ->assertText('Select a value for Drupal Entity Bundle in order to map fields.', 'Fieldmap instructions give updated information again of what is required to start mapping.');
}