You are here

public function SalesforceMappingEntitiesTestCase::testRecordMapEntity in Salesforce Suite 7.3

Test the salesforce_mapping_object entity.

File

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

Class

SalesforceMappingEntitiesTestCase
Tests the entities storing the Drupal to Salesforce mapping.

Code

public function testRecordMapEntity() {

  // Map entity type exists.
  $entity_info = entity_get_info('salesforce_mapping_object');
  $this
    ->assertTrue(isset($entity_info['label']), 'Entity has a label');
  $this
    ->assertEqual('Salesforce Object Mapping', $entity_info['label'], 'Entity has expected label.');

  // Create a salesforce_mapping_object entity object.
  $test_map = entity_create('salesforce_mapping_object', $this->example_map_object);
  $this
    ->assertEqual('salesforce_mapping_object', $test_map
    ->entityType(), 'Creating a new entity object works as expected.');

  // Save the entity to the database.
  $result = entity_save('salesforce_mapping_object', $test_map);
  $this
    ->assertEqual(SAVED_NEW, $result, 'Entity saved as new.');
  $test_map_dbs = entity_load('salesforce_mapping_object', FALSE, array(
    'entity_type' => 'foobar',
    'entity_id' => 3,
  ));
  $test_map_db = reset($test_map_dbs);
  $this
    ->assertEqual($this->example_map_object['salesforce_id'], $test_map_db->salesforce_id, 'Newly created entity has the correct object type.');

  // Save the entity again and see it be updated.
  $result = entity_save('salesforce_mapping_object', $test_map);
  $this
    ->assertEqual(SAVED_UPDATED, $test_map->revision_id, 'Re-saved entity saved as updated.');

  // Delete the entity from the database.
  entity_delete('salesforce_mapping_object', $test_map_db->salesforce_mapping_object_id);
  $all_entities = entity_load('salesforce_mapping_object');
  $this
    ->assertTrue(empty($all_entities));
}