You are here

public function SalesforceMappingEntitiesTestCase::testObjectTypeMapCrud in Salesforce Suite 7.3

Tests API for interacting with salesforce_mapping.

File

modules/salesforce_mapping/tests/salesforce_mapping.entities.test, line 105

Class

SalesforceMappingEntitiesTestCase
Tests the entities storing the Drupal to Salesforce mapping.

Code

public function testObjectTypeMapCrud() {

  // Create two mapping entities to work with.
  $test_map = entity_create('salesforce_mapping', $this->example_map);
  entity_save('salesforce_mapping', $test_map);
  $this->example_map2 = $this->example_map;
  $this->example_map2['name'] = 'bazbang';
  $this->example_map2['label'] = 'Baz Bang';
  $this->example_map2['drupal_bundle'] = 'event';
  $test_map2 = entity_create('salesforce_mapping', $this->example_map2);
  entity_save('salesforce_mapping', $test_map2);

  // salesforce_mapping_load() all available.
  $result = salesforce_mapping_load();
  $this
    ->assertTrue(is_array($result), 'Loading maps without stating a specific name returned an array.');
  $this
    ->assertEqual(2, count($result), 'Loading maps without stating a specific name returned 2 maps.');

  // salesforce_mapping_load() specific map.
  $result = salesforce_mapping_load($test_map->name);
  $this
    ->assertTrue(is_object($result), 'Loading maps stating a specific name returned an object.');
  $this
    ->assertEqual($test_map->label, $result->label, 'Loading maps stating a specific name returned the requested map.');
  $result = salesforce_mapping_load($test_map2->name);
  $this
    ->assertTrue(is_object($result), 'Loading maps stating a specific name returned an object.');
  $this
    ->assertEqual($test_map2->label, $result->label, 'Loading maps stating a specific name returned the requested map.');

  // salesforce_mapping_load() retreive nothing.
  $result = salesforce_mapping_load('nothing');
  $this
    ->assertFalse(is_object($result), 'Loading maps stating a name that does not exist does not return an object.');
  $this
    ->assertFalse(is_array($result), 'Loading maps stating a name that does not exist does not return an array.');
  $this
    ->assertTrue(empty($result), 'Loading maps stating a name that does not exist returns nothing.');

  // salesforce_mapping_load_multiple() all available.
  $result = salesforce_mapping_load_multiple();
  $this
    ->assertTrue(is_array($result), 'Loading maps without stating a specific property returned an array.');
  $this
    ->assertEqual(2, count($result), 'Loading maps without stating a specific property returned 2 maps.');

  // salesforce_mapping_load_multiple() single property.
  $result = salesforce_mapping_load_multiple(array(
    'drupal_bundle' => 'event',
  ));
  $this
    ->assertTrue(is_array($result), 'Loading maps stating the drupal_bundle returned an array.');
  $this
    ->assertEqual(1, count($result), 'Loading maps stating the drupal_bundle property returned 1 map.');
  $map = reset($result);
  $this
    ->assertEqual($test_map2->label, $map->label, 'Loading maps stating the drupal_bundle property returned the expected map.');
  $result = salesforce_mapping_load_multiple(array(
    'drupal_entity_type' => 'node',
  ));
  $this
    ->assertEqual(2, count($result), 'Loading maps stating the drupal_entity_type property returned 2 maps.');

  // salesforce_mapping_load_multiple() multiple property.
  $result = salesforce_mapping_load_multiple(array(
    'drupal_entity_type' => 'node',
    'drupal_bundle' => 'event',
  ));
  $this
    ->assertTrue(is_array($result), 'Loading maps stating the drupal_entity_type and drupal_bundle properties returned an array.');
  $this
    ->assertEqual(1, count($result), 'Loading maps stating the drupal_entity_type and drupal_bundle properties returned 1 map.');
  $map = reset($result);
  $this
    ->assertEqual($test_map2->label, $map->label, 'Loading maps stating the drupal_entity_type and drupal_bundle properties returned the expected map.');
  $result = salesforce_mapping_load_multiple(array(
    'salesforce_object_type' => 'bar',
    'salesforce_record_type' => 'baz',
  ));
  $this
    ->assertEqual(2, count($result), 'Loading maps stating the salesforce_object_type and salesforce_record_type returned 2 maps.');

  // salesforce_mapping_load_multiple() retreive nothing.
  $result = salesforce_mapping_load_multiple(array(
    'drupal_entity_type' => 'nothing',
  ));
  $this
    ->assertFalse(is_object($result), 'Loading maps stating a drupal_entity_type that does not exist does not return an object.');
  $this
    ->assertTrue(is_array($result), 'Loading maps stating a drupal_entity_type that does not exist does returns an array.');
  $this
    ->assertTrue(empty($result), 'Loading maps stating a drupal_entity_type that does not exist returns an empty array.');
}