You are here

protected function SalesforceMappingTestCase::createSalesforceMapping in Salesforce Suite 7.3

Submits a salesforce mapping form of your configuration or a default one.

Parameters

string $label: Desired lable for the mapping.

string $machine_name: Desired machine name of the mapping. If none is provided, one will be automatically generated from the label.

array $config: Desired mapping configuration. If none is provided, a default mapping configuration will be generated.

3 calls to SalesforceMappingTestCase::createSalesforceMapping()
SalesforceMappingMapTestCase::testMapOverview in modules/salesforce_mapping/tests/salesforce_mapping.map.test
Tests mapping overview form.
SalesforceMappingMapTestCase::testMappingCreate in modules/salesforce_mapping/tests/salesforce_mapping.map.test
Tests the creation of a map.
SalesforceMappingMapTestCase::testMappingValidation in modules/salesforce_mapping/tests/salesforce_mapping.map.test
Test validation of the mapping form.

File

modules/salesforce_mapping/tests/salesforce_mapping.test, line 59

Class

SalesforceMappingTestCase
Sets up basic tools for the testing of mapping Drupal to Salesforce.

Code

protected function createSalesforceMapping($label, $machine_name = NULL, $config = array()) {

  // Give a default configuration if one is not provided for us.
  if (empty($config)) {
    $config = array(
      'drupal_entity_type' => 'user',
      'drupal_bundle' => 'user',
      'salesforce_object_type' => 'Contact',
      'key' => 1,
      'mapping' => array(
        array(
          'fieldmap_type' => 'property',
          'fieldmap_value' => 'name',
          'salesforce_field' => 'Name',
          'direction' => 'drupal_sf',
        ),
        array(
          'fieldmap_type' => 'property',
          'fieldmap_value' => 'mail',
          'salesforce_field' => 'Email',
          'direction' => 'sync',
        ),
        array(
          'fieldmap_type' => 'property',
          'fieldmap_value' => 'name',
          'salesforce_field' => 'LastName',
          'direction' => 'sf_drupal',
        ),
      ),
      'sync_triggers' => array(
        '1' => TRUE,
        '2' => TRUE,
        '4' => TRUE,
        '8' => TRUE,
        '16' => TRUE,
        '32' => TRUE,
      ),
      'push_async' => TRUE,
    );
  }
  $edit = array();
  $machine_name = is_null($machine_name) ? str_replace(' ', '_', strtolower($label)) : $machine_name;
  $this
    ->drupalGet($this->addMapPath);
  $this
    ->assertNoText('You are not authorized to access this page.', 'Able to access the create map page.');

  // Get all of the AJAX behaviors out of the way.
  $edit['drupal_entity_type'] = $config['drupal_entity_type'];
  $this
    ->drupalPostAjax(NULL, $edit, 'drupal_entity_type');
  unset($config['drupal_entity_type']);
  $edit['drupal_bundle'] = $config['drupal_bundle'];
  $this
    ->drupalPostAjax(NULL, $edit, 'drupal_bundle');
  unset($config['drupal_bundle']);
  $edit['salesforce_object_type'] = $config['salesforce_object_type'];
  $this
    ->drupalPostAjax(NULL, $edit, 'salesforce_object_type');
  unset($config['salesforce_object_type']);
  foreach ($config['mapping'] as $delta => $map) {
    $edit['salesforce_field_mappings[' . $delta . '][drupal_field][fieldmap_type]'] = $map['fieldmap_type'];
    $this
      ->drupalPostAjax(NULL, $edit, 'salesforce_field_mappings[' . $delta . '][drupal_field][fieldmap_type]');
    $this
      ->drupalPostAjax(NULL, $edit, array(
      'salesforce_add_field' => 'Add another field mapping',
    ));
    unset($config['mapping'][$delta]['fieldmap_type']);
  }

  // Fill out the rest of the form.
  $edit['label'] = $label;
  $edit['name'] = $machine_name;
  foreach ($config as $key => $data) {
    switch ($key) {
      case 'mapping':
        foreach ($data as $delta => $fields) {
          foreach ($fields as $field => $value) {
            if ($field == 'fieldmap_value') {
              $edit['salesforce_field_mappings[' . $delta . '][drupal_field][fieldmap_value]'] = $value;
            }
            else {
              $edit['salesforce_field_mappings[' . $delta . '][' . $field . ']'] = $value;
            }
          }
        }
        break;
      case 'sync_triggers':
        foreach ($data as $value => $flag) {
          $edit['sync_triggers[' . $value . ']'] = $flag;
        }
        break;
      default:
        $edit[$key] = $data;
    }
  }

  // Submit form unsuccessfully.
  $this
    ->drupalPost(NULL, $edit, 'Save mapping');
  $this
    ->assertText('Salesforce field Email is not configured as an external id.', 'Invalid key not allowed');
  unset($edit['key']);

  // Submit form.
  $this
    ->drupalPost(NULL, $edit, 'Save mapping');
  $this
    ->assertText('Salesforce field mapping saved.', 'Form posted as expected.');
  $this
    ->assertRaw('id="salesforce-mapping-overview-form"', 'Redirected to the mappings overview table.');
  $this
    ->assertRaw('(Machine name: ' . $machine_name . ')', 'New map successfully appears on overview page.');
  $this
    ->assertLink($label, 0, 'Link to edit new map appears.');
}